From a5f7f4d1d9ef2f4de9e542543b4f7b07369d6994 Mon Sep 17 00:00:00 2001 From: Rein Appeldoorn Date: Thu, 12 Sep 2024 10:04:10 +0200 Subject: [PATCH] fix(steering-odometry): convert twist to steering angle --- steering_controllers_library/src/steering_odometry.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/steering_controllers_library/src/steering_odometry.cpp b/steering_controllers_library/src/steering_odometry.cpp index 824ec86f59..dbe210ed41 100644 --- a/steering_controllers_library/src/steering_odometry.cpp +++ b/steering_controllers_library/src/steering_odometry.cpp @@ -208,12 +208,9 @@ void SteeringOdometry::set_odometry_type(const unsigned int type) { config_type_ double SteeringOdometry::convert_twist_to_steering_angle(double v_bx, double omega_bz) { - if (fabs(v_bx) < std::numeric_limits::epsilon()) - { - // avoid division by zero - return 0.; - } - return std::atan(omega_bz * wheelbase_ / v_bx); + // phi can be nan if both v_bx and omega_bz are zero + const auto phi = std::atan(omega_bz * wheelbase_ / v_bx); + return std::isfinite(phi) ? phi : 0.0; } std::tuple, std::vector> SteeringOdometry::get_commands(