Skip to content

Commit b8f6971

Browse files
committed
Make NavigateThroughPoses navigator report waypoint statuses information
Signed-off-by: zz990099 <[email protected]>
1 parent 58619d2 commit b8f6971

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

nav2_bt_navigator/behavior_trees/navigate_through_poses_w_replanning_and_recovery.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RateController hz="0.333">
1515
<RecoveryNode number_of_retries="1" name="ComputePathThroughPoses">
1616
<ReactiveSequence>
17-
<RemovePassedGoals input_goals="{goals}" output_goals="{goals}" radius="0.7"/>
17+
<RemovePassedGoals input_goals="{goals}" output_goals="{goals}" radius="0.7" waypoint_statuses_id="{waypoint_statuses_id}" />
1818
<ComputePathThroughPoses goals="{goals}" path="{path}" planner_id="{selected_planner}" error_code_id="{compute_path_error_code}" error_msg="{compute_path_error_msg}"/>
1919
</ReactiveSequence>
2020
<Sequence>

nav2_bt_navigator/include/nav2_bt_navigator/navigators/navigate_through_poses.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "geometry_msgs/msg/pose_stamped.hpp"
2424
#include "nav2_core/behavior_tree_navigator.hpp"
2525
#include "nav2_msgs/action/navigate_through_poses.hpp"
26+
#include "nav2_msgs/msg/waypoint_status.hpp"
2627
#include "nav_msgs/msg/path.hpp"
2728
#include "nav2_util/robot_utils.hpp"
2829
#include "nav2_util/geometry_utils.hpp"
@@ -109,6 +110,7 @@ class NavigateThroughPosesNavigator
109110
rclcpp::Time start_time_;
110111
std::string goals_blackboard_id_;
111112
std::string path_blackboard_id_;
113+
std::string waypoint_statuses_blackboard_id_;
112114

113115
// Odometry smoother object
114116
std::shared_ptr<nav2_util::OdomSmoother> odom_smoother_;

nav2_bt_navigator/src/navigators/navigate_through_poses.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ NavigateThroughPosesNavigator::configure(
4242

4343
path_blackboard_id_ = node->get_parameter("path_blackboard_id").as_string();
4444

45+
if (!node->has_parameter("waypoint_statuses_blackboard_id")) {
46+
node->declare_parameter("waypoint_statuses_blackboard_id", std::string("waypoint_statuses"));
47+
}
48+
49+
waypoint_statuses_blackboard_id_ =
50+
node->get_parameter("waypoint_statuses_blackboard_id").as_string();
51+
4552
// Odometry smoother object for getting current speed
4653
odom_smoother_ = odom_smoother;
4754

@@ -100,6 +107,9 @@ NavigateThroughPosesNavigator::goalCompleted(
100107
result->error_code,
101108
result->error_msg.c_str());
102109
}
110+
auto blackboard = bt_action_server_->getBlackboard();
111+
result->waypoint_statuses =
112+
blackboard->get<std::vector<nav2_msgs::msg::WaypointStatus>>(waypoint_statuses_blackboard_id_);
103113
}
104114

105115
void
@@ -116,6 +126,9 @@ NavigateThroughPosesNavigator::onLoop()
116126
nav_msgs::msg::Goals goal_poses;
117127
[[maybe_unused]] auto res = blackboard->get(goals_blackboard_id_, goal_poses);
118128

129+
feedback_msg->waypoint_statuses =
130+
blackboard->get<std::vector<nav2_msgs::msg::WaypointStatus>>(waypoint_statuses_blackboard_id_);
131+
119132
if (goal_poses.goals.size() == 0) {
120133
bt_action_server_->publishFeedback(feedback_msg);
121134
return;
@@ -262,6 +275,16 @@ NavigateThroughPosesNavigator::initializeGoalPoses(ActionT::Goal::ConstSharedPtr
262275
blackboard->set<nav_msgs::msg::Goals>(goals_blackboard_id_,
263276
std::move(goals_array));
264277

278+
// Reset the waypoint states vector in the blackboard
279+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses(goals_array.goals.size());
280+
for (size_t waypoint_index = 0 ; waypoint_index < goals_array.goals.size() ; ++waypoint_index) {
281+
waypoint_statuses[waypoint_index].index = waypoint_index;
282+
waypoint_statuses[waypoint_index].goal = goals_array.goals[waypoint_index];
283+
}
284+
blackboard->set<decltype(waypoint_statuses)>(waypoint_statuses_blackboard_id_,
285+
std::move(waypoint_statuses));
286+
blackboard->set<std::string>("waypoint_statuses_id", waypoint_statuses_blackboard_id_);
287+
265288
return true;
266289
}
267290

0 commit comments

Comments
 (0)