Skip to content

Commit 91a7f9f

Browse files
authored
Controller FollowPath feedback: Fix wrong frame in distance calculation, add more info to feedback (#4931)
* Add more info to feedback, fix wrong frame in distance calculation Signed-off-by: Adi Vardi <[email protected]> * Write FollowPath Feedback to blackboard Signed-off-by: Adi Vardi <[email protected]> * first publish velocity, then try to publish feedback also remove debug prints Signed-off-by: Adi Vardi <[email protected]> * Revert "Write FollowPath Feedback to blackboard" This reverts commit 1ee9ec1. Signed-off-by: Adi Vardi <[email protected]> * small fixes to na2_tree_nodes.xml Signed-off-by: Adi Vardi <[email protected]> * fix formatting issue Signed-off-by: Adi Vardi <[email protected]> * remove additional feedback fields from FollowPath action Signed-off-by: Adi Vardi <[email protected]> * throw if transform failed Signed-off-by: Adi Vardi <[email protected]> --------- Signed-off-by: Adi Vardi <[email protected]>
1 parent 9f09b06 commit 91a7f9f

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

nav2_behavior_tree/nav2_tree_nodes.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<input_port name="time_allowance">Allowed time for reversing</input_port>
1414
<input_port name="server_name">Server name</input_port>
1515
<input_port name="server_timeout">Server timeout</input_port>
16-
<input_port name="disable_collision_checks">Disable collision checking</input_port>
16+
<input_port name="disable_collision_checks" type="bool" default="false">Disable collision checking</input_port>
1717
<output_port name="error_code_id">"Back up error code"</output_port>
1818
<output_port name="error_msg">"Back up error message"</output_port>
1919
</Action>
@@ -131,7 +131,7 @@
131131
<input_port name="path">Path to follow</input_port>
132132
<input_port name="goal_checker_id">Goal checker</input_port>
133133
<input_port name="progress_checker_id">Progress checker</input_port>
134-
<input_port name="service_name">Service name</input_port>
134+
<input_port name="server_name">Action server name</input_port>
135135
<input_port name="server_timeout">Server timeout</input_port>
136136
<output_port name="error_code_id">Follow Path error code</output_port>
137137
<output_port name="error_msg">Follow Path error message</output_port>

nav2_controller/include/nav2_controller/controller_server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ControllerServer : public nav2_util::LifecycleNode
186186
*/
187187
bool isGoalReached();
188188
/**
189-
* @brief Obtain current pose of the robot
189+
* @brief Obtain current pose of the robot in costmap's frame
190190
* @param pose To store current pose of the robot
191191
* @return true if able to obtain current pose of the robot, else false
192192
*/

nav2_controller/src/controller_server.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -668,18 +668,31 @@ void ControllerServer::computeAndPublishVelocity()
668668
}
669669
}
670670

671+
RCLCPP_DEBUG(get_logger(), "Publishing velocity at time %.2f", now().seconds());
672+
publishVelocity(cmd_vel_2d);
673+
674+
// Find the closest pose to current pose on global path
675+
geometry_msgs::msg::PoseStamped robot_pose_in_path_frame;
676+
rclcpp::Duration tolerance(rclcpp::Duration::from_seconds(costmap_ros_->getTransformTolerance()));
677+
if (!nav_2d_utils::transformPose(
678+
costmap_ros_->getTfBuffer(), current_path_.header.frame_id, pose,
679+
robot_pose_in_path_frame, tolerance))
680+
{
681+
throw nav2_core::ControllerTFError("Failed to transform robot pose to path frame");
682+
}
683+
671684
std::shared_ptr<Action::Feedback> feedback = std::make_shared<Action::Feedback>();
672685
feedback->speed = std::hypot(cmd_vel_2d.twist.linear.x, cmd_vel_2d.twist.linear.y);
673686

674-
// Find the closest pose to current pose on global path
675687
nav_msgs::msg::Path & current_path = current_path_;
676-
auto find_closest_pose_idx =
677-
[&pose, &current_path]() {
688+
auto find_closest_pose_idx = [&robot_pose_in_path_frame, &current_path]()
689+
{
678690
size_t closest_pose_idx = 0;
679691
double curr_min_dist = std::numeric_limits<double>::max();
680692
for (size_t curr_idx = 0; curr_idx < current_path.poses.size(); ++curr_idx) {
681-
double curr_dist = nav2_util::geometry_utils::euclidean_distance(
682-
pose, current_path.poses[curr_idx]);
693+
double curr_dist =
694+
nav2_util::geometry_utils::euclidean_distance(robot_pose_in_path_frame,
695+
current_path.poses[curr_idx]);
683696
if (curr_dist < curr_min_dist) {
684697
curr_min_dist = curr_dist;
685698
closest_pose_idx = curr_idx;
@@ -688,12 +701,10 @@ void ControllerServer::computeAndPublishVelocity()
688701
return closest_pose_idx;
689702
};
690703

691-
feedback->distance_to_goal =
692-
nav2_util::geometry_utils::calculate_path_length(current_path_, find_closest_pose_idx());
704+
const std::size_t closest_pose_idx = find_closest_pose_idx();
705+
feedback->distance_to_goal = nav2_util::geometry_utils::calculate_path_length(current_path_,
706+
closest_pose_idx);
693707
action_server_->publish_feedback(feedback);
694-
695-
RCLCPP_DEBUG(get_logger(), "Publishing velocity at time %.2f", now().seconds());
696-
publishVelocity(cmd_vel_2d);
697708
}
698709

699710
void ControllerServer::updateGlobalPath()

0 commit comments

Comments
 (0)