Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
validate_path_action.hpp
1 // Copyright (c) 2021 Joshua Wallace
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__VALIDATE_PATH_ACTION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__VALIDATE_PATH_ACTION_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "nav2_ros_common/lifecycle_node.hpp"
23 #include "behaviortree_cpp/action_node.h"
24 #include "behaviortree_cpp/json_export.h"
25 #include "geometry_msgs/msg/pose_stamped.hpp"
26 #include "nav2_msgs/srv/is_path_valid.hpp"
27 #include "nav2_ros_common/service_client.hpp"
28 #include "nav2_behavior_tree/bt_utils.hpp"
29 #include "nav2_behavior_tree/json_utils.hpp"
30 #include "nav2_behavior_tree/bt_service_node.hpp"
31 
32 namespace nav2_behavior_tree
33 {
34 
70 class ValidatePath : public BtServiceNode<nav2_msgs::srv::IsPathValid>
71 {
72 public:
79  const std::string & service_node_name,
80  const BT::NodeConfiguration & conf);
81 
86  void on_tick() override;
87 
93  BT::NodeStatus on_completion(std::shared_ptr<nav2_msgs::srv::IsPathValid::Response> response)
94  override;
95 
100  static BT::PortsList providedPorts()
101  {
102  // Register JSON definitions for the types used in the ports
103  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
104  BT::RegisterJsonDefinition<std::chrono::milliseconds>();
105  BT::RegisterJsonDefinition<std::vector<geometry_msgs::msg::PoseStamped>>();
106 
107  return providedBasicPorts(
108  {
109  BT::InputPort<nav_msgs::msg::Path>("path", "Path to Check"),
110  BT::InputPort<unsigned int>("max_cost", 254, "Maximum cost of the path"),
111  BT::InputPort<bool>(
112  "consider_unknown_as_obstacle", false,
113  "Whether to consider unknown cost as obstacle"),
114  BT::InputPort<std::string>(
115  "layer_name", "",
116  "Name of the costmap layer to check against (empty = full costmap)"),
117  BT::InputPort<std::string>(
118  "footprint", "",
119  "Custom footprint specification as bracketed array of arrays, e.g., "
120  "[[x1,y1],[x2,y2],...] (empty = use robot footprint)"),
121  BT::InputPort<bool>(
122  "stop_at_first_collision", true,
123  "Whether to stop validation at first collision (true) or check all poses (false)"),
124  BT::InputPort<double>(
125  "max_lookahead_distance", -1.0,
126  "Maximum distance ahead of the robot to validate (-1 = full path)"),
127  BT::OutputPort<std::vector<geometry_msgs::msg::PoseStamped>>(
128  "collision_poses",
129  "Poses in the path that are in collision")
130  });
131  }
132 
133 private:
134  unsigned int max_cost_;
135  bool consider_unknown_as_obstacle_;
136  std::string layer_name_;
137  std::string footprint_;
138  bool stop_at_first_collision_;
139  double max_lookahead_distance_;
140  nav_msgs::msg::Path path_;
141 };
142 
143 } // namespace nav2_behavior_tree
144 
145 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__VALIDATE_PATH_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 validates a path by calling the IsPathValid service on...
static BT::PortsList providedPorts()
Creates list of BT ports.
BT::NodeStatus on_completion(std::shared_ptr< nav2_msgs::srv::IsPathValid::Response > response) override
Function to perform some user-defined operation after receiving a result from the service.
void on_tick() override
The main override required by a BT service.
ValidatePath(const std::string &service_node_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::ValidatePath.