19 #include "nav2_behavior_tree/plugins/action/validate_path_action.hpp"
21 namespace nav2_behavior_tree
25 const std::string & service_node_name,
26 const BT::NodeConfiguration & conf)
27 :
BtServiceNode<nav2_msgs::srv::IsPathValid>(service_node_name, conf,
"is_path_valid")
34 getInput<unsigned int>(
"max_cost", max_cost_);
35 getInput<bool>(
"consider_unknown_as_obstacle", consider_unknown_as_obstacle_);
36 getInput<std::string>(
"layer_name", layer_name_);
37 getInput<std::string>(
"footprint", footprint_);
38 getInput<bool>(
"stop_at_first_collision", stop_at_first_collision_);
39 getInput<double>(
"max_lookahead_distance", max_lookahead_distance_);
40 getInput(
"path", path_);
42 request_ = std::make_shared<nav2_msgs::srv::IsPathValid::Request>();
43 request_->path = path_;
44 request_->max_cost = max_cost_;
45 request_->consider_unknown_as_obstacle = consider_unknown_as_obstacle_;
46 request_->layer_name = layer_name_;
47 request_->footprint = footprint_;
48 request_->stop_at_first_collision = stop_at_first_collision_;
49 request_->max_lookahead_distance = max_lookahead_distance_;
53 std::shared_ptr<nav2_msgs::srv::IsPathValid::Response> response)
56 if (!response->success) {
59 "IsPathValid service failed to validate path");
60 return BT::NodeStatus::FAILURE;
63 if (response->is_valid) {
65 std::vector<geometry_msgs::msg::PoseStamped> collision_poses;
66 setOutput(
"collision_poses", collision_poses);
67 return BT::NodeStatus::SUCCESS;
71 std::vector<geometry_msgs::msg::PoseStamped> collision_poses;
72 if (!response->invalid_pose_indices.empty()) {
74 ss <<
"Path validation failed. Invalid pose indices: [";
75 for (
size_t i = 0; i < response->invalid_pose_indices.size(); ++i) {
76 int32_t idx = response->invalid_pose_indices[i];
78 if (i < response->invalid_pose_indices.size() - 1) {
82 if (idx >= 0 &&
static_cast<size_t>(idx) < path_.poses.size()) {
83 collision_poses.push_back(path_.poses[idx]);
87 RCLCPP_WARN(node_->get_logger(),
"%s", ss.str().c_str());
91 setOutput(
"collision_poses", collision_poses);
93 return BT::NodeStatus::FAILURE;
98 #include "behaviortree_cpp/bt_factory.h"
99 BT_REGISTER_NODES(factory)
Abstract class representing a service based BT node.
A nav2_behavior_tree::BtServiceNode class that validates a path by calling the IsPathValid service on...
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.