Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
wait_action.cpp
1 // Copyright (c) 2018 Samsung Research America
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 <string>
16 #include <memory>
17 #include <cmath>
18 
19 #include "nav2_behavior_tree/plugins/action/wait_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<nav2_msgs::action::Wait>(xml_tag_name, action_name, conf)
29 {
30 }
31 
33 {
34  double duration;
35  getInput("wait_duration", duration);
36  if (duration <= 0) {
37  RCLCPP_WARN(
38  node_->get_logger(), "Wait duration is negative or zero "
39  "(%f). Setting to positive.", duration);
40  duration *= -1;
41  }
42 
43  goal_.time = rclcpp::Duration::from_seconds(duration);
44 }
45 
47 {
48  if (!BT::isStatusActive(status())) {
49  initialize();
50  }
51 
53 }
54 
55 } // namespace nav2_behavior_tree
56 
57 #include "behaviortree_cpp/bt_factory.h"
58 BT_REGISTER_NODES(factory)
59 {
60  BT::NodeBuilder builder =
61  [](const std::string & name, const BT::NodeConfiguration & config)
62  {
63  return std::make_unique<nav2_behavior_tree::WaitAction>(name, "wait", config);
64  };
65 
66  factory.registerBuilder<nav2_behavior_tree::WaitAction>("Wait", builder);
67 }
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::Wait.
Definition: wait_action.hpp:30
WaitAction(const std::string &xml_tag_name, const std::string &action_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::WaitAction.
Definition: wait_action.cpp:24
void on_tick() override
Function to perform some user-defined operation on tick.
Definition: wait_action.cpp:46
void initialize()
Function to read parameters and initialize class variables.
Definition: wait_action.cpp:32