Hardware Academy
Robotics

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.

SubsystemJobCourse robot
PowerStore energy, regulate rails, protectTwo 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
ComputeRun the loop, talk to the outsideESP32: two 240 MHz cores, 520 KB SRAM, Wi-Fi and Bluetooth
SensingMeasure the robot and the worldTwo Hall encoders (7 pulses per motor turn), an HC-SR04 ultrasonic ranger, two TCRT5000 line sensors
ActuationTurn commands into motionTwo 6 V N20 gearmotors on a TB6612FNG dual H-bridge; an SG90 servo pans the ultrasonic sensor
CommunicationMove data on and off the robotGPIO, I2C and UART on board; Wi-Fi telemetry at 10 Hz
MechanicsHold it together, transmit forceChassis, 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.

LoopTypical rateExample
Motor current and torque10-40 kHzField-oriented control inside a BLDC drive
Attitude and balance0.2-8 kHzDrone flight controllers at several kHz; balancing robots at 200-500 Hz
Wheel speed and heading100 Hz-1 kHzThe course robot's 100 Hz PID loop
Local planning and avoidance10-50 HzThe ROS 2 Nav2 controller server defaults to 20 Hz
Mapping, global planning, mission0.1-5 HzReplanning 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.

Block diagram of the course robot with motor, 5 V and 3.3 V power domains sharing one groundMOTOR DOMAIN · pack voltage 6.0–8.4 V · amps, noisy5 V DOMAIN · buck3.3 V DOMAIN · LDO · quiet2S Li-ion pack2 × 18650 cells7.4 V nominal3 A fuse+ switchTB6612FNGdual H-bridge, VM ≤ 13.5 V1.2 A/ch, 3.2 A peakN20 motor L + encoderN20 motor R + encoderBuck converter7.4 V → 5 V, 3 ASG90 servo0.7 A stalledHC-SR045 V, 15 mAESP32 DevKitC5V pin → onboardAMS1117 LDOESP32-WROOM-322 × 240 MHz, 520 KB SRAMWi-Fi + BluetoothGPIO are 3.3 V onlyBattery monitorpack + → 100 kΩ / 33 kΩ divider8.4 V → 2.08 V on an ADC1 pinEncoders × 2 (Hall)TCRT5000 line sensors × 2TB6612FNG logic (VCC)PWM 20 kHz + direction, STBYservo pulse · TRIG · ECHO via 1 kΩ/2 kΩ dividerGND: every domain returns to one star point at the pack's negative terminalsolid = power · dashed = signal
The course robot: the pack feeds the motor driver directly, a buck makes 5 V, and the DevKitC's LDO makes the quiet 3.3 V rail. Dashed lines are signals.

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.

A robot approaching a stop line while sampling the floor once per control-loop cyclestop tape, 19 mmplayback 0.27× real timerobotsamples0100200300400500600 mmSenseThinkAct#0Sense: read the line sensorThink: on the tape? then stopAct: write the motor PWM20 Hz loop, ring slowed to followWhere the overshoot comes from050100150200250 mmseen late: 7.5 mmreaction, 1 cycle: 25 mmbraking v²/2a: 42 mmtotal 74 mm
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.

  1. List every powered part from the bill of materials.
  2. Group the parts into power domains by supply voltage and draw each domain as a box.
  3. Write the worst-case current next to every part and total each rail. Size each regulator for at least 1.5 times that total.
  4. Draw signals as dashed lines, mark their voltage, and flag every 5 V output that enters a 3.3 V pin.
  5. Mark where the grounds join.

Worked answer.

power budget and signal maptext
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?
It is the cycle every robot repeats: read the sensors, decide what to do, command the actuators, and start again. On a small ESP32 robot it is literally the body of a fixed-rate loop: read the encoders and line sensors, run the controller and behavior logic, and write PWM duty cycles to the motor driver. It runs at a fixed rate, typically 100 Hz to 1 kHz for wheel control, because the controller math assumes a constant time step. Slower loops sit on top of it, such as a 10-20 Hz behavior state machine or path planner.
screenWhy do robots separate motor power from logic power?
Motors draw large, fast-changing currents: a small gearmotor can pull more than an amp at stall and roughly twice that when it is reversed at full speed. Those spikes, flowing through the battery's internal resistance and the wiring, make the supply sag and ring, and a microcontroller on the same rail can brown out and reset. So the motors run from the raw pack through the driver, and the logic gets its own regulated rail, for example a buck to 5 V and an LDO to 3.3 V, with bulk capacitance at the driver. The grounds still have to be common so signals share a reference, ideally joined at one star point near the battery.
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?
At 1 m/s and 50 Hz the robot moves 20 mm between decisions, and it can react up to one period late plus actuator delay, so anything narrower than about 20 mm can be missed entirely. I would start from the smallest feature or error I must resolve, say a 19 mm tape line or ±5 mm of position, and pick a rate that keeps travel per cycle well below it, here 200 Hz or more. I would also check it against the dynamics: a loop should run roughly 10-20 times faster than the bandwidth it controls, so a wheel-speed loop with a few hertz of bandwidth is comfortable at 100-200 Hz. Finally I would measure the real period and its worst-case jitter on the hardware, because one blocking call can quietly cut the rate in half.
screenWhat is a degree of freedom? How many does a differential-drive robot have, and how many does a robot arm need?
A degree of freedom is one independent way something can move. A differential-drive robot on the floor has a 3-DOF pose, x, y and heading, but only two inputs, the wheel speeds, so it cannot move sideways; that is a nonholonomic constraint. To place a tool at any position and orientation in 3D space an arm needs six joints, three for position and three for orientation, like a UR5e. Seven-joint arms such as the Franka or KUKA iiwa add a redundant joint so they can reach around obstacles while holding the same tool pose.
deepHow would you split work between a microcontroller and a single-board computer on a robot?
I give the microcontroller everything with hard timing: PWM generation, encoder counting, the 100 Hz to 1 kHz motor and balance loops, and safety such as current limits and a watchdog. The single-board computer, say a Raspberry Pi or a Jetson, runs the heavy soft-real-time work: camera and lidar processing, mapping and planning at 5-30 Hz, and networking. They talk over UART, USB or SPI, or through micro-ROS on a ROS 2 robot, with the computer sending velocity setpoints and the microcontroller streaming odometry back. The microcontroller must also fail safe on its own: if no command has arrived for about 200 ms it ramps the motors to zero.

Quiz

1. A robot drives at 0.5 m/s and its control loop runs at 20 Hz. How far does it travel between two decisions?
2. Which of these is a proprioceptive sensor?
3. Why does the course robot feed its motors from the pack through the driver, but its ESP32 through a buck converter and an LDO?
4. How many joints does a robot arm need to put its tool at any position and orientation within its workspace?
5. What is a typical rate for the wheel-speed control loop of a small mobile robot?
6. A robot with a 100 Hz loop drives at 0.6 m/s and stops 60 mm past its stop line. Which change helps most?

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.

  1. 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.

  2. Bookfree online

    Nikolaus Correll, Bradley Hayes, Christoffer Heckman and Alessandro Roncone (2022). Introduction to Autonomous Robots: Mechanisms, Sensors, Actuators, and Algorithms. MIT Press.

    Read: The introduction and the chapter on robot architectures.

  3. 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.