Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
distance_traveled_condition.hpp
1 // Copyright (c) 2020 Sarthak Mittal
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__DISTANCE_TRAVELED_CONDITION_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__DISTANCE_TRAVELED_CONDITION_HPP_
18 
19 #include <string>
20 #include <memory>
21 
22 #include "behaviortree_cpp/condition_node.h"
23 
24 #include "nav2_ros_common/lifecycle_node.hpp"
25 #include "geometry_msgs/msg/pose_stamped.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 #include "nav2_behavior_tree/bt_utils.hpp"
28 
29 namespace nav2_behavior_tree
30 {
31 
42 class DistanceTraveledCondition : public BT::ConditionNode
43 {
44 public:
51  const std::string & condition_name,
52  const BT::NodeConfiguration & conf);
53 
54  DistanceTraveledCondition() = delete;
55 
60  BT::NodeStatus tick() override;
61 
65  void initialize();
66 
71  static BT::PortsList providedPorts()
72  {
73  return {
74  BT::InputPort<double>("distance", 1.0, "Distance"),
75  BT::InputPort<std::string>("global_frame", "Global frame"),
76  BT::InputPort<std::string>("robot_base_frame", "Robot base frame")
77  };
78  }
79 
80 private:
81  nav2::LifecycleNode::SharedPtr node_;
82  nav2::TransformBuffer::SharedPtr tf_;
83 
84  geometry_msgs::msg::PoseStamped start_pose_;
85 
86  double distance_;
87  double transform_tolerance_;
88  std::string global_frame_, robot_base_frame_;
89 };
90 
91 } // namespace nav2_behavior_tree
92 
93 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__DISTANCE_TRAVELED_CONDITION_HPP_
A BT::ConditionNode that returns SUCCESS every time the robot travels a specified distance and FAILUR...
BT::NodeStatus tick() override
The main override required by a BT action.
static BT::PortsList providedPorts()
Creates list of BT ports.
void initialize()
Function to read parameters and initialize class variables.