Skip to main content

Lesson 1-6 · Differential Drive & Motor Control

Module 1 · Learning to Drive

Lesson 1-6 · Differential Drive & Motor Control

60–75 minDriving ChallengesUnder the hoodSlides (PowerPoint)
👩‍🏫

Teacher mode is on. Toggle it off (bottom-right) to preview the student view.

Every Straight and Turn you've used is really controlling two motors behind the scenes. In this lesson you'll take the wheel yourself — driving the left and right motors directly to make curves, spins, and smooth steering that the high-level blocks can't do on their own. Along the way you'll find out what the word effort actually means, and why it isn't the same thing as speed.

Learning Objectives

By the end of this lesson you will be able to:

  • Explain differential drive — steering by running the two wheels at different speeds
  • Predict the robot's motion from what each side's motor is doing
  • Use Set effort to control the motors directly (-1 to 1), and explain how effort differs from speed
  • Steer with Arcade, and say what changing its Turn number does to the size of the circle the robot drives
  • Decide when to use direct motor control vs. the high-level Straight/Turn

How the robot really steers​

The XRP is a differential drive robot: it has no steering wheel. The only thing it can control is how fast each side turns, and in which direction — and that turns out to be enough to produce every motion it can make.

Predict first: which way will the robot drive?​

In each picture below, the robot is seen from above and the arrows show what each side's motor is doing: which way it turns, and how fast (longer arrow = faster). For each one, decide before you press Drive it: does the robot drive straight, curve, swing around, or spin? Then watch and check.

An XRP seen from above, front at the top; both side arrows point forward and are the same length. Pressing Drive it plays an animation: Both sides forward at the same speed: the robot drives straight ahead and its path is a straight line. It never turns, so it has no turning center.
Case 1 — both sides forward, same speed. Which way will it drive? Decide, then press Drive it.
An XRP seen from above, front at the top; both side arrows point forward, but the left one is much longer than the right. Pressing Drive it plays an animation: Left side fast, right side slow: the robot curves to the right, circling a turning center that is off the robot, beyond its slower right side. A dotted circle shows the path around that point.
Case 2 — both sides forward, but one side faster than the other. Which way will it drive? Decide, then press Drive it.
An XRP seen from above, front at the top; the right side has a forward arrow and the left side is marked stopped. Pressing Drive it plays an animation: Left side stopped, right side forward: the robot swings around its stopped left wheel, which is the turning center.
Case 3 — one side driving, the other side stopped. Which way will it drive? Decide, then press Drive it.
An XRP seen from above, front at the top; the left side arrow points backward and the right side arrow points forward. Pressing Drive it plays an animation: Left side backward, right side forward: the robot spins on the spot, turning around the pen hole in the chassis, midway between the wheels.
Case 4 — the two sides driving in opposite directions. Which way will it drive? Decide, then press Drive it.

The whole rule, in three lines​

Every one of those outcomes comes from the same idea — you operate the left and right sides of the driveline independently:

Same

Both sides, same speed

Drives straight. Match the two sides and there's nothing to turn the robot.

Different

One side faster

Turns. The bigger the difference, the tighter the curve — until one side stops and it swings about that wheel.

Opposite

Each side opposite

Turns in place. The robot rotates about its own center without going anywhere.

Knowledge Check

Your robot is supposed to drive straight but keeps drifting to the left. What does that tell you about the two sides?

Commanding the motors: the Set effort block​

The Set effort block gives you that direct control. Effort runs from -1 (full reverse) through 0 (stopped) to 1 (full forward), and you set each wheel separately — so each of the four cases above is just a pair of effort numbers.

There's a catch, and it's the big idea of this lesson. Straight finishes: it drives its 20 cm, stops the motors, and hands the program to the next block. Set effort doesn't finish — it switches the motors on and moves straight to the next block, leaving them running. They keep running until something stops them.

So a Set effort program has to answer a question Straight never asks you: when should the motors stop? For a first look, we'll answer it with a Sleep — but keep an eye on how well that works.

wait_for_button_press block
set_effort block← left: 0.5, right: 0.5 → straight
sleep block← 3 seconds — the motors are still running the whole time
Direct motor control: Set effort starts both wheels, and they stay on while the program sleeps.
Knowledge Check

You run Set effort with left 0.5 and right 0.5. What does the robot do?

Knowledge Check

What happens with left 0.5 and right -0.5 (one wheel forward, one backward)?

Effort is not the same as speed​

The block is called Set effort, not "set speed," and the difference matters. Effort is how hard the motors try — electrically, it's how much voltage they get. Think of it the way you'd think about your own effort in a sport:

Line drawings of a cyclist, a skater, a swimmer, and a hiker, illustrating effort
Effort is how hard you're working — not how fast you're actually going.

Those two things come apart as soon as the world pushes back. Pedal a bike uphill at a constant effort and you slow down; the same effort on the flat carries you much faster. Effort is your input. Speed is the result — and it depends on the hill, the carpet, the battery, and how much the robot is carrying.

