-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Centralize path handler logic in controller server #5446
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
mini-1235
wants to merge
45
commits into
ros-navigation:main
Choose a base branch
from
mini-1235:feat/goal_checker
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.
+2,037
−2,875
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
7179777
Add path goal checker plugin
mini-1235 7cb5903
Use local plan's last pose as end pose
mini-1235 5da8e04
Move path handler from plugin to controller level
mini-1235 9cd76c9
Add exact path following in path handler and parameter handler
mini-1235 b3da38b
Move more parameters
mini-1235 6945d17
Rotation shim
mini-1235 d6ec61a
RPP
mini-1235 fb204d2
Graceful
mini-1235 843f02c
MPPI
mini-1235 3753769
Remove goal from MPPI
mini-1235 8588935
Update setPlan api
mini-1235 3d4e366
Fix naming and doxygen
mini-1235 44227f7
Remove path complete goal checker
mini-1235 60997a3
Revert "Use local plan's last pose as end pose"
mini-1235 79aaf69
Linting
mini-1235 55df452
Add prune distance
mini-1235 99047cd
Add dynamic parameter
mini-1235 8ed2ce4
Revert unrelated changes
mini-1235 4b3ffa9
DWB
mini-1235 0c00776
Revert "Remove goal from MPPI"
mini-1235 29932a1
New idea
mini-1235 013a3a4
Rename
mini-1235 a9dffa0
Use new api
mini-1235 6f3171c
Make path handler a controller server's plugin
mini-1235 8773c19
Fix dynamic parameters handling
mini-1235 5a873f1
Add mppi path handler
mini-1235 af0aeb5
Fix tests
mini-1235 ffb5a0e
Add path length checking in position goal checker
mini-1235 aa07557
Remove controller frequency in dynamic parameters
mini-1235 621ee2a
Fix as suggested
mini-1235 efc7617
Add api, fix dynamic parameters
mini-1235 c3bc248
Linting
mini-1235 db3a49e
Add mppi logic in simple path handler
mini-1235 9eedef4
Simplify test logic
mini-1235 645367c
Merge remote-tracking branch 'origin/main' into feat/goal_checker
mini-1235 7a2944c
Minor fix
mini-1235 6d91c7e
Linting
mini-1235 8a6cd69
Add output port in FollowPath
mini-1235 d63d21e
Merge remote-tracking branch 'origin/main' into feat/goal_checker
mini-1235 2261466
Linting
mini-1235 66f91c8
Always return local plan in odom frame
mini-1235 bbd2458
Linting
mini-1235 0357f37
Minor fix
mini-1235 7f43fb7
Revert tracking feedback output port
mini-1235 e8590d2
Create post callback first
mini-1235 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
110 changes: 110 additions & 0 deletions
110
nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/path_handler_selector_node.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,110 @@ | ||
// Copyright (c) 2025 Maurice Alexander Purnawan | ||
// | ||
// 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__ACTION__PATH_HANDLER_SELECTOR_NODE_HPP_ | ||
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PATH_HANDLER_SELECTOR_NODE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <chrono> | ||
|
||
#include "std_msgs/msg/string.hpp" | ||
|
||
#include "behaviortree_cpp/action_node.h" | ||
|
||
#include "nav2_ros_common/lifecycle_node.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
/** | ||
* @brief The PathHandlerSelector behavior is used to switch the path handler | ||
* of the controller server. It subscribes to a topic "path_handler_selector" | ||
* to get the decision about what path_handler must be used. It is usually used before | ||
* the FollowPath. The selected_path_handler output port is passed to path_handler_id | ||
* input port of the FollowPath | ||
* @note This is an Asynchronous node. It will re-initialize when halted. | ||
*/ | ||
class PathHandlerSelector : public BT::SyncActionNode | ||
{ | ||
public: | ||
/** | ||
* @brief A constructor for nav2_behavior_tree::PathHandlerSelector | ||
* | ||
* @param xml_tag_name Name for the XML tag for this node | ||
* @param conf BT node configuration | ||
*/ | ||
PathHandlerSelector( | ||
const std::string & xml_tag_name, | ||
const BT::NodeConfiguration & conf); | ||
|
||
/** | ||
* @brief Creates list of BT ports | ||
* @return BT::PortsList Containing basic ports along with node-specific ports | ||
*/ | ||
static BT::PortsList providedPorts() | ||
{ | ||
return { | ||
BT::InputPort<std::string>( | ||
"default_path_handler", | ||
"the default path_handler to use if there is not any external topic message received."), | ||
|
||
BT::InputPort<std::string>( | ||
"topic_name", | ||
"path_handler_selector", | ||
"the input topic name to select the path_handler"), | ||
|
||
BT::OutputPort<std::string>( | ||
"selected_path_handler", | ||
"Selected path_handler by subscription") | ||
}; | ||
} | ||
|
||
private: | ||
/** | ||
* @brief Function to read parameters and initialize class variables | ||
*/ | ||
void initialize(); | ||
/** | ||
* @brief Function to create ROS interfaces | ||
*/ | ||
void createROSInterfaces(); | ||
|
||
/** | ||
* @brief Function to perform some user-defined operation on tick | ||
*/ | ||
BT::NodeStatus tick() override; | ||
|
||
/** | ||
* @brief callback function for the path_handler_selector topic | ||
* | ||
* @param msg the message with the id of the path_handler_selector | ||
*/ | ||
void callbackPathHandlerSelect(const std_msgs::msg::String::SharedPtr msg); | ||
|
||
nav2::Subscription<std_msgs::msg::String>::SharedPtr path_handler_selector_sub_; | ||
|
||
std::string last_selected_path_handler_; | ||
|
||
nav2::LifecycleNode::SharedPtr node_; | ||
rclcpp::CallbackGroup::SharedPtr callback_group_; | ||
rclcpp::executors::SingleThreadedExecutor callback_group_executor_; | ||
|
||
std::string topic_name_; | ||
std::chrono::milliseconds bt_loop_duration_; | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PATH_HANDLER_SELECTOR_NODE_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
104 changes: 104 additions & 0 deletions
104
nav2_behavior_tree/plugins/action/path_handler_selector_node.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,104 @@ | ||
// Copyright (c) 2025 Maurice Alexander Purnawan | ||
// | ||
// 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 <string> | ||
#include <memory> | ||
|
||
#include "std_msgs/msg/string.hpp" | ||
|
||
#include "nav2_behavior_tree/plugins/action/path_handler_selector_node.hpp" | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
using std::placeholders::_1; | ||
|
||
PathHandlerSelector::PathHandlerSelector( | ||
const std::string & name, | ||
const BT::NodeConfiguration & conf) | ||
: BT::SyncActionNode(name, conf) | ||
{ | ||
initialize(); | ||
bt_loop_duration_ = | ||
config().blackboard->template get<std::chrono::milliseconds>("bt_loop_duration"); | ||
} | ||
|
||
void PathHandlerSelector::initialize() | ||
{ | ||
createROSInterfaces(); | ||
} | ||
|
||
void PathHandlerSelector::createROSInterfaces() | ||
{ | ||
std::string topic_new; | ||
getInput("topic_name", topic_new); | ||
if (topic_new != topic_name_ || !path_handler_selector_sub_) { | ||
topic_name_ = topic_new; | ||
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()); | ||
|
||
path_handler_selector_sub_ = node_->create_subscription<std_msgs::msg::String>( | ||
topic_name_, | ||
std::bind(&PathHandlerSelector::callbackPathHandlerSelect, this, _1), | ||
nav2::qos::LatchedSubscriptionQoS(), | ||
callback_group_); | ||
} | ||
} | ||
|
||
BT::NodeStatus PathHandlerSelector::tick() | ||
{ | ||
if (!BT::isStatusActive(status())) { | ||
initialize(); | ||
} | ||
|
||
callback_group_executor_.spin_all(bt_loop_duration_); | ||
|
||
// This behavior always use the last selected path_handler received from the topic input. | ||
// When no input is specified it uses the default path handler. | ||
// If the default path handler is not specified then we work in "required path handler mode": | ||
// In this mode, the behavior returns failure if the path handler selection is not received from | ||
// the topic input. | ||
if (last_selected_path_handler_.empty()) { | ||
std::string default_path_handler; | ||
getInput("default_path_handler", default_path_handler); | ||
if (default_path_handler.empty()) { | ||
return BT::NodeStatus::FAILURE; | ||
} else { | ||
last_selected_path_handler_ = default_path_handler; | ||
} | ||
} | ||
|
||
setOutput("selected_path_handler", last_selected_path_handler_); | ||
|
||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
void | ||
PathHandlerSelector::callbackPathHandlerSelect(const std_msgs::msg::String::SharedPtr msg) | ||
{ | ||
last_selected_path_handler_ = msg->data; | ||
} | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#include "behaviortree_cpp/bt_factory.h" | ||
BT_REGISTER_NODES(factory) | ||
{ | ||
factory.registerNodeType<nav2_behavior_tree::PathHandlerSelector>("PathHandlerSelector"); | ||
} |
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.
Per usual: new BT nodes, parameters, etc should have configuration guide updates and migration guide entries. For new BT nodes and plugins, add them to the Navigation Plugins table
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.
Will add when this PR is close to merge