Steering a two-wheeled robot with PID

The robot has no steering wheel. It turns only by running its left and right wheels at different speeds. A PID controller decides how different. Click the arena to place targets, then change the gains and watch.

Click to add targets. The robot visits them in order (that is the simplest possible path plan). Dashed line = where it should be heading.

Heading error over the last 6 seconds

Angle between where the robot points and where the target is. The controller tries to hold this at zero.

Controller gains

Turn harder the further off-course you are.
Remember error that lingers and push against it.
Brake the turn when the error is shrinking fast.

Wheel speed commands

Left
0
Right
0
u = Kp·e + Ki·∫e + Kd·de/dt
left = speed − u
right = speed + u

Equal speeds: straight line. Right faster than left: turns left. The PID output u is the speed difference.

Things to try

  • Start with Gentle P: it arrives smoothly.
  • Too much P: it overreacts and wobbles. Motors take time to respond, so it overshoots.
  • Tamed with D: same strong P, but the wobble is damped.
  • Weak motor: P alone leaves a steady heading offset. Add I and it is removed.