D.HOSKIA
Module 2·50 min

Encoders and Position Feedback

Encoders and Position Feedback

A robot without position feedback is open-loop. Open-loop robots are brittle. Encoders close the loop.

Encoder Types

Incremental encoders output pulses as the shaft rotates. You count pulses to determine position — but you lose position on power cycle.

Absolute encoders output the actual angular position as a digital word. CatBot uses absolute magnetic encoders (AS5047 or similar) on each joint output — no homing routine needed.

Resolution

Resolution = pulses per revolution (PPR) or bits (for absolute):

14-bit encoder → 2¹⁴ = 16,384 positions per revolution
Angular resolution = 360° / 16,384 ≈ 0.022°

Quadrature Decoding

Incremental encoders typically have two channels (A and B) offset by 90°. Reading both channels gives:

  • 4× resolution multiplication
  • Direction detection
# Simple quadrature state machine
states = {(0,0): 0, (1,0): 1, (1,1): 2, (0,1): 3}
direction = states[current] - states[previous]
if direction > 1: direction -= 4   # handle wrap
position += direction

SPI Interface

Most precision encoders communicate via SPI (Serial Peripheral Interface):

MOSI: Master Out Slave In
MISO: Master In Slave Out  
SCK:  Clock
CS:   Chip Select (active low)

Typical transaction: assert CS → send 16-bit request → read 16-bit response → deassert CS.