Skip to content

Commit

Permalink
Use return value of std::clamp (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <luca@openrobotics.org>
  • Loading branch information
luca-della-vedova committed Sep 13, 2021
1 parent 2626d08 commit b70c6a0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rmf_robot_sim_common/src/slotcar_common.cpp
Expand Up @@ -722,7 +722,7 @@ SlotcarCommon::UpdateResult SlotcarCommon::update_ackermann(
double dotp = heading.dot(dpos_norm);
double cross = heading.x() * dpos_norm.y() - heading.y() * dpos_norm.x();
// Clamp to avoid numerical errors due to floating point precision
std::clamp(dotp, -1.0, 1.0);
dotp = std::clamp(dotp, -1.0, 1.0);
result.w = cross < 0.0 ? -acos(dotp) : acos(dotp);
}
else
Expand All @@ -745,7 +745,7 @@ SlotcarCommon::UpdateResult SlotcarCommon::update_ackermann(
double cross = heading.x() * target_heading.y() - heading.y() *
target_heading.x();
// Clamp to avoid numerical errors due to floating point precision
std::clamp(heading_dotp, -1.0, 1.0);
heading_dotp = std::clamp(heading_dotp, -1.0, 1.0);
result.w = cross <
0.0 ? -acos(heading_dotp) : acos(heading_dotp);

Expand Down

0 comments on commit b70c6a0

Please sign in to comment.