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