Capability:Optical Odometry

From Bespoke Robot Society
Revision as of 16:16, 11 October 2025 by John (talk | contribs) (Claude edited based on my notes, prompt, and SimpleBot code repository)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Optical Odometry
Type Sensing
Measures/Controls Wheel rotation distance by counting optical encoder pulses
Common Hardware Slotted encoder wheels + IR LED/photoresistor pairs + comparator (LM393)
Enables Activities Activity:Dead Reckoning Navigation, distance measurement, speed control
Used In SimpleBot
Status Fully Documented


Optical odometry is a method of measuring a robot's motion by optically detecting the rotation of its wheels. By counting pulses generated as slotted encoder wheels rotate, a microcontroller can calculate distance traveled, speed, and (for differential drive robots) changes in heading angle. This forms the foundation for Activity:Dead Reckoning Navigation.

Overview

Odometry comes from the Greek words hodos (journey) and metron (measure). Optical odometry specifically uses optical sensors to detect wheel rotation, converting mechanical motion into electrical pulses that can be counted digitally.

Unlike GPS which measures absolute position, odometry measures relative motion - how far the robot has moved from its starting point. This makes it work indoors, require no external infrastructure, and provide high-frequency updates (typically 100+ Hz), but it suffers from cumulative drift over long distances.

How It Works

The optical odometry system consists of four key components working together:

Encoder Wheel

A disc with evenly-spaced slots (or alternatively, alternating black/white segments) is rigidly attached to either:

  • The drive wheel itself (SimpleBot approach)
  • The motor output shaft before the gearbox

As the wheel or shaft rotates, the slots pass between an emitter and detector.

Optical Emitter

An infrared LED provides a constant light source aimed at the detector. IR is preferred over visible light because:

  • Less susceptible to ambient light interference
  • Standard photoresistors and phototransistors have good IR sensitivity
  • Does not distract operators with visible blinking

Optical Detector

A photoresistor (CdS cell) or phototransistor detects the light. When a slot passes by, light reaches the detector (low resistance/high current). When the solid part of the wheel blocks the light, the detector sees darkness (high resistance/low current). This creates an analog signal that oscillates between two voltage levels.

Signal Conditioning

The analog signal from the detector is converted to clean digital pulses using a comparator IC such as the LM393. The comparator has:

  • A reference voltage (threshold) on one input
  • The detector signal on the other input
  • Digital output: HIGH when light detected, LOW when blocked

This produces clean square waves suitable for microcontroller interrupt pins or counter inputs.

Implementation Approaches

Wheel-Based Encoding (SimpleBot)

SimpleBot attaches slotted encoder wheels directly to the drive wheels.

Advantages:

  • Simple mechanical attachment
  • Directly measures wheel rotation (what you care about for odometry)
  • No need for special motors with built-in encoders
  • Easy to retrofit to existing robots

Disadvantages:

  • Adds width to the robot
  • Wheel slippage affects both propulsion and measurement equally
  • Lower resolution unless using large diameter encoder wheels

Motor Shaft Encoding

Many commercial motors include quadrature encoders on the motor shaft before the gearbox.

