Skip to content

Commit 2d88d14

Browse files
[RPP] Remove dependency on collision checking to carrot location (#2211)
* Remove dependency on collision checking to carrot location * Fix i removal * changing API to be consistent with collision updates
1 parent 992deb0 commit 2d88d14

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

nav2_regulated_pure_pursuit_controller/include/nav2_regulated_pure_pursuit_controller/regulated_pure_pursuit_controller.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ class RegulatedPurePursuitController : public nav2_core::Controller
177177
*/
178178
bool isCollisionImminent(
179179
const geometry_msgs::msg::PoseStamped &,
180-
const geometry_msgs::msg::PoseStamped &,
181-
const double &, const double &, const double &);
180+
const double &, const double &);
182181

183182
/**
184183
* @brief Whether point is in collision

nav2_regulated_pure_pursuit_controller/src/regulated_pure_pursuit_controller.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ geometry_msgs::msg::TwistStamped RegulatedPurePursuitController::computeVelocity
272272
}
273273

274274
// Collision checking on this velocity heading
275-
if (isCollisionImminent(pose, carrot_pose, curvature, linear_vel, angular_vel)) {
275+
if (isCollisionImminent(pose, linear_vel, angular_vel)) {
276276
throw std::runtime_error("RegulatedPurePursuitController detected collision ahead!");
277277
}
278278

@@ -335,16 +335,13 @@ geometry_msgs::msg::PoseStamped RegulatedPurePursuitController::getLookAheadPoin
335335

336336
bool RegulatedPurePursuitController::isCollisionImminent(
337337
const geometry_msgs::msg::PoseStamped & robot_pose,
338-
const geometry_msgs::msg::PoseStamped & carrot_pose,
339-
const double & curvature, const double & linear_vel,
340-
const double & angular_vel)
338+
const double & linear_vel, const double & angular_vel)
341339
{
342340
// Note(stevemacenski): This may be a bit unusual, but the robot_pose is in
343341
// odom frame and the carrot_pose is in robot base frame.
344342

345343
// check current point is OK
346-
if (inCollision(robot_pose.pose.position.x, robot_pose.pose.position.y))
347-
{
344+
if (inCollision(robot_pose.pose.position.x, robot_pose.pose.position.y)) {
348345
return true;
349346
}
350347

@@ -356,29 +353,23 @@ bool RegulatedPurePursuitController::isCollisionImminent(
356353
pose_msg.header.frame_id = arc_pts_msg.header.frame_id;
357354
pose_msg.header.stamp = arc_pts_msg.header.stamp;
358355

359-
// Using curvature (k = 1 / R) and carrot distance (chord on circle R), project the command
360-
const double chord_len = hypot(carrot_pose.pose.position.x, carrot_pose.pose.position.y);
361-
362-
// Find the number of increments by finding the arc length of the chord on circle
363-
const double r = fabs(1.0 / curvature);
364-
const double alpha = 2.0 * asin(chord_len / (2 * r)); // central angle
365-
const double arc_len = alpha * r;
366-
const double delta_dist = costmap_->getResolution();
367-
const unsigned int num_pts = static_cast<unsigned int>(ceil(arc_len / delta_dist));
368356
const double projection_time = costmap_->getResolution() / linear_vel;
369357

370358
geometry_msgs::msg::Pose2D curr_pose;
371359
curr_pose.x = robot_pose.pose.position.x;
372360
curr_pose.y = robot_pose.pose.position.y;
373361
curr_pose.theta = tf2::getYaw(robot_pose.pose.orientation);
374362

375-
for (unsigned int i = 1; i < num_pts; i++) {
363+
int i = 1;
364+
while (true) {
376365
// only forward simulate within time requested
377366
if (i * projection_time > max_allowed_time_to_collision_) {
378367
break;
379368
}
369+
370+
i++;
380371

381-
// apply velocity at curr_pose over distance delta_dist
372+
// apply velocity at curr_pose over distance
382373
curr_pose.x += projection_time * (linear_vel * cos(curr_pose.theta));
383374
curr_pose.y += projection_time * (linear_vel * sin(curr_pose.theta));
384375
curr_pose.theta += projection_time * angular_vel;

0 commit comments

Comments
 (0)