Skip to content

Commit 572d0f8

Browse files
doisygGuillaume Doisy
andauthored
protect invalid max_velocity min_velocity (#3953)
Co-authored-by: Guillaume Doisy <guillaume@dexory.com>
1 parent 5053226 commit 572d0f8

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎nav2_velocity_smoother/src/velocity_smoother.cpp‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ VelocitySmoother::on_configure(const rclcpp_lifecycle::State &)
8383
throw std::runtime_error(
8484
"Negative values set of acceleration! These should be positive to speed up!");
8585
}
86+
if (min_velocities_[i] > 0.0) {
87+
throw std::runtime_error(
88+
"Positive values set of min_velocities! These should be negative!");
89+
}
90+
if (max_velocities_[i] < 0.0) {
91+
throw std::runtime_error(
92+
"Negative values set of max_velocities! These should be positive!");
93+
}
8694
if (min_velocities_[i] > max_velocities_[i]) {
8795
throw std::runtime_error(
8896
"Min velocities are higher than max velocities!");
@@ -361,9 +369,29 @@ VelocitySmoother::dynamicParametersCallback(std::vector<rclcpp::Parameter> param
361369
}
362370

363371
if (name == "max_velocity") {
364-
max_velocities_ = parameter.as_double_array();
372+
for (unsigned int i = 0; i != 3; i++) {
373+
if (parameter.as_double_array()[i] < 0.0) {
374+
RCLCPP_WARN(
375+
get_logger(),
376+
"Negative values set of max_velocity! These should be positive!");
377+
result.successful = false;
378+
}
379+
}
380+
if (result.successful) {
381+
max_velocities_ = parameter.as_double_array();
382+
}
365383
} else if (name == "min_velocity") {
366-
min_velocities_ = parameter.as_double_array();
384+
for (unsigned int i = 0; i != 3; i++) {
385+
if (parameter.as_double_array()[i] > 0.0) {
386+
RCLCPP_WARN(
387+
get_logger(),
388+
"Positive values set of min_velocity! These should be negative!");
389+
result.successful = false;
390+
}
391+
}
392+
if (result.successful) {
393+
min_velocities_ = parameter.as_double_array();
394+
}
367395
} else if (name == "max_accel") {
368396
for (unsigned int i = 0; i != 3; i++) {
369397
if (parameter.as_double_array()[i] < 0.0) {

0 commit comments

Comments
 (0)