The chassis rides on four wheel contacts sampled from the terrain height field h(x,z). Fitting a plane through those four contact heights gives the chassis's own pitch and roll — the tilt a rigid vehicle body would have on that ground:
pitch_chassis = atan2(h_front − h_rear, wheelbase)
roll_chassis = atan2(h_left − h_right, track_width)
The stretcher sits on four independent vertical actuators mounted at the chassis corners. With leveling ON, each actuator's target extension cancels the local tilt contribution at its own mounting point, so the actuator tops always form a world-level plane at a fixed ride height h₀ above the chassis:
target_i = h0 − (dz_i·sin(pitch_chassis) + dx_i·sin(roll_chassis))
actual_i += (target_i − actual_i) · (1 − e^(−dt·k_response))
k_response falls as the carried load grows (a heavier stretcher makes the hydraulics slower to catch up), so heavier loads show more transient sway before the platform settles level. With leveling OFF, every actuator holds a fixed length h₀ instead — the stretcher is rigidly bolted to the chassis and tips exactly as much as the ground does.
The stability margin approximates tip-over risk from the classic zero-moment-point idea: it shrinks as roll grows and as the load's center of mass sits higher and heavier relative to the track width, and would hit 0% right at the point the combined center of gravity crosses outside the wheel base.
Real-world relevance: this is the same self-leveling-payload principle used on stretcher/litter UGVs, ambulance gurney mounts, and camera-stabilization gimbals — decouple the payload's orientation from the carrier's motion using local tilt sensing and fast corrective actuators.