Advantages:

  • Very high resolution (motor shaft spins faster than wheel)
  • Compact - built into motor housing
  • Can detect wheel slippage (motor turns but wheel doesn't)
  • Often provides direction information via quadrature encoding

Disadvantages:

  • Requires encoder-equipped motors (more expensive)
  • Gearbox backlash between motor and wheel
  • Must account for gear ratio in calculations

Resolution and Distance Calculation

The encoder's resolution determines how precisely distance can be measured.

Basic Formula

For a wheel-based encoder:

Distance per pulse=π×DN

Where:

  • D = wheel diameter
  • N = number of slots in encoder wheel

Example (SimpleBot):

  • Wheel diameter: 65mm
  • Encoder slots: 20
  • Distance per pulse: π×65mm20=10.2mm

To calculate distance traveled:

Distance=Pulses counted×π×DN

Motor Shaft Encoders

For motor shaft encoders, include the gear ratio:

Distance per pulse=π×DN×G

Where G is the gear ratio.

Example:

  • Wheel diameter: 70mm
  • Motor encoder pulses per revolution: 64
  • Gear ratio: 120:1
  • Distance per pulse: π×7064×120=0.029mm

This much higher resolution is why shaft encoders are preferred in precision applications.

Accuracy and Error Sources

Optical odometry is subject to several error sources that cause the calculated position to drift from the true position:

Wheel Slip

The dominant error source. When wheels slip on the surface:

  • The wheel rotates but the robot doesn't move proportionally
  • Encoder counts pulses but robot travels less distance
  • Turns on slippery surfaces are especially problematic

Mitigation:

  • Use high-traction wheels (rubber, not hard plastic)
  • Avoid sudden acceleration/deceleration
  • Keep robot weight low to reduce momentum
  • Slower speeds reduce slip

Encoder Resolution

Limited resolution means distance is quantized. With SimpleBot's ~10mm per pulse:

  • Distances between 0-10mm all register as "0"
  • Actual distance of 15mm registers as "10mm"
  • This causes ±5-10mm random error per measurement

Higher resolution encoders (more slots, or motor shaft encoders) reduce this error.

Mechanical Issues

  • Backlash: Play in gearboxes causes encoder to turn without wheel moving
  • Wheel diameter variation: Wear, tire pressure, or asymmetric wheels cause errors
  • Axle flexing: On flexible chassis, wheels may move without encoder detecting it

Calibration Errors

  • Incorrect wheel diameter measurement (measure loaded wheel, not unloaded)
  • Miscounted encoder slots
  • Incorrect gear ratio

Typical Performance

For a well-built system like SimpleBot with wheel-based encoders:

  • Short distances (< 1m): ±5% error
  • Medium distances (1-3m): ±10-15% error
  • Long distances (> 3m): Drift becomes significant (±20%+)

The error is cumulative - it grows with distance traveled, not with time. This is because each wheel rotation measurement includes a small error, and these errors add up.

Differential Drive Odometry

For differential drive robots like SimpleBot, having independent encoders on left and right wheels enables both position and orientation tracking.

Position Update Equations

Given pulse counts since last update (PL for left, PR for right):

DL=PL×πDN,DR=PR×πDN
Dcenter=DL+DR2
Δθ=DRDLW

Where W is the wheelbase (distance between wheels).

The robot's new position:

xnew=xold+Dcentercos(θold+Δθ/2)
ynew=yold+Dcentersin(θold+Δθ/2)
θnew=θold+Δθ

These equations integrate wheel motion into a 2D pose estimate.

Rotation Detection

  • Equal forward pulses: Straight line motion
  • Unequal pulses: Curved path (arc)
  • Left forward, right backward (or vice versa): Rotation in place

This allows the robot to maintain an estimated heading angle, critical for Activity:Dead Reckoning Navigation.

SimpleBot Implementation

SimpleBot uses a straightforward wheel-based optical odometry system:

Hardware:

  • 20-slot laser-cut acrylic encoder wheels mounted on drive wheel hubs
  • Infrared LED emitters (940nm typical)
  • CdS photoresistor detectors
  • LM393 dual comparator IC for signal conditioning
  • Encoder wheels positioned outside the main chassis, with emitter/detector in slots

Circuit:

  • LED connected through current-limiting resistor to constant power
  • Photoresistor in voltage divider configuration
  • Comparator compares detector voltage to adjustable reference voltage (potentiometer)
  • Output connects to microcontroller interrupt-capable pins

Software:

  • Interrupt service routine (ISR) increments counter on each pulse
  • Main loop periodically reads counters and calculates distance/position
  • Counters reset after each position update to avoid overflow

The system provides approximately 10mm resolution per pulse, adequate for SimpleBot's educational mission while remaining mechanically simple.

Comparison to Other Odometry Methods

Method Resolution Cost Complexity Slip Detection
Optical (wheel) Medium (5-20mm) Low ($2-5) Low No
Optical (shaft) High (0.01-0.1mm) Medium ($10-30) Medium Yes
Magnetic encoders Medium-High Medium Medium Varies
Visual odometry Very High High ($50+) High Yes
IMU integration Varies Medium High N/A (different principle)

SimpleBot's wheel-based optical approach prioritizes simplicity and cost over ultimate precision, making it ideal for education and hobby robotics.

See Also