Interface contracts
A lidar says the wall is 0.4 away. The safety monitor reads 0.4 too, and slams the brakes. Both programs are correct. What went wrong?
About 35 min · 2 goals · Checked by automated tests
1.Why should I care?
Interface faults are the classic integration bug: nothing crashes, every unit test passes, and the robot still does the wrong thing. A written contract for each signal is the cheapest prevention there is.
- ◇ Specify an interface between two subsystems: signal, unit, frame, rate and timing.
- ◇ Diagnose a fault caused by mismatched units, rates or frames from its symptoms.
2.Predict
A producer publishes data at 50 Hz; the consumer runs at 200 Hz and uses the latest value. What does the consumer see?
Guess first. Being wrong here is how the surprise works.
3.Discover
For each link, compare what is sent with what is expected and read the symptom. Tick every mismatch before checking. Which symptom gave the clearest clue?
Loading the interactive…
Can't use the interactive? Read a description instead
The integration-bug finder lists four links. Lidar to emergency stop: sent in metres, expected in millimetres, a unit mismatch. Odometry to planner: odom frame used as map frame, a frame mismatch. IMU to balance loop: 50 Hz published, 200 Hz expected, a rate mismatch. Encoders to dashboard: no mismatch.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
A planner's paths bend away from the map after each turn, though odometry looks fine on its own. Which mismatch is most likely?
5.Understand
What a contract says
For every signal crossing between subsystems, write: name and meaning, unit, coordinate frame (robot, odom, map, camera), rate (how often), latency (how old it may be when used), range and what an invalid value looks like. Both teams sign up to the same text.
Three silent mismatches
Units: metres read as millimetres is a factor of 1000. Frames: a pose in the odometry frame used as if in the map frame drifts once the two frames separate. Rates: a slow producer starves a fast consumer, which then reuses stale data. None of these raises an error by itself.
Make the contract checkable
Put units in names (range_m), stamp every message with time and frame, and add integration tests that send a known value across the link and check what arrives. A runtime check that rejects data older than its latency limit turns a silent fault into a loud one.
Explain it another way
Two people building a bridge from opposite banks must agree on where they will meet, in the same units, before they start.
Interface control documents (or message definitions with typed fields, units and frame ids) are the contract; middleware timestamps and frame identifiers let consumers verify freshness and frame at runtime.
Robot software frameworks commonly attach a timestamp and a frame id to each message for exactly these reasons. A famous spacecraft loss was traced to one team using imperial units where another expected metric.
Worked example 1
Write a contract for an IMU tilt signal used by a balance loop.
'tilt: pitch angle of the robot body, radians, robot frame, positive nose-up, published at ≥ 200 Hz, used within 5 ms of measurement, range ±π/2, NaN on sensor fault.'
Common mix-ups
- If two programs exchange numbers without errors, the interface is fine.
✓ Units, frames and timing are invisible to the computer unless you encode and check them.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A tilt sensor publishes at 50 Hz and the balance loop runs at 200 Hz. On average, how many loop cycles use each tilt value?
Practice 3
A range of 0.4 m is read by code that expects millimetres. What distance does the code think the obstacle is at, in metres?
Practice 4
Which addition to a message most helps a consumer detect stale data at runtime?
Practice 5 · a fresh version every time
A robot's motor-current loop runs at 2000 Hz and its path planner at 10 Hz. How many current-loop updates happen between two planner updates?
7.Apply it
Write interface contracts for three signals in your vacuum-cleaner block diagram from week 28. For each, describe the symptom you would expect if one field were wrong.
8.Reflect
Concepts: System integration and interface contracts