Robots must sense, decide, and act within very small time windows. A real-time operating system, or RTOS, helps a robot run many jobs such as motor control, sensor reading, communication, and safety checks without letting critical timing slip. This matters because a late control signal can make a robot wobble, miss a target, or become unsafe.
In robotics, correctness depends not only on what the program computes, but also on when it computes it.
An RTOS uses a scheduler to choose which task runs next based on priorities, deadlines, and timing rules. High-priority tasks such as a balance control loop can interrupt lower-priority tasks such as logging data to memory. Compared with bare-metal programming, an RTOS adds structure for multitasking, timing, synchronization, and resource sharing.
The goal is deterministic behavior, meaning the robot's software responds in a predictable and bounded amount of time.
Key Facts
- A real-time system must meet timing constraints, not just produce correct answers.
- Control-loop period is the time between updates: f = 1/T, where f is frequency and T is period.
- Worst-case execution time, or WCET, is the longest time a task can take to run under expected conditions.
- A task meets its deadline when response time R is less than or equal to deadline D: R <= D.
- In fixed-priority scheduling, the highest-priority ready task runs first.
- CPU utilization for periodic tasks can be estimated by U = C1/T1 + C2/T2 + ... + Cn/Tn, where C is execution time and T is period.
Vocabulary
- RTOS
- A real-time operating system is software that schedules tasks so important actions happen within predictable time limits.
- Task
- A task is a small program unit that performs one job, such as reading a sensor or updating a motor command.
- Scheduler
- A scheduler is the RTOS component that decides which ready task runs on the processor at a given moment.
- Deadline
- A deadline is the latest time by which a task must finish for the system to behave correctly.
- Jitter
- Jitter is variation in the timing of a repeated event, such as a control loop starting slightly early or late.
Common Mistakes to Avoid
- Treating fast code as real-time code, which is wrong because real-time behavior requires bounded worst-case timing, not just high average speed.
- Giving every task high priority, which is wrong because the scheduler then cannot clearly protect the most time-critical control or safety tasks.
- Ignoring jitter in control loops, which is wrong because uneven update timing can reduce stability even when the average loop frequency seems correct.
- Using blocking delays inside important tasks, which is wrong because a blocked high-priority task can miss deadlines and prevent timely robot response.
Practice Questions
- 1 A motor control loop runs every 5 ms. What is its update frequency in hertz?
- 2 Three periodic robot tasks have execution times and periods of 1 ms every 5 ms, 2 ms every 10 ms, and 3 ms every 20 ms. Compute the total CPU utilization U.
- 3 A robot uses bare-metal code with one long loop that reads sensors, logs data, updates motors, and checks a wireless link. Explain why moving to an RTOS could improve reliability for the motor control loop.