Skip to content

Commit 1714665

Browse files
author
Guillaume Doisy
committed
min_distance_to_obstacle
1 parent 14e1e84 commit 1714665

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

nav2_regulated_pure_pursuit_controller/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Note: The maximum allowed time to collision is thresholded by the lookahead poin
7777
| `approach_velocity_scaling_dist` | Integrated distance from end of transformed path at which to start applying velocity scaling. This defaults to the forward extent of the costmap minus one costmap cell length. |
7878
| `use_collision_detection` | Whether to enable collision detection. |
7979
| `max_allowed_time_to_collision_up_to_carrot` | The time to project a velocity command to check for collisions when `use_collision_detection` is `true`. It is limited to maximum distance of lookahead distance selected. |
80+
| `min_distance_to_obstacle` | The shorter distance at which the robot is allowed to be from an obstacle along its trajectory. Set <= 0.0 to disable. It is limited to maximum distance of lookahead distance selected. |
8081
| `use_regulated_linear_velocity_scaling` | Whether to use the regulated features for curvature |
8182
| `use_cost_regulated_linear_velocity_scaling` | Whether to use the regulated features for proximity to obstacles |
8283
| `cost_scaling_dist` | The minimum distance from an obstacle to trigger the scaling of linear velocity, if `use_cost_regulated_linear_velocity_scaling` is enabled. The value set should be smaller or equal to the `inflation_radius` set in the inflation layer of costmap, since inflation is used to compute the distance from obstacles |

nav2_regulated_pure_pursuit_controller/include/nav2_regulated_pure_pursuit_controller/parameter_handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct Parameters
4242
double min_approach_linear_velocity;
4343
double approach_velocity_scaling_dist;
4444
double max_allowed_time_to_collision_up_to_carrot;
45+
double min_distance_to_obstacle;
4546
bool use_regulated_linear_velocity_scaling;
4647
bool use_cost_regulated_linear_velocity_scaling;
4748
double cost_scaling_dist;

nav2_regulated_pure_pursuit_controller/src/collision_checker.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,21 @@ bool CollisionChecker::isCollisionImminent(
9090
curr_pose.x = robot_pose.pose.position.x;
9191
curr_pose.y = robot_pose.pose.position.y;
9292
curr_pose.theta = tf2::getYaw(robot_pose.pose.orientation);
93+
double accumulated_distance = 0.0;
9394

9495
// only forward simulate within time requested
9596
int i = 1;
96-
while (i * projection_time < params_->max_allowed_time_to_collision_up_to_carrot) {
97+
while (i * projection_time < params_->max_allowed_time_to_collision_up_to_carrot ||
98+
(accumulated_distance < params_->min_distance_to_obstacle &&
99+
projection_time * linear_vel > 0.01))
100+
{
97101
i++;
98102

99103
// apply velocity at curr_pose over distance
100104
curr_pose.x += projection_time * (linear_vel * cos(curr_pose.theta));
101105
curr_pose.y += projection_time * (linear_vel * sin(curr_pose.theta));
102106
curr_pose.theta += projection_time * angular_vel;
107+
accumulated_distance += projection_time * linear_vel;
103108

104109
// check if past carrot pose, where no longer a thoughtfully valid command
105110
if (hypot(curr_pose.x - robot_xy.x, curr_pose.y - robot_xy.y) > carrot_dist) {

nav2_regulated_pure_pursuit_controller/src/parameter_handler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ ParameterHandler::ParameterHandler(
6060
declare_parameter_if_not_declared(
6161
node, plugin_name_ + ".max_allowed_time_to_collision_up_to_carrot",
6262
rclcpp::ParameterValue(1.0));
63+
declare_parameter_if_not_declared(
64+
node, plugin_name_ + ".min_distance_to_obstacle",
65+
rclcpp::ParameterValue(-1.0));
6366
declare_parameter_if_not_declared(
6467
node, plugin_name_ + ".use_regulated_linear_velocity_scaling", rclcpp::ParameterValue(true));
6568
declare_parameter_if_not_declared(
@@ -128,6 +131,9 @@ ParameterHandler::ParameterHandler(
128131
node->get_parameter(
129132
plugin_name_ + ".max_allowed_time_to_collision_up_to_carrot",
130133
params_.max_allowed_time_to_collision_up_to_carrot);
134+
node->get_parameter(
135+
plugin_name_ + ".min_distance_to_obstacle",
136+
params_.min_distance_to_obstacle);
131137
node->get_parameter(
132138
plugin_name_ + ".use_regulated_linear_velocity_scaling",
133139
params_.use_regulated_linear_velocity_scaling);
@@ -233,6 +239,8 @@ ParameterHandler::dynamicParametersCallback(
233239
params_.curvature_lookahead_dist = parameter.as_double();
234240
} else if (name == plugin_name_ + ".max_allowed_time_to_collision_up_to_carrot") {
235241
params_.max_allowed_time_to_collision_up_to_carrot = parameter.as_double();
242+
} else if (name == plugin_name_ + ".min_distance_to_obstacle") {
243+
params_.min_distance_to_obstacle = parameter.as_double();
236244
} else if (name == plugin_name_ + ".cost_scaling_dist") {
237245
params_.cost_scaling_dist = parameter.as_double();
238246
} else if (name == plugin_name_ + ".cost_scaling_gain") {

nav2_regulated_pure_pursuit_controller/test/test_regulated_pp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ TEST(RegulatedPurePursuitTest, testDynamicParameter)
701701
rclcpp::Parameter("test.rotate_to_heading_angular_vel", 18.0),
702702
rclcpp::Parameter("test.min_approach_linear_velocity", 1.0),
703703
rclcpp::Parameter("test.max_allowed_time_to_collision_up_to_carrot", 2.0),
704+
rclcpp::Parameter("test.min_distance_to_obstacle", 2.0),
704705
rclcpp::Parameter("test.cost_scaling_dist", 2.0),
705706
rclcpp::Parameter("test.cost_scaling_gain", 4.0),
706707
rclcpp::Parameter("test.regulated_linear_scaling_min_radius", 10.0),
@@ -729,6 +730,7 @@ TEST(RegulatedPurePursuitTest, testDynamicParameter)
729730
EXPECT_EQ(
730731
node->get_parameter(
731732
"test.max_allowed_time_to_collision_up_to_carrot").as_double(), 2.0);
733+
EXPECT_EQ(node->get_parameter("test.min_distance_to_obstacle").as_double(), 2.0);
732734
EXPECT_EQ(node->get_parameter("test.cost_scaling_dist").as_double(), 2.0);
733735
EXPECT_EQ(node->get_parameter("test.cost_scaling_gain").as_double(), 4.0);
734736
EXPECT_EQ(node->get_parameter("test.regulated_linear_scaling_min_radius").as_double(), 10.0);

0 commit comments

Comments
 (0)