Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
truncate_path_local_action.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Francisco Martin Rico
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__ACTION__TRUNCATE_PATH_LOCAL_ACTION_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__TRUNCATE_PATH_LOCAL_ACTION_HPP_
18 
19 #include <memory>
20 #include <string>
21 #include <limits>
22 
23 #include "behaviortree_cpp/action_node.h"
24 #include "behaviortree_cpp/json_export.h"
25 #include "nav_msgs/msg/path.hpp"
26 #include "nav2_behavior_tree/bt_utils.hpp"
27 #include "nav2_behavior_tree/json_utils.hpp"
28 #include "nav2_ros_common/tf2_factories.hpp"
29 #include "rclcpp/clock.hpp"
30 #include "nav2_ros_common/lifecycle_node.hpp"
31 
32 
33 namespace nav2_behavior_tree
34 {
35 
45 class TruncatePathLocal : public BT::ActionNodeBase
46 {
47 public:
54  const std::string & xml_tag_name,
55  const BT::NodeConfiguration & conf);
56 
61  static BT::PortsList providedPorts()
62  {
63  // Register JSON definitions for the types used in the ports
64  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
65  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
66 
67  return {
68  BT::InputPort<nav_msgs::msg::Path>("input_path", "Original Path"),
69  BT::OutputPort<nav_msgs::msg::Path>(
70  "output_path", "Path truncated to a certain distance around robot"),
71  BT::InputPort<double>(
72  "distance_forward", 8.0,
73  "Distance in forward direction"),
74  BT::InputPort<double>(
75  "distance_backward", 4.0,
76  "Distance in backward direction"),
77  BT::InputPort<std::string>(
78  "robot_base_frame",
79  "Robot base frame id"),
80  BT::InputPort<double>(
81  "transform_tolerance", 0.2,
82  "Transform lookup tolerance"),
83  BT::InputPort<geometry_msgs::msg::PoseStamped>(
84  "pose", "Manually specified pose to be used"
85  "if overriding current robot pose"),
86  BT::InputPort<double>(
87  "angular_distance_weight", 0.0,
88  "Weight of angular distance relative to positional distance when finding which path "
89  "pose is closest to robot. Not applicable on paths without orientations assigned"),
90  BT::InputPort<double>(
91  "max_robot_pose_search_dist", std::numeric_limits<double>::infinity(),
92  "Maximum forward integrated distance along the path (starting from the last detected pose) "
93  "to bound the search for the closest pose to the robot. When set to infinity (default), "
94  "whole path is searched every time"),
95  };
96  }
97 
98 private:
102  void halt() override {}
103 
108  BT::NodeStatus tick() override;
109 
116  bool getRobotPose(std::string path_frame_id, geometry_msgs::msg::PoseStamped & pose);
117 
126  static double poseDistance(
127  const geometry_msgs::msg::PoseStamped & pose1,
128  const geometry_msgs::msg::PoseStamped & pose2,
129  const double angular_distance_weight);
130 
131  nav2::TransformBuffer::SharedPtr tf_buffer_;
132 
133  nav_msgs::msg::Path path_;
134  nav_msgs::msg::Path::_poses_type::iterator closest_pose_detection_begin_;
135 };
136 
137 } // namespace nav2_behavior_tree
138 
139 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__TRUNCATE_PATH_LOCAL_ACTION_HPP_
A BT::ActionNodeBase to shorten path to some distance around robot.
static BT::PortsList providedPorts()
Creates list of BT ports.
TruncatePathLocal(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A nav2_behavior_tree::TruncatePathLocal constructor.