Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
distance_controller.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Sarthak Mittal
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__DECORATOR__DISTANCE_CONTROLLER_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__DISTANCE_CONTROLLER_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "geometry_msgs/msg/pose_stamped.hpp"
23 #include "nav2_ros_common/tf2_factories.hpp"
24 
25 #include "behaviortree_cpp/decorator_node.h"
26 #include "nav2_behavior_tree/bt_utils.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
43 class DistanceController : public BT::DecoratorNode
44 {
45 public:
52  const std::string & name,
53  const BT::NodeConfiguration & conf);
54 
59  static BT::PortsList providedPorts()
60  {
61  return {
62  BT::InputPort<double>("distance", 1.0, "Distance"),
63  BT::InputPort<std::string>("global_frame", "Global frame"),
64  BT::InputPort<std::string>("robot_base_frame", "Robot base frame")
65  };
66  }
67 
68 private:
73  BT::NodeStatus tick() override;
74 
75  nav2::LifecycleNode::SharedPtr node_;
76 
77  nav2::TransformBuffer::SharedPtr tf_;
78  double transform_tolerance_;
79 
80  geometry_msgs::msg::PoseStamped start_pose_;
81  double distance_;
82  std::string global_frame_, robot_base_frame_;
83 
84  bool first_time_;
85 };
86 
87 } // namespace nav2_behavior_tree
88 
89 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__DISTANCE_CONTROLLER_HPP_
A BT::DecoratorNode that ticks its child every time the robot travels a specified distance.
static BT::PortsList providedPorts()
Creates list of BT ports.
DistanceController(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::DistanceController.