Skip to content

Commit e7b797b

Browse files
pele1410Christopher Thompson
authored andcommitted
Bugfix inactive publishers (ros-navigation#5748)
* Do not publish costmap unless active Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Fix style Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Fix typo Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Use layers isEnabled() to prevent publishing Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Fix style Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Add missing include for CostmapLayer type Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> * Remove extra scoping Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> --------- Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com> Co-authored-by: Christopher Thompson <cthompson@metalsharkboats.com>
1 parent b282da0 commit e7b797b

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

nav2_costmap_2d/include/nav2_costmap_2d/costmap_2d_publisher.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,11 @@ class Costmap2DPublisher
123123
}
124124

125125
/**
126-
* @brief Publishes the visualization data over ROS
126+
* @brief Publishes the visualization data over ROS
127+
* @note Only publishes when the associated layer is enabled
127128
*/
128129
void publishCostmap();
129130

130-
/**
131-
* @brief Check if the publisher is active
132-
* @return True if the frequency for the publisher is non-zero, false otherwise
133-
*/
134-
bool active()
135-
{
136-
return active_;
137-
}
138-
139131
private:
140132
/** @brief Prepare grid_ message for publication. */
141133
void prepareGrid();
@@ -166,7 +158,6 @@ class Costmap2DPublisher
166158
unsigned int x0_, xn_, y0_, yn_;
167159
double saved_origin_x_;
168160
double saved_origin_y_;
169-
bool active_;
170161
bool always_send_full_costmap_;
171162
double map_vis_z_;
172163

nav2_costmap_2d/src/costmap_2d_publisher.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* David V. Lu!!
3838
*********************************************************************/
3939
#include "nav2_costmap_2d/costmap_2d_publisher.hpp"
40+
#include "nav2_costmap_2d/costmap_layer.hpp"
4041

4142
#include <string>
4243
#include <memory>
@@ -59,7 +60,6 @@ Costmap2DPublisher::Costmap2DPublisher(
5960
: costmap_(costmap),
6061
global_frame_(global_frame),
6162
topic_name_(topic_name),
62-
active_(false),
6363
always_send_full_costmap_(always_send_full_costmap),
6464
map_vis_z_(map_vis_z)
6565
{
@@ -236,6 +236,11 @@ std::unique_ptr<nav2_msgs::msg::CostmapUpdate> Costmap2DPublisher::createCostmap
236236

237237
void Costmap2DPublisher::publishCostmap()
238238
{
239+
auto const costmap_layer = dynamic_cast<CostmapLayer *>(costmap_);
240+
if (costmap_layer != nullptr && !costmap_layer->isEnabled()) {
241+
return;
242+
}
243+
239244
float resolution = costmap_->getResolution();
240245
if (always_send_full_costmap_ || grid_resolution_ != resolution ||
241246
grid_width_ != costmap_->getSizeInCellsX() ||

0 commit comments

Comments
 (0)