Skip to content

Conversation

DylanDeCoeyer-Quimesis
Copy link
Contributor

Until now, the special OccupancyGrid value "99" attributed to the inscribed inflated obstacles was mapped to 251 on conversion to Costmap2D, using the default linear relation. This is incorrect since a special value exists in the Costmap2D for inscribed obstacles: 253.

This commit makes sure that the correct value is used in case of inflated obstacle.


Basic Info

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

Description of documentation updates required from your changes

Description of how this change was tested


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

@SteveMacenski
Copy link
Member

@DylanDeCoeyer-Quimesis I need much more detailed explanation of this, possibly with a diagram to meaningfully review it. I believe you that something may benefit from this, but I need to understand in detail like you do with references 😉

This touches a very old and very established piece of software, so some explanation for myself and future readers is important

@DylanDeCoeyer-Quimesis
Copy link
Contributor Author

@SteveMacenski sure! The class Costmap2DPublisher is using a cost translation table when converting Costmap2D to OccupancyGrid. This conversion table associates the value nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE (253) to 99.

To recover the original Costmap2D from the OccupancyGrid on the subscription side, the subscribers must use the same (reciprocal) conversion table. However, in the case of the StaticLayer subscription, the special value attributed to the inscribed inflated obstacle was ignored. The usual scaling factor was applied:

double scale = static_cast<double>(value) / lethal_threshold_; // for inscr. inflated obst.: 99 / 100 = 0.99
return scale * LETHAL_OBSTACLE; // for inscr. inflated obst.: 0.99 * 254 = 251.46 => 251

So, this costmap layer initially supposed to copy the incoming costmap was transforming every inscribed inflated obstacle cells (253) into non lethal obstacle cells with cost of 251.

If this is the expected behavior for any historical reason, then I'll have at least to make the StaticLayer::interpretValue method virtual to let inheriting classes customize the behavior of this method and add INSCRIBED_INFLATED_OBSTACLE.

@SteveMacenski
Copy link
Member

Thanks! LGTM. CI had an unexpected test fail, so running again to make sure it wasn't just a rare one off.

@SteveMacenski
Copy link
Member

SteveMacenski commented Sep 30, 2025

@DylanDeCoeyer-Quimesis please rebase or pull in main to acquire #5569 to fix CI

@DylanDeCoeyer-Quimesis DylanDeCoeyer-Quimesis force-pushed the fix_static_layer_interpretation branch 5 times, most recently from 2d67d9b to 6a58990 Compare October 1, 2025 12:36
@DylanDeCoeyer-Quimesis
Copy link
Contributor Author

@SteveMacenski there is still an issue with the unit tests, but I don't understand it. It says the number of INSCRIBED_INFLATED_OBSTACLE cells is 28 while 78 was expected by the ASSERT_EQ. But when I modify the ASSERT_EQ to expect 28, it says that the number of cells is 78...

    [costmap_tests-4] /opt/overlay_ws/src/navigation2/nav2_costmap_2d/test/integration/inflation_tests.cpp:465: Failure
    [costmap_tests-4] Expected equality of these values:
    [costmap_tests-4]   countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
    [costmap_tests-4]     Which is: 28
    [costmap_tests-4]   78u
    [costmap_tests-4]     Which is: 78

@SteveMacenski
Copy link
Member

I'm not sure - I'd look at printing the map (uncommenting printMap line) and seeing what it looks like to debug further. I see inline in the code it has 28u - not that I think it'll solve it, but I triggered CI again to see what it does

@kira-oli
Copy link

kira-oli commented Oct 8, 2025

@DylanDeCoeyer-Quimesis I have one question about this. For the e.g. the smac planner to work we need a inflation layer. Will inflation as is work with an already inflated static layer properly? I guess yes because it starts with the lethal pixels and builds the map from it or do I miss anything?

@DylanDeCoeyer-Quimesis
Copy link
Contributor Author

@kira-oli Yes that's right, if my understanding is correct. The inflation layer starts from the lethal pixels and does not mind about the inscribed inflated pixels: https://github.com/ros-navigation/navigation2/blob/main/nav2_costmap_2d/include/nav2_costmap_2d/inflation_layer.hpp#L159

When setting the pixel cost, it takes the highest value between the new and the old cost: https://github.com/ros-navigation/navigation2/blob/main/nav2_costmap_2d/plugins/inflation_layer.cpp#L297

@SteveMacenski
Copy link
Member

@DylanDeCoeyer-Quimesis I'm retriggering CI to see if that fixes things. If you could pull in main / rebase, that would be appreciated. We fixed some stuff recently that should make this pass if that is indeed a flaky issue

…ribed inflated obstacles

Until now, the special OccupancyGrid value "99" attributed to the
inscribed inflated obstacles was mapped to 251 on conversion to
Costmap2D, using the default linear relation. This is incorrect since a
special value exists in the Costmap2D for inscribed obstacles: 253.

This commit makes sure that the correct value is used in case of
inflated obstacle.

Signed-off-by: Dylan De Coeyer <[email protected]>
@DylanDeCoeyer-Quimesis DylanDeCoeyer-Quimesis force-pushed the fix_static_layer_interpretation branch from 6a58990 to 056485c Compare October 9, 2025 08:07
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.

Final test failed:

