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


gmcl
Author(s): Mhd Ali Alshikh Khalil, adler1994@gmail.com
autogenerated on Wed Mar 2 2022 00:20:14