Description
mju_springDamper selects the overdamped, critically damped, or underdamped solution using a fixed absolute tolerance on the characteristic discriminant. This makes the returned trajectory depend on the chosen time units.
For the system
x'' + Kv*x' + Kp*x = 0,
rescaling time by a positive factor s transforms the inputs as follows while preserving the same position trajectory:
vel0 -> s*vel0
Kp -> s^2*Kp
Kv -> s*Kv
dt -> dt/s
Reproduction
With pos0=1 and vel0=0, these two calls describe the same system under different time units:
Kp=0.025, Kv=1, dt=10 returns 0.7946142382307649.
- With
s=1e-8, Kp=2.5e-18, Kv=1e-8, dt=1e9 returns 0.0404276819945128.
Both should return 0.7946142382307650, the analytical overdamped solution.
Cause
The scaled discriminant is Kv^2 - 4*Kp = 9e-17. The current fixed comparison against +/- mjMINVAL classifies it as critically damped even though the equivalent unscaled system is overdamped.
Expected behavior
Damping-regime selection and the returned position should be invariant to a consistent change of time units. A relative tolerance scaled by the discriminant terms preserves the existing near-critical safeguard without changing the public API.
I have a small patch with analytical coverage for all three damping regimes and a regression test for the time-scaling property.
Description
mju_springDamperselects the overdamped, critically damped, or underdamped solution using a fixed absolute tolerance on the characteristic discriminant. This makes the returned trajectory depend on the chosen time units.For the system
x'' + Kv*x' + Kp*x = 0,rescaling time by a positive factor
stransforms the inputs as follows while preserving the same position trajectory:vel0 -> s*vel0Kp -> s^2*KpKv -> s*Kvdt -> dt/sReproduction
With
pos0=1andvel0=0, these two calls describe the same system under different time units:Kp=0.025,Kv=1,dt=10returns0.7946142382307649.s=1e-8,Kp=2.5e-18,Kv=1e-8,dt=1e9returns0.0404276819945128.Both should return
0.7946142382307650, the analytical overdamped solution.Cause
The scaled discriminant is
Kv^2 - 4*Kp = 9e-17. The current fixed comparison against+/- mjMINVALclassifies it as critically damped even though the equivalent unscaled system is overdamped.Expected behavior
Damping-regime selection and the returned position should be invariant to a consistent change of time units. A relative tolerance scaled by the discriminant terms preserves the existing near-critical safeguard without changing the public API.
I have a small patch with analytical coverage for all three damping regimes and a regression test for the time-scaling property.