Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
remove_in_collision_goals_action.hpp
1 // Copyright (c) 2024 Angsa Robotics
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_IN_COLLISION_GOALS_ACTION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__REMOVE_IN_COLLISION_GOALS_ACTION_HPP_
17 
18 #include <vector>
19 #include <memory>
20 #include <string>
21 
22 #include "nav2_ros_common/lifecycle_node.hpp"
23 #include "nav_msgs/msg/goals.hpp"
24 #include "nav2_behavior_tree/bt_service_node.hpp"
25 #include "nav2_msgs/srv/get_costs.hpp"
26 #include "nav2_msgs/msg/waypoint_status.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
43 class RemoveInCollisionGoals : public BtServiceNode<nav2_msgs::srv::GetCosts>
44 {
45 public:
52  const std::string & service_node_name,
53  const BT::NodeConfiguration & conf);
54 
59  void on_tick() override;
60 
61  BT::NodeStatus on_completion(std::shared_ptr<nav2_msgs::srv::GetCosts::Response> response)
62  override;
63 
64  static BT::PortsList providedPorts()
65  {
66  // Register JSON definitions for the types used in the ports
67  BT::RegisterJsonDefinition<nav_msgs::msg::Goals>();
68  BT::RegisterJsonDefinition<nav2_msgs::msg::WaypointStatus>();
69  BT::RegisterJsonDefinition<std::vector<nav2_msgs::msg::WaypointStatus>>();
70 
71  return providedBasicPorts(
72  {
73  BT::InputPort<nav_msgs::msg::Goals>(
74  "input_goals",
75  "Original goals to remove from"),
76  BT::InputPort<double>(
77  "cost_threshold", 254.0,
78  "Cost threshold for considering a goal in collision"),
79  BT::InputPort<bool>("use_footprint", true, "Whether to use footprint cost"),
80  BT::InputPort<bool>(
81  "consider_unknown_as_obstacle", false,
82  "Whether to consider unknown cost as obstacle"),
83  BT::OutputPort<nav_msgs::msg::Goals>(
84  "output_goals",
85  "Goals with in-collision goals removed"),
86  BT::InputPort<std::vector<nav2_msgs::msg::WaypointStatus>>(
87  "input_waypoint_statuses",
88  "Original waypoint_statuses to mark waypoint status from"),
89  BT::OutputPort<std::vector<nav2_msgs::msg::WaypointStatus>>(
90  "output_waypoint_statuses",
91  "Waypoint_statuses with in-collision waypoints marked")
92  });
93  }
94 
95 private:
96  bool use_footprint_;
97  bool consider_unknown_as_obstacle_;
98  double cost_threshold_;
99  nav_msgs::msg::Goals input_goals_;
100 };
101 
102 } // namespace nav2_behavior_tree
103 
104 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__REMOVE_IN_COLLISION_GOALS_ACTION_HPP_
Abstract class representing a service based BT node.
static BT::PortsList providedBasicPorts(BT::PortsList addition)
Any subclass of BtServiceNode that accepts parameters must provide a providedPorts method and call pr...
A nav2_behavior_tree::BtServiceNode class that removes goals that are in collision in on the global c...
void on_tick() override
The main override required by a BT service.
RemoveInCollisionGoals(const std::string &service_node_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::RemoveInCollisionGoals.