Skip to content

Commit 44b3450

Browse files
mlherdCarl Delsey
authored andcommitted
fix for #1363 - use clearMap instead of reset to clear costmaps (#1412)
* -fix for #1363. -created clearMap function for each layer. -use clearMap instead of reset to clear the costmaps * -function name change -infilation layer clearMap change -make resetMap a pure virtual function * Changing clearMaps back to reset * Fix uncrustify error * Fixing lifecycle transitions and tests now that reset doesn't act as a cleanup function * Updating this based on the approach taken in PR #1431 * Moving voxel_grid reset to the resetMaps function. * Missed adding resetMaps back to header. * Adding some comments to help navigate the inheritance hierarchy
1 parent f5c216b commit 44b3450

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

nav2_costmap_2d/include/nav2_costmap_2d/inflation_layer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class InflationLayer : public Layer
9999

100100
virtual void reset()
101101
{
102-
onInitialize();
102+
matchSize();
103103
}
104104

105105
/** @brief Given a distance, compute a cost.

nav2_costmap_2d/include/nav2_costmap_2d/layer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Layer // TODO(mjeronimo): public nav2_util::LifecycleHelperInterface
6969
std::shared_ptr<nav2_util::ParameterEventsSubscriber> param_subscriber = nullptr);
7070
virtual void deactivate() {} /** @brief Stop publishers. */
7171
virtual void activate() {} /** @brief Restart publishers if they've been stopped. */
72-
virtual void reset() {}
72+
virtual void reset() = 0;
7373

7474
/**
7575
* @brief This is called by the LayeredCostmap to poll this plugin as to how

nav2_costmap_2d/include/nav2_costmap_2d/obstacle_layer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class ObstacleLayer : public CostmapLayer
8383
virtual void activate();
8484
virtual void deactivate();
8585
virtual void reset();
86+
/**
87+
* @brief triggers the update of observations buffer
88+
*/
89+
void resetBuffersLastUpdated();
8690

8791
/**
8892
* @brief A callback to handle buffering LaserScan messages

nav2_costmap_2d/plugins/obstacle_layer.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,9 @@ ObstacleLayer::activate()
619619
observation_subscribers_[i]->subscribe();
620620
}
621621
}
622-
623-
for (unsigned int i = 0; i < observation_buffers_.size(); ++i) {
624-
if (observation_buffers_[i]) {
625-
observation_buffers_[i]->resetLastUpdated();
626-
}
627-
}
622+
resetBuffersLastUpdated();
628623
}
624+
629625
void
630626
ObstacleLayer::deactivate()
631627
{
@@ -651,10 +647,19 @@ ObstacleLayer::updateRaytraceBounds(
651647
void
652648
ObstacleLayer::reset()
653649
{
654-
deactivate();
655650
resetMaps();
651+
resetBuffersLastUpdated();
656652
current_ = true;
657-
activate();
653+
}
654+
655+
void
656+
ObstacleLayer::resetBuffersLastUpdated()
657+
{
658+
for (unsigned int i = 0; i < observation_buffers_.size(); ++i) {
659+
if (observation_buffers_[i]) {
660+
observation_buffers_[i]->resetLastUpdated();
661+
}
662+
}
658663
}
659664

660665
} // namespace nav2_costmap_2d

nav2_costmap_2d/plugins/static_layer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ StaticLayer::deactivate()
122122
void
123123
StaticLayer::reset()
124124
{
125-
map_sub_.reset();
126-
map_update_sub_.reset();
127-
128-
onInitialize();
125+
has_updated_data_ = true;
129126
}
130127

131128
void

nav2_costmap_2d/plugins/voxel_layer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,18 @@ void VoxelLayer::matchSize()
167167

168168
void VoxelLayer::reset()
169169
{
170-
voxel_pub_->on_deactivate();
171-
deactivate();
170+
// Call the base class method before adding our own functionality
171+
ObstacleLayer::reset();
172172
resetMaps();
173-
activate();
174-
voxel_pub_->on_activate();
175173
}
176174

177175
void VoxelLayer::resetMaps()
178176
{
179-
Costmap2D::resetMaps();
177+
// Call the base class method before adding our own functionality
178+
// Note: at the time this was written, ObstacleLayer doesn't implement
179+
// resetMaps so this goes to the next layer down Costmap2DLayer which also
180+
// doesn't implement this, so it actually goes all the way to Costmap2D
181+
ObstacleLayer::resetMaps();
180182
voxel_grid_.reset();
181183
}
182184

0 commit comments

Comments
 (0)