Skip to content

Conversation

@sd-kudan
Copy link


Basic Info

Info Please fill out this column
Ticket(s) this addresses #5476
Primary OS tested on Ubuntu
Robotic platform tested on gazebo simulation
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

To address issue reported in #5476 of obstacles being cleared when reversing away from them, the following changes are made:

  • When marking obstacles from new observations, the check against obstacle_max_range is done in grid cell space for consistency with the ray tracing free space check against raytrace_max_range
  • When ray tracing, excluded the cell containing the observation point so that an obstacle is not cleared if it is present in the current measurement but raytrace_max_range > obstacle_max_range

Description of documentation updates required from your changes

Description of how this change was tested

  • Unit tests added for obstacle layer marking and clearing
  • Tested in gazebo simulation

Demo

Before:

obstacle_layer_clearing.mp4

After:

obstacle_layer.mp4

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 Nov 20, 2025

@sd-kudan, 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).

@SteveMacenski
Copy link
Member

Can you rebase / pull in main (we squash merge anyways) to get CI to turn over? I want to see the tests pass before I dig in. I'm going to need to really dive into code surrounding this for a full review since its a big change with subtle potential issues, so before I do that I want to make sure automated testing doesn't already flag issues that makes my time unnecessary :-)

Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>
Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>
Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>
Signed-off-by: Simon Dathan <simon.dathan@kudan.eu>
@sd-kudan sd-kudan force-pushed the sdathan/update-obstacle-layer-usage-of-max-range branch from be10620 to cea3222 Compare November 25, 2025 09:25
Comment on lines 555 to 563
unsigned int origin_cell_x;
unsigned int origin_cell_y;
worldToMap(obs.origin_.x, obs.origin_.y, origin_cell_x, origin_cell_y);
unsigned int point_cell_x;
unsigned int point_cell_y;
worldToMap(px, py, point_cell_x, point_cell_y);
int delta_x = point_cell_x - origin_cell_x;
int delta_y = point_cell_y - origin_cell_y;
unsigned int max_delta = std::max(std::abs(delta_x), std::abs(delta_y));
Copy link
Member

Choose a reason for hiding this comment

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

This needs to compute the L2 distance (squared or unsquared) - just takign the maximum of X or Y is not a valid distance calculation for range. I think you're misunderstanding the raytraceLine / bresenham2D algorithm. We are marching in the X or Y direction but we do so scaled from the total length to march the L2 distance.

I think essentially the previous calculation should remain, but based on cell length rather than world coordinates.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for taking a look - have updated to use squared distance.

Comment on lines 790 to 798
// Calculate the distance to the endpoint in cells to limit the maximum length of the raytrace
// and avoid clearing the endpoint cell.
int delta_x = x1 - x0;
int delta_y = y1 - y0;
unsigned int cell_dist_to_endpoint = std::max(std::abs(delta_x), std::abs(delta_y));
if (cell_dist_to_endpoint < 1) {
continue;
}
cell_raytrace_max_range = std::min(cell_raytrace_max_range, cell_dist_to_endpoint - 1);
Copy link
Member

Choose a reason for hiding this comment

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

All marking is done after all clearing, so this shouldn't be necessary.

for (const auto & clearing_observation : clearing_observations) {
raytraceFreespace(*clearing_observation, min_x, min_y, max_x, max_y);
}
// place the new obstacles into a priority queue... each with a priority of zero to begin with
for (const auto & observation : observations) {
const Observation & obs = *observation;

Copy link
Author

Choose a reason for hiding this comment

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

This allows setting raytrace_max_range > obstacle_max_range which can help clear obstacles which are moving away from the sensor, without clearing stationary obstacles while moving away from them for example.

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

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
nav2_costmap_2d/plugins/obstacle_layer.cpp 82.67% <100.00%> (+0.43%) ⬆️

... 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants