Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
follow_object_action.hpp
1 // Copyright (c) 2024 Open Navigation LLC
2 // Copyright (c) 2024 Alberto J. Tudela Roldán
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_OBJECT_ACTION_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_OBJECT_ACTION_HPP_
18 
19 #include <string>
20 #include <memory>
21 #include <vector>
22 
23 #include "nav2_behavior_tree/bt_action_node.hpp"
24 #include "nav2_msgs/action/follow_object.hpp"
25 
26 
27 namespace nav2_behavior_tree
28 {
29 
34  : public nav2_behavior_tree::BtActionNode<nav2_msgs::action::FollowObject>
35 {
36  using Action = nav2_msgs::action::FollowObject;
37  using ActionResult = Action::Result;
38 
39 public:
47  const std::string & xml_tag_name,
48  const std::string & action_name,
49  const BT::NodeConfiguration & conf);
50 
54  void on_tick() override;
55 
59  BT::NodeStatus on_success() override;
60 
64  BT::NodeStatus on_aborted() override;
65 
69  BT::NodeStatus on_cancelled() override;
70 
75  static BT::PortsList providedPorts()
76  {
77  return providedBasicPorts(
78  {
79  BT::InputPort<std::string>(
80  "pose_topic", "dynamic_pose", "Topic to publish the pose of the object to follow"),
81  BT::InputPort<std::string>(
82  "tracked_frame", "Target frame to follow (Optional, used if pose_topic is not set)"),
83  BT::InputPort<float>(
84  "max_duration", 0.0, "The maximum duration to follow the object (Optional)"),
85 
86  BT::OutputPort<ActionResult::_total_elapsed_time_type>(
87  "total_elapsed_time", "Total elapsed time"),
88  BT::OutputPort<ActionResult::_error_code_type>(
89  "error_code_id", "Error code"),
90  BT::OutputPort<std::string>(
91  "error_msg", "Error message"),
92  });
93  }
94 };
95 
96 } // namespace nav2_behavior_tree
97 
98 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_OBJECT_ACTION_HPP_
Abstract class representing an action based BT node.
static BT::PortsList providedBasicPorts(BT::PortsList addition)
Any subclass of BtActionNode that accepts parameters must provide a providedPorts method and call pro...
nav2_behavior_tree::BtActionNode class that wraps nav2_msgs/FollowObject
BT::NodeStatus on_cancelled() override
Function to perform some user-defined operation upon cancellation of the action.
void on_tick() override
Function to perform some user-defined operation on tick.
FollowObjectAction(const std::string &xml_tag_name, const std::string &action_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::FollowObjectAction.
static BT::PortsList providedPorts()
Creates list of BT ports.
BT::NodeStatus on_aborted() override
Function to perform some user-defined operation upon abortion of the action.
BT::NodeStatus on_success() override
Function to perform some user-defined operation upon successful completion of the action.