Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

ParticleFilter< ParticleT > Class Template Reference

#include <ParticleFilter.h>

List of all members.


Detailed Description

template<typename ParticleT>
class ParticleFilter< ParticleT >

Implements a particle filter with support for a variety of applications through the usage of arbitrary combination of a variety of models and policies.

The particle type is passed as a template parameter, which provides the implementation advantage of being able to directly store arrays of particles as contiguous blocks in memory. This allows better cache coherency and enables platform-specific acceleration tricks, such as SIMD calls.

There are a number of embedded classes which together form the implementation of the particle filter. The advantage of this architecture is that you can mix and match any combination of modules to get the features needed for your application.

  • SensorModel: pass one of these to updateSensors in order to evaluate the particles as new information is discovered. You may have several different sensors at the same time, simply create a model for each type of sensor, and pass it to the filter when updated.
  • MotionModel: modifies particle states based on the expected outcome of any controls you might have over the system. See DeadReckoningBehavior for an example. Generally, you will install one motion model, and this model will be given a opportunity to update expected particle state before each sensor update. (unless you pass 'false' to updateSensors()). MotionModel can be NULL if you have no control over the system.
  • DistributionPolicy: defines how to generate random particles and "jiggle" existing ones. The default DistributionPolicy is usually specified via a typedef in the particle itself, and is stored as a property of the ResamplingPolicy (next item) since that is what will use it.
  • ResamplingPolicy: Following a sensor update, you may wish to re-evaluate the particles in use, making copies of the "good" particles, and dropping those which are not matching sensor values. If you receive a group of different sensor readings, you may want to hold off on resampling until they have all been applied for better evaluation of the particles before selecting which to replicate. Similarly, if your sensors are noisy, you may want to take several readings before allowing resampling so you don't kill off all the "good" particles based on a bad reading. Pass 'false' to updateSensors() or use the delayCount parameter of LowVarianceResamplingPolicy. The resampling policy can be 'NULL' if you never want to resample, but it defaults to an instance of LowVarianceResamlingPolicy.

Generally, preparing to use a particle filter requires these prerequisites:

Once these are available, usage goes something like this:

  1. create particle filter, optionally passing motion model and/or resampling policy
  2. customize parameters for resampling and distribution policies
  3. while active (note these are all "as needed", in no particular order):
    • update motion model whenever there's a change in controls (e.g. call setVelocity() on a HolonomicMotionModel)
    • create/pass SensorModel(s) for any measurements obtained (e.g. call updateSensors() on the particle filter)
    • query getBestParticle() on the particle filter to obtain current state estimate

Remember that the particle filter takes responsibility for deallocating all policies and the motion model when they are removed. Do not attempt to reuse them between particle filters. SensorModels are the only exception -- they are not retained between calls to updateSensors, so you can reuse them.

Definition at line 127 of file ParticleFilter.h.

Public Types

typedef ParticleT particle_type
 redefinition here allows reference to the particle type even if the template parameter may be abstracted away due to a typedef
typedef std::vector< particle_typeparticle_collection
 the collection type we'll be using to store the particles
typedef particle_collection::size_type index_t
 index type for refering to particles within the collection

Public Member Functions

 ParticleFilter (unsigned int numParticles, MotionModel *mm=NULL, ResamplingPolicy *rs=new LowVarianceResamplingPolicy)
 Constructor for the particle filter, specify number of particles and optionally pass a motion model and resampling policy.
virtual ~ParticleFilter ()
 Destructor.
virtual MotionModelgetMotionModel () const
 Returns the current motion model (motion).
virtual void installMotionModel (MotionModel *mm)
 Reassigns the motion model, deleting the old one; motion model can be NULL.
virtual ResamplingPolicygetResamplingPolicy () const
 Returns the current resampling policy (resampler).
virtual void installResamplingPolicy (ResamplingPolicy *rs)
 Reassigns the resampling policy, deleting the old one; resampling policy can be NULL (although not recommended...).
virtual void setResampleDelay (unsigned int d)
 Sets the resampling policy's resampleDelay, which controls how many sensor updates to process before resampling the particles; policy must be a LowVarianceResamplingPolicy.
virtual void setMinAcceptableWeight (float w)
 Sets the resampling policy's minimum acceptable weight for a particle; policy must be a LowVarianceResamplingPolicy.
virtual void setMaxRedistribute (float r)
virtual void setVarianceScale (float s)
virtual void updateMotion ()
 Allows you to manually request a position update -- you might want to call this before using getBestParticle's state information.
virtual void updateSensors (SensorModel &sm, bool updateMot=true, bool doResample=true)
 Applies the sensor model's evaluation to the particles, optionally updating the motion model and resampling first.
virtual void resample ()
 A manual call to trigger resampling.
virtual void resetWeights (float w)
 Assigns the specified weight value to all of the particles.
