Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
undock_robot.cpp
1 // Copyright (c) 2024 Open Navigation LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <memory>
16 #include <string>
17 
18 #include "opennav_docking_bt/undock_robot.hpp"
19 
20 namespace opennav_docking_bt
21 {
22 
24  const std::string & xml_tag_name,
25  const std::string & action_name,
26  const BT::NodeConfiguration & conf)
27 : BtActionNode<Action>(xml_tag_name, action_name, conf)
28 {
29 }
30 
32 {
33  // Get core inputs about what to perform
34  getInput("dock_type", goal_.dock_type);
35  getInput("max_undocking_time", goal_.max_undocking_time);
36 }
37 
39 {
40  setOutput("success", result_.result->success);
41  setOutput("error_code_id", ActionResult::NONE);
42  return BT::NodeStatus::SUCCESS;
43 }
44 
46 {
47  setOutput("success", result_.result->success);
48  setOutput("error_code_id", result_.result->error_code);
49  return BT::NodeStatus::FAILURE;
50 }
51 
53 {
54  setOutput("error_code_id", ActionResult::NONE);
55  return BT::NodeStatus::SUCCESS;
56 }
57 
59 {
60  BtActionNode::halt();
61 }
62 
63 } // namespace opennav_docking_bt
64 
65 #include "behaviortree_cpp/bt_factory.h"
66 BT_REGISTER_NODES(factory)
67 {
68  BT::NodeBuilder builder =
69  [](const std::string & name, const BT::NodeConfiguration & config)
70  {
71  return std::make_unique<opennav_docking_bt::UndockRobotAction>(
72  name, "undock_robot", config);
73  };
74 
75  factory.registerBuilder<opennav_docking_bt::UndockRobotAction>(
76  "UndockRobot", builder);
77 }
nav2_behavior_tree::BtActionNode class that wraps nav2_msgs/UndockRobot
BT::NodeStatus on_success() override
Function to perform some user-defined operation upon successful completion of the action.
void on_tick() override
Function to perform some user-defined operation on tick.
void halt() override
Override required by the a BT action. Cancel the action and set the path output.
BT::NodeStatus on_cancelled() override
Function to perform some user-defined operation upon cancellation of the action.
BT::NodeStatus on_aborted() override
Function to perform some user-defined operation upon abortion of the action.
UndockRobotAction(const std::string &xml_tag_name, const std::string &action_name, const BT::NodeConfiguration &conf)
A constructor for opennav_docking_bt::UndockRobotAction.