ContentsSet up a safe, repeatable test
- Set up a safe, repeatable test
- 1. Check encoder counts and direction
- Counts are not always pulses
- 2. Convert counts to wheel travel
- 3. Calibrate wheel radius with straight runs
- 4. Calibrate track width with turns
- 5. Validate, then configure your software
- Troubleshooting and limits
- Frequently asked questions
- Does more encoder resolution eliminate odometry drift?
- Can I calibrate on a stand?
- Should I use the physical or calibrated track width?
A robot can drive two meters and report that it traveled 1.9. It can also turn in place and report the wrong heading. Differential drive wheel odometry calibration reduces these repeatable errors by checking encoder counts, effective wheel radius and track width against measurements on the floor.
Assume a two-wheel robot with an encoder on each driven side, a level surface, low speed, no slip and a consistent payload. The examples are illustrative, not measured results. For sensor basics, see robot sensors explained.
Set up a safe, repeatable test
You need a tape measure, floor tape, encoder and wheel-odometry logs, and a heading reference such as a marked floor protractor or overhead camera. Use a clear area, a flat, high-traction surface and an accessible stop control. Secure wiring and keep fingers clear of wheels.
Start with the intended battery, payload and tire condition. Measure the loaded wheel diameter to estimate radius, and measure track width between the left and right wheel contact centers. These are starting values; the effective values during motion may differ. Use meters for distance and radians for calculations involving angles.
1. Check encoder counts and direction
Disable motor power and secure the robot with its wheels off the ground. Power encoder electronics only if required and safe. Mark each wheel, turn it slowly through one revolution and record the count change. Turn it back and check that the count reverses. Do not force a gearbox that cannot be back-driven; use a controlled, low-power test instead.
Choose a convention: forward wheel travel is positive on both sides. Check that physically moving either wheel forward increases its normalized count, even if raw signals are mirrored. A left turn produces positive heading change; in an in-place left turn, the right wheel moves forward and the left backward. This matches the ROS body-frame convention: x forward, y left, z up, with counterclockwise yaw positive.
Counts are not always pulses
A quadrature encoder has A and B signals whose phase relationship indicates direction. Given pulses per revolution on one channel, x1 decoding counts one selected edge per pulse, x2 counts both edges on one channel, and x4 counts both edges on both channels. See Dynapar's quadrature guide.
For an encoder on the motor shaft, with a gearbox ratio expressed as motor revolutions per wheel revolution:
Counts per wheel revolution = pulses per motor revolution per channel × decoding factor × gear ratio
For example, 12 pulses per motor revolution per channel, x4 decoding and an exact 30:1 reduction give 12 × 4 × 30 = 1,440 counts per wheel revolution. For an encoder on the output shaft, omit the gearbox ratio. Use the exact ratio when available.
Manufacturers use CPR and PPR inconsistently. Some specifications already give decoded counts. Pololu's gearmotor documentation, for example, specifies 12 counts per motor revolution after counting both edges of both channels; multiply by the gearbox ratio, not by four again. Confirm your decoder mode and the shaft named in your datasheet. With a fractional ratio, average several turns if possible; a single turn's integer count can vary with starting phase.
2. Convert counts to wheel travel
For each side, use the signed change in decoded counts over the same time interval:
Wheel travel (m) = count change ÷ counts per wheel revolution × 2π × effective radius (m)
With 1,440 counts per revolution, a 0.050 m radius and +360 counts, travel is 360 ÷ 1,440 × 2π × 0.050 = 0.0785 m. Reverse travel has negative counts. Use each wheel's own count scale and radius.
For left and right wheel increments ΔL and ΔR, with track width b in meters, the standard differential-drive model gives:
Center travel = (ΔR + ΔL) ÷ 2
Heading change = (ΔR − ΔL) ÷ b, in radians
The ROS 2 kinematics guide gives the corresponding velocity equations. Odometry integrates successive increments and headings to estimate pose; one total-distance calculation cannot describe an arbitrary curved path.
3. Calibrate wheel radius with straight runs
Mark start and end lines about 2 m apart. Record the start position of a chassis reference mark, encoder counts and odometry. Drive slowly and nearly straight, stop, and measure the mark's actual displacement along the start direction. Record wheel-odometry center travel over the same run. Repeat several times in both directions.
If the robot follows a visibly curved path or the results vary widely, fix the steering, traction or counting problem before applying a scale correction. For a nearly straight, low-slip run, if both wheels share the same scale error, use:
New radius = old radius × actual center distance ÷ odometry center distance
If radius is 0.050 m, measured distance is 2.00 m and odometry reports 1.90 m, the corrected radius is 0.050 × 2.00 ÷ 1.90 = 0.0526 m. Use matching units and compare magnitudes for reverse runs. Change the radius once and remeasure; do not also apply the factor to encoder counts.
If the robot travels physically straight but reported heading changes, the side scales may differ. Mark floor positions below a fixed point near each wheel center at the start and finish of a nearly straight run. Compare each measured forward displacement with that side's encoder-derived travel; apply the measured ÷ estimated ratio to each radius separately. This approximation requires little heading change, not a pronounced arc. A robot curving in reality while odometry reports the same curvature may need wheel-speed control or mechanical attention instead.
4. Calibrate track width with turns
Once the wheel-distance scales are close, mark the starting heading against an independent floor reference. Make a slow in-place turn and record the actual angle and wheel-odometry angle over the same motion. Repeat clockwise and counterclockwise. Use signed angles with the same convention, or magnitudes consistently.
For a full revolution, track the angle continuously or count the revolution: a final wrapped heading alone cannot distinguish 0° from 360°. Do not use the commanded turn as the actual angle. If the turns slip or differ substantially by direction, fix that first or treat a single width as an approximation.
With the wheel radii held fixed, calculate:
New track width = old track width × odometry angle ÷ actual angle
For example, with a 0.200 m configured width, an unwrapped odometry turn of 360° and an independently measured turn of 330°, the correction is 0.200 × 360 ÷ 330 = 0.218 m. Degrees are acceptable in this ratio because both angles use the same unit; use radians in the heading-change equation. Re-test both turn directions after updating the width.
5. Validate, then configure your software
Repeat the tests after each change. Log measurements, estimates, surface, load and settings. Try a square path clockwise and counterclockwise, comparing final measured and reported poses. One direction can conceal errors visible in the other; the original UMBmark paper explains why. A simple square check is not a complete UMBmark calibration.
For ROS 2, the Jazzy diff_drive_controller documentation describes wheel_radius, wheel_separation, separate left/right radius multipliers and a separation multiplier. Apply a correction in one place, not twice. Check the installed version and hardware interface: with open_loop set to true, this controller calculates odometry from commanded values rather than encoder feedback, so it is not the wheel-feedback estimate used in these tests.
Troubleshooting and limits
- Distance is off by about two or four times: Check the x1/x2/x4 decoder mode and whether the published count already includes quadrature decoding. Also verify motor-shaft versus output-shaft counts.
- Both wheels report opposite signs when rolling forward: Correct the encoder direction convention before tuning geometry. Check left/right labels and motor direction separately.
- Counts change at rest or disappear at speed: Check connections, signal voltage, grounding, noise and whether the counter can keep up. Confirm behavior with the motors stopped as well as running.
- Turns vary between trials: Look for tire slip, caster drag, uneven load, backlash or abrupt acceleration. Recalibrate on the surface and with the load you expect to use.
Wheel odometry accumulates error; it cannot tell on its own that a wheel spun without moving the robot. A calibrated gyro, vision or other external references can help, but each has its own failure modes. For a next step, see the ROS 2 dual-EKF localization guide rather than treating wheel odometry as a global position fix.
Frequently asked questions
Does more encoder resolution eliminate odometry drift?
No. More counts can make small rotations easier to resolve, but they do not correct slip, incorrect wheel geometry or missed counts.
Can I calibrate on a stand?
A stand is useful for checking counts and direction. Radius and track-width calibration need ground measurements under representative load because the effective rolling geometry depends on contact with the surface.
Should I use the physical or calibrated track width?
Start with the physical measurement, then use a repeatable effective width from turning tests for the operating conditions. If it changes markedly with surface or maneuver, document that limitation instead of assuming one value is universal.
