2WD robot car chassis

The body of nearly every robot car kit: two TT gear motors on 65 mm wheels, a caster and encoder discs, driving across the canvas.

It is an acrylic deck, two yellow TT gear motors with 65 mm wheels, a ball caster at the back, and a 20-slot encoder disc on each motor shaft.

On the canvas it is the part that moves. Power its motors from an H bridge and the car drives across the floor drawn inside it, with the track it has left behind it. It turns the way a real one does: it has no steering, so it runs one wheel faster than the other.

Pins

Pin What it does
L+, L- The left motor. Current from L+ to L- drives the left wheel forward.
R+, R- The right motor. Current from R+ to R- drives the right wheel forward.
VCC, GND Power for the two slot-sensor modules that read the encoder discs: 3.3 V to 5 V.
ENCL, ENCR The slot sensors' outputs, one per wheel.

Leave VCC, GND, ENCL and ENCR unwired if the sketch does not count wheel turns. The discs still spin.

Wiring it

Each motor goes to one channel of a motor driver: the L298N, the DRV8833, or any H bridge. A motor is never wired to a board pin directly. It needs far more current than a pin can give, and it needs to be turned both ways.

The two motors sit mirror image on a real chassis, so wired the same way round, one wheel runs backwards. That is the first thing that goes wrong on every robot car, and the fix is to swap that motor's two wires. This part's leads are labeled for the car rather than for the motor: + to - is forward on both sides, which is the wiring after that swap.

Driving it

Left wheel Right wheel The car
forward forward drives straight ahead
forward, slower forward curves left
reverse forward spins left on the spot
stopped forward pivots about the left wheel
reverse reverse backs up

With the defaults, a wheel at full speed turns at 200 rpm, which is 681 mm a second at the rim of a 65 mm wheel. A driver keeps some of the battery for itself (about 2.5 V on an L298N, almost nothing on a DRV8833), so the car is slower than the motors' label says.

The encoders

Each slot sensor is an LM393 board (the FC-03 or HC-020K kind). Its output is high while a vane of the disc blocks the beam and low through a slot, so a wheel turn is 20 pulses. The output is open collector with a 10k pull-up on the module. Count the rising edges with an interrupt, and the count divided by 20 times 204 mm is how far that wheel has rolled.

Properties

Property Default What it is
voltage 6 The motors' rated voltage: full speed at this many volts.
rpm 200 Wheel speed at the rated voltage with no load.
resistance 6 Each motor winding, in ohms.
inertia 150 How long the car takes to get up to speed, in milliseconds.
back_emf 0.85 The back EMF at full speed, as a fraction of the rated voltage.
wheel 65 Wheel diameter in millimeters.
track 130 Distance between the two wheels, in millimeters.
slots 20 Slots in each encoder disc.

What the model gets right

  • Each motor is the same model as the DC motor: a winding behind a back EMF, so a stalled motor draws far more than a spinning one, and the speed follows the average of a PWM drive.
  • Differential drive, with the pose worked out from the two wheel speeds.
  • 20 pulses a wheel turn on each encoder output.

What it does not model

  • Walls. The floor is flat and endless, so nothing the car does reaches the other sensors in the circuit. An HC-SR04 on the canvas sees what its slider says, and that slider is the obstacle.
  • Wheel slip, the caster's drag and the weight of the car beyond the lag.
  • Two motors that do not quite match. A real car drifts when both motors get the same PWM; this one drives dead straight.

The small button in the corner of the floor puts the car back where it started.