Skip to content

Commit 8c06085

Browse files
committed
handled last_fixes
Signed-off-by: silanus23 <[email protected]>
1 parent 4768016 commit 8c06085

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

nav2_controller/include/nav2_controller/controller_server.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class ControllerServer : public nav2::LifecycleNode
241241
std::unique_ptr<nav2_util::OdomSmoother> odom_sub_;
242242
std::unique_ptr<nav2_util::TwistPublisher> vel_publisher_;
243243
nav2::Subscription<nav2_msgs::msg::SpeedLimit>::SharedPtr speed_limit_sub_;
244-
rclcpp::Publisher<nav2_msgs::msg::TrackingError>::SharedPtr tracking_error_pub_;
244+
nav2::Publisher<nav2_msgs::msg::TrackingError>::SharedPtr tracking_error_pub_;
245245

246246
// Progress Checker Plugin
247247
pluginlib::ClassLoader<nav2_core::ProgressChecker> progress_checker_loader_;
@@ -291,6 +291,9 @@ class ControllerServer : public nav2::LifecycleNode
291291
// Current path container
292292
nav_msgs::msg::Path current_path_;
293293

294+
// Last tracking error
295+
double signed_distance_ = 0;
296+
294297
private:
295298
/**
296299
* @brief Callback for speed limiting messages

nav2_controller/src/controller_server.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ void ControllerServer::computeAndPublishVelocity()
704704
feedback->distance_to_goal = nav2_util::geometry_utils::calculate_path_length(current_path_,
705705
closest_pose_idx);
706706
action_server_->publish_feedback(feedback);
707+
feedback->tracking_error = signed_distance_;
707708
}
708709

709710
void ControllerServer::updateGlobalPath()
@@ -786,9 +787,6 @@ void ControllerServer::publishTrackingState()
786787
return;
787788
}
788789

789-
const double distance_to_goal = nav2_util::geometry_utils::euclidean_distance(
790-
robot_pose, end_pose_in_robot_frame);
791-
792790
const auto path_search_result = nav2_util::distance_from_path(
793791
current_path_, robot_pose_in_path_frame.pose, start_index_, search_window_);
794792

@@ -802,16 +800,14 @@ void ControllerServer::publishTrackingState()
802800
double cross_product = nav2_util::geometry_utils::cross_product_2d(
803801
robot_pose_in_path_frame.pose.position, segment_start.pose, segment_end.pose);
804802

805-
nav2_msgs::msg::TrackingError tracking_error_msg;
806-
tracking_error_msg.header.stamp = now();
807-
tracking_error_msg.header.frame_id = robot_pose.header.frame_id;
808-
tracking_error_msg.tracking_error = path_search_result.distance;
809-
tracking_error_msg.last_index = closest_idx;
810-
tracking_error_msg.cross_product = cross_product;
811-
tracking_error_msg.distance_to_goal = distance_to_goal;
812-
tracking_error_msg.robot_pose = robot_pose;
813-
814-
tracking_error_pub_->publish(tracking_error_msg);
803+
signed_distance_ = path_search_result.distance * (cross_product >= 0.0 ? 1.0 : -1.0);
804+
auto tracking_error_msg = std::make_unique<nav2_msgs::msg::TrackingError>();
805+
tracking_error_msg->header.stamp = now();
806+
tracking_error_msg->header.frame_id = robot_pose.header.frame_id;
807+
tracking_error_msg->tracking_error = signed_distance_;
808+
tracking_error_msg->current_path_index = closest_idx;
809+
tracking_error_msg->robot_pose = robot_pose;
810+
tracking_error_pub_->publish(std::move(tracking_error_msg));
815811
}
816812

817813
void ControllerServer::publishVelocity(const geometry_msgs::msg::TwistStamped & velocity)

nav2_msgs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
3939
"msg/RouteNode.msg"
4040
"msg/RouteEdge.msg"
4141
"msg/EdgeCost.msg"
42+
"msg/TrackingError.msg"
4243
"msg/Trajectory.msg"
4344
"msg/TrajectoryPoint.msg"
4445
"srv/GetCosts.srv"

nav2_msgs/action/FollowPath.action

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ string error_msg
2525
#feedback definition
2626
float32 distance_to_goal
2727
float32 speed
28+
float32 tracking_error

nav2_msgs/msg/TrackingError.msg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Real-time tracking error for Nav2 controller
22

33
std_msgs/Header header
4+
# The sign of the tracking error indicates which side of the path the robot is on
5+
# Positive sign indicates the robot is to the left of the path, negative to the right
46
float32 tracking_error
5-
uint32 last_index
6-
float32 cross_product
7+
uint32 current_path_index
78
geometry_msgs/PoseStamped robot_pose
8-
float32 distance_to_goal

0 commit comments

Comments
 (0)