Skip to content

Commit ad8563d

Browse files
doisygGuillaume Doisy
andauthored
add is_rotating_to_heading feedback (#4395)
Co-authored-by: Guillaume Doisy <guillaume@dexory.com>
1 parent 7dc76da commit ad8563d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎nav2_regulated_pure_pursuit_controller/include/nav2_regulated_pure_pursuit_controller/regulated_pure_pursuit_controller.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "pluginlib/class_loader.hpp"
2828
#include "pluginlib/class_list_macros.hpp"
2929
#include "geometry_msgs/msg/pose2_d.hpp"
30+
#include "std_msgs/msg/bool.hpp"
3031
#include "nav2_regulated_pure_pursuit_controller/path_handler.hpp"
3132
#include "nav2_regulated_pure_pursuit_controller/collision_checker.hpp"
3233
#include "nav2_regulated_pure_pursuit_controller/parameter_handler.hpp"
@@ -218,12 +219,15 @@ class RegulatedPurePursuitController : public nav2_core::Controller
218219
double control_duration_;
219220
bool cancelling_ = false;
220221
bool finished_cancelling_ = false;
222+
bool is_rotating_to_heading_ = false;
221223

222224
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> global_path_pub_;
223225
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::PointStamped>>
224226
carrot_pub_;
225227
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::PointStamped>>
226228
curvature_carrot_pub_;
229+
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<std_msgs::msg::Bool>>
230+
is_rotating_to_heading_pub_;
227231
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> carrot_arc_pub_;
228232
std::unique_ptr<nav2_regulated_pure_pursuit_controller::PathHandler> path_handler_;
229233
std::unique_ptr<nav2_regulated_pure_pursuit_controller::ParameterHandler> param_handler_;

‎nav2_regulated_pure_pursuit_controller/src/regulated_pure_pursuit_controller.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void RegulatedPurePursuitController::configure(
7676
carrot_pub_ = node->create_publisher<geometry_msgs::msg::PointStamped>("lookahead_point", 1);
7777
curvature_carrot_pub_ = node->create_publisher<geometry_msgs::msg::PointStamped>(
7878
"curvature_lookahead_point", 1);
79+
is_rotating_to_heading_pub_ = node->create_publisher<std_msgs::msg::Bool>(
80+
"is_rotating_to_heading", 1);
7981
}
8082

8183
void RegulatedPurePursuitController::cleanup()
@@ -88,6 +90,7 @@ void RegulatedPurePursuitController::cleanup()
8890
global_path_pub_.reset();
8991
carrot_pub_.reset();
9092
curvature_carrot_pub_.reset();
93+
is_rotating_to_heading_pub_.reset();
9194
}
9295

9396
void RegulatedPurePursuitController::activate()
@@ -100,6 +103,7 @@ void RegulatedPurePursuitController::activate()
100103
global_path_pub_->on_activate();
101104
carrot_pub_->on_activate();
102105
curvature_carrot_pub_->on_activate();
106+
is_rotating_to_heading_pub_->on_activate();
103107
}
104108

105109
void RegulatedPurePursuitController::deactivate()
@@ -112,6 +116,7 @@ void RegulatedPurePursuitController::deactivate()
112116
global_path_pub_->on_deactivate();
113117
carrot_pub_->on_deactivate();
114118
curvature_carrot_pub_->on_deactivate();
119+
is_rotating_to_heading_pub_->on_deactivate();
115120
}
116121

117122
std::unique_ptr<geometry_msgs::msg::PointStamped> RegulatedPurePursuitController::createCarrotMsg(
@@ -228,11 +233,14 @@ geometry_msgs::msg::TwistStamped RegulatedPurePursuitController::computeVelocity
228233
// - otherwise equal to curvature_lookahead_pose (which can be interpolated after goal)
229234
double angle_to_heading;
230235
if (shouldRotateToGoalHeading(carrot_pose)) {
236+
is_rotating_to_heading_ = true;
231237
double angle_to_goal = tf2::getYaw(transformed_plan.poses.back().pose.orientation);
232238
rotateToHeading(linear_vel, angular_vel, angle_to_goal, speed);
233239
} else if (shouldRotateToPath(rotate_to_path_carrot_pose, angle_to_heading, x_vel_sign)) {
240+
is_rotating_to_heading_ = true;
234241
rotateToHeading(linear_vel, angular_vel, angle_to_heading, speed);
235242
} else {
243+
is_rotating_to_heading_ = false;
236244
applyConstraints(
237245
regulation_curvature, speed,
238246
collision_checker_->costAtPose(pose.pose.position.x, pose.pose.position.y), transformed_plan,
@@ -267,6 +275,11 @@ geometry_msgs::msg::TwistStamped RegulatedPurePursuitController::computeVelocity
267275
throw nav2_core::NoValidControl("RegulatedPurePursuitController detected collision ahead!");
268276
}
269277

278+
// Publish whether we are rotating to goal heading
279+
std_msgs::msg::Bool is_rotating_to_heading_msg;
280+
is_rotating_to_heading_msg.data = is_rotating_to_heading_;
281+
is_rotating_to_heading_pub_->publish(is_rotating_to_heading_msg);
282+
270283
// populate and return message
271284
geometry_msgs::msg::TwistStamped cmd_vel;
272285
cmd_vel.header = pose.header;

0 commit comments

Comments
 (0)