Robot turns the wrong angle: encoder, gyro and wheel slip

Use a gyro for the turn angle and slow down before the target. Encoders alone trust the wheels not to slip.

What the message means

On a slippery floor wheels turn more than the robot does. A gyro measures the real rotation, although it needs offset calibration.

Fix it in this order

  1. Measure the real turn with a gyro and compare it with the encoder count.
  2. Calibrate the gyro offset at rest before the run.
  3. Slow the motors near the target angle to cut overshoot.
  4. Improve grip with better tyres or a softer surface.
  5. Use a small dead band so the robot does not hunt around the target.
  6. Check the battery level, since the same command gives different motion on a low battery.

Why it happens

Wheel encoders count rotation, but wheel slip and a wrong track-width value make the calculated turn differ from the real one. A gyroscope measures turning directly but drifts over time.

Use the gyro for short turns, calibrate its offset at rest, check the track width and wheel diameter used in the maths, and combine both if you need accuracy over a long run.

If you see this, do this

You seeDo this
Over-turns on slippery floorWheel slip. Add a gyro.
Different results each runBattery level or speed.

gyro drift, wheel traction.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

A two-wheel robot turns by driving the wheels by different amounts. The heading change is the difference of the two wheel distances divided by the track width, the distance between the wheel contact points. An encoder only counts wheel rotation, so every error in the wheel diameter, the track width, or any wheel slip goes straight into the calculated angle.

A gyroscope measures rotation rate directly and does not care about slip. Its weakness is a small constant offset, which grows into drift when you integrate the rate over time. For a short turn, a calibrated gyro usually beats the encoders on a slippery floor.

How to confirm the cause

  • Command ten full turns and mark the starting direction. Count how far the robot is from the mark. Divide the error by ten for the error per turn.
  • Repeat at two speeds. If the error changes with speed, suspect slip or acceleration limits, not geometry.
  • Log the gyro with the robot still for five seconds. The average is the offset; a large spread means vibration or noise.
  • Turn once and compare the encoder-calculated angle with the gyro angle. A big difference means slip or a wrong track width.
  • Check the battery. A weak battery changes motor torque and speed for the same command.

Worked example

Encoder counts for an on-the-spot 90 degree turn, with example dimensions: track width 0.150 m, wheel diameter 0.065 m, 360 counts per wheel revolution.

arc per wheel = pi * 0.150 / 4  = 0.1178 m
wheel circumference = pi * 0.065 = 0.2042 m
revolutions = 0.1178 / 0.2042    = 0.577
counts      = 0.577 * 360        = about 208

If the real track is 0.152 m but the code uses 0.150 m:
turn = 90 * 0.150 / 0.152 = 88.8 degrees (about 1.2 degrees short)

Common mistakes

  • Mixing degrees per second and radians per second in the gyro maths.
  • Calibrating the gyro offset while the robot is still vibrating or being carried.
  • Using a fixed time step in integration when the loop time varies.
  • Measuring the wheel diameter of a hard wheel, when a soft tyre squashes under load.
  • Trusting the nominal track width without measuring contact points.

If this did not fix it

  • Unequal motors or gear backlash, so the two sides do not start together.
  • Missed encoder counts from polling too slowly. Use interrupts or a hardware counter.
  • A gyro read too slowly or over a noisy bus, so rate samples are lost.