19 #include "nav_msgs/msg/path.hpp"
20 #include "nav2_util/geometry_utils.hpp"
21 #include "nav2_ros_common/tf2_factories.hpp"
23 #include "nav2_behavior_tree/plugins/action/remove_passed_goals_action.hpp"
25 namespace nav2_behavior_tree
28 RemovePassedGoals::RemovePassedGoals(
29 const std::string & name,
30 const BT::NodeConfiguration & conf)
31 : BT::ActionNodeBase(name, conf),
32 viapoint_achieved_radius_(0.5)
35 void RemovePassedGoals::initialize()
37 getInput(
"radius", viapoint_achieved_radius_);
39 tf_ = config().blackboard->get<nav2::TransformBuffer::SharedPtr>(
"tf_buffer");
40 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
41 clock_ = node_->get_clock();
42 node_->get_parameter(
"transform_tolerance", transform_tolerance_);
43 transform_staleness_threshold_ = node_->declare_or_get_parameter(
44 "transform_staleness_threshold", 0.0);
46 robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
47 node_,
"robot_base_frame",
this);
50 inline BT::NodeStatus RemovePassedGoals::tick()
52 if (!BT::isStatusActive(status())) {
56 nav_msgs::msg::Goals goal_poses;
57 getInput(
"input_goals", goal_poses);
59 if (goal_poses.goals.empty()) {
60 setOutput(
"output_goals", goal_poses);
61 return BT::NodeStatus::SUCCESS;
64 using namespace nav2_util::geometry_utils;
66 geometry_msgs::msg::PoseStamped current_pose;
67 if (!nav2_util::getFreshPose(
68 *tf_, goal_poses.goals[0].header.frame_id, robot_base_frame_, clock_->now(),
69 transform_staleness_threshold_, current_pose))
71 return BT::NodeStatus::FAILURE;
75 std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses;
76 auto waypoint_statuses_get_res = getInput(
"input_waypoint_statuses", waypoint_statuses);
77 if (!waypoint_statuses_get_res) {
78 RCLCPP_ERROR_ONCE(node_->get_logger(),
"Missing [input_waypoint_statuses] port input!");
82 while (goal_poses.goals.size() > 1) {
83 dist_to_goal = euclidean_distance(goal_poses.goals[0].pose, current_pose.pose);
85 if (dist_to_goal > viapoint_achieved_radius_) {
90 if (waypoint_statuses_get_res) {
91 auto cur_waypoint_index =
92 find_next_matching_goal_in_waypoint_statuses(waypoint_statuses, goal_poses.goals[0]);
93 if (cur_waypoint_index == -1) {
94 RCLCPP_ERROR_ONCE(node_->get_logger(),
"Failed to find matching goal in waypoint_statuses");
95 return BT::NodeStatus::FAILURE;
97 waypoint_statuses[cur_waypoint_index].waypoint_status =
98 nav2_msgs::msg::WaypointStatus::COMPLETED;
101 goal_poses.goals.erase(goal_poses.goals.begin());
104 setOutput(
"output_goals", goal_poses);
106 setOutput(
"output_waypoint_statuses", waypoint_statuses);
108 return BT::NodeStatus::SUCCESS;
113 #include "behaviortree_cpp/bt_factory.h"
114 BT_REGISTER_NODES(factory)
A BT::ActionNodeBase that removes goals that the robot passed near to.