[costmap_tests-4] [ RUN      ] TestNode.testInflation
[costmap_tests-4] [INFO] [1759998159.472056047] [inflation_test_node]: 
[costmap_tests-4] 	inflation_test_node lifecycle node launched. 
[costmap_tests-4] 	Waiting on external lifecycle transitions to activate
[costmap_tests-4] 	See https://design.ros2.org/articles/node_lifecycle.html for more information.
[costmap_tests-4] [INFO] [1759998159.472279993] [inflation_test_node]: Subscribing to the map topic (/map) with transient local durability
[costmap_tests-4] [INFO] [1759998159.474496863] [inflation_test_node]: Subscribed to Topics: 
[costmap_tests-4] [INFO] [1759998159.475486091] [inflation_test_node]: StaticLayer: Resizing costmap to 10 X 10 at 1.000000 m/pix
[costmap_tests-4] /opt/overlay_ws/src/navigation2/nav2_costmap_2d/test/integration/inflation_tests.cpp:465: Failure
[costmap_tests-4] Expected equality of these values:
[costmap_tests-4]   countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
[costmap_tests-4]     Which is: 28
[costmap_tests-4]   78u
[costmap_tests-4]     Which is: 78
[costmap_tests-4] 
[costmap_tests-4] [INFO] [1759998159.475806143] [inflation_test_node]: Destroying
[costmap_tests-4] [WARN] [1759998159.475823890] [rclcpp_lifecycle]: LifecycleNode is not shut down: Node still in state(1) in destructor
[costmap_tests-4] [  FAILED  ] TestNode.testInflation (207 ms)

@DylanDeCoeyer-Quimesis DylanDeCoeyer-Quimesis force-pushed the fix_static_layer_interpretation branch 3 times, most recently from da70a3e to a67f218 Compare October 10, 2025 11:50
@DylanDeCoeyer-Quimesis
Copy link
Contributor Author

DylanDeCoeyer-Quimesis commented Oct 10, 2025

Final test failed:

[costmap_tests-4] [ RUN      ] TestNode.testInflation
[costmap_tests-4] [INFO] [1759998159.472056047] [inflation_test_node]: 
[costmap_tests-4] 	inflation_test_node lifecycle node launched. 
[costmap_tests-4] 	Waiting on external lifecycle transitions to activate
[costmap_tests-4] 	See https://design.ros2.org/articles/node_lifecycle.html for more information.
[costmap_tests-4] [INFO] [1759998159.472279993] [inflation_test_node]: Subscribing to the map topic (/map) with transient local durability
[costmap_tests-4] [INFO] [1759998159.474496863] [inflation_test_node]: Subscribed to Topics: 
[costmap_tests-4] [INFO] [1759998159.475486091] [inflation_test_node]: StaticLayer: Resizing costmap to 10 X 10 at 1.000000 m/pix
[costmap_tests-4] /opt/overlay_ws/src/navigation2/nav2_costmap_2d/test/integration/inflation_tests.cpp:465: Failure
[costmap_tests-4] Expected equality of these values:
[costmap_tests-4]   countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
[costmap_tests-4]     Which is: 28
[costmap_tests-4]   78u
[costmap_tests-4]     Which is: 78
[costmap_tests-4] 
[costmap_tests-4] [INFO] [1759998159.475806143] [inflation_test_node]: Destroying
[costmap_tests-4] [WARN] [1759998159.475823890] [rclcpp_lifecycle]: LifecycleNode is not shut down: Node still in state(1) in destructor
[costmap_tests-4] [  FAILED  ] TestNode.testInflation (207 ms)

@SteveMacenski As I said above, the output is very weird. I've set the expected value to 28 following your comment, and here is the output that I get now for the same test:

 [costmap_tests-4] [ RUN      ] TestNode.testInflation
    [costmap_tests-4] [INFO] [1760097423.428364045] [inflation_test_node]: 
    [costmap_tests-4]   inflation_test_node lifecycle node launched. 
    [costmap_tests-4]   Waiting on external lifecycle transitions to activate
    [costmap_tests-4]   See https://design.ros2.org/articles/node_lifecycle.html for more information.
    [costmap_tests-4] [INFO] [1760097423.428587300] [inflation_test_node]: Subscribing to the map topic (/map) with transient local durability
    [costmap_tests-4] [INFO] [1760097423.430805467] [inflation_test_node]: Subscribed to Topics: 
    [costmap_tests-4] [INFO] [1760097423.431805358] [inflation_test_node]: StaticLayer: Resizing costmap to 10 X 10 at 1.000000 m/pix
    [costmap_tests-4] /opt/overlay_ws/src/navigation2/nav2_costmap_2d/test/integration/inflation_tests.cpp:465: Failure
    [costmap_tests-4] Expected equality of these values:
    [costmap_tests-4]   countValues(*costmap, nav2_costmap_2d::INSCRIBED_INFLATED_OBSTACLE)
    [costmap_tests-4]     Which is: 78
    [costmap_tests-4]   28u
    [costmap_tests-4]     Which is: 28
    [costmap_tests-4] 
    [costmap_tests-4] [INFO] [1760097423.432055519] [inflation_test_node]: Destroying

@SteveMacenski
Copy link
Member

I agree its very weird. Try busting the cache to see if that helps. In the .circleci directory config, change the vXX (I think v39 or v40 right now) and increment one. There are 3 places it appears and you need to change all 3.

@DylanDeCoeyer-Quimesis DylanDeCoeyer-Quimesis force-pushed the fix_static_layer_interpretation branch 2 times, most recently from 3272a15 to 23a3aa5 Compare October 13, 2025 08:27
@DylanDeCoeyer-Quimesis DylanDeCoeyer-Quimesis force-pushed the fix_static_layer_interpretation branch from 23a3aa5 to cd74efa Compare October 13, 2025 10:30
@SteveMacenski
Copy link
Member

Still failing that test :( Do you see this issue locally too?

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.

3 participants