Skip to content

Commit

Permalink
protect invalid max_velocity min_velocity (#3953)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Doisy <[email protected]>
  • Loading branch information
2 people authored and SteveMacenski committed Jan 24, 2024
1 parent 4b4442d commit 31c6ccb
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions nav2_velocity_smoother/src/velocity_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)
throw std::runtime_error(
"Negative values set of acceleration! These should be positive to speed up!");
}
if (min_velocities_[i] > 0.0) {
throw std::runtime_error(
"Positive values set of min_velocities! These should be negative!");
}
if (max_velocities_[i] < 0.0) {
throw std::runtime_error(
"Negative values set of max_velocities! These should be positive!");
}
if (min_velocities_[i] > max_velocities_[i]) {
throw std::runtime_error(
"Min velocities are higher than max velocities!");
Expand Down Expand Up @@ -361,9 +369,29 @@ VelocitySmoother::dynamicParametersCallback(std::vector<rclcpp::Parameter> param
}

if (name == "max_velocity") {
max_velocities_ = parameter.as_double_array();
for (unsigned int i = 0; i != 3; i++) {
if (parameter.as_double_array()[i] < 0.0) {
RCLCPP_WARN(
get_logger(),
"Negative values set of max_velocity! These should be positive!");
result.successful = false;
}
}
if (result.successful) {
max_velocities_ = parameter.as_double_array();
}
} else if (name == "min_velocity") {
min_velocities_ = parameter.as_double_array();
for (unsigned int i = 0; i != 3; i++) {
if (parameter.as_double_array()[i] > 0.0) {
RCLCPP_WARN(
get_logger(),
"Positive values set of min_velocity! These should be negative!");
result.successful = false;
}
}
if (result.successful) {
min_velocities_ = parameter.as_double_array();
}
} else if (name == "max_accel") {
for (unsigned int i = 0; i != 3; i++) {
if (parameter.as_double_array()[i] < 0.0) {
Expand Down

0 comments on commit 31c6ccb

Please sign in to comment.