Skip to content

Commit 3871dc7

Browse files
committed
[mppi] fix division by zero
leading to cost values being NaNs, which then propagate through all the critics and results in NaN control_sequence. These NaNs were removed by the hard applyControlSequenceConstraints(), but replaced with ax_max & wz_max. These lead to high steering at the start of a run Signed-off-by: Adi Vardi <adi.vardi@enway.ai>
1 parent 1779d92 commit 3871dc7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nav2_mppi_controller/src/critics/constraint_critic.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ void ConstraintCritic::score(CriticData & data)
8282
if (acker != nullptr) {
8383
auto & vx = data.state.vx;
8484
auto & wz = data.state.wz;
85-
float min_turning_rad = acker->getMinTurningRadius();
86-
auto out_of_turning_rad_motion = (min_turning_rad - (vx.abs() / wz.abs())).max(0.0f);
85+
const float min_turning_rad = acker->getMinTurningRadius();
86+
87+
const float epsilon = 1e-6f;
88+
auto wz_safe = wz.abs().max(epsilon); // Replace small wz values with epsilon to avoid division by 0
89+
auto out_of_turning_rad_motion = (min_turning_rad - (vx.abs() / wz_safe)).max(0.0f);
90+
8791
if (power_ > 1u) {
8892
data.costs += ((((vx - max_vel_).max(0.0f) + (min_vel_ - vx).max(0.0f) +
8993
out_of_turning_rad_motion) * data.model_dt).rowwise().sum().eval() *

0 commit comments

Comments
 (0)