Robotics & Mechatronics · Embedded execution and hardware contracts
Read a minimal robot control loop
A small robot loop can be understood as repeated decisions over a record. You do not need to write software to trace its outputs, but you do need to know which value is read, which condition is checked and what state is remembered.
All numerical tables, scenarios and records are original constructed teaching data unless a specific external dataset is named. No physical experiment is claimed. A worked simulation model is distinguished from an executed simulator.
Lesson preparation and course links
Use the local explanations and supplied units, diagrams, tables and examples; advanced chapters build on the named local chapters. External links are point-of-need depth, not a requirement to finish an entire map.
Back to the Robotics chapterAfter reading, you can
Introduce locally the variables, branch decisions and repeated update needed to inspect a small robot task; keep a trace-table alternative for learners not yet writing code.
Read names as quantities and remembered state
A variable is a named stored value. Here x_mm is a measured position in millimetres, fresh is a validity decision and state is one of READY, MOVE, STOP_REQUESTED or FAULT. A condition chooses a branch. Repeating the update means read inputs again, make the next decision and send the resulting output.
The order matters. Validate required input before comparing it with a threshold. Use the same acquired snapshot for that decision; otherwise the freshness flag and position could describe different messages. A state remembers that a stop has already been requested.
Trace a supplied decision loop
This pseudocode is an original teaching state machine, not deployable equipment control. Stop/fault outputs refer to the module’s declared response.
| Order | Rule |
|---|---|
| 1 | Read one snapshot: position, acquisition time, reference, quality |
| 2 | If required snapshot invalid: state ← FAULT; output ← declared fault response |
| 3 | Else if state=MOVE and x_mm≥70: state ← STOP_REQUESTED; output ← normal stop |
| 4 | Else if state=MOVE: output ← +20 mm/s |
| 5 | Else: preserve the defined non-moving/latched state output |
| 6 | Record snapshot identity, chosen branch, state and output |
Run the loop on paper
Initial state is MOVE. Later valid values do not clear a latched FAULT.
| Input x / mm | Fresh? | Prior state | Next state/output |
|---|---|---|---|
| 68 | Yes | MOVE | MOVE; +20 mm/s |
| 69 | No | MOVE | FAULT; declared fault response |
| 72 | Yes | FAULT | FAULT remains; no automatic MOVE |
| 70 | Yes | MOVE in a separate test | STOP_REQUESTED; normal stop |
Check the equality and the invalid case
The threshold is inclusive:70 satisfies x≥70. Using x>70 changes the boundary. A missing value must not default to 0 mm and trigger the below-threshold branch. Define numerical range checks and clock/reference validity before using x.
A stopped state must not return to MOVE merely because a later measurement drops below 70. A new task requires its own acceptance path. This small loop illustrates execution semantics; real protective functions and certified controllers have separate design and evidence requirements.
Use a trace table as a programming alternative
Cover the output column, predict each row and then compare. Explain the first row where your prediction differs. In a simulation, replay the same snapshots and compare logged branch/state/output with the paper result. Matching this trace establishes the implemented decision for these inputs, not every possible program path.
Keep the input sequence, initial state and reset/new-task rules. A program listing without its initial state can have several legitimate traces.
Repair a plausible-looking loop
An incorrect loop first tests x<70 and sends MOVE, then checks freshness. With stale x=
For a 20 mm/s ideal segment, one unintended 20 ms update corresponds to 0.4 mm additional command-time travel. Actual response depends on device dynamics and delay; the arithmetic explains why update order can matter.
Try the reasoning
Why does x=
70 take the stop branch? Show the answer and reasoning
The supplied condition is x≥70, inclusive of equality.
Why retain state after the threshold?
Show the answer and reasoning
It prevents later low/noisy values from automatically restarting the task.
What is a snapshot in this loop?
Show the answer and reasoning
A coherent acquired record whose position, time, reference and quality belong together.
Can the paper route establish understanding without writing code?
Show the answer and reasoning
Yes. Predicting branches, state and outputs for valid/boundary/fault cases demonstrates the same decision reasoning.
What to carry forward
Read, validate, decide, commit and record. Trace tables expose robot-loop logic without requiring a programming curriculum.
References
Sources supporting this lesson’s explanations and examples.