Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
navigate_to_pose_action.cpp
1 // Copyright (c) 2018 Intel Corporation
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 "nav2_behavior_tree/plugins/action/navigate_to_pose_action.hpp"
19 
20 namespace nav2_behavior_tree
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 
31 {
32  if (!getInput("goal", goal_.pose)) {
33  RCLCPP_ERROR(
34  node_->get_logger(),
35  "NavigateToPoseAction: goal not provided");
36  return;
37  }
38  getInput("behavior_tree", goal_.behavior_tree);
39 }
40 
42 {
43  setOutput("error_code_id", ActionResult::NONE);
44  setOutput("error_msg", "");
45  return BT::NodeStatus::SUCCESS;
46 }
47 
49 {
50  setOutput("error_code_id", result_.result->error_code);
51  setOutput("error_msg", result_.result->error_msg);
52  return BT::NodeStatus::FAILURE;
53 }
54 
56 {
57  // Set empty error code, action was cancelled
58  setOutput("error_code_id", ActionResult::NONE);
59  setOutput("error_msg", "");
60  return BT::NodeStatus::SUCCESS;
61 }
62 
63 } // namespace nav2_behavior_tree
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<nav2_behavior_tree::NavigateToPoseAction>(
72  name, "navigate_to_pose", config);
73  };
74 
75  factory.registerBuilder<nav2_behavior_tree::NavigateToPoseAction>(
76  "NavigateToPose", builder);
77 }
Abstract class representing an action based BT node.
A nav2_behavior_tree::BtActionNode class that wraps nav2_msgs::action::NavigateToPose.
BT::NodeStatus on_aborted() override
Function to perform some user-defined operation upon abortion of the action.
BT::NodeStatus on_cancelled() override
Function to perform some user-defined operation upon cancellation of the action.
BT::NodeStatus on_success() override
Function to perform some user-defined operation upon successful completion of the action.
NavigateToPoseAction(const std::string &xml_tag_name, const std::string &action_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::NavigateToPoseAction.
void on_tick() override
Function to perform some user-defined operation on tick.