Skip to content

Commit

Permalink
Fix Wrong Map Pointer (#3311)
Browse files Browse the repository at this point in the history
Not assigning fixed map pointer to particle filter, using latest when resample.

Signed-off-by: Borong Yuan <yuanborong@hotmail.com>
  • Loading branch information
borongyuan committed Dec 6, 2022
1 parent ca48280 commit cc6f205
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions nav2_amcl/include/nav2_amcl/pf/pf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ typedef struct _pf_t

// Function used to draw random pose samples
pf_init_model_fn_t random_pose_fn;
void * random_pose_data;

double dist_threshold; // distance threshold in each axis over which the pf is considered to not
// be converged
Expand All @@ -141,7 +140,7 @@ typedef struct _pf_t
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);
pf_init_model_fn_t random_pose_fn);

// Free an existing filter
void pf_free(pf_t * pf);
Expand All @@ -159,7 +158,7 @@ void pf_update_action(pf_t * pf, pf_action_model_fn_t action_fn, void * action_d
void pf_update_sensor(pf_t * pf, pf_sensor_model_fn_t sensor_fn, void * sensor_data);

// Resample the distribution
void pf_update_resample(pf_t * pf);
void pf_update_resample(pf_t * pf, void * random_pose_data);

// Compute the CEP statistics (mean and variance).
void pf_get_cep_stats(pf_t * pf, pf_vector_t * mean, double * var);
Expand Down
5 changes: 2 additions & 3 deletions nav2_amcl/src/amcl_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ AmclNode::laserReceived(sensor_msgs::msg::LaserScan::ConstSharedPtr laser_scan)

// Resample the particles
if (!(++resample_count_ % resample_interval_)) {
pf_update_resample(pf_);
pf_update_resample(pf_, reinterpret_cast<void *>(map_));
resampled = true;
}

Expand Down Expand Up @@ -1334,8 +1334,7 @@ AmclNode::initParticleFilter()
// Create the particle filter
pf_ = pf_alloc(
min_particles_, max_particles_, alpha_slow_, alpha_fast_,
(pf_init_model_fn_t)AmclNode::uniformPoseGenerator,
reinterpret_cast<void *>(map_));
(pf_init_model_fn_t)AmclNode::uniformPoseGenerator);
pf_->pop_err = pf_err_;
pf_->pop_z = pf_z_;

Expand Down
7 changes: 3 additions & 4 deletions nav2_amcl/src/pf/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int pf_resample_limit(pf_t * pf, int k);
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)
pf_init_model_fn_t random_pose_fn)
{
int i, j;
pf_t * pf;
Expand All @@ -59,7 +59,6 @@ pf_t * pf_alloc(
pf = calloc(1, sizeof(pf_t));

pf->random_pose_fn = random_pose_fn;
pf->random_pose_data = random_pose_data;

pf->min_samples = min_samples;
pf->max_samples = max_samples;
Expand Down Expand Up @@ -291,7 +290,7 @@ void pf_update_sensor(pf_t * pf, pf_sensor_model_fn_t sensor_fn, void * sensor_d


// Resample the distribution
void pf_update_resample(pf_t * pf)
void pf_update_resample(pf_t * pf, void * random_pose_data)
{
int i;
double total;
Expand Down Expand Up @@ -344,7 +343,7 @@ void pf_update_resample(pf_t * pf)
sample_b = set_b->samples + set_b->sample_count++;

if (drand48() < w_diff) {
sample_b->pose = (pf->random_pose_fn)(pf->random_pose_data);
sample_b->pose = (pf->random_pose_fn)(random_pose_data);
} else {
// Can't (easily) combine low-variance sampler with KLD adaptive
// sampling, so we'll take the more traditional route.
Expand Down

0 comments on commit cc6f205

Please sign in to comment.