Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
remove_passed_goals_action.hpp
1 // Copyright (c) 2021 Samsung Research America
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__REMOVE_PASSED_GOALS_ACTION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__REMOVE_PASSED_GOALS_ACTION_HPP_
17 
18 #include <vector>
19 #include <memory>
20 #include <string>
21 
22 #include "behaviortree_cpp/action_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "nav_msgs/msg/goals.hpp"
25 #include "nav2_behavior_tree/bt_utils.hpp"
26 #include "nav2_behavior_tree/json_utils.hpp"
27 #include "nav2_msgs/msg/waypoint_status.hpp"
28 #include "nav2_util/geometry_utils.hpp"
29 #include "nav2_util/robot_utils.hpp"
30 #include "nav2_ros_common/lifecycle_node.hpp"
31 #include "nav2_ros_common/tf2_factories.hpp"
32 #include "rclcpp/clock.hpp"
33 
34 namespace nav2_behavior_tree
35 {
36 
48 class RemovePassedGoals : public BT::ActionNodeBase
49 {
50 public:
52  const std::string & xml_tag_name,
53  const BT::NodeConfiguration & conf);
54 
58  void initialize();
59 
60  static BT::PortsList providedPorts()
61  {
62  // Register JSON definitions for the types used in the ports
63  BT::RegisterJsonDefinition<nav_msgs::msg::Goals>();
64  BT::RegisterJsonDefinition<nav2_msgs::msg::WaypointStatus>();
65  BT::RegisterJsonDefinition<std::vector<nav2_msgs::msg::WaypointStatus>>();
66 
67  return {
68  BT::InputPort<nav_msgs::msg::Goals>(
69  "input_goals",
70  "Original goals to remove viapoints from"),
71  BT::OutputPort<nav_msgs::msg::Goals>(
72  "output_goals",
73  "Goals with passed viapoints removed"),
74  BT::InputPort<double>("radius", 0.5, "radius to goal for it to be considered for removal"),
75  BT::InputPort<std::string>("robot_base_frame", "Robot base frame"),
76  BT::InputPort<std::vector<nav2_msgs::msg::WaypointStatus>>(
77  "input_waypoint_statuses",
78  "Original waypoint_statuses to mark waypoint status from"),
79  BT::OutputPort<std::vector<nav2_msgs::msg::WaypointStatus>>(
80  "output_waypoint_statuses",
81  "Waypoint_statuses with passed waypoints marked")
82  };
83  }
84 
85 private:
86  void halt() override {}
87  BT::NodeStatus tick() override;
88 
89  double viapoint_achieved_radius_;
90  double transform_tolerance_;
91  nav2::LifecycleNode::SharedPtr node_;
92  nav2::TransformBuffer::SharedPtr tf_;
93  std::string robot_base_frame_;
94 };
95 
96 } // namespace nav2_behavior_tree
97 
98 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__REMOVE_PASSED_GOALS_ACTION_HPP_
A BT::ActionNodeBase that removes goals that the robot passed near to.
void initialize()
Function to read parameters and initialize class variables.