pf.h
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2003
00004  *     Andrew Howard
00005  *     Brian Gerkey    
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 
00024 /**************************************************************************
00025  * Desc: Simple particle filter for localization.
00026  * Author: Andrew Howard
00027  * Date: 10 Dec 2002
00028  * CVS: $Id: pf.h 8108 2009-07-23 23:03:37Z thjc $
00029  *************************************************************************/
00030 
00031 #ifndef PF_H
00032 #define PF_H
00033 
00034 #include "pf_vector.h"
00035 #include "pf_kdtree.h"
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 // Forward declarations
00042 struct _pf_t;
00043 struct _rtk_fig_t;
00044 struct _pf_sample_set_t;
00045 
00046 // Function prototype for the initialization model; generates a sample pose from
00047 // an appropriate distribution.
00048 typedef pf_vector_t (*pf_init_model_fn_t) (void *init_data);
00049 
00050 // Function prototype for the action model; generates a sample pose from
00051 // an appropriate distribution
00052 typedef void (*pf_action_model_fn_t) (void *action_data, 
00053                                       struct _pf_sample_set_t* set);
00054 
00055 // Function prototype for the sensor model; determines the probability
00056 // for the given set of sample poses.
00057 typedef double (*pf_sensor_model_fn_t) (void *sensor_data, 
00058                                         struct _pf_sample_set_t* set);
00059 
00060 
00061 // Information for a single sample
00062 typedef struct
00063 {
00064   // Pose represented by this sample
00065   pf_vector_t pose;
00066 
00067   // Weight for this pose
00068   double weight;
00069   
00070 } pf_sample_t;
00071 
00072 
00073 // Information for a cluster of samples
00074 typedef struct
00075 {
00076   // Number of samples
00077   int count;
00078 
00079   // Total weight of samples in this cluster
00080   double weight;
00081 
00082   // Cluster statistics
00083   pf_vector_t mean;
00084   pf_matrix_t cov;
00085 
00086   // Workspace
00087   double m[4], c[2][2];
00088   
00089 } pf_cluster_t;
00090 
00091 
00092 // Information for a set of samples
00093 typedef struct _pf_sample_set_t
00094 {
00095   // The samples
00096   int sample_count;
00097   pf_sample_t *samples;
00098 
00099   // A kdtree encoding the histogram
00100   pf_kdtree_t *kdtree;
00101 
00102   // Clusters
00103   int cluster_count, cluster_max_count;
00104   pf_cluster_t *clusters;
00105   
00106 } pf_sample_set_t;
00107 
00108 
00109 // Information for an entire filter
00110 typedef struct _pf_t
00111 {
00112   // This min and max number of samples
00113   int min_samples, max_samples;
00114 
00115   // Population size parameters
00116   double pop_err, pop_z;
00117   
00118   // The sample sets.  We keep two sets and use [current_set]
00119   // to identify the active set.
00120   int current_set;
00121   pf_sample_set_t sets[2];
00122 
00123 } pf_t;
00124 
00125 
00126 // Create a new filter
00127 pf_t *pf_alloc(int min_samples, int max_samples);
00128 
00129 // Free an existing filter
00130 void pf_free(pf_t *pf);
00131 
00132 // Initialize the filter using a guassian
00133 void pf_init(pf_t *pf, pf_vector_t mean, pf_matrix_t cov);
00134 
00135 // Initialize the filter using some model
00136 void pf_init_model(pf_t *pf, pf_init_model_fn_t init_fn, void *init_data);
00137 
00138 // Update the filter with some new action
00139 void pf_update_action(pf_t *pf, pf_action_model_fn_t action_fn, void *action_data);
00140 
00141 // Update the filter with some new sensor observation
00142 void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data);
00143 
00144 // Resample the distribution
00145 void pf_update_resample(pf_t *pf);
00146 
00147 // Compute the CEP statistics (mean and variance).
00148 void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var);
00149 
00150 // Compute the statistics for a particular cluster.  Returns 0 if
00151 // there is no such cluster.
00152 int pf_get_cluster_stats(pf_t *pf, int cluster, double *weight,
00153                          pf_vector_t *mean, pf_matrix_t *cov);
00154 
00155 // Display the sample set
00156 void pf_draw_samples(pf_t *pf, struct _rtk_fig_t *fig, int max_samples);
00157 
00158 // Draw the histogram (kdtree)
00159 void pf_draw_hist(pf_t *pf, struct _rtk_fig_t *fig);
00160 
00161 // Draw the CEP statistics
00162 void pf_draw_cep_stats(pf_t *pf, struct _rtk_fig_t *fig);
00163 
00164 // Draw the cluster statistics
00165 void pf_draw_cluster_stats(pf_t *pf, struct _rtk_fig_t *fig);
00166 
00167 #ifdef __cplusplus
00168 }
00169 #endif
00170 
00171 
00172 #endif

Last updated 25 May 2011 21:17:00