Strip away the motors and the marketing and every robot is the same program:
loop forever:
readings = sense() # lidar, camera, wheel encoders
plan = think(readings) # decide what to do
act(plan) # set motor commands
That’s it. A vacuum cleaner, a drone and a self-driving car differ in how good each of the three steps is and how fast the loop spins, not in the shape of the program.
Why the loop speed matters
If your rover drives 0.6 m/s and your loop runs at 10 Hz, it moves 6 cm between decisions. A wall that appears 5 cm ahead is already a collision. Faster loops mean fresher information — but only if think finishes inside one tick. This is why robotics code obsesses over latency in a way web code rarely does.
Open-loop vs closed-loop
Try this in the simulator: program the rover to “drive forward for 3 seconds”. It travels roughly 1.8 m — roughly, because friction and the floor are never exactly what you assumed. That’s open-loop: you act without checking.
Now program “drive until the goal is closer than 0.2 m”. That closes the loop: the sense step (distance to goal) feeds the act step. Same rover, same motors, far more robust. Almost everything interesting in robotics is some way of closing a loop.
Try it
- Open the Robo simulator and start lesson 1 (drive 2 m). Solve it open-loop with a timer.
- Solve it again using the distance to goal block inside a repeat until loop. Nudge the goal in a later lesson and see which solution survives.
- Open the </> Code view. Each block is an
await api.…call — the simulator’stick()is literally the loop above.
Takeaways
- A robot is
sense → think → act, repeated. - Open-loop programs assume the world; closed-loop programs measure it.
- Next: the simplest, most widely used way to turn a measurement into a motor command — PID control.