Skip to content

Commit

Permalink
fix: remove numeric errors during yaw setpoint simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
vasarhelyi committed Nov 7, 2023
1 parent 41bb9bd commit b4a6fe0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modules/sbstudio/model/yaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def simplify(self: C) -> C:
raise RuntimeError(
f"Yaw timestamps are not causal ({setpoint.time} <= {new_setpoints[-1].time})"
)
angular_speed = (setpoint.angle - new_setpoints[-1].angle) / dt
# when calculating angular speed, we round timestamps and angles
# to avoid large numeric errors at division by small numbers
angular_speed = (
round(setpoint.angle, ndigits=3)
- round(new_setpoints[-1].angle, ndigits=3)
) / round(dt, ndigits=3)
if abs(angular_speed - last_angular_speed) < 1e-6:
new_setpoints[-1] = setpoint
else:
Expand Down

0 comments on commit b4a6fe0

Please sign in to comment.