Skip to content

Commit c181750

Browse files
doisygGuillaume Doisy
andauthored
[AMCL] Rebuild cspace map only when needed (#5076)
* for LikelihoodFieldModel Signed-off-by: Guillaume Doisy <guillaume@dexory.com> * for LikelihoodFieldModelProb Signed-off-by: Guillaume Doisy <guillaume@dexory.com> * typo Signed-off-by: Guillaume Doisy <guillaume@dexory.com> * init max_occ_dist in map.c and remove unnecessary condition Signed-off-by: Guillaume Doisy <guillaume@dexory.com> --------- Signed-off-by: Guillaume Doisy <guillaume@dexory.com> Co-authored-by: Guillaume Doisy <guillaume@dexory.com>
1 parent 1a365e6 commit c181750

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

‎nav2_amcl/src/map/map.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ map_t * map_alloc(void)
4949
// Allocate storage for main map
5050
map->cells = (map_cell_t *) NULL;
5151

52+
// Initialize max_occ_dist to 0.0
53+
map->max_occ_dist = 0.0;
54+
5255
return map;
5356
}
5457

‎nav2_amcl/src/sensors/laser/likelihood_field_model.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ LikelihoodFieldModel::LikelihoodFieldModel(
3535
z_hit_ = z_hit;
3636
z_rand_ = z_rand;
3737
sigma_hit_ = sigma_hit;
38-
map_update_cspace(map, max_occ_dist);
38+
39+
// recompute cspace only when necessary, i.e. if:
40+
// - max_occ_dist changed
41+
// OR
42+
// - cspace was not computed yet, i.e. when map->max_occ_dist == 0.0 (and hence different from
43+
// max_occ_dist)
44+
if (map->max_occ_dist != max_occ_dist) {
45+
map_update_cspace(map, max_occ_dist);
46+
}
3947
}
4048

4149
double

‎nav2_amcl/src/sensors/laser/likelihood_field_model_prob.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ LikelihoodFieldModelProb::LikelihoodFieldModelProb(
4343
beam_skip_distance_ = beam_skip_distance;
4444
beam_skip_threshold_ = beam_skip_threshold;
4545
beam_skip_error_threshold_ = beam_skip_error_threshold;
46-
map_update_cspace(map, max_occ_dist);
46+
47+
// recompute cspace only when necessary, i.e. if:
48+
// - max_occ_dist changed
49+
// OR
50+
// - cspace was not computed yet, i.e. when map->max_occ_dist == 0.0 (and hence different from
51+
// max_occ_dist)
52+
if (map->max_occ_dist != max_occ_dist) {
53+
map_update_cspace(map, max_occ_dist);
54+
}
4755
}
4856

4957
// Determine the probability for the given pose

0 commit comments

Comments
 (0)