Anatomy of a robot
Sense, think, act: the subsystems every robot has and why loop rate matters.
Day 7 · 40 min
After this lesson
- You can draw the block diagram of a mobile robot with its power domains.
- You can explain the sense-think-act loop and typical control rates.
- You can relate loop rate to how far a robot travels between decisions.
Sense, think, act: what a robot is made of
A robot is a machine that closes a loop through the physical world. It senses (reads its encoders, a range finder, a line sensor), thinks (estimates where it is and decides what to do) and acts (sets motor duty cycles), then does it all again. SRI's Shakey (1966-1972) ran this cycle as sense-plan-act and often paused for minutes to plan a single move; a balancing robot today runs its inner loop 200-500 times a second. The loop is the robot. Every part you add either feeds it or is driven by it.
Six subsystems
Every mobile robot, from a $50 kit to a warehouse robot, has the same six subsystems. The table maps them onto the robot you will build in this track.
| Subsystem | Job | Course robot |
|---|---|---|
| Power | Store energy, regulate rails, protect | Two 18650 Li-ion cells in series: 7.4 V nominal, 8.4 V full, about 6.0 V empty; 5 V buck; 3.3 V LDO |
| Compute | Run the loop, talk to the outside | ESP32: two 240 MHz cores, 520 KB SRAM, Wi-Fi and Bluetooth |
| Sensing | Measure the robot and the world | Two Hall encoders (7 pulses per motor turn), an HC-SR04 ultrasonic ranger, two TCRT5000 line sensors |
| Actuation | Turn commands into motion | Two 6 V N20 gearmotors on a TB6612FNG dual H-bridge; an SG90 servo pans the ultrasonic sensor |
| Communication | Move data on and off the robot | GPIO, I2C and UART on board; Wi-Fi telemetry at 10 Hz |
| Mechanics | Hold it together, transmit force | Chassis, 50:1 gearboxes, 44 mm wheels, a ball caster |
Sensors split into proprioceptive ones, which measure the robot itself (encoders, IMU, motor current), and exteroceptive ones, which measure the world (ultrasonic, lidar, camera). You need both: encoders tell you how far the wheels turned, but only an exteroceptive sensor notices the wall.
Robot types and degrees of freedom
A degree of freedom (DOF) is one independent way to move. A rigid body in space has six: three translations and three rotations.
- Differential drive (the course robot, a Roomba): two driven wheels. Its pose on the floor has 3 DOF (x, y, heading) but it has only 2 inputs and cannot slide sideways. That restriction is called nonholonomic.
- Car-like (Ackermann) steering: also nonholonomic, and it needs room to turn.
- Mecanum or omni wheels: holonomic; four wheels give independent control of x, y and rotation.
- Arms: six joints place a tool at any position and orientation (UR5e); a seventh adds redundancy (Franka, KUKA iiwa).
- Legged: Boston Dynamics' Spot has 12 leg joints, three per leg.
- Quadrotors: four motors control a 6-DOF body, so they are underactuated and must tilt to move sideways.
Loop rates: a robot is a stack of loops
A real robot runs several loops at different rates. Each inner loop runs 5-10 times faster than the loop that commands it, and fast enough to sample its own dynamics 10-20 times per response time.
| Loop | Typical rate | Example |
|---|---|---|
| Motor current and torque | 10-40 kHz | Field-oriented control inside a BLDC drive |
| Attitude and balance | 0.2-8 kHz | Drone flight controllers at several kHz; balancing robots at 200-500 Hz |
| Wheel speed and heading | 100 Hz-1 kHz | The course robot's 100 Hz PID loop |
| Local planning and avoidance | 10-50 Hz | The ROS 2 Nav2 controller server defaults to 20 Hz |
| Mapping, global planning, mission | 0.1-5 Hz | Replanning a path around a new obstacle |
The rate that matters most on a small robot is the one that decides when to stop or turn, because the robot drives blind between decisions. Travel per cycle is speed divided by rate. At 0.5 m/s a 1 kHz loop moves 0.5 mm per cycle, 100 Hz moves 5 mm, 20 Hz moves 25 mm and 5 Hz moves 100 mm. A strip of electrical tape is 19 mm wide, so a line sensor read at 20 Hz can step over a stop line without ever seeing it.
Rate is not the only delay. Stopping distance is the travel while noticing the event (up to one period), plus the travel during compute and actuator delay, plus the braking distance v²/2a. A small robot short-braking at about 3 m/s² needs 42 mm to stop from 0.5 m/s even with an infinitely fast loop, and braking distance grows with the square of speed.
The course robot's power architecture
The robot you will build on day 9 has three power domains that share one ground:
- Motor domain, 6.0-8.4 V. The pack feeds the TB6612FNG's motor supply (VM, rated 2.5-13.5 V) directly. Each N20 can pull more than an amp at stall; the driver handles 1.2 A continuous and 3.2 A peak per channel. A 6 V motor on an 8.4 V pack should be limited to about 70% PWM duty.
- 5 V domain. A buck converter rated about 3 A feeds the ESP32 DevKitC's 5 V pin, the HC-SR04 and the SG90, which can draw 0.7 A when it stalls.
- 3.3 V domain. The DevKitC's onboard LDO powers the ESP32, the TB6612FNG's logic supply, the encoder Hall sensors and the line sensors. Espressif recommends a 3.3 V supply good for at least 500 mA, because Wi-Fi transmit bursts draw well over 200 mA.
Signals cross domains, and every crossing needs a check. ESP32 pins are 3.3 V only, so the HC-SR04's 5 V echo goes through a divider (1 kΩ over 2 kΩ gives 3.3 V). All grounds meet at one point near the battery, so motor return current never flows through the logic ground.
Interactive: loop rate versus the stop line
Sense, think, act at a fixed rate
The robot looks at the floor once per loop cycle (ticks under the track), reacts one cycle after it sees the tape, then brakes at 3 m/s². Change the loop rate and speed and watch where it stops.
- Travel per cycle
- 25 mm (50 ms period)
- Line detected
- sample 16, 7.5 mm onto the tape
- Braking distance
- 42 mm
- Stops
- 74 mm past the line
Start at 20 Hz and 0.5 m/s: the robot sees the tape late and stops about 74 mm past it. Slide the loop phase to 80% and the samples straddle the tape completely. Then raise the rate to 1 kHz at 1 m/s: sampling delay vanishes, and braking (167 mm) is all that is left.
In practice
Practice
Draw your robot's block diagram with power domains
Draw the course robot (or your own design) on paper or in a drawing tool, then compare it with the worked answer below.
- List every powered part from the bill of materials.
- Group the parts into power domains by supply voltage and draw each domain as a box.
- Write the worst-case current next to every part and total each rail. Size each regulator for at least 1.5 times that total.
- Draw signals as dashed lines, mark their voltage, and flag every 5 V output that enters a 3.3 V pin.
- Mark where the grounds join.
Worked answer.
MOTOR DOMAIN 2S Li-ion pack, 6.0-8.4 V, 3 A fuse + switch
TB6612FNG VM -> 2 x N20 gearmotor ~0.15 A each running, ~1.5 A each at stall
Worst case: about 3 A peaks (both motors stalled or reversing)
5 V DOMAIN buck converter 7.4 V -> 5 V, rated 3 A
ESP32 DevKitC 5V pin (feeds the 3.3 V LDO below) 0.50 A peak
SG90 servo 0.25 A moving, 0.7 A stalled 0.70 A
HC-SR04 15 mA 0.02 A
Total worst case ~1.2 A -> ~0.9 A from the pack at 90 % efficiency
3.3 V DOMAIN AMS1117 LDO on the DevKitC, 1 A maximum
ESP32-WROOM-32 ~80 mA computing, ~240 mA on Wi-Fi transmit
2 x encoder Hall sensors 2 x 5 mA
2 x TCRT5000 modules (IR LED + comparator) 2 x 25 mA
TB6612FNG VCC (logic) < 2 mA
Total worst case ~0.4 A -> LDO burns (5 - 3.3) V x 0.4 A = 0.7 W
SIGNALS (dashed) level
ESP32 -> TB6612 PWMA, PWMB at 20 kHz; AIN1/2, BIN1/2; STBY 3.3 V
encoders -> ESP32 A and B, both wheels 3.3 V (sensors powered at 3.3 V)
ESP32 -> HC-SR04 TRIG 3.3 V triggers it
HC-SR04 -> ESP32 ECHO through a 1 k / 2 k divider 5 V -> 3.3 V
TCRT5000 -> ESP32 digital out or ADC1 input 3.3 V
ESP32 -> SG90 50 Hz servo pulse 3.3 V
GROUND one star point at the pack's negative terminal; motor current returns there directly.The 5 V rail needs about 1.2 A worst case, so a 3 A buck has margin, and it draws about 0.9 A from the pack. The motor domain sees peaks near 3 A, which is why the pack connects to the driver with short, thick wires and a 470 µF capacitor at VM. The onboard LDO burns about 0.7 W at 0.4 A: acceptable, but the reason not to hang more 3.3 V loads on it.
Real-world scenario
Real-world scenario
Line follower drives straight through its stop line at speed
A team's line-following robot stops cleanly on a 19 mm strip of black electrical tape at 0.2 m/s. For the competition they raise cruise speed to 0.6 m/s and add an HC-SR04 read with pulseIn() inside loop() so the robot also stops for obstacles. On the practice track it now sails past the stop line on about half the runs, and when it does stop it ends up 6-10 cm beyond the tape.
Symptoms
- At 0.2 m/s the robot stops on the tape every time; at 0.6 m/s it misses the line on roughly half the runs.
- When it does stop, it ends 60-100 mm past the tape instead of on it.
- A loop-timing printout shows the period jumping between 10 ms and about 48 ms; the long cycles happen when nothing is in front of the ultrasonic sensor.
- Commenting out the ultrasonic read makes the misses disappear, even at 0.6 m/s.
Interview questions
screenWhat is the sense-think-act loop, and how does it show up on a small mobile robot?
screenWhy do robots separate motor power from logic power?
deepYour robot drives at 1 m/s and its control loop runs at 50 Hz. Is that enough, and how would you choose a loop rate?
screenWhat is a degree of freedom? How many does a differential-drive robot have, and how many does a robot arm need?
deepHow would you split work between a microcontroller and a single-board computer on a robot?
Quiz
References and further reading
Where the ideas in this lesson come from, and what to read next. Books are the standard texts; papers are the original sources; standards are what employers work to.
- Book
Roland Siegwart, Illah R. Nourbakhsh and Davide Scaramuzza (2011). Introduction to Autonomous Mobile Robots. MIT Press, 2nd edition.
Read: Chapter 1 and the locomotion chapter.
- Bookfree online
Read: The introduction and the chapter on robot architectures.
- Paper
Rodney A. Brooks (1986). A Robust Layered Control System for a Mobile Robot. IEEE Journal of Robotics and Automation 2(1), 14-23.doi:10.1109/JRA.1986.1087032
Read: The subsumption architecture: layering simple behaviours.