virtual void resetFilter (float w)
 Requests that the resampler's distribution policy randomly distribute all of the particles, and reset weights to w.
virtual index_t getBestIndex () const
 Returns the index of the best particle in particles.
virtual const particle_typegetBestParticle () const
 Returns a reference to the best particle in particles.
virtual particle_collectiongetParticles ()
 Returns a reference to particles itself (if you want to modify the particles, generally better to formulate it in terms of a sensor model or motion model for consistency).
virtual const particle_collectiongetParticles () const
 Returns a reference to particles itself (if you want to modify the particles, generally better to formulate it in terms of a sensor model or motion model for consistency).
virtual void setPosition (const particle_type &pos, float variance=0)
 if you know the position in state space, pass it here, along with a positive varianceScale if you want some jiggle from the distribution policy
virtual float getConfidenceInterval () const
 Returns a confidence interval based on the particle_type's sumSqErr implementation (see ParticleBase::sumSqErr()).
virtual void resizeParticles (unsigned int numParticles)
 Adjusts the size of the particle collection -- more particles gives better coverage, but more computation.

Static Protected Member Functions

static bool weightLess (const particle_type *a, const particle_type *b)
 < used for sorting particles in resizeParticles() to drop the least weighted particles first

Protected Attributes

particle_collection particles
 storage of the particles (no particular order)
index_t bestIndex
 index of the currently highest-rated particle
MotionModelmotion
 motion model, can be NULL if you have no control or knowledge of changes in the system
ResamplingPolicyresampler
 resampling policy refocuses filter on "good" particles, can be NULL but filter won't work well without a resampler
bool hasEvaluation
 set to true following each call to updateSensors, and false following resample() or resetWeights(); avoids repeated resamplings

Private Member Functions

 ParticleFilter (const ParticleFilter &)
 don't call (copy constructor)
ParticleFilteroperator= (const ParticleFilter &)
 don't call (assignment operator)

Classes

class  DistributionPolicy
 A distribution policy provides the ability to randomize ("redistribute") or tweak the values of a group of particles. More...
class  LowVarianceResamplingPolicy
 This class provides a generic, default ResamplingPolicy. It is based on the low variance resampling policy algorithm found in "Probabilistic Robotics" by Sebastian Thrun, Wolfram Burgard, Dieter Fox. More...
class  MotionModel
 A motion model is retained by the particle filter to query before evaluating sensor measurements so all known influences are accounted for before testing the particles. More...
class  ResamplingPolicy
 The resampling policy focuses the particle filter on those particles which are performing well, and dropping those which are poorly rated. More...
class  SensorModel
 A sensor model is used to update particle weights to account based on each particle's ability to explain observations taken from the system. More...


Constructor & Destructor Documentation

template<typename ParticleT>
ParticleFilter< ParticleT >::ParticleFilter ( unsigned int  numParticles,
MotionModel mm = NULL,
ResamplingPolicy rs = new LowVarianceResamplingPolicy 
) [inline, explicit]

Constructor for the particle filter, specify number of particles and optionally pass a motion model and resampling policy.

The particle filter assumes responsibility for eventual deallocation of the motion model and resampling policy

Definition at line 322 of file ParticleFilter.h.


Member Function Documentation

template<typename ParticleT>
virtual void ParticleFilter< ParticleT >::resetFilter ( float  w  )  [inline, virtual]

Requests that the resampler's distribution policy randomly distribute all of the particles, and reset weights to w.

You might want to do this if you believe you have been "kidnapped" by some unmodeled motion to a new area of state space, and need to restart the filter to determine the new location.

Definition at line 414 of file ParticleFilter.h.

Referenced by ParticleFilter< ParticleT >::ParticleFilter().

template<typename ParticleT>
virtual void ParticleFilter< ParticleT >::resizeParticles ( unsigned int  numParticles  )  [inline, virtual]

Adjusts the size of the particle collection -- more particles gives better coverage, but more computation.

You may wish to shrink the number of particles when the confidence interval is small or particle weights are high, and increase particles when the filter is getting "lost".

Definition at line 443 of file ParticleFilter.h.

template<typename ParticleT>
virtual void ParticleFilter< ParticleT >::updateSensors ( SensorModel sm,
bool  updateMot = true,
bool  doResample = true 
) [inline, virtual]

Applies the sensor model's evaluation to the particles, optionally updating the motion model and resampling first.

If you are applying a group of sensor readings, you probably only want to update motion for the first one (since no motion is occuring between the readings if they were taken at the same time), and may want to hold off on resampling until the end (so the particles are better evaluated). If using the default LowVarianceResamplingPolicy, see also LowVarianceResamplingPolicy::resampleDelay.

Definition at line 389 of file ParticleFilter.h.


The documentation for this class was generated from the following file:

Tekkotsu v3.0
Generated Fri May 11 20:08:30 2007 by Doxygen 1.4.7