Skip to content

Conversation

@pele1410
Copy link
Contributor

@pele1410 pele1410 commented Dec 1, 2025

Basic Info

Info Please fill out this column
Ticket(s) this addresses #5710
Primary OS tested on Ubuntu 24.04 docker container
Robotic platform tested on Gazebo simulation of a USV
Does this PR contain AI generated software? No
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

Prevent the costmap_2d_publisher from trying to publish when it is not active.

Description of documentation updates required from your changes

N/A

Description of how this change was tested

Replicated the steps to produce the issue in #5710 and did not see the issue.


Future work that may be required in bullet points

This is not likely the root cause for the out-of-bounds index access but:

  • it seems logically correct to prevent publication unless active
  • it has the affect of side-stepping the issue

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists
  • Should this be backported to current distributions? If so, tag with backport-*.
Christopher Thompson added 3 commits December 1, 2025 12:53
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
@pele1410
Copy link
Contributor Author

pele1410 commented Dec 1, 2025

Updated against main branch instead of jazzy

@SteveMacenski SteveMacenski linked an issue Dec 1, 2025 that may be closed by this pull request

void Costmap2DPublisher::publishCostmap()
{
if(!active_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!active_) {
if (!active_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is active_ ever set to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question. I naively thought it was already used and working. Will look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is active_ ever set to true?

Ok, looking at the active_ variable, it is definitely never set. The doxy says it's based on the update frequency, but that's not a property of the costmap it's a property of the Costmap2DROS object. I don't know if this was a property that was moved at some point in time and active_ is just leftover cruft or if it's some unimplemented feature.

I see there are 2 options:

  1. Just yank active_ and active() from the Costmap2DPublisher
  2. Add a setter to so Costmap2DPublisher can set active_. This could be directly (void set_active(bool active)) or indirectly (void set_publish_rate (double rate)). The former seems to make more sense given there is no concept of a rate in the Costmap2DPublisher

I'm inclined to think this is just cruft, so should go with option 1. Up to you guys.

Copy link
Contributor Author

@pele1410 pele1410 Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is a 3rd option where the Costmap2DROS or Costmap2DPublisher integrate the actual enabled param for each layer into the decision to publish. I need to look into how that param gets plumbed through to see if it's available to use in the Costmap2DROS

Edit: I don't think this will work. I worked up a stub change where the Costmap2DROS simply doesn't create the publishers if the plugin isn't enabled; but that happens in on_configure stage and would be fine except most layers allow dynamic params which would mean the layer could get an updated "enable" value but the Costmap2DROS would have no way (without additional plumbing) to suddenly create a publisher for it.

Putting the check lower in Costmap2DROS::mapUpdateLoop there isn't any association with the layer Publisher and layer itself; and the latter is what has the isEnabled() flag.

The only way I can see to implement this functionality is to

  1. Remove active as a concept from the Costmap2DPublisher
  2. Pass a weak_pointer of the Layer to the Costmap2DPublisher so it can check on each publishCostmap call whether the layer is enabled or not.
@SteveMacenski
Copy link
Member

@pele1410 any update?

@SteveMacenski
Copy link
Member

@pele1410 hey any updates? We'd love this in before the holiday season to knock this out

@pele1410
Copy link
Contributor Author

Sorry, got busy at work and haven't had a chance to circle back to this. Hoping to look into it over the Christmas break

@pele1410
Copy link
Contributor Author

Figured out that I could use the costmap_ object, so I went with slightly different implementation of choice 3

@pele1410 pele1410 force-pushed the bugfix-inactive-publishers branch from bab0d31 to 53714fc Compare December 30, 2025 19:44
Christopher Thompson added 2 commits December 30, 2025 13:47
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
@pele1410 pele1410 force-pushed the bugfix-inactive-publishers branch from 53714fc to 036e198 Compare December 30, 2025 19:47
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
...d/include/nav2_costmap_2d/costmap_2d_publisher.hpp 100.00% <ø> (ø)
nav2_costmap_2d/src/costmap_2d_publisher.cpp 85.71% <100.00%> (+0.09%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Copy link
Collaborator

@mini-1235 mini-1235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM functionally, just remove the extra scope

Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
@SteveMacenski SteveMacenski merged commit b766611 into ros-navigation:main Dec 31, 2025
17 checks passed
@pele1410
Copy link
Contributor Author

pele1410 commented Jan 5, 2026

Do I need to specifically request for this to be backported to Kilted? Or should I do it myself?

mergify bot pushed a commit that referenced this pull request Jan 5, 2026
* 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>
(cherry picked from commit b766611)
mergify bot pushed a commit that referenced this pull request Jan 5, 2026
* 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>
(cherry picked from commit b766611)
@mini-1235
Copy link
Collaborator

Hmm, I believe this would break the ABI since the active_ member variable is being removed. We’d be happy to accept the PR if you could backport just the following logic manually instead:

auto const costmap_layer = dynamic_cast<CostmapLayer *>(costmap_);
  if (costmap_layer != nullptr && !costmap_layer->isEnabled()) {
    return;
  }
@pele1410
Copy link
Contributor Author

pele1410 commented Jan 5, 2026

Hmm, I believe this would break the ABI since the active_ member variable is being removed. We’d be happy to accept the PR if you could backport just the following logic manually instead:

auto const costmap_layer = dynamic_cast<CostmapLayer *>(costmap_);
  if (costmap_layer != nullptr && !costmap_layer->isEnabled()) {
    return;
  }

Can do. Is there a deprecation marking you would like added to active_ (and associated method) since it was removed in main?

@mini-1235
Copy link
Collaborator

Can do. Is there a deprecation marking you would like added to active_ (and associated method) since it was removed in main?

No, at least for now we don't do that in Nav2. It's something we might consider in the future

Lotusymt pushed a commit to Lotusymt/navigation2 that referenced this pull request Jan 16, 2026
* 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>
SteveMacenski pushed a commit that referenced this pull request Jan 24, 2026
* 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>
SteveMacenski added a commit that referenced this pull request Jan 24, 2026
* No need to spam the logs (#5674)

Signed-off-by: Tim Clephas <tim.clephas@nobleo.nl>

* Conditionally call onLoop based on node status (#5700)

Signed-off-by: Steve Macenski <stevenmacenski@gmail.com>

* Allow for no progress checkers to be configured (#5701)

Signed-off-by: SteveMacenski <stevenmacenski@gmail.com>

* Fix: wait for drive_on_heading_client instead of backup_client (#5724)

The basic navigator was waiting for the backup_client in the
driveOnHeading function.

Signed-off-by: agennart <antoine.gennart@quimesis.be>
Co-authored-by: agennart <antoine.gennart@quimesis.be>

* Fix: reset controller_server loop_rate when missed desired rate #5712 (#5723)

When a single iteration takes longer than the expected period,
this impacts the next iterations behavior since they will have
less time to perform the control logic, thus increasing the actual
controller_frequency. By resetting the loop_rate on sleep() failure,
this ensures that each iteration will have a full period to exectue its
logic.

Signed-off-by: agennart <antoine.gennart@quimesis.be>
Co-authored-by: agennart <antoine.gennart@quimesis.be>

* temporary fix bug null pointer (#5749)

* temporary fix bug null pointer

Signed-off-by: suifengersan123 <yangabc810@gmail.com>

* add return

Signed-off-by: suifengersan123 <yangabc810@gmail.com>

* remove return

Signed-off-by: suifengersan123 <yangabc810@gmail.com>

---------

Signed-off-by: suifengersan123 <yangabc810@gmail.com>

* fix: change warning to exception when goal poses cannot be transformed (#5759)

- Replace RCLCPP_WARN with std::runtime_error exception in onPreempt method
- Remove bt_action_server_->terminatePendingGoal() call after accepting goal
- Add required stdexcept include for exception handling

Fixes issue where navigators accept pending goal but are not properly
terminated if rejected during goal pose transformation.

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>

* Update obstacle layer usage of max ranges (#5697)

* Use cell distance for obstacle marking max range

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Don't raytrace clear the cell containing the current observation

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Add tests for max marking and clearing ranges

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Fix cpplint failures

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Fix distance calculation

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* fix casting, formatting

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* check origin is in map, update CMakeLists

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* use hypot instead of squared dist

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Move origin calc out of loop

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Revert don't raytrace observation cell

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Revert don't raytrace origin if it is observation cell

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* Remove new line

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

---------

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>

* [mppi] Don't reset zone-based speed limits (#5768)

* [mppi] Don't reset zone-based speed limits

Signed-off-by: Adi Vardi <adi.vardi@enway.ai>

* [mppi] update motion model params from speed_limit

Signed-off-by: Adi Vardi <adi.vardi@enway.ai>

* fix linting issue

Signed-off-by: Adi Vardi <adi.vardi@enway.ai>

* Revert: reset speed limits after param change

Signed-off-by: Adi Vardi <adi.vardi@enway.ai>

---------

Signed-off-by: Adi Vardi <adi.vardi@enway.ai>

* Bugfix inactive publishers (#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>

* Fix MAX_NON_OBSTACLE_COST in theta star planner (#5865)

Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>

* Bump jazzy to 1.3.11 for release

Signed-off-by: SteveMacenski <stevenmacenski@gmail.com>

---------

Signed-off-by: Tim Clephas <tim.clephas@nobleo.nl>
Signed-off-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: SteveMacenski <stevenmacenski@gmail.com>
Signed-off-by: agennart <antoine.gennart@quimesis.be>
Signed-off-by: suifengersan123 <yangabc810@gmail.com>
Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>
Signed-off-by: Adi Vardi <adi.vardi@enway.ai>
Signed-off-by: Christopher Thompson <cthompson@metalsharkboats.com>
Signed-off-by: mini-1235 <mauricepurnawan@gmail.com>
Co-authored-by: Tim Clephas <tim.clephas@nobleo.nl>
Co-authored-by: Saitama <gennartan@users.noreply.github.com>
Co-authored-by: agennart <antoine.gennart@quimesis.be>
Co-authored-by: suifengersan123 <136066397+suifengersan123@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Simon Dathan <simon.dathan@kudan.eu>
Co-authored-by: Adi Vardi <57910756+adivardi@users.noreply.github.com>
Co-authored-by: Christopher Thompson <pele1410@gmail.com>
Co-authored-by: Christopher Thompson <cthompson@metalsharkboats.com>
Co-authored-by: Maurice Alexander Purnawan <mauricepurnawan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment