30 #include <sys/types.h> 43 max_samples(0), max_obs(0),
149 double obs_range, obs_bearing;
159 for (j = 0; j <
set->sample_count; j++)
161 sample =
set->samples + j;
169 step = (data->
range_count - 1) / (self->max_beams - 1);
172 obs_range = data->
ranges[i][0];
173 obs_bearing = data->
ranges[i][1];
181 z = obs_range - map_range;
182 pz +=
self->z_hit * exp(-(z * z) / (2 * self->sigma_hit * self->sigma_hit));
186 pz +=
self->z_short *
self->lambda_short * exp(-self->lambda_short*obs_range);
190 pz +=
self->z_max * 1.0;
193 if(obs_range < data->range_max)
194 pz +=
self->z_rand * 1.0/data->
range_max;
207 total_weight += sample->
weight;
210 return(total_weight);
219 double obs_range, obs_bearing;
230 for (j = 0; j <
set->sample_count; j++)
232 sample =
set->samples + j;
241 double z_hit_denom = 2 *
self->sigma_hit *
self->sigma_hit;
242 double z_rand_mult = 1.0/data->
range_max;
244 step = (data->
range_count - 1) / (self->max_beams - 1);
252 obs_range = data->
ranges[i][0];
253 obs_bearing = data->
ranges[i][1];
260 if(obs_range != obs_range)
266 hit.
v[0] = pose.
v[0] + obs_range * cos(pose.
v[2] + obs_bearing);
267 hit.
v[1] = pose.
v[1] + obs_range * sin(pose.
v[2] + obs_bearing);
277 z =
self->map->max_occ_dist;
279 z =
self->map->cells[
MAP_INDEX(self->map,mi,mj)].occ_dist;
282 pz +=
self->z_hit * exp(-(z * z) / z_hit_denom);
284 pz +=
self->z_rand * z_rand_mult;
297 total_weight += sample->
weight;
300 return(total_weight);
309 double obs_range, obs_bearing;
319 step = ceil((data->
range_count) /
static_cast<double>(
self->max_beams));
326 double z_hit_denom = 2 *
self->sigma_hit *
self->sigma_hit;
327 double z_rand_mult = 1.0/data->
range_max;
329 double max_dist_prob = exp(-(self->map->max_occ_dist * self->map->max_occ_dist) / z_hit_denom);
340 if(do_beamskip && !
set->converged){
345 int *obs_count =
new int[
self->max_beams]();
348 bool *obs_mask =
new bool[
self->max_beams]();
353 bool realloc =
false;
356 if(self->max_obs < self->max_beams){
360 if(self->max_samples <
set->sample_count){
365 self->reallocTempData(
set->sample_count, self->max_beams);
366 fprintf(stderr,
"Reallocing temp weights %d - %d\n", self->max_samples, self->max_obs);
371 for (j = 0; j <
set->sample_count; j++)
373 sample =
set->samples + j;
383 for (i = 0; i < data->
range_count; i += step, beam_ind++)
385 obs_range = data->
ranges[i][0];
386 obs_bearing = data->
ranges[i][1];
394 if(obs_range != obs_range){
401 hit.
v[0] = pose.
v[0] + obs_range * cos(pose.
v[2] + obs_bearing);
402 hit.
v[1] = pose.
v[1] + obs_range * sin(pose.
v[2] + obs_bearing);
413 pz +=
self->z_hit * max_dist_prob;
416 z =
self->map->cells[
MAP_INDEX(self->map,mi,mj)].occ_dist;
417 if(z < beam_skip_distance){
418 obs_count[beam_ind] += 1;
420 pz +=
self->z_hit * exp(-(z * z) / z_hit_denom);
427 pz +=
self->z_rand * z_rand_mult;
438 self->temp_obs[j][beam_ind] = pz;
442 sample->
weight *= exp(log_p);
443 total_weight += sample->
weight;
448 int skipped_beam_count = 0;
449 for (beam_ind = 0; beam_ind <
self->max_beams; beam_ind++){
450 if((obs_count[beam_ind] / static_cast<double>(
set->sample_count)) > beam_skip_threshold){
451 obs_mask[beam_ind] =
true;
454 obs_mask[beam_ind] =
false;
455 skipped_beam_count++;
465 if(skipped_beam_count >= (beam_ind * self->beam_skip_error_threshold)){
466 fprintf(stderr,
"Over %f%% of the observations were not in the map - pf may have converged to wrong pose - integrating all observations\n", (100 * self->beam_skip_error_threshold));
470 for (j = 0; j <
set->sample_count; j++)
472 sample =
set->samples + j;
477 for (beam_ind = 0; beam_ind <
self->max_beams; beam_ind++){
478 if(error || obs_mask[beam_ind]){
479 log_p += log(self->temp_obs[j][beam_ind]);
483 sample->
weight *= exp(log_p);
485 total_weight += sample->
weight;
491 return(total_weight);
double beam_skip_distance
double(* pf_sensor_model_fn_t)(void *sensor_data, struct _pf_sample_set_t *set)
void map_update_cspace(map_t *map, double max_occ_dist)
void pf_update_sensor(pf_t *pf, pf_sensor_model_fn_t sensor_fn, void *sensor_data)
#define MAP_VALID(map, i, j)
#define MAP_INDEX(map, i, j)
void SetModelBeam(double z_hit, double z_short, double z_max, double z_rand, double sigma_hit, double labda_short, double chi_outlier)
double map_calc_range(map_t *map, double ox, double oy, double oa, double max_range)
void reallocTempData(int max_samples, int max_obs)
double beam_skip_error_threshold
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
virtual bool UpdateSensor(pf_t *pf, AMCLSensorData *data)
static double LikelihoodFieldModelProb(AMCLLaserData *data, pf_sample_set_t *set)
void SetModelLikelihoodField(double z_hit, double z_rand, double sigma_hit, double max_occ_dist)
pf_vector_t pf_vector_coord_add(pf_vector_t a, pf_vector_t b)
static double LikelihoodFieldModel(AMCLLaserData *data, pf_sample_set_t *set)
TFSIMD_FORCE_INLINE const tfScalar & z() const
static double BeamModel(AMCLLaserData *data, pf_sample_set_t *set)
AMCLLaser(size_t max_beams, map_t *map)
double beam_skip_threshold
void SetModelLikelihoodFieldProb(double z_hit, double z_rand, double sigma_hit, double max_occ_dist, bool do_beamskip, double beam_skip_distance, double beam_skip_threshold, double beam_skip_error_threshold)