srinivas.siteApplied RoboticsUnit 07

Unit 07 · Phase 2 · Movement & control

Differential drive and odometry

Mission: Drive the rover straight for 1 m and turn it 90° in place, predict from encoder counts where it ends up, then find out why a straight command veers.

The interactive version of this unit needs JavaScript. Below are its steps as text.

Steps

1. One wheel turn rolls one circumference

Unit 06 left you with two motors you can see through their encoders. Press the button to turn both wheels exactly one revolution and watch the tape on the floor.

Why it matters: A wheel that rolls without slipping lays its whole rim on the floor once per turn. That rim length is the circumference, π times the diameter. Turning speed only changes how long it takes, not how far one turn goes. This one fact turns wheel rotation into floor distance.

2. Encoder counts become distance

Watch the encoder close-up at the top right. Press the button to drive one revolution slowly while the count climbs.

Why it matters: Your encoder reports counts, not millimetres. Dividing the circumference by the counts per revolution gives distance per count, so distance = counts × 0.567 mm for this model rover. A count is the smallest step the robot can notice, which is its resolution. Your own motor's counts per revolution may differ; Unit 06 is where you measured it.

3. Different wheel speeds draw an arc

The left wheel will turn at 0.5 rev/s and the right wheel at 1.0 rev/s for 4 s. Press the button and watch the two wheel tracks.

Why it matters: A rover steered only by its two wheel speeds is called differential drive. The faster wheel covers more floor, so it must be on the outside of the curve. Equal speeds give a straight line and unequal speeds give an arc. Steering is nothing more than the difference between the two wheels.

4. Find the turning centre

Same speeds as before. Press the button to drive the arc again with the turning centre and the radius lines drawn.

Why it matters: At each instant the whole rover rotates about one point on the wheel axle line, the instantaneous centre of rotation. Its distance is R = (track ÷ 2) × (vR + vL) ÷ (vR − vL), here 65 mm × 1.5 ÷ 0.5 = 195 mm. Equal speeds push the centre infinitely far away, which is a straight line. Opposite speeds bring it to the middle of the axle.

5. Spin in place and measure the angle

Left wheel −0.5 rev/s, right wheel +0.5 rev/s. Press the button and watch the heading readout and the two wheel arcs.

Why it matters: A turn in place moves each wheel along an arc whose radius is half the track. Arc length = radius × angle in radians, and 90° is π ÷ 2 rad, so 65 mm × 1.571 = 102 mm. Radians are what make this one multiplication. A wrong track width gives a wrong turn even when the counts are exact.

6. Keep a running pose

The rover will drive straight, curve, then drive straight again. Press the button and watch a pose dot drop every 0.25 s.

Why it matters: Position and heading together are the rover's pose: x, y and which way it faces. Adding up many small count-based moves to track the pose is odometry. Nothing outside the rover is used, which is why it works anywhere. It is also why every small error stays in the sum.

7. Heading comes from the count difference

The left wheel will count 360 and the right 540 in the same second. Press the button and watch the heading wedge open.

Why it matters: Heading change in radians = (right travel − left travel) ÷ track width. The average of the two travels is how far the centre moved. Two counts in, a distance and an angle out. A heading error now bends every later metre of the estimate.

8. Estimate and truth, in a perfect world

The blue outline is where odometry thinks the rover is. The solid rover is where it really is, what a tape measure would find. Press the button to drive 1 m.

Why it matters: Odometry is only as good as its picture of the wheels and the floor. Here that picture is exactly right, so the estimate cannot drift. Real floors and real wheels are never exactly like the picture. The next steps break one assumption at a time.

9. A slippery patch

A dusty patch lies under the left wheel's path. There the left tyre loses 30 % of its grip. Press the button and watch both rovers.

Why it matters: An encoder measures how much the wheel turned, not how far the rover moved. When a wheel slips, those two differ, and odometry cannot tell. The heading error then sends the true path further away with every metre. That is drift: errors that accumulate.

10. One worn wheel: why a straight command veers

The left tyre has worn to 64 mm while the code still assumes 65 mm. Both wheels get exactly the same command, 1 rev/s. Press the button to drive 2 m.

Why it matters: A straight command is a command for equal wheel turns, not for a straight path. Any difference in wheel diameter, tyre pressure, or a wheel that runs slower on the same command makes the two wheels lay down different distances. The error is small per metre but builds up steadily. This is the honest answer to the unit question, and Unit 08 is how the rover fights back.

11. Wrong counts per revolution

This encoder really gives 400 counts per revolution, but the code was written for 360. Press the button to drive 1 m straight.

Why it matters: A wrong counts-per-revolution or wheel-diameter value scales every distance by the same factor. If it is wrong on both wheels equally, the path shape stays right but its size is wrong. If it is wrong on one wheel only, the heading goes wrong too. Measuring one lifted wheel turn, as in Unit 06, catches it.

12. Plan the tape test

Press the button to see the marked floor: a start line, a 1 m line, a straight reference tape, and the two marks on the rover that give its heading.

Why it matters: The tape is the independent check; it does not trust the counts. Two marks 100 mm apart on the rover's centreline turn a heading into two distances you can measure with a ruler. Decide what you measure before the run so the counts cannot influence you. Three trials show whether the error repeats or wanders.

13. Worked example: three simulated trials

Press the button to run three simulated straight trials with slightly different slip each time. Read the counts and the taped results in the readout.

Why it matters: A worked example shows the arithmetic: counts → predicted travel and heading, tape → measured, difference → error. A repeated left drift suggests a wheel size or speed mismatch; a scatter that changes sign suggests slip. These numbers are SIMULATED and are not your results. Your notebook fields stay empty until you measure.

14. Your three trials

Set up the floor as planned, with the program tested first on lifted wheels. Press the button to see the four things to record each trial, then open the Notebook tab.

Why it matters: The pass evidence is a comparison: encoder-predicted travel and heading against tape, in three trials. Write the counts first, predict, then measure, so the tape is a real test. If they disagree, the size and pattern of the gap point to slip, unequal wheels or a wrong counts-per-revolution value. Unit 08 asks what changes when the rover can correct its own error.

Go deeper

The maths in this unit

Arc length, radians and wheel circumference are the whole of differential-drive odometry.

circumference      C = π × d
distance per count = C ÷ counts_per_rev
wheel travel       dL = nL × C ÷ cpr,   dR = nR × C ÷ cpr
centre travel      ds = (dL + dR) ÷ 2
heading change     dθ = (dR − dL) ÷ b      (radians; b = track width)
turning radius     R  = (b ÷ 2) × (vR + vL) ÷ (vR − vL)
arc length         s  = R × θ

The pose update used here follows the exact arc for each small step: x += R(sin(θ + dθ) − sin θ), y −= R(cos(θ + dθ) − cos θ), with R = ds ÷ dθ, and a straight line when dθ is zero. Many robots use the simpler x += ds cos θ, which is close when each step is small.

Model limits

Watch / read