Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
spin_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 
17 #include "nav2_behavior_tree/plugins/action/spin_action.hpp"
18 
19 namespace nav2_behavior_tree
20 {
21 
23  const std::string & xml_tag_name,
24  const std::string & action_name,
25  const BT::NodeConfiguration & conf)
26 : BtActionNode<nav2_msgs::action::Spin>(xml_tag_name, action_name, conf) {}
27 
29 {
30  double dist;
31  getInput("spin_dist", dist);
32  double time_allowance;
33  getInput("time_allowance", time_allowance);
34  goal_.target_yaw = dist;
35  goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance);
36  getInput("is_recovery", is_recovery_);
37 }
38 
40 {
41  if (!BT::isStatusActive(status())) {
42  initialize();
43  }
44 
45  if (is_recovery_) {
47  }
48 }
49 
50 BT::NodeStatus SpinAction::on_success()
51 {
52  setOutput("error_code_id", ActionResult::NONE);
53  return BT::NodeStatus::SUCCESS;
54 }
55 
56 BT::NodeStatus SpinAction::on_aborted()
57 {
58  setOutput("error_code_id", result_.result->error_code);
59  return BT::NodeStatus::FAILURE;
60 }
61 
62 BT::NodeStatus SpinAction::on_cancelled()
63 {
64  setOutput("error_code_id", ActionResult::NONE);
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::SpinAction>(name, "spin", config);
77  };
78 
79  factory.registerBuilder<nav2_behavior_tree::SpinAction>("Spin", builder);
80 }
Abstract class representing an action based BT node.
void increment_recovery_count()
Function to increment recovery count on blackboard if this node wraps a recovery.
A nav2_behavior_tree::BtActionNode class that wraps nav2_msgs::action::Spin.
Definition: spin_action.hpp:30
BT::NodeStatus on_success() override
Function to perform some user-defined operation upon successful completion of the action.
Definition: spin_action.cpp:50
void initialize()
Function to read parameters and initialize class variables.
Definition: spin_action.cpp:28
void on_tick() override
Function to perform some user-defined operation on tick.
Definition: spin_action.cpp:39
SpinAction(const std::string &xml_tag_name, const std::string &action_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::SpinAction.
Definition: spin_action.cpp:22
BT::NodeStatus on_cancelled() override
Function to perform some user-defined operation upon cancellation of the action.
Definition: spin_action.cpp:62
BT::NodeStatus on_aborted() override
Function to perform some user-defined operation upon abortion of the action.
Definition: spin_action.cpp:56