Skip to content

Commit 1db63c0

Browse files
committed
Add waypoint_statuses records in RemoveInCollisionGoals/RemovePassedGoals actions
Signed-off-by: zz990099 <771647586@qq.com>
1 parent 99b4a9b commit 1db63c0

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/remove_in_collision_goals_action.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "nav_msgs/msg/goals.hpp"
2424
#include "nav2_behavior_tree/bt_service_node.hpp"
2525
#include "nav2_msgs/srv/get_costs.hpp"
26+
#include "nav2_msgs/msg/waypoint_status.hpp"
2627

2728
namespace nav2_behavior_tree
2829
{
@@ -63,6 +64,10 @@ class RemoveInCollisionGoals : public BtServiceNode<nav2_msgs::srv::GetCosts>
6364
"Whether to consider unknown cost as obstacle"),
6465
BT::OutputPort<nav_msgs::msg::Goals>("output_goals",
6566
"Goals with in-collision goals removed"),
67+
BT::InputPort<std::vector<nav2_msgs::msg::WaypointStatus>>("input_waypoint_statuses",
68+
"Original waypoint statuses vector to be modified"),
69+
BT::OutputPort<std::vector<nav2_msgs::msg::WaypointStatus>>("output_waypoint_statuses",
70+
"waypoint statuses vector with states modified"),
6671
});
6772
}
6873

nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/remove_passed_goals_action.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "nav2_util/robot_utils.hpp"
2525
#include "behaviortree_cpp/action_node.h"
2626
#include "nav2_behavior_tree/bt_utils.hpp"
27+
#include "nav2_msgs/msg/waypoint_status.hpp"
2728

2829
namespace nav2_behavior_tree
2930
{
@@ -49,6 +50,10 @@ class RemovePassedGoals : public BT::ActionNodeBase
4950
"Goals with passed viapoints removed"),
5051
BT::InputPort<double>("radius", 0.5, "radius to goal for it to be considered for removal"),
5152
BT::InputPort<std::string>("robot_base_frame", "Robot base frame"),
53+
BT::InputPort<std::vector<nav2_msgs::msg::WaypointStatus>>("input_waypoint_statuses",
54+
"Original waypoint statuses vector to be modified"),
55+
BT::OutputPort<std::vector<nav2_msgs::msg::WaypointStatus>>("output_waypoint_statuses",
56+
"waypoint statuses vector with states modified"),
5257
};
5358
}
5459

nav2_behavior_tree/plugins/action/remove_in_collision_goals_action.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,18 @@ BT::NodeStatus RemoveInCollisionGoals::on_completion(
6363
return BT::NodeStatus::FAILURE;
6464
}
6565

66+
// get the `waypoint_statuses` vector if provided
67+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses;
68+
auto get_waypoint_statuses_res = getInput("input_waypoint_statuses", waypoint_statuses);
69+
6670
nav_msgs::msg::Goals valid_goal_poses;
6771
for (size_t i = 0; i < response->costs.size(); ++i) {
6872
if ((response->costs[i] == 255 && !consider_unknown_as_obstacle_) ||
6973
response->costs[i] < cost_threshold_)
7074
{
7175
valid_goal_poses.goals.push_back(input_goals_.goals[i]);
76+
} else if (get_waypoint_statuses_res) {
77+
waypoint_statuses[i].waypoint_status = nav2_msgs::msg::WaypointStatus::SKIPPED;
7278
}
7379
}
7480
// Inform if all goals have been removed
@@ -78,6 +84,9 @@ BT::NodeStatus RemoveInCollisionGoals::on_completion(
7884
"All goals are in collision and have been removed from the list");
7985
}
8086
setOutput("output_goals", valid_goal_poses);
87+
if (get_waypoint_statuses_res) {
88+
setOutput("output_waypoint_statuses", waypoint_statuses);
89+
}
8190
return BT::NodeStatus::SUCCESS;
8291
}
8392

nav2_behavior_tree/plugins/action/remove_passed_goals_action.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ inline BT::NodeStatus RemovePassedGoals::tick()
6767
return BT::NodeStatus::FAILURE;
6868
}
6969

70+
// get the `waypoint_statuses` vector if provided
71+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses;
72+
auto get_waypoint_statuses_res = getInput("input_waypoint_statuses", waypoint_statuses);
73+
size_t cur_waypoint_index = 0;
74+
if (get_waypoint_statuses_res) {
75+
while (cur_waypoint_index < waypoint_statuses.size()) {
76+
if (waypoint_statuses[cur_waypoint_index].waypoint_status ==
77+
nav2_msgs::msg::WaypointStatus::PENDING)
78+
{
79+
break;
80+
}
81+
++cur_waypoint_index;
82+
}
83+
}
84+
7085
double dist_to_goal;
7186
while (goal_poses.goals.size() > 1) {
7287
dist_to_goal = euclidean_distance(goal_poses.goals[0].pose, current_pose.pose);
@@ -76,9 +91,18 @@ inline BT::NodeStatus RemovePassedGoals::tick()
7691
}
7792

7893
goal_poses.goals.erase(goal_poses.goals.begin());
94+
// mark waypoint statuses if the vector is provided
95+
if (get_waypoint_statuses_res) {
96+
waypoint_statuses[cur_waypoint_index].waypoint_status =
97+
nav2_msgs::msg::WaypointStatus::COMPLETED;
98+
++cur_waypoint_index;
99+
}
79100
}
80101

81102
setOutput("output_goals", goal_poses);
103+
if (get_waypoint_statuses_res) {
104+
setOutput("output_waypoint_statuses", waypoint_statuses);
105+
}
82106

83107
return BT::NodeStatus::SUCCESS;
84108
}

0 commit comments

Comments
 (0)