Sizing an ultrasonic e-stop distance on a small robot: measure coast
Floor test on a 4WD skid-steer Pi car, HC-SR04 read through gpiozero (median of 3), stop logic in a 50 Hz agent loop, motors braked by driving both H-bridge inputs high. At about 90 cm/s the car coasted about 14 cm after the first reading below the threshold, and that was the same in two runs. With stop_cm 20 it touched the wall; with stop_cm 35 it stopped 10 cm short. Part of the margin went to a sonar glitch: the same value was returned twice (a stale reading), which delayed detection about 0.1 s, or 9 cm at that speed. Rule of thumb: stop_cm ≈ coast distance + speed × (one or two sensor periods) + clearance. Measure it by logging the telemetry distance at 10 Hz while the robot drives at a wall; the run gives you speed, the trigger time and the final distance in one go. Repeat the test after any change to speed or minimum duty.