-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add nav2_behavior_tree::BtActionServer #2010
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
Merged
SteveMacenski
merged 14 commits into
ros-navigation:main
from
naiveHobo:bt-action-server
Jan 13, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb351fc
Add nav2_behavior_tree::BtActionServer
naiveHobo 2391129
Fix cpplint errors
naiveHobo bfcd681
Remove unnecessary statements in BtActionServer
naiveHobo 33312ec
Make nav2_behavior_tree::BtActionServer a composable object
naiveHobo 046c78d
Add comments
naiveHobo ef18169
Add on preempt callback, fix naming issues, and move tf to bt navigator
naiveHobo a478cfa
Add separate implementation header for BtActionServer
naiveHobo e68a45c
Fix cpplint error
naiveHobo 3a600c5
Pass plugin library names as argument to BtActionServer
naiveHobo 6809176
Remove action server getter and update onPreempt to not load BT
naiveHobo 8cab84c
Fix unnecessary include
naiveHobo e9b684c
Fix function names
naiveHobo 2c45ab3
Merge branch 'main' of github.com:ros-planning/navigation2 into bt-ac…
naiveHobo 41a201b
Fix typo
naiveHobo 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
200 changes: 200 additions & 0 deletions
200
nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server.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,200 @@ | ||
| // Copyright (c) 2020 Sarthak Mittal | ||
| // | ||
| // 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__BT_ACTION_SERVER_HPP_ | ||
| #define NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_HPP_ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "geometry_msgs/msg/pose_stamped.hpp" | ||
| #include "nav2_behavior_tree/behavior_tree_engine.hpp" | ||
| #include "nav2_behavior_tree/ros_topic_logger.hpp" | ||
| #include "nav2_util/lifecycle_node.hpp" | ||
| #include "nav2_util/simple_action_server.hpp" | ||
|
|
||
| namespace nav2_behavior_tree | ||
| { | ||
| /** | ||
| * @class nav2_behavior_tree::BtActionServer | ||
| * @brief An action server that uses behavior tree to execute an action | ||
| */ | ||
| template<class ActionT> | ||
| class BtActionServer | ||
| { | ||
| public: | ||
| using ActionServer = nav2_util::SimpleActionServer<ActionT>; | ||
|
|
||
| typedef std::function<bool (typename ActionT::Goal::ConstSharedPtr)> OnGoalReceivedCallback; | ||
| typedef std::function<void ()> OnLoopCallback; | ||
| typedef std::function<void ()> OnPreemptCallback; | ||
|
|
||
| /** | ||
| * @brief A constructor for nav2_behavior_tree::BtActionServer class | ||
| */ | ||
| explicit BtActionServer( | ||
| const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, | ||
| const std::string & action_name, | ||
| const std::vector<std::string> & plugin_lib_names, | ||
| OnGoalReceivedCallback on_goal_received_callback, | ||
| OnLoopCallback on_loop_callback, | ||
| OnPreemptCallback on_preempt_callback = nullptr); | ||
|
|
||
| /** | ||
| * @brief A destructor for nav2_behavior_tree::BtActionServer class | ||
| */ | ||
| ~BtActionServer(); | ||
|
|
||
| /** | ||
| * @brief Configures member variables | ||
| * | ||
| * Initializes action server for, builds behavior tree from xml file, | ||
| * and calls user-defined onConfigure. | ||
| * @return true on SUCCESS and false on FAILURE | ||
| */ | ||
| bool on_configure(); | ||
|
|
||
| /** | ||
| * @brief Activates action server | ||
| * @return true on SUCCESS and false on FAILURE | ||
| */ | ||
| bool on_activate(); | ||
|
|
||
| /** | ||
| * @brief Deactivates action server | ||
| * @return true on SUCCESS and false on FAILURE | ||
| */ | ||
| bool on_deactivate(); | ||
|
|
||
| /** | ||
| * @brief Resets member variables | ||
| * @return true on SUCCESS and false on FAILURE | ||
| */ | ||
| bool on_cleanup(); | ||
|
|
||
| /** | ||
| * @brief Called when in shutdown state | ||
| * @return true on SUCCESS and false on FAILURE | ||
| */ | ||
| bool on_shutdown(); | ||
|
|
||
| /** | ||
| * @brief Replace current BT with another one | ||
| * @param bt_xml_filename The file containing the new BT, uses default filename if empty | ||
| * @return true if the resulting BT correspond to the one in bt_xml_filename. false | ||
| * if something went wrong, and previous BT is maintained | ||
| */ | ||
| bool loadBehaviorTree(const std::string & bt_xml_filename = ""); | ||
|
|
||
| /** | ||
| * @brief Getter function for BT Blackboard | ||
| * @return shared pointer to current BT blackboard | ||
| */ | ||
| BT::Blackboard::Ptr getBlackboard() const | ||
| { | ||
| return blackboard_; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Getter function for current BT XML filename | ||
| * @return string | ||
| */ | ||
| std::string getCurrentBTFilename() const | ||
| { | ||
| return current_bt_xml_filename_; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Wrapper function to accept pending goal if a preempt has been requested | ||
| */ | ||
| const std::shared_ptr<const typename ActionT::Goal> acceptPendingGoal() | ||
| { | ||
| return action_server_->accept_pending_goal(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Wrapper function to get current goal | ||
| */ | ||
| const std::shared_ptr<const typename ActionT::Goal> getCurrentGoal() const | ||
| { | ||
| return action_server_->get_current_goal(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Wrapper function to publish action feedback | ||
| */ | ||
| void publishFeedback(typename std::shared_ptr<typename ActionT::Feedback> feedback) | ||
| { | ||
| action_server_->publish_feedback(feedback); | ||
| } | ||
|
|
||
| protected: | ||
| /** | ||
| * @brief Action server callback | ||
| */ | ||
| void executeCallback(); | ||
|
|
||
| // Action name | ||
| std::string action_name_; | ||
|
|
||
| // Our action server implements the template action | ||
| std::shared_ptr<ActionServer> action_server_; | ||
|
|
||
| // Behavior Tree to be executed when goal is received | ||
| BT::Tree tree_; | ||
naiveHobo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // The blackboard shared by all of the nodes in the tree | ||
| BT::Blackboard::Ptr blackboard_; | ||
naiveHobo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // The XML file that cointains the Behavior Tree to create | ||
| std::string current_bt_xml_filename_; | ||
naiveHobo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::string default_bt_xml_filename_; | ||
|
|
||
| // The wrapper class for the BT functionality | ||
| std::unique_ptr<nav2_behavior_tree::BehaviorTreeEngine> bt_; | ||
|
|
||
| // Libraries to pull plugins (BT Nodes) from | ||
| std::vector<std::string> plugin_lib_names_; | ||
|
|
||
| // A regular, non-spinning ROS node that we can use for calls to the action client | ||
| rclcpp::Node::SharedPtr client_node_; | ||
|
|
||
| // Parent node | ||
| rclcpp_lifecycle::LifecycleNode::WeakPtr node_; | ||
|
|
||
| // Clock | ||
| rclcpp::Clock::SharedPtr clock_; | ||
|
|
||
| // Logger | ||
| rclcpp::Logger logger_{rclcpp::get_logger("BtActionServer")}; | ||
|
|
||
| // To publish BT logs | ||
| std::unique_ptr<RosTopicLogger> topic_logger_; | ||
|
|
||
| // Parameters for Groot monitoring | ||
| bool enable_groot_monitoring_; | ||
| int groot_zmq_publisher_port_; | ||
| int groot_zmq_server_port_; | ||
|
|
||
| // User-provided callbacks | ||
| OnGoalReceivedCallback on_goal_received_callback_; | ||
| OnLoopCallback on_loop_callback_; | ||
| OnPreemptCallback on_preempt_callback_; | ||
| }; | ||
|
|
||
| } // namespace nav2_behavior_tree | ||
|
|
||
| #include <nav2_behavior_tree/bt_action_server_impl.hpp> // NOLINT(build/include_order) | ||
| #endif // NAV2_BEHAVIOR_TREE__BT_ACTION_SERVER_HPP_ | ||
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.