pub struct SolRef {
pub timeconst: f64,
pub dampratio: f64,
}Expand description
MuJoCo-style solref: the reference response of a violated constraint.
The pair (timeconst, dampratio) describes the mass-normalized damped
spring the solver pretends the constraint is, rather than a raw
stiffness/damping pair. Parameterizing by a time constant is what makes the
behaviour independent of the contacting bodies’ masses: a 20 ms recovery is
20 ms whether the box weighs a gram or a tonne.
Fields§
§timeconst: f64Time constant of the constraint’s reference response, in seconds.
MuJoCo’s default is 0.02, and its guidance — that it should be at
least twice the timestep — applies here for the same reason: the
discrete correction below reduces to a per-step gain of
dt / (2*timeconst*dampratio^2 + dt), which saturates at 1 (a full,
popping correction in one step) as timeconst -> 0.
dampratio: f64Damping ratio. 1 is critically damped, which is what a contact
wants: penetration decays without overshooting into a bounce.
Implementations§
Source§impl SolRef
impl SolRef
Sourcepub fn error_reduction(&self, dt: f64) -> f64
pub fn error_reduction(&self, dt: f64) -> f64
Fraction of the current penetration to remove in a step of dt.
Derived from the reference spring rather than picked: a critically
damped spring with time constant tau and damping ratio zeta has
mass-normalized k = 1/(tau^2 zeta^2) and b = 2/(tau zeta^2). One
implicit step of that spring removes
dt*k / (b + dt*k) = dt / (2*tau*zeta^2 + dt)of the violation. Taking the implicit (rather than the explicit
dt^2 k) gain is what keeps the correction bounded by 1 for every
dt, so a large step can never over-correct and launch the body.