Speed is the other way of asking: you name the speed you want, and the robot adjusts its own effort to hold it — pushing harder up the hill, easing off on the way down:

An animation of an XRP, seen from the side, driving over a hill: flat ground, an uphill slope, a flat top and a downhill slope, with an effort gauge and a speed gauge beside it. Effort control: the effort gauge stays at the same level the whole way, and the robot crawls up the slope, speeds up on the flat top and goes fastest down the other side; red dots dropped at equal time steps bunch together uphill and spread out downhill. Speed control: the speed gauge stays the same the whole way while the effort gauge climbs high going uphill, drops to medium on the top and falls low going downhill; blue dots are evenly spaced.
Press each button and watch the two gauges. Effort control holds the effort and lets the hill change the speed; speed control holds the speed and changes the effort to keep it.

This is why the same Set effort numbers don't always produce the same motion. Effort 0.5 on a smooth floor is quicker than effort 0.5 on thick carpet, and quicker again with a fresh battery. It's also why Straight and Turn are more repeatable than raw effort — they watch the robot's sensors and adjust, instead of blindly holding one voltage.

Knowledge Check

You set both motors to effort 0.5 and drive across a smooth floor, then across a thick carpet. What happens?

Knowledge Check

A robot is asked to hold a steady speed as it drives up and over a hill. What does its effort do?

Blocks that finish vs. blocks that don't​

Run the program above three times: once with a fresh battery, once on carpet, and once on a smooth floor. Measure how far the robot goes each time.

Three seconds at effort 0.5 is not a distance. It's three seconds — and the distance you get out of it changes with the battery, the surface, the weight on the robot, even whether the floor slopes. That's the effort-isn't-speed idea from the first section, showing up as a practical problem.

Now compare the two kinds of block:

Finishes

Straight / Turn

Runs until the job is done — the distance driven, the angle turned — then stops the motors by itself. The next block doesn't start until it's finished.

Doesn't finish

Set effort / Arcade

Switches the motors on and moves to the next block immediately. The motors stay on until something stops them.

Three things can stop them: a Stop motors block stop_motors block, another Set effort (including effort 0), or the program ending. You don't need a stop block at the end of a program — the robot stops the motors when the program is over — but any time the motors should quit while the program keeps going, that's what Stop motors is for.

Which leaves the real question: what should the robot wait for before it stops? A Sleep is the crudest possible answer, and you just measured why. The answer you'll use for the rest of this course is to stop on something the robot senses — drive until the rangefinder says the wall is 10 cm away, until the reflectance sensor sees the line, until the encoder has counted far enough. Same Set effort, but the robot decides when it's done instead of the clock. That's where Module 2 goes next.

Knowledge Check

What's the difference between what Straight does and what Set effort does?

Knowledge Check

Why is 'Set effort 0.5, Sleep 3 seconds' a poor way to travel a set distance?

Smooth steering with Arcade​

Setting two efforts by hand is fiddly. The Arcade block is friendlier — you give it two numbers, like a game controller, and it works out the two motor efforts for you:

  • Straight — how fast it drives forward (this is the one people call speed).
  • Turn — how hard it bends, and which way. 0 is dead straight; positive and negative bend opposite ways.
wait_for_button_press block
arcade block← Straight: 0.5, Turn: 0.3 → forward, curving left
sleep block← 3 seconds — again, a stand-in until we have sensors
Arcade combines forward motion and steering into one intuitive block.
Knowledge Check

When is the Arcade block a better choice than Set effort?

Activity · Get a feel for circles​

Before you try to draw a shape with curves, you need a feel for what the two numbers in Arcade actually do to the robot. The fastest way to get it is to drive circles and watch them change size.

Put a dry-erase marker in the robot's marker holder and work on a whiteboard panel, and the robot draws its own circle for you to measure. No marker? Chalk a starting mark on the floor and eyeball it.

Step 1 · Change one number and watch​

Use the three-block program from the section above — wait for button, Arcade, Sleep — with Straight at 0.5 and a Sleep long enough to come round at least once. Now run it three or four times, changing only Turn each time:

StraightTurnHow big was the circle?
0.50.15
0.50.3
0.50.5
0.50.8

You don't need exact measurements here. You're after the relationship — one sentence you could say out loud about what happens to the circle when the turn number goes up. Write it down before you move on.

Knowledge Check

You run Arcade with Straight 0.5 and Turn 0.3, then change Turn to 0.6. What happens to the circle?

Step 2 · Find a circle that fits​

Now aim for something specific: a circle roughly 12 to 18 inches (30–45 cm) across — about the width of a sheet of paper turned sideways, up to a bit more. That size fits on a whiteboard panel and it will fit on your desk space later.

Don't calculate it. Change Turn, run it, look, change it again. Three or four tries is normal.

When you've got one you like, write both numbers down and don't lose them:

My circle: Straight ______ Turn ______

Every robot lands on slightly different numbers, and the rest of this lesson uses yours.

Step 3 · Time a half circle​

