Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
path_expiring_timer_condition.hpp
1 // Copyright (c) 2022 Joshua Wallace
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 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__PATH_EXPIRING_TIMER_CONDITION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__PATH_EXPIRING_TIMER_CONDITION_HPP_
17 
18 #include <string>
19 
20 #include "rclcpp/rclcpp.hpp"
21 #include "behaviortree_cpp/condition_node.h"
22 #include "behaviortree_cpp/json_export.h"
23 #include "nav_msgs/msg/path.hpp"
24 #include "nav2_behavior_tree/bt_utils.hpp"
25 #include "nav2_behavior_tree/json_utils.hpp"
26 
27 namespace nav2_behavior_tree
28 {
29 
34 class PathExpiringTimerCondition : public BT::ConditionNode
35 {
36 public:
43  const std::string & condition_name,
44  const BT::NodeConfiguration & conf);
45 
46  PathExpiringTimerCondition() = delete;
47 
52  BT::NodeStatus tick() override;
53 
58  static BT::PortsList providedPorts()
59  {
60  // Register JSON definitions for the types used in the ports
61  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
62 
63  return {
64  BT::InputPort<double>("seconds", 1.0, "Seconds"),
65  BT::InputPort<nav_msgs::msg::Path>("path")
66  };
67  }
68 
69 private:
70  rclcpp::Node::SharedPtr node_;
71  rclcpp::Time start_;
72  nav_msgs::msg::Path prev_path_;
73  double period_;
74  bool first_time_;
75 };
76 
77 } // namespace nav2_behavior_tree
78 
79 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__PATH_EXPIRING_TIMER_CONDITION_HPP_
A BT::ConditionNode that returns SUCCESS every time a specified time period passes and FAILURE otherw...
static BT::PortsList providedPorts()
Creates list of BT ports.
BT::NodeStatus tick() override
The main override required by a BT action.