← Control Loops Outside the Lab

Control Loops Outside the Lab · 04

Choosing the Damping of a Spring

Position error pulls toward the target; velocity feedback controls the approach. A practical model for cameras, animation, and mechanical motion.

A camera that follows a player needs more than a destination. It needs a rule for getting there. Setting its position directly can transmit every small movement. Moving a fixed fraction of the remaining distance each frame introduces lag, and makes the response depend on frame rate unless the fraction accounts for elapsed time.

A damped spring gives us a useful alternative: keep both position and velocity, accelerate toward the target, and apply resistance proportional to velocity.

The same model describes some simple mechanical systems. It also gives us two parameters whose effects are reasonably easy to predict.

Separate speed from damping

For a unit-mass follower, the equation is:

acceleration = omega² * (target - position)
               - 2 * zeta * omega * velocity

omega is the undamped natural angular frequency, in radians per second. Raising it makes the response faster. zeta is the dimensionless damping ratio. It determines the shape of that response.

For a fixed target and an initial state at rest, a damping ratio below one produces overshoot and oscillation. At one, the response is critically damped. Above one, it approaches without oscillating, but more slowly than the critical case at the same natural frequency.

The initial conditions matter. A critically damped follower that is already moving quickly toward a nearby target can still cross it. “Critical damping never overshoots” is too broad a promise.

  • Target (drag it)
  • Underdamped ζ=0.3
  • Yours (slider)
  • Overdamped ζ=2.2
Presets

The outer followers keep damping ratios of 0.3 and 2.2. The middle follower uses the slider. Compare them at the same natural frequency, then change that frequency without changing the damping ratio.

The target normally alternates between two positions. You can step it manually or drag it. These moving-target experiments are useful precisely because they are not the clean, from-rest step response used to classify the three regimes.

Why velocity feedback helps

Position error tells the spring which way to accelerate. It does not tell it how much momentum it already has.

As the follower approaches its target, the spring force becomes smaller. With no damping, however, the accumulated velocity carries it through the target. The spring then accelerates it back in the other direction.

Velocity feedback removes energy during that motion. It can slow the follower before the position error changes sign. For a stationary target, this is closely related to the derivative term of a position controller.

A moving target adds a design choice. Damping the follower’s absolute velocity is different from damping its velocity relative to the target. The latter requires an estimate of target velocity and can behave differently at sudden target jumps. The lab uses absolute follower velocity.

Critical for which objective?

For this linear model, a step from rest, and fixed natural frequency, critical damping gives the fastest monotonic approach among the critically damped and overdamped cases.

That does not make it optimal for every application. A slightly underdamped response may enter a chosen tolerance band sooner if some overshoot is acceptable. A camera may need collision constraints, speed limits, or different responses on different axes. A door closer has geometry, friction, and often separate control near the latch. None of those details fit into one damping ratio.

Start by deciding what a bad response looks like. If crossing the target is visually distracting, a monotonic response is a useful requirement. If lag is more objectionable than a small overshoot, some underdamping may be a better choice.

Then define what “settled” means. The lab reports time inside a fixed position tolerance for a short hold period. It clears that measurement if the follower leaves the band again. A different tolerance will produce a different settling time.

The numerical method is part of the system

The lab updates velocity and then position with a fixed 1/120-second step. Rendering uses a separate clock, so a high-refresh display does not make the spring run faster.

That integration method is adequate for the frequencies exposed by the controls. It is not unconditionally stable. Raising stiffness far beyond the available range, or feeding a long frame stall directly into the physics step, can make the numerical simulation oscillate even when the continuous model would not.

For a linear spring, an analytic update is another useful option, especially when you need reliable behavior across widely varying time steps. For a more general simulation, use a suitable integrator and test its step-size limits.

A spring is a compact piece of code, but its behavior comes from the equation, the initial conditions, the target motion, and the numerical update together. Keeping those explicit makes tuning considerably less mysterious.