Here's the number you actually need. Keep Straight and Turn exactly as they are, and change only the Sleep until the robot comes round to face the opposite direction from where it started — a half circle.

Half of one is easier to judge than a whole one: "is it pointing backwards?" is a question you can answer by looking, while "is it back where it started?" is a guess. Start from a wall or a tape line so you have something to judge against.

My half circle takes ______ seconds

A full circle takes twice that, which is the last thing you need for the next activity.

Knowledge Check

Your half circle takes 1.4 seconds. Roughly how long is a full circle at the same Straight and Turn?

Activity · Earth – Moon – Earth​

Tape an Earth and a Moon to your whiteboard panel, about 18–24 inches (45–60 cm) apart. Your robot is a spacecraft, and its mission is to swing around the Moon, cross to the Earth, swing around the Earth the other way, and come back to rejoin its own lunar orbit.

An Earth disc and a Moon disc of equal size side by side, making an infinity symbol: a dashed three-quarter circle around each body, joined by two solid straight diagonals that cross at forty-five degrees in the middle. Dots mark the four points where a curve becomes a straight line. A small XRP flies the mission: from the crossing straight out to the Moon, three-quarters of the way around it bending right, straight back across to the Earth, three-quarters of the way around it bending left, and straight home to the crossing. A line at the top names each move and the block that drives it.
The mission, flown. Dashed is curved and timed; solid is straight and measured; the dots are where one becomes the other. The robot starts and finishes at the crossing.

There's a printable Earth and Moon in this lesson's Resources at the bottom of the page — print it, cut both discs out, tape them down.

The two bodies are drawn the same size, which is not remotely true and is very convenient: it means both of your orbits are the same size, so the numbers you found in the last activity work for each of them. (The real Moon is about a quarter of Earth's width, and thirty Earths would fit in the gap between them.)

Step 1 · Plan the mission on paper​

Before you touch a block, draw the path. Mark where the robot starts, which way it goes round the Moon, where it crosses to the Earth, and which way it goes round that. You should end up with a shape you recognize.

The thing to notice on your drawing: the robot bends one way around the Moon and the other way around the Earth. That's the whole trick, and it's why Straight and Turn blocks can't draw this shape at all.

Step 2 · Build the mission​

Four moves, and you already have the numbers for two of them:

#MoveBlockThe number
1Orbit the MoonArcade + Sleepyour Straight and Turn
2Cross to the EarthStraightthe gap, in cm
3Orbit the Earth, the other wayArcade + Sleepsame, with Turn negated
4Cross back to the MoonStraightthe same gap

For the orbits, use a Sleep of about three-quarters of a full circle — 1.5 times your half-circle time. That is not a guess: with the bodies spaced as above, three-quarters of a turn is exactly what brings the robot out of a swing pointing at the other body. Tune from there rather than starting from nothing.

Notice which blocks do which job — it's why the picture above draws them differently. The crossings use Straight, which finishes: it drives a measured distance and stops itself, so it lands the same way every run, and it's drawn solid. The swings have to use Arcade, which doesn't finish, so they need a Sleep to say when to stop, and they're drawn dashed because a time is a much shakier thing to rely on than a distance. That's the distinction from earlier in this lesson, doing real work in one program.

Step 3 · Fly it, then fix it​

It will not work first time. That's the job:

  • Overshooting the turn round the Moon — the robot leaves pointing the wrong way. Shorten that Sleep.
  • Missing the Earth entirely — the crossing distance is wrong, or the orbit before it left the robot off-heading. Fix the heading first; the distance can't be right until the direction is.
  • A lopsided path — the two Turn values aren't true mirror images. Check the sign is the only thing that changed between them.

You've succeeded when the marker traces a path that loops the Moon, crosses to the Earth, loops it the other way, and comes back to meet where it started.

Challenge — move the two bodies further apart without changing the size of your orbits. Which of the four numbers has to change, and which don't?

Real-world connections​

Direct motor control is how machines that don't drive in straight lines work:

Mobility

Wheelchairs & rovers

Powered wheelchairs and Mars rovers steer by differential drive — exactly this left/right speed trick.

Gaming

Twin-stick control

Tank-style games map two sticks to two "tracks," the same idea as setting two efforts.

Heavy equipment

Skid-steer loaders

Construction "skid steers" turn by driving their left and right wheels at different speeds.

Spaceflight

The free-return trajectory

Apollo flew a real figure-eight: loop behind the Moon, let its gravity throw you back at Earth. It brought Apollo 13 home.

Wrap-up​

  • How does a differential-drive robot turn? (By running its wheels at different speeds.)
  • What happens to the motors when a Straight block finishes? What about a Set effort block? (Straight stops them; Set effort leaves them running.)
  • Why is timed driving unreliable, and what should a robot stop on instead? (Effort isn't speed — battery and surface change the distance; stop on a sensor reading.)
  • When would you pick the Straight/Turn blocks over Set effort? (When you need precise, repeatable distances and angles.)
  • In the Arcade block, which number changes the size of the circle, and which way? (Turn — bigger Turn, tighter circle.)

Resources​