-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Draft] CollisionMonitor: add CostmapSource + dataset-based bag test #5642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Lotusymt
wants to merge
6
commits into
ros-navigation:main
Choose a base branch
from
Lotusymt:feature/costmap-source-main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1743667
Collision Monitor: add costmap sourced(unit tests)
Lotusymt 80bfe5c
nav2_collision_monitor: modified CostmapSource + dataset-based bag te…
Lotusymt 7bb7663
modified: nav2_collision_monitor/README.md
Lotusymt 4203283
- annotate files to indicate AI-assisted drafts
Lotusymt fc27b4c
collision_monitor: fix linter and address issues in the comment
Lotusymt 09d2f6a
nav2_collision_monitor: fix lint, coverage, and collision_monitor_nod…
Lotusymt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
nav2_collision_monitor/include/nav2_collision_monitor/costmap.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Copyright (c) 2025 Angsa Robotics | ||
| // Copyright (c) 2025 lotusymt | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_COLLISION_MONITOR__COSTMAP_HPP_ | ||
| #define NAV2_COLLISION_MONITOR__COSTMAP_HPP_ | ||
|
|
||
| /** | ||
| * @file costmap.hpp | ||
| * @brief Observation source that converts a Nav2 costmap topic into 2D points for Collision Monitor. | ||
| */ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "nav2_collision_monitor/source.hpp" | ||
| #include "nav2_msgs/msg/costmap.hpp" | ||
| #include <nav2_ros_common/lifecycle_node.hpp> | ||
| #include <nav2_ros_common/subscription.hpp> | ||
|
|
||
| namespace nav2_collision_monitor | ||
| { | ||
|
|
||
| /** | ||
| * @class CostmapSource | ||
| * @brief Reads nav2_msgs::msg::Costmap and produces obstacle points for Collision Monitor. | ||
| * | ||
| * Cells with cost >= @ref cost_threshold_ are exported as points. Optionally, NO_INFORMATION (255) | ||
| * can be treated as obstacles via @ref treat_unknown_as_obstacle_. | ||
| * | ||
| * Parameters (declared/queried in @ref getParameters): | ||
| * - `topic` (std::string): costmap topic name (relative is recommended). | ||
| * - `cost_threshold` (int, 0..255): minimum cost to consider a cell occupied. | ||
| * - `treat_unknown_as_obstacle` (bool): whether cost 255 should be treated as occupied. | ||
| */ | ||
| class CostmapSource : public Source | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Construct a CostmapSource. | ||
| * @param node Weak pointer to the lifecycle node. | ||
| * @param source_name Logical name of this source instance (for params/logs). | ||
| * @param tf_buffer Shared TF buffer for frame transforms. | ||
| * @param base_frame_id Robot base frame (e.g., "base_footprint"). | ||
| * @param global_frame_id Global frame of the costmap (e.g., "odom" or "map"). | ||
| * @param transform_tolerance Allowed TF age for transforms. | ||
| * @param source_timeout Max age of data before it is considered stale. | ||
| * @param base_shift_correction Whether to compensate robot motion during simulation checks. | ||
| */ | ||
| CostmapSource( | ||
| const nav2::LifecycleNode::WeakPtr & node, | ||
| const std::string & source_name, | ||
| const std::shared_ptr<tf2_ros::Buffer> tf_buffer, | ||
| const std::string & base_frame_id, | ||
| const std::string & global_frame_id, | ||
| const tf2::Duration & transform_tolerance, | ||
| const rclcpp::Duration & source_timeout, | ||
| const bool base_shift_correction); | ||
|
|
||
| /// @brief Destructor. | ||
| ~CostmapSource(); | ||
|
|
||
| /** | ||
| * @brief Declare and get parameters; create the subscription. | ||
| * | ||
| * Must be called during the node’s configuration phase (after construction, before use). | ||
| * Reads `topic`, `cost_threshold`, and `treat_unknown_as_obstacle`. | ||
| */ | ||
| void configure(); | ||
|
|
||
| /** | ||
| * @brief Produce current obstacle points from the latest costmap. | ||
| * @param curr_time Current time used for staleness checks and TF queries. | ||
| * @param[out] data Output vector of points in the base frame. | ||
| * @return true if valid, non-stale data were produced; false otherwise. | ||
| * | ||
| * @details | ||
| * - Returns false if no message has arrived or data are older than @ref source_timeout_. | ||
| * - Transforms points from costmap frame to @ref base_frame_id using @ref tf_buffer_. | ||
| * - Applies @ref cost_threshold_ and @ref treat_unknown_as_obstacle_. | ||
| */ | ||
| bool getData( | ||
| const rclcpp::Time & curr_time, | ||
| std::vector<Point> & data) override; | ||
|
|
||
| /** | ||
| * @brief Read parameters specific to the costmap source. | ||
| * @param[out] source_topic Resolved topic name to subscribe to. | ||
| * | ||
| * Declares/gets: `topic`, `cost_threshold`, `treat_unknown_as_obstacle`. | ||
| */ | ||
| void getParameters(std::string & source_topic); | ||
|
|
||
| private: | ||
| /** | ||
| * @brief Subscription callback to store the latest costmap message. | ||
| * @param msg Incoming costmap. | ||
| */ | ||
| void dataCallback(nav2_msgs::msg::Costmap::ConstSharedPtr msg); | ||
|
|
||
| /// @brief Latest costmap message. | ||
| nav2_msgs::msg::Costmap::ConstSharedPtr data_; | ||
|
|
||
| /// @brief Subscription handle for the costmap topic. | ||
| nav2::Subscription<nav2_msgs::msg::Costmap>::SharedPtr data_sub_; | ||
|
|
||
| /** | ||
| * @brief Minimum cost (0..255) considered as an obstacle. | ||
| * @note Typical values: 253 (inscribed), 254 (lethal). Inflation = 1..252. | ||
| */ | ||
| int cost_threshold_{253}; | ||
|
|
||
| /** | ||
| * @brief Whether cost 255 (NO_INFORMATION) is treated as an obstacle. | ||
| */ | ||
| bool treat_unknown_as_obstacle_{true}; | ||
| }; | ||
|
|
||
| } // namespace nav2_collision_monitor | ||
|
|
||
| #endif // NAV2_COLLISION_MONITOR__COSTMAP_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.