Package lejos.robotics.localization
Class MCLPoseProvider
- java.lang.Object
-
- lejos.robotics.localization.MCLPoseProvider
-
- All Implemented Interfaces:
PoseProvider,MoveListener,Transmittable
public class MCLPoseProvider extends java.lang.Object implements PoseProvider, MoveListener, Transmittable
Maintains an estimate of the robot pose using sensor data. It uses Monte Carlo Localization (See section 8.3 of "Probabilistic Robotics" by Thrun et al.
Uses aMCLParticleSetto represent the probability distribution of the estimated pose. It uses aMoveProviderto supply odometry data whenever a movement is completed, from which thePoseof each particle is updated. It then uses aRangeScannerto provideRangeReadingswhich are used, together with theRangeMapto calculate the probability weight of eachMCLParticle.- Author:
- Lawrie Griffiths and Roger Glassey
-
-
Constructor Summary
Constructors Constructor Description MCLPoseProvider(RangeMap map, int numParticles, int border)Constructor for use on PCMCLPoseProvider(MoveProvider mp, RangeScanner scanner, RangeMap map, int numParticles, int border)Allocates a new MCLPoseProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddumpObject(java.io.DataOutputStream dos)Dump the serialized estimate of pose to a data output streamvoidestimatePose()Estimate pose from weighted average of the particles Calculate statisticsvoidgenerateParticles()Generate a new particle set, uniformly distributed within the map, and uniformly distributed heading.Rectangle2DgetErrorRect()Returns the minimum rectangle enclosing all the particlesPosegetEstimatedPose()floatgetMaxX()Returns the maximum value of X in the particle setfloatgetMaxY()Returns the maximum value of Y in the particle set;floatgetMinX()Returns the minimum value of X in the particle set;floatgetMinY()Returns the minimum value of Y in the particle set;MCLParticleSetgetParticles()Returns the particle setPosegetPose()Returns the best best estimate of the current pose;RangeReadingsgetRangeReadings()Returns most recent range readingsRangeReadingsgetReadings()Get the current range readingsRangeScannergetScanner()Returns the range scannerfloatgetSigmaHeading()Returns the standard deviation of the heading values in the particle set;floatgetSigmaX()Returns the standard deviation of the X values in the particle set;floatgetSigmaY()Returns the standard deviation of the Y values in the particle set;floatgetXRange()Returns the difference between max X and min XfloatgetYRange()Return difference between max Y and min YbooleanincompleteRanges()returns range scanner failure statusbooleanisBusy()returns true if particle weights are being updated.booleanisLost()returns lost status - all particles have very low probability weightsbooleanisUpdated()Returns update success flagvoidloadObject(java.io.DataInputStream dis)Load serialized estimated pose from a data input streamvoidmoveStarted(Move event, MoveProvider mp)Required by MoveListener interface; does nothingvoidmoveStopped(Move event, MoveProvider mp)Required by MoveListener interface.voidsetDebug(boolean on)Set debugging on or offvoidsetInitialPose(Pose aPose, float radiusNoise, float headingNoise)Generates an initial particle set in a circular normal distribution, centered on aPose.voidsetInitialPose(RangeReadings readings, float sigma)Generates an initial particle set using the range readings.voidsetMap(RangeMap map)Associates a map with the MCLPoseProvider (for example a map send from the PC).voidsetParticles(MCLParticleSet particles)Associate a particle set with the MCLPoseProvider (e.g.voidsetPose(Pose aPose)set the initial pose cloud with radius noise 1 and heading noise 1booleanupdate()Calls range scanner to get range readings, calculates the probabilities of each particle from the range readings and the map and calls resample(()booleanupdate(RangeReadings readings)Calculates particle weights from readings, then resamples the particle set;
-
-
-
Constructor Detail
-
MCLPoseProvider
public MCLPoseProvider(MoveProvider mp, RangeScanner scanner, RangeMap map, int numParticles, int border)
Allocates a new MCLPoseProvider.- Parameters:
mp- - the MoveProivderscanner- - the RangeScannermap- - the RangeMapnumParticles- number of particlesborder- of the map
-
MCLPoseProvider
public MCLPoseProvider(RangeMap map, int numParticles, int border)
Constructor for use on PC- Parameters:
map- the RangeMapnumParticles- the numbers of particlesborder- of the map
-
-
Method Detail
-
setMap
public void setMap(RangeMap map)
Associates a map with the MCLPoseProvider (for example a map send from the PC).- Parameters:
map- the RangeMap
-
setInitialPose
public void setInitialPose(Pose aPose, float radiusNoise, float headingNoise)
Generates an initial particle set in a circular normal distribution, centered on aPose.- Parameters:
aPose- - center of the cloudradiusNoise- - standard deviation of the radius of the cloudheadingNoise- - standard deviation of the heading;
-
setInitialPose
public void setInitialPose(RangeReadings readings, float sigma)
Generates an initial particle set using the range readings. The particles have a significant probability weight given the readings.- Parameters:
readings-sigma- range reading noise standard deviation.
-
setDebug
public void setDebug(boolean on)
Set debugging on or off- Parameters:
on- true = on, false = off
-
setPose
public void setPose(Pose aPose)
set the initial pose cloud with radius noise 1 and heading noise 1- Specified by:
setPosein interfacePoseProvider
-
getParticles
public MCLParticleSet getParticles()
Returns the particle set- Returns:
- the particle set
-
getReadings
public RangeReadings getReadings()
Get the current range readings- Returns:
- the RangeReadings object
-
setParticles
public void setParticles(MCLParticleSet particles)
Associate a particle set with the MCLPoseProvider (e.g. particles sent from the PC)- Parameters:
particles- the particle set
-
generateParticles
public void generateParticles()
Generate a new particle set, uniformly distributed within the map, and uniformly distributed heading.
-
moveStarted
public void moveStarted(Move event, MoveProvider mp)
Required by MoveListener interface; does nothing- Specified by:
moveStartedin interfaceMoveListener- Parameters:
event- the movementmp- the movement provider
-
moveStopped
public void moveStopped(Move event, MoveProvider mp)
Required by MoveListener interface. The pose of each particle is updated using the odometry data of the Move object.- Specified by:
moveStoppedin interfaceMoveListener- Parameters:
event- the move just completedmp- the MoveProvider
-
update
public boolean update()
Calls range scanner to get range readings, calculates the probabilities of each particle from the range readings and the map and calls resample(()- Returns:
- true if update was successful
-
update
public boolean update(RangeReadings readings)
Calculates particle weights from readings, then resamples the particle set;- Parameters:
readings-- Returns:
- true if update was successful.
-
isUpdated
public boolean isUpdated()
Returns update success flag- Returns:
- true if update is successful
-
isLost
public boolean isLost()
returns lost status - all particles have very low probability weights- Returns:
- true if robot is lost
-
incompleteRanges
public boolean incompleteRanges()
returns range scanner failure status- Returns:
- true if range readings are incomplete
-
getXRange
public float getXRange()
Returns the difference between max X and min X- Returns:
- the difference between min and max X
-
getYRange
public float getYRange()
Return difference between max Y and min Y- Returns:
- difference between max and min Y
-
getPose
public Pose getPose()
Returns the best best estimate of the current pose;- Specified by:
getPosein interfacePoseProvider- Returns:
- the estimated pose
-
getEstimatedPose
public Pose getEstimatedPose()
-
estimatePose
public void estimatePose()
Estimate pose from weighted average of the particles Calculate statistics
-
getRangeReadings
public RangeReadings getRangeReadings()
Returns most recent range readings- Returns:
- the range readings
-
getErrorRect
public Rectangle2D getErrorRect()
Returns the minimum rectangle enclosing all the particles- Returns:
- rectangle : the minimum rectangle enclosing all the particles
-
getMaxX
public float getMaxX()
Returns the maximum value of X in the particle set- Returns:
- max X
-
getMinX
public float getMinX()
Returns the minimum value of X in the particle set;- Returns:
- minimum X
-
getMaxY
public float getMaxY()
Returns the maximum value of Y in the particle set;- Returns:
- max y
-
getMinY
public float getMinY()
Returns the minimum value of Y in the particle set;- Returns:
- minimum Y
-
getSigmaX
public float getSigmaX()
Returns the standard deviation of the X values in the particle set;- Returns:
- sigma X
-
getSigmaY
public float getSigmaY()
Returns the standard deviation of the Y values in the particle set;- Returns:
- sigma Y
-
getSigmaHeading
public float getSigmaHeading()
Returns the standard deviation of the heading values in the particle set;- Returns:
- sigma heading
-
getScanner
public RangeScanner getScanner()
Returns the range scanner- Returns:
- the range scanner
-
dumpObject
public void dumpObject(java.io.DataOutputStream dos) throws java.io.IOExceptionDump the serialized estimate of pose to a data output stream- Specified by:
dumpObjectin interfaceTransmittable- Parameters:
dos- the data output stream- Throws:
java.io.IOException
-
loadObject
public void loadObject(java.io.DataInputStream dis) throws java.io.IOExceptionLoad serialized estimated pose from a data input stream- Specified by:
loadObjectin interfaceTransmittable- Parameters:
dis- the data input stream- Throws:
java.io.IOException
-
isBusy
public boolean isBusy()
returns true if particle weights are being updated. The robot should not move while this is happening otherwise the prediction from odometry data may introduce errors into the updating.- Returns:
- true if weight update is in progress.
-
-