-
Couldn't load subscription status.
- Fork 1.6k
Path trackin conditon node #5602
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
Draft
silanus23
wants to merge
7
commits into
ros-navigation:main
Choose a base branch
from
silanus23:path-trackin-conditon-node
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.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a16f0ee
header added
silanus23 2425452
source file addition
silanus23 a303564
test file added
silanus23 6b4e7f8
Last additions
silanus23 7a02bf6
Styling changes
silanus23 3ea85d8
Adding left, right side errors
silanus23 9e50b94
minor changes
silanus23 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
75 changes: 75 additions & 0 deletions
75
...include/nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.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,75 @@ | ||
| // Copyright (c) 2025 Berkan Tali | ||
| // | ||
| // 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_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_WITHIN_PATH_TRACKING_BOUNDS_CONDITION_HPP_ | ||
| #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_WITHIN_PATH_TRACKING_BOUNDS_CONDITION_HPP_ | ||
|
|
||
| #include <string> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <limits> | ||
|
|
||
| #include "behaviortree_cpp/condition_node.h" | ||
| #include "nav2_ros_common/lifecycle_node.hpp" | ||
| #include "nav2_msgs/msg/tracking_feedback.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
|
|
||
| namespace nav2_behavior_tree | ||
| { | ||
|
|
||
| /** | ||
| * @brief A BT::ConditionNode that subscribes to /tracking_feedback and returns SUCCESS | ||
| * if the error is within the max_error input port, FAILURE otherwise | ||
| */ | ||
| class IsWithinPathTrackingBoundsCondition : public BT::ConditionNode | ||
| { | ||
| public: | ||
| IsWithinPathTrackingBoundsCondition( | ||
| const std::string & condition_name, | ||
| const BT::NodeConfiguration & conf); | ||
|
|
||
| IsWithinPathTrackingBoundsCondition() = delete; | ||
| ~IsWithinPathTrackingBoundsCondition() override = default; | ||
|
|
||
| /** | ||
| * @brief Function to read parameters and initialize class variables | ||
| */ | ||
| void initialize(); | ||
|
|
||
| BT::NodeStatus tick() override; | ||
|
|
||
| static BT::PortsList providedPorts() | ||
| { | ||
| return { | ||
| BT::InputPort<double>("max_error_right", "Maximum allowed tracking error on the right side"), | ||
| BT::InputPort<double>("max_error_left", "Maximum allowed tracking error left side") | ||
| }; | ||
| } | ||
|
|
||
| private: | ||
| rclcpp::Logger logger_{rclcpp::get_logger("is_within_path_tracking_bounds_node")}; | ||
| rclcpp::CallbackGroup::SharedPtr callback_group_; | ||
| rclcpp::executors::SingleThreadedExecutor callback_group_executor_; | ||
| rclcpp::Subscription<nav2_msgs::msg::TrackingFeedback>::SharedPtr tracking_feedback_sub_; | ||
| double last_error_{0.0}; | ||
| double max_error_right_{1.5}; | ||
| double max_error_left_{1.5}; | ||
| std::chrono::milliseconds bt_loop_duration_; | ||
|
|
||
| void trackingFeedbackCallback(const nav2_msgs::msg::TrackingFeedback::SharedPtr msg); | ||
| }; | ||
|
|
||
| } // namespace nav2_behavior_tree | ||
|
|
||
| #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_WITHIN_PATH_TRACKING_BOUNDS_CONDITION_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
113 changes: 113 additions & 0 deletions
113
nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.cpp
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,113 @@ | ||
| // Copyright (c) 2025 Berkan Tali | ||
| // | ||
| // 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. | ||
|
|
||
| #include "nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.hpp" | ||
|
|
||
| namespace nav2_behavior_tree | ||
| { | ||
|
|
||
| IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition( | ||
| const std::string & condition_name, | ||
| const BT::NodeConfiguration & conf) | ||
| : BT::ConditionNode(condition_name, conf), | ||
| last_error_(std::numeric_limits<double>::max()) | ||
| { | ||
| auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node"); | ||
| callback_group_ = node->create_callback_group( | ||
| rclcpp::CallbackGroupType::MutuallyExclusive, | ||
| false); | ||
| callback_group_executor_.add_callback_group(callback_group_, node->get_node_base_interface()); | ||
|
|
||
| tracking_feedback_sub_ = node->create_subscription<nav2_msgs::msg::TrackingFeedback>( | ||
| "tracking_feedback", | ||
| std::bind(&IsWithinPathTrackingBoundsCondition::trackingFeedbackCallback, this, | ||
| std::placeholders::_1), | ||
| rclcpp::SystemDefaultsQoS(), | ||
| callback_group_); | ||
|
|
||
| bt_loop_duration_ = | ||
| config().blackboard->template get<std::chrono::milliseconds>("bt_loop_duration"); | ||
|
|
||
| RCLCPP_INFO(logger_, "Initialized IsWithinPathTrackingBoundsCondition BT node"); | ||
| initialize(); | ||
| } | ||
|
|
||
| void IsWithinPathTrackingBoundsCondition::trackingFeedbackCallback( | ||
| const nav2_msgs::msg::TrackingFeedback::SharedPtr msg) | ||
| { | ||
| last_error_ = msg->tracking_error; | ||
| } | ||
|
|
||
| void IsWithinPathTrackingBoundsCondition::initialize() | ||
| { | ||
| getInput("max_error_left", max_error_left_); | ||
| getInput("max_error_right", max_error_right_); | ||
| } | ||
|
|
||
| BT::NodeStatus IsWithinPathTrackingBoundsCondition::tick() | ||
| { | ||
| if (!BT::isStatusActive(status())) { | ||
| initialize(); | ||
| } | ||
|
|
||
| callback_group_executor_.spin_all(bt_loop_duration_); | ||
|
|
||
| if (!getInput("max_error_left", max_error_left_)) { | ||
| RCLCPP_ERROR(logger_, "max_error_left parameter not provided"); | ||
| return BT::NodeStatus::FAILURE; | ||
| } | ||
|
|
||
| if (max_error_left_ < 0.0) { | ||
| RCLCPP_WARN(logger_, "max_error_left should be positive, using absolute value"); | ||
| max_error_left_ = std::abs(max_error_left_); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also check if we've recieved a path tracking error message yet. |
||
| if (!getInput("max_error_right", max_error_right_)) { | ||
| RCLCPP_ERROR(logger_, "max_error_right parameter not provided"); | ||
| return BT::NodeStatus::FAILURE; | ||
| } | ||
|
|
||
| if (max_error_right_ < 0.0) { | ||
| RCLCPP_WARN(logger_, "max_error_right should be positive, using absolute value"); | ||
| max_error_right_ = std::abs(max_error_right_); | ||
| } | ||
|
|
||
| if (last_error_ == std::numeric_limits<double>::max()) { | ||
| RCLCPP_WARN(logger_, "No tracking feedback received yet."); | ||
| return BT::NodeStatus::FAILURE; | ||
| } | ||
|
|
||
| if (last_error_ > 0.0) { // Positive = left side | ||
| if (last_error_ > max_error_left_) { | ||
| return BT::NodeStatus::FAILURE; | ||
| } else { | ||
| return BT::NodeStatus::SUCCESS; | ||
| } | ||
| } else { // Negative = right side | ||
| if (std::abs(last_error_) > max_error_right_) { | ||
| return BT::NodeStatus::FAILURE; | ||
| } else { | ||
| return BT::NodeStatus::SUCCESS; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace nav2_behavior_tree | ||
|
|
||
| #include "behaviortree_cpp/bt_factory.h" | ||
| BT_REGISTER_NODES(factory) | ||
| { | ||
| factory.registerNodeType<nav2_behavior_tree::IsWithinPathTrackingBoundsCondition>( | ||
| "IsWithinPathTrackingBounds"); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For docs: this needs to be having its configuration guide page + add to Navigation Plugins table + migration guide with the larger feature description