pf.h

00001 
00002 /**************************************************************************
00003  * Desc: Simple particle filter for localization.
00004  * Author: Andrew Howard
00005  * Date: 10 Dec 2002
00006  * CVS: $Id: pf.h 3293 2005-11-19 08:37:45Z gerkey $
00007  *************************************************************************/
00008 
00009 #ifndef PF_H
00010 #define PF_H
00011 
00012 #include "pf_vector.h"
00013 #include "pf_kdtree.h"
00014 
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018 
00019 // Forward declarations
00020 struct _pf_t;
00021 struct _rtk_fig_t;
00022 struct _pf_sample_set_t;
00023 
00024 // Function prototype for the initialization model; generates a sample pose from
00025 // an appropriate distribution.
00026 typedef pf_vector_t (*pf_init_model_fn_t) (void *init_data);
00027 
00028 // Function prototype for the action model; generates a sample pose from
00029 // an appropriate distribution
00030 typedef void (*pf_action_model_fn_t) (void *action_data, 
00031                                       struct _pf_sample_set_t* set);
00032 
00033 // Function prototype for the sensor model; determines the probability
00034 // for the given set of sample poses.
00035 typedef double (*pf_sensor_model_fn_t) (void *sensor_data, 
00036                                         struct _pf_sample_set_t* set);
00037 
00038 
00039 // Information for a single sample
00040 typedef struct
00041 {
00042   // Pose represented by this sample
00043   pf_vector_t pose;
00044 
00045   // Weight for this pose
00046   double weight;
00047   
00048 } pf_sample_t;
00049 
00050 
00051 // Information for a cluster of samples
00052 typedef struct
00053 {
00054   // Number of samples
00055   int count;
00056 
00057   // Total weight of samples in this cluster
00058   double weight;
00059 
00060   // Cluster statistics
00061   pf_vector_t mean;
00062   pf_matrix_t cov;
00063 
00064   // Workspace
00065   double m[4], c[2][2];
00066   
00067 } pf_cluster_t;
00068 
00069 
00070 // Information for a set of samples
00071 typedef struct _pf_sample_set_t
00072 {
00073   // The samples
00074   int sample_count;
00075   pf_sample_t *samples;
00076 
00077   // A kdtree encoding the histogram
00078   pf_kdtree_t *kdtree;
00079 
00080   // Clusters
00081   int cluster_count, cluster_max_count;
00082   pf_cluster_t *clusters;
00083   
00084 } pf_sample_set_t;
00085 
00086 
00087 // Information for an entire filter
00088 typedef struct _pf_t
00089 {
00090   // This min and max number of samples
00091   int min_samples, max_samples;
00092 
00093   // Population size parameters
00094   double pop_err, pop_z;
00095   
00096   // The sample sets.  We keep two sets and use [current_set]
00097   // to identify the active set.
00098   int current_set;
00099   pf_sample_set_t sets[2];
00100 
00101 } pf_t;
00102 
00103 
00104 // Create a new filter
00105 pf_t *pf_alloc(int min_samples, int max_samples);
00106 
00107 // Free an existing filter
00108 void pf_free(pf_t *pf);
00109 
00110 // Initialize the filter using a guassian
00111 void pf_init(pf_t *pf, pf_vector_t mean, pf_matrix_t cov);
00112 
00113 // Initialize the filter using some model
00114 void pf_init_model(pf_t *pf, pf_init_model_fn_t init_fn, void *init_data);
00115 
00116 // Update the filter with some new action
00117 void pf_update_action(pf_t *pf, pf_action_model_fn_t action_fn, void *action_data);
00118 
00119 // Update the filter with some new sensor observation
00120 void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data);
00121 
00122 // Resample the distribution
00123 void pf_update_resample(pf_t *pf);
00124 
00125 // Compute the CEP statistics (mean and variance).
00126 void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var);
00127 
00128 // Compute the statistics for a particular cluster.  Returns 0 if
00129 // there is no such cluster.
00130 int pf_get_cluster_stats(pf_t *pf, int cluster, double *weight,
00131                          pf_vector_t *mean, pf_matrix_t *cov);
00132 
00133 // Display the sample set
00134 void pf_draw_samples(pf_t *pf, struct _rtk_fig_t *fig, int max_samples);
00135 
00136 // Draw the histogram (kdtree)
00137 void pf_draw_hist(pf_t *pf, struct _rtk_fig_t *fig);
00138 
00139 // Draw the CEP statistics
00140 void pf_draw_cep_stats(pf_t *pf, struct _rtk_fig_t *fig);
00141 
00142 // Draw the cluster statistics
00143 void pf_draw_cluster_stats(pf_t *pf, struct _rtk_fig_t *fig);
00144 
00145 #ifdef __cplusplus
00146 }
00147 #endif
00148 
00149 
00150 #endif

Last updated 12 September 2005 21:38:45