Nav2 Navigation Stack - humble  humble
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 "tf2_ros/buffer.h"
24 
25 #include "behaviortree_cpp_v3/decorator_node.h"
26 
27 namespace nav2_behavior_tree
28 {
29 
34 class DistanceController : public BT::DecoratorNode
35 {
36 public:
43  const std::string & name,
44  const BT::NodeConfiguration & conf);
45 
50  static BT::PortsList providedPorts()
51  {
52  return {
53  BT::InputPort<double>("distance", 1.0, "Distance"),
54  BT::InputPort<std::string>("global_frame", std::string("map"), "Global frame"),
55  BT::InputPort<std::string>("robot_base_frame", std::string("base_link"), "Robot base frame")
56  };
57  }
58 
59 private:
64  BT::NodeStatus tick() override;
65 
66  rclcpp::Node::SharedPtr node_;
67 
68  std::shared_ptr<tf2_ros::Buffer> tf_;
69  double transform_tolerance_;
70 
71  geometry_msgs::msg::PoseStamped start_pose_;
72  double distance_;
73 
74  std::string global_frame_;
75  std::string robot_base_frame_;
76 
77  bool first_time_;
78 };
79 
80 } // namespace nav2_behavior_tree
81 
82 #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.