Nav2 Navigation Stack - rolling  main
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.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 
37 class DistanceController : public BT::DecoratorNode
38 {
39 public:
46  const std::string & name,
47  const BT::NodeConfiguration & conf);
48 
53  static BT::PortsList providedPorts()
54  {
55  return {
56  BT::InputPort<double>("distance", 1.0, "Distance"),
57  BT::InputPort<std::string>("global_frame", "Global frame"),
58  BT::InputPort<std::string>("robot_base_frame", "Robot base frame")
59  };
60  }
61 
62 private:
67  BT::NodeStatus tick() override;
68 
69  nav2::LifecycleNode::SharedPtr node_;
70 
71  std::shared_ptr<tf2_ros::Buffer> tf_;
72  double transform_tolerance_;
73 
74  geometry_msgs::msg::PoseStamped start_pose_;
75  double distance_;
76  std::string global_frame_, robot_base_frame_;
77 
78  bool first_time_;
79 };
80 
81 } // namespace nav2_behavior_tree
82 
83 #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.