pf.h
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
4  * gerkey@usc.edu kaspers@robotics.usc.edu
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 /**************************************************************************
22  * Desc: Simple particle filter for localization.
23  * Author: Andrew Howard
24  * Date: 10 Dec 2002
25  * CVS: $Id: pf.h 3293 2005-11-19 08:37:45Z gerkey $
26  *************************************************************************/
27 
28 #ifndef PF_H
29 #define PF_H
30 
31 #include "pf_vector.h"
32 #include "pf_kdtree.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // Forward declarations
39 struct _pf_t;
40 struct _rtk_fig_t;
41 struct _pf_sample_set_t;
42 
43 // Function prototype for the initialization model; generates a sample pose from
44 // an appropriate distribution.
45 typedef pf_vector_t (*pf_init_model_fn_t) (void *init_data);
46 
47 // Function prototype for the action model; generates a sample pose from
48 // an appropriate distribution
49 typedef void (*pf_action_model_fn_t) (void *action_data,
50  struct _pf_sample_set_t* set);
51 
52 // Function prototype for the sensor model; determines the probability
53 // for the given set of sample poses.
54 typedef double (*pf_sensor_model_fn_t) (void *sensor_data,
55  struct _pf_sample_set_t* set);
56 
57 
58 // Information for a single sample
59 typedef struct
60 {
61  // Pose represented by this sample
63 
64  // Weight for this pose
65  double weight;
66 
67 } pf_sample_t;
68 
69 
70 // Information for a cluster of samples
71 typedef struct
72 {
73  // Number of samples
74  int count;
75 
76  // Total weight of samples in this cluster
77  double weight;
78 
79  // Cluster statistics
82 
83  // Workspace
84  double m[4], c[2][2];
85 
86 } pf_cluster_t;
87 
88 
89 // Information for a set of samples
90 typedef struct _pf_sample_set_t
91 {
92  // The samples
95 
96  // A kdtree encoding the histogram
98 
99  // Clusters
102 
103  // Filter statistics
106  int converged;
107  double n_effective;
109 
110 
111 // Information for an entire filter
112 typedef struct _pf_t
113 {
114  // This min and max number of samples
116 
117  // Population size parameters
118  double pop_err, pop_z;
119 
120  // Resample limit cache
122 
123  // The sample sets. We keep two sets and use [current_set]
124  // to identify the active set.
127 
128  // Running averages, slow and fast, of likelihood
129  double w_slow, w_fast;
130 
131  // Decay rates for running averages
133 
134  // Function used to draw random pose samples
137 
138  double dist_threshold; //distance threshold in each axis over which the pf is considered to not be converged
139  int converged;
140 
141  // boolean parameter to enamble/diable selective resampling
143 } pf_t;
144 
145 
146 // Create a new filter
147 pf_t *pf_alloc(int min_samples, int max_samples,
148  double alpha_slow, double alpha_fast,
149  pf_init_model_fn_t random_pose_fn, void *random_pose_data);
150 
151 // Free an existing filter
152 void pf_free(pf_t *pf);
153 
154 // Initialize the filter using a guassian
155 void pf_init(pf_t *pf, pf_vector_t mean, pf_matrix_t cov);
156 
157 // Initialize the filter using some model
158 void pf_init_model(pf_t *pf, pf_init_model_fn_t init_fn, void *init_data);
159 
160 // Update the filter with some new action
161 void pf_update_action(pf_t *pf, pf_action_model_fn_t action_fn, void *action_data);
162 
163 // Update the filter with some new sensor observation
164 void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data);
165 
166 // Resample the distribution
167 void pf_update_resample(pf_t *pf);
168 
169 // set selective resampling parameter
170 void pf_set_selective_resampling(pf_t *pf, int selective_resampling);
171 
172 // Compute the CEP statistics (mean and variance).
173 void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var);
174 
175 // Compute the statistics for a particular cluster. Returns 0 if
176 // there is no such cluster.
177 int pf_get_cluster_stats(pf_t *pf, int cluster, double *weight,
178  pf_vector_t *mean, pf_matrix_t *cov);
179 
180 // Re-compute the cluster statistics for a sample set
181 void pf_cluster_stats(pf_t *pf, pf_sample_set_t *set);
182 
183 
184 // Display the sample set
185 void pf_draw_samples(pf_t *pf, struct _rtk_fig_t *fig, int max_samples);
186 
187 // Draw the histogram (kdtree)
188 void pf_draw_hist(pf_t *pf, struct _rtk_fig_t *fig);
189 
190 // Draw the CEP statistics
191 void pf_draw_cep_stats(pf_t *pf, struct _rtk_fig_t *fig);
192 
193 // Draw the cluster statistics
194 void pf_draw_cluster_stats(pf_t *pf, struct _rtk_fig_t *fig);
195 
196 //calculate if the particle filter has converged -
197 //and sets the converged flag in the current set and the pf
198 int pf_update_converged(pf_t *pf);
199 
200 //sets the current set and pf converged values to zero
201 void pf_init_converged(pf_t *pf);
202 
203 void pf_copy_set(pf_sample_set_t* set_a, pf_sample_set_t* set_b);
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 
210 #endif
pf_sample_t::weight
double weight
Definition: pf.h:65
_pf_t::selective_resampling
int selective_resampling
Definition: pf.h:142
_pf_t::alpha_fast
double alpha_fast
Definition: pf.h:132
pf_copy_set
void pf_copy_set(pf_sample_set_t *set_a, pf_sample_set_t *set_b)
pf_kdtree.h
pf_vector_t
Definition: pf_vector.h:38
_pf_t::w_fast
double w_fast
Definition: pf.h:129
_pf_t::random_pose_data
void * random_pose_data
Definition: pf.h:136
pf_init_converged
void pf_init_converged(pf_t *pf)
Definition: pf.c:213
_pf_sample_set_t::samples
pf_sample_t * samples
Definition: pf.h:94
_pf_sample_set_t::n_effective
double n_effective
Definition: pf.h:107
_pf_t::pop_err
double pop_err
Definition: pf.h:118
_pf_sample_set_t::converged
int converged
Definition: pf.h:106
pf_get_cluster_stats
int pf_get_cluster_stats(pf_t *pf, int cluster, double *weight, pf_vector_t *mean, pf_matrix_t *cov)
Definition: pf.c:744
_pf_sample_set_t::clusters
pf_cluster_t * clusters
Definition: pf.h:101
_pf_sample_set_t::kdtree
pf_kdtree_t * kdtree
Definition: pf.h:97
_pf_sample_set_t::sample_count
int sample_count
Definition: pf.h:93
_pf_sample_set_t
Definition: pf.h:90
_pf_t::dist_threshold
double dist_threshold
Definition: pf.h:138
_pf_t::converged
int converged
Definition: pf.h:139
pf_t
struct _pf_t pf_t
pf_init
void pf_init(pf_t *pf, pf_vector_t mean, pf_matrix_t cov)
Definition: pf.c:136
pf_update_action
void pf_update_action(pf_t *pf, pf_action_model_fn_t action_fn, void *action_data)
Definition: pf.c:254
_pf_sample_set_t::cluster_max_count
int cluster_max_count
Definition: pf.h:100
_pf_t::alpha_slow
double alpha_slow
Definition: pf.h:132
_pf_t
Definition: pf.h:112
pf_sensor_model_fn_t
double(* pf_sensor_model_fn_t)(void *sensor_data, struct _pf_sample_set_t *set)
Definition: pf.h:54
pf_init_model_fn_t
pf_vector_t(* pf_init_model_fn_t)(void *init_data)
Definition: pf.h:45
_pf_sample_set_t::mean
pf_vector_t mean
Definition: pf.h:104
_pf_t::sets
pf_sample_set_t sets[2]
Definition: pf.h:126
_pf_t::min_samples
int min_samples
Definition: pf.h:115
pf_cluster_t::mean
pf_vector_t mean
Definition: pf.h:80
pf_draw_cluster_stats
void pf_draw_cluster_stats(pf_t *pf, struct _rtk_fig_t *fig)
pf_kdtree_t
Definition: pf_kdtree.h:62
pf_get_cep_stats
void pf_get_cep_stats(pf_t *pf, pf_vector_t *mean, double *var)
Definition: pf.c:701
_pf_t::pop_z
double pop_z
Definition: pf.h:118
pf_update_converged
int pf_update_converged(pf_t *pf)
Definition: pf.c:220
pf_update_sensor
void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data)
Definition: pf.c:268
_pf_sample_set_t::cluster_count
int cluster_count
Definition: pf.h:100
_pf_t::limit_cache
int * limit_cache
Definition: pf.h:121
pf_draw_cep_stats
void pf_draw_cep_stats(pf_t *pf, struct _rtk_fig_t *fig)
pf_sample_t
Definition: pf.h:59
pf_cluster_stats
void pf_cluster_stats(pf_t *pf, pf_sample_set_t *set)
Definition: pf.c:559
set
ROSCPP_DECL void set(const std::string &key, bool b)
pf_update_resample
void pf_update_resample(pf_t *pf)
Definition: pf.c:363
pf_sample_set_t
struct _pf_sample_set_t pf_sample_set_t
pf_sample_t::pose
pf_vector_t pose
Definition: pf.h:62
pf_cluster_t
Definition: pf.h:71
pf_draw_hist
void pf_draw_hist(pf_t *pf, struct _rtk_fig_t *fig)
pf_cluster_t::weight
double weight
Definition: pf.h:77
_pf_t::w_slow
double w_slow
Definition: pf.h:129
pf_alloc
pf_t * pf_alloc(int min_samples, int max_samples, double alpha_slow, double alpha_fast, pf_init_model_fn_t random_pose_fn, void *random_pose_data)
Definition: pf.c:46
pf_set_selective_resampling
void pf_set_selective_resampling(pf_t *pf, int selective_resampling)
Definition: pf.c:695
pf_matrix_t
Definition: pf_vector.h:45
pf_init_model
void pf_init_model(pf_t *pf, pf_init_model_fn_t init_fn, void *init_data)
Definition: pf.c:178
_pf_t::max_samples
int max_samples
Definition: pf.h:115
_pf_t::random_pose_fn
pf_init_model_fn_t random_pose_fn
Definition: pf.h:135
pf_cluster_t::cov
pf_matrix_t cov
Definition: pf.h:81
_pf_t::current_set
int current_set
Definition: pf.h:125
pf_action_model_fn_t
void(* pf_action_model_fn_t)(void *action_data, struct _pf_sample_set_t *set)
Definition: pf.h:49
pf_cluster_t::count
int count
Definition: pf.h:74
pf_vector.h
pf_draw_samples
void pf_draw_samples(pf_t *pf, struct _rtk_fig_t *fig, int max_samples)
_pf_sample_set_t::cov
pf_matrix_t cov
Definition: pf.h:105
pf_free
void pf_free(pf_t *pf)
Definition: pf.c:118


amcl
Author(s): Brian P. Gerkey, contradict@gmail.com
autogenerated on Mon Mar 6 2023 03:50:13