Skip to content

Conversation

@Lotusymt
Copy link


Basic Info

Info Please fill out this column
Ticket(s) this addresses Fixes/Implements #4794
Primary OS tested on Ubuntu 22.04 (ROS 2 Rolling)
Robotic platform tested on unit tests + launch test (no physical robot)
Does this PR contain AI generated software? Yes and it is marked inline in the code
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

  • Add CostmapSource to Collision Monitor to allow collision checks against a subscribed local costmap (nav2_msgs/Costmap).
  • Wire CostmapSource into CollisionMonitor::configureSources() and expose params:
    • *.topic, *.cost_threshold (0–255), *.treat_unknown_as_obstacle (bool).
  • Provide minimal example in params/collision_monitor_params.yaml.
  • Update README.md:
    • Add Costmap to the list of supported sources.
    • Add a concise note about latency warning when using a costmap source.
  • Add dataset-based integration test (bag replay):
    • test/collision_monitor_node_bag.cpp (metrics: time-to-stop, hold-stop%, time-to-resume, false-stop%).
    • test/collision_monitor_node_bag.launch.py to bring up CM, play a tiny bag, and run gtest.
    • Tiny mcap.zstd bag + test YAML installed for get_package_share_directory().

Description of documentation updates required from your changes

  • docs.nav2.org (separate PR): add a short .. warning:: box on the Collision Monitor page describing the trade-offs of using a costmap source (persistence vs. latency/staleness), and list the new parameters.
  • Ensure the new source and parameters are included in any parameter reference and tuning sections.
  • (This PR) README.md already updated with a brief note and source entry.

Description of how this change was tested

  • Unit/launch tests: Added a launch gtest that replays a tiny bag and checks CM behavior (time-to-stop, hold-stop%, time-to-resume, false-stop%). Ran colcon test --packages-select nav2_collision_monitor; existing unit tests + the new launch test pass on Ubuntu.
  • ABI: Verified that ABI was preserved.

Future work that may be required in bullet points

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-*.

@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2025

@Lotusymt, your PR has failed to build. Please check CI outputs and resolve issues.
You may need to rebase or pull in main due to API changes (or your contribution genuinely fails).

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

Checkout Linting / CI jobs that are failing. You may need to pull in main / rebase as well.

Please provide some comments inline in the test files so someone can understand what each are doing -- its a little difficult to read them and understand (1) fully what each do, (2) the difference in what one covers the other doesn't, and (3) the intent

But, by in large, this looks great!

find_package(nav2_costmap_2d REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(nav2_util REQUIRED)
find_package(rosgraph_msgs REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

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

Add this to the build testing section


> **⚠️ when using CostmapSource**
> Collision Monitor normally **bypasses the costmap** to minimize reaction latency using fresh sensor data.
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
> Use at your own caution or when using external costmap sources from derived sources.

max_height: 0.5
use_global_height: False
enabled: True
costmap:
Copy link
Member

Choose a reason for hiding this comment

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

You can keep this in the file as an example, but please comment out so its not active. Also change the topic to local_costmap/costmap so namespaces works

{
public:
CostmapSource(

Copy link
Member

Choose a reason for hiding this comment

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

Remove extra sapce

}
std::string source_topic;
getParameters(source_topic);
rclcpp::QoS qos = rclcpp::SystemDefaultsQoS();
Copy link
Member

Choose a reason for hiding this comment

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

Use Nav2 QoS profiles from nav2_ros_common

Comment on lines 128 to 130
nav2::declare_parameter_if_not_declared(
node, thresh_name, rclcpp::ParameterValue(253));
int v = node->get_parameter(thresh_name).as_int();
Copy link
Member

Choose a reason for hiding this comment

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

Use the new declare_or_get_parameter API in nav2::LIfecycleNode

const int idx = y * meta.size_x + x;

const uint8_t c = cm.data[idx];
const bool is_obstacle = (c >= cost_threshold_ && c < 255) ||
Copy link
Member

Choose a reason for hiding this comment

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

Use the costmap values for UNKNOWN rather than hardcoding 255

def __init__(self):
super().__init__('fake_cm_bag_source')
# Use sim time so /clock drives timestamps
# self.set_parameters([Parameter('use_sim_time', value=True)])
Copy link
Member

Choose a reason for hiding this comment

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

Commented out?

// Window where obstacle exists in the bag
stop_window_start_ = this->declare_parameter<double>("stop_window_start", 3.0);
stop_window_end_ = this->declare_parameter<double>("stop_window_end", 8.0);

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

@Lotusymt
Copy link
Author

Thanks for the detailed review, Steve!
I’ll address the issues over the next couple of days and push updates soon.

@SteveMacenski
Copy link
Member

SteveMacenski commented Oct 23, 2025

Just so you're aware, I'm leaving tomorrow morning for ROSCon so it might be a little while (a week or so) before I give it another review, but it is not forgotten!

@Lotusymt Lotusymt force-pushed the feature/costmap-source-main branch from b4d7608 to fc27b4c Compare October 31, 2025 03:56
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nav2_collision_monitor/src/costmap.cpp 86.36% 6 Missing ⚠️
Files with missing lines Coverage Δ
...2_collision_monitor/src/collision_monitor_node.cpp 97.01% <100.00%> (+0.04%) ⬆️
nav2_collision_monitor/src/costmap.cpp 86.36% <86.36%> (ø)

... and 13 files with indirect coverage changes

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

@Lotusymt
Copy link
Author

Hi Steve,
I know this update may trigger a notification, but it’s not ready yet. I’m still investigating an unexpected test failure, so please skip this revision for now. I’ll ping you once it’s ready. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants