Encoders: Knowing Where You Are
Two light sensors and a slotted disc give a machine odometry — and the quarter-slot offset between them encodes direction.
Builds on: 19.2 Servos & Steppers7.3 Memory & Counters11.2 Reading the Analog World
Odometry from a slotted disc
Bolt a slotted disc to a wheel and shine a light through it onto a sensor: every slot edge is one click of known distance. Count clicks, know how far you’ve rolled — odometry, the first sense any mobile robot grows. But one sensor has a blind spot: clicks look identical whether the wheel rolls forward or backward.
Quadrature: the quarter-slot trick
Add a second sensor, offset by a quarter of a slot, and the ambiguity dies. The two square waves — channels A and B — are 90° apart (quadrature, the same quarter-cycle idea as I/Q in 18.2!), and which one leads tells the direction:
Every mouse wheel, printer carriage and robot wheel uses this. Combine encoder feedback with the PID of 14.2 driving the H-bridge of 19.1 and you have a servo system of your own making — the industrial-grade version of the hobby servo’s little pot, good for unlimited rotation and real precision. That closed motion loop — sense position, compare, drive — is the beating heart of CNC machines, robot arms and self-balancing anythings.
Odometry drifts (wheels slip), so real robots fuse it with other senses: IMUs (accelerometer + gyroscope chips), distance sensors, cameras. Sensor fusion is a rich field — but every input still arrives as a voltage into an ADC (11.2) or bits on a bus (17.2). No new physics; just more of what you own.
⚡ Lab — The Quarter-Slot Trick
A slotted wheel, two offset sensors, and their quadrature waveforms live.
- Spin forward: A leads B, and the count climbs. Reverse: B leads, count falls.
- Stop the wheel mid-slot — the count holds. Position memory, no drift while still.
- Watch the scope: 90° apart, always — the offset is mechanical, so it can’t lie.