Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
follow_object_action.cpp
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 #include <memory>
17 #include <string>
18 
19 #include "nav2_behavior_tree/plugins/action/follow_object_action.hpp"
20 
21 namespace nav2_behavior_tree
22 {
23 
25  const std::string & xml_tag_name,
26  const std::string & action_name,
27  const BT::NodeConfiguration & conf)
28 : BtActionNode<Action>(xml_tag_name, action_name, conf)
29 {
30 }
31 
33 {
34  // Get core inputs about what to perform
35  getInput("pose_topic", goal_.pose_topic);
36  getInput("tracked_frame", goal_.tracked_frame);
37  double max_duration;
38  getInput("max_duration", max_duration);
39 
40  // Populate the input message
41  goal_.max_duration = rclcpp::Duration::from_seconds(max_duration);
42 }
43 
45 {
46  setOutput("total_elapsed_time", result_.result->total_elapsed_time);
47  setOutput("error_code_id", ActionResult::NONE);
48  setOutput("error_msg", "");
49  return BT::NodeStatus::SUCCESS;
50 }
51 
53 {
54  setOutput("total_elapsed_time", result_.result->total_elapsed_time);
55  setOutput("error_code_id", result_.result->error_code);
56  setOutput("error_msg", result_.result->error_msg);
57  return BT::NodeStatus::FAILURE;
58 }
59 
61 {
62  setOutput("total_elapsed_time", result_.result->total_elapsed_time);
63  setOutput("error_code_id", ActionResult::NONE);
64  setOutput("error_msg", "");
65  return BT::NodeStatus::SUCCESS;
66 }
67 
68 } // namespace nav2_behavior_tree
69 
70 #include "behaviortree_cpp/bt_factory.h"
71 BT_REGISTER_NODES(factory)
72 {
73  BT::NodeBuilder builder =
74  [](const std::string & name, const BT::NodeConfiguration & config)
75  {
76  return std::make_unique<nav2_behavior_tree::FollowObjectAction>(
77  name, "follow_object", config);
78  };
79 
80  factory.registerBuilder<nav2_behavior_tree::FollowObjectAction>(
81  "FollowObject", builder);
82 }
Abstract class representing an action based BT node.
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.
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.