The Speed Bot: a driving base that measures its own trip. Then it works out how fast it went.
Your robot already knows two things. It has never put them together. Since Lesson 11, the Hammering Machine, it can say how far its motor has turned. Since Level 1, it can say how long something took.
Speed is just distance and time. Today the robot stops showing raw numbers. It starts showing centimetres, and centimetres per second. Those are numbers a person can really use.
In the real world 5 min
Where you have seen it
A bike computer is cheap. It tells you your speed, how far you went, and your average. It uses just one magnet on a spoke and a sensor on the frame. It counts how many times the wheel goes round. That is all it gets.
A bike speed dial and distance counter. The dial shows speed. The counter under it adds up the distance. Photo: Illustratedjc / Wikimedia Commons (CC BY-SA 4.0).
Why it is built that way
Nothing in a bike computer measures distance, and nothing measures speed. It counts turns of the wheel. Then it does the same sums you are about to do.
One turn of the wheel moves the bike forward by the distance round the tyre. That distance is called the circumference. So distance is turns × circumference. Speed is that distance divided by the time it took. The clever part is not the sensor. It is the sum.
That is why a bike computer first asks for your wheel size. Get that wrong, and every number it shows is wrong by the same amount each time.
What would go wrong without it
A robot that says 1800 degrees has not told you anything useful. Is that far? Is it fast? You cannot compare it. You cannot tell a person about it. You cannot use it to decide anything. Raw numbers only help once they are turned into units people think in.
Sensors give you numbers. Sums turn them into answers.
The main concept — three sums 6 min
Everything today is one of three steps. Each one takes a number you already have. It turns it into a more useful one.
Step
The sum
Turns…
1 · Rotations
degrees ÷ 360
a number only a robot cares about into how many times the wheel turned
2 · Distance
rotations × circumference
wheel turns into centimetres travelled
3 · Speed
distance ÷ time
centimetres into centimetres per second
The green blocks
(([B v] degrees counted) / (360)) :: operators
A number block inside a maths block. The answer is a number block too. So it can go inside another one.
That last sentence is the whole trick. A maths block is a number, so it fits anywhere a number fits. It even fits inside another maths block. Put them inside each other, and you build a formula:
Speed, all in one: degrees to rotations, rotations to centimetres, then centimetres divided by seconds.
That is hard to read. Each answer goes straight into the next block. A variable could hold the in-between answers, but today you do not use one. For now, build it from the inside out. Test each layer before you add the next.
Measure your own wheel
The 17.6 above is for a standard EV3 wheel. Yours may be different. The circumference is the distance round the tyre. Roll the wheel one full turn along a ruler, and read how far it went. That is your number. You measured it, so you know it is right.
ComponentControl5 min
Comparing and combining
A sensor that reports a number cannot be used to make a decision on its own — 23 is neither true nor false. An operator turns that number into an answer by comparing it with something.
Blocks reference
Block
What it does
<(x) > (50)>
True when the left value is bigger than the right.
<(x) < (50)>
True when it is smaller.
<<> and <>>
True only when both conditions are true.
<<> or <>>
True when at least one of them is.
Try it: which way round does it go?
Forget the symbols for a moment. A comparison is a question about position on a number line: is x to the left of the other number, or to the right? Left is smaller, right is bigger — and that is the whole of it.
Drag the orange x and the black marker, and change the comparison. The green stretch is every position of x that would make the answer true — so you can see where the answer flips before you get there. Turn not on and watch the green jump to the other side.
Drag either marker, or use the arrow keys.
-3 < 4true
is x to the LEFT of it?
< is true while x sits on the left. Slide x past the marker and it flips.
> is the same question the other way round — so exactly one of the two is true, unless the markers are on the same spot.
= is true for one single position out of twenty-one. Try landing on it. That is why a sensor is almost never compared with =: a reading passes straight through the exact number without ever being measured there.
not flips the answer, whatever it was. not (x < 4) covers everything x < 4 does not — including landing exactly on 4.
Try it: which numbers make it true?
The lab above asks one question at a time: is this x true? A robot never has just one x, though — a sensor reading slides up and down all the time, so what really matters is which stretch of the line makes the condition true. This one draws the whole answer at once.
Drag the circle to move the number you are comparing against, and change the comparison. Everything shaded green is a value of x that would make it true.
Drag the circle, or use the arrow keys. It moves in steps of 0.2.
x < 0.2x < 0.2
Every number to the left of 0.2 — but not 0.2 itself, so the circle is hollow.
Watch the circle, because it carries the part everyone gets wrong:
Hollow ○ — the boundary is not included. x < 0.2 shades everything left of 0.2 but leaves 0.2 itself out, because 0.2 is not less than 0.2.
Filled ● — the boundary is included. Choose = and nothing is shaded at all: one single number qualifies.
Now turn not on with x > 2 selected and watch two things happen together. The shading jumps to the other side, and the circle fills in — because “not greater than 2” means 2 or less, and 2 has to be part of it. That pairing is the whole reason a hollow circle is worth drawing.
Why a robot cares. Two conditions that look almost identical — light < 30 and not (light > 30) — differ by exactly one value, the reading of precisely 30. A robot sitting right on its threshold behaves differently under the two, and that is the sort of bug that only shows up occasionally and looks like a broken sensor.
Try it: and, or, not
These three join answers together rather than numbers. The trap is that English is looser than a program: “stop if it is close and the bumper is pressed” sounds like it covers both situations, when it covers neither on its own.
Flip the two conditions and watch the table. There are only four possible situations in total, and and and or differ on exactly two of them.
close: trueandbumper: falsefalse
close
bumper
and
or
true
true
true
true
true
false
false
true
false
true
false
true
false
false
false
false
and is fussy: it wants both. Three of the four rows are false.
and is true on one row out of four. It narrows — the robot acts less often, but more certainly.
or is true on three rows out of four. It widens — the robot acts more readily.
The two agree on the top and bottom rows and disagree in the middle. Whenever swapping one for the other seems to make no difference, you have only tried the rows where they agree.
Watch them decide
Two sensors are running below: an Ultrasonic reporting a number, and a Touch Sensor reporting true or false. Watch the comparison turn the number into an answer, and watch and and or disagree.
when program starts
forever
if distance < 15 and is pressed? then
stop moving
if distance < 15 or is pressed? then
play beep 60 for 0.2 seconds
Nothing is within 15 cm and the bumper is out. Both conditions are false.Something comes close. The comparison flips to true — the bumper has not been touched.It backs away, and instead the bumper is pressed. Now the other condition is the true one.Close AND pressed. Only now is «and» true — while «or» has been true ever since the first of them was.Finished. Four situations, and the two operators disagreed in three of them.
and false · or false
and was true in one row out of four. or was true in three. That is the whole difference, and it is why one of them makes a robot look broken.
The comparison is doing one job: it takes a reading that is neither true nor false and, by holding it against a number you chose, produces something a decision can use. The moment the blue fill crosses the black marker is the moment the answer changes.
Choosing the threshold
The number you compare against is a design decision, not a fact. “Close” for a parking sensor might be 15 cm; for a robot arm it might be 3. Pick it by measuring what the sensor actually reads in the situation you care about, then leave a margin.
Combining two conditions
and narrows: both must hold, so the robot acts less often but more certainly — stop only if something is close and the bumper is pressed. or widens: either will do, so the robot acts more readily — stop if something is close or the bumper is pressed.
In the four situations above, and was true in one of them and or in three. That is the practical difference: swapping one for the other does not adjust a robot slightly, it changes how often it reacts at all.
Work the sum out on paper first. The screen only shows what it worked out. It cannot tell you if you asked for the right thing.
▶Where the two numbers come fromThe motor's degree counter from Lesson 11, and the Brick's timer from Level 1, side by side.Show meHide
ComponentSensing5 min
Reading a motor's position
Every EV3 motor contains a sensor that counts how far it has actually turned. That means a motor is not only an output — you can ask it where it is, and the answer describes what really happened rather than what you asked for.
The counting happens inside the motor housing, on this shaft. That is why the reading describes what the motor did — not necessarily what the robot did, if a wheel slipped.
Blocks reference
Block
What it does
([A v] degrees counted :: sensors)
Reports how far this motor has actually turned since the count was last reset, in degrees.
[A v] reset degrees counted :: motors
Sets the count back to zero, making right here the new reference point.
([A v] speed :: sensors)
Reports how fast the motor is turning right now, as a percentage. A motor that is being driven but reads zero is a motor that is stuck.
Asked for, versus achieved
Those two are not always the same. Here are two identical motors, running the same program, with only their mechanisms different.
Both motors are told to turn two rotations — 720 degrees. Both counters start at zero.Both turning. The counters climb together, and so far the two motors agree.The right-hand arm has run into the post and cannot go past it. The motor is still straining against it, the counter has stopped, and the program is still waiting on that block.The left motor finished at 720. The right is stuck at 284 — it never got past the post, and that gap is the only way the robot can tell.Finished on the left. The right-hand program is still waiting, and will wait for ever.
stopped
Nothing on the Brick announces a stall. The only evidence is that the counter stopped changing while the motor was still being told to turn.
Nothing on the Brick announces the jam. The motor is still being driven, the program is still sitting on the same block, and the only trace of the problem anywhere is a counter that has stopped climbing. Comparing what you asked for with what was counted is how a robot notices — which is the whole of stall detection.
Zero is wherever you say it is
When the Brick powers on, the count is simply whatever it happens to be. It is not a position on the machine — it becomes one only when you tie it to something physical.
That is what reset degrees counted is for, and it is not just a tidy-up block for the top of a program. Where you put it decides what zero means, so putting it part-way through — after the mechanism has been driven somewhere known — is the normal way to use it, not an abuse of it.
Find home first, then reset
A conveyor has no idea where it is. Give it a touch sensor at one end and it can find out: drive it until the sensor is pressed, and it is now at a place you can name. Only then reset the count, and that end becomes 0.
when program starts :: events hat
[A v] start motor [counterclockwise v] :: motors
[1 v] wait until [pressed v] :: sensors
[A v] stop motor :: motors
[A v] reset degrees counted :: motors
The order is the whole point. Reset before the sensor is pressed and you have zeroed a random spot; reset after it, and every later reading means “how far from home”. This is called homing, and it is why a printer rattles its head to one side when you switch it on.
Drive towards home gently. The mechanism is deliberately being run into its own end stop, so a slow speed saves the gears — and the touch sensor is what stops it, which means it stops in the same place every time regardless of where it started.
Putting zero somewhere more useful
Home is often a corner, and a corner is an awkward place to measure from. Say the conveyor carries a chute that dispenses bricks, and you would rather describe its position as left and right of the middle. Then home once, drive the known distance to the middle, and reset again there:
when program starts :: events hat
[A v] start motor [counterclockwise v] :: motors
[1 v] wait until [pressed v] :: sensors
[A v] stop motor :: motors
[A v] reset degrees counted :: motors
[A v] run [clockwise v] for (900) [degrees v] :: motors
[A v] reset degrees counted :: motors
Now the middle is 0. Moving right counts up, moving left counts down past zero into negative numbers — the count is perfectly happy to go negative — and “go back to the middle” becomes the simplest instruction in the program: drive until the count reaches 0.
Both resets earn their place. The first one turns a meaningless number into a distance from a real, repeatable place. The second one moves zero to where the maths is easiest. A reset in the middle of a program is only a mistake when the mechanism is somewhere you cannot name.
Turning turns into distance
Because the count is in degrees, and a wheel of known size travels a known distance per turn, the reading can be converted into how far the robot has actually driven. That is how a robot reports a distance in centimetres rather than in rotations — and it is why changing the wheels changes the answer.
Why it matters
This is how a printer knows the paper jammed, how a car window stops when it meets your hand, and how a robot arm knows it has reached its limit. A machine that can only give orders is fragile; one that can check what happened can recover.
ComponentControl4 min
The Timer
A wait pauses for a length of time. The timer is different: it runs in the background and can be read at any moment, so the robot can know how long something has taken while it is still happening.
Blocks reference
Block
What it does
(timer)
Reports the seconds since the timer was last reset.
reset timer
Sets it back to zero, so the next reading counts from here.
The timeout — a safety net
The most valuable use of a timer is escaping a wait that might never end. A robot told to drive until it sees a wall will drive for ever if the wall is not there. Combined with a timer, it can give up:
Repeat until the wall is close or five seconds have passed. That one change turns a program that can hang into one that always finishes. Both robots below are looking for a wall that is not there.
no way out
repeat until distance < 15
start moving straight: 0
with a timeout
reset timer
repeat until distance < 15 or timer> 5
start moving straight: 0
write GAVE UP at line 1
1.2stimer212cm · distance
Both robots are told to drive until something is within 15 cm. The room ahead is empty.Three seconds. No wall. Both are still driving — and the right-hand program is also watching its timer.The timer passes 5. The right-hand robot gives up, stops, and says so.The left robot is still going. Its condition can never become true, so that block will hold the program for ever.The right-hand program finished. The left one has not, and there is nothing to say why.
timer 1.2 s
The sensor is not faulty and the program is not wrong. There is simply no wall, and only one of these two programs has a way of noticing that.
The left-hand robot is not broken, and neither is its sensor. Its condition is simply one that will never come true, so the program sits on that block for ever — with nothing on the Brick to say so. The right-hand program asks the same question with an escape route bolted on, and finishes every time.
Why it matters
Real systems time themselves out constantly — a lift that cannot close its doors eventually gives up and beeps rather than trying for ever. A robot with no timeout simply stops responding, and there is nothing on screen to say why.
Say this back before you move on: “Speed is distance divided by time.”
What’s in this build 4 min
Part
What it is doing here
EV3 Intelligent Brick
Keeps the timer and does the sums. Today it is a calculator that can also drive.
Large Motor ×2 — the drive
Ports B and C. The maths reads only one of them. The Movement blocks keep them in step, so either will do. But pick one and stick with it.
The wheels (not electronic)
The most important number in the lesson comes from here. To the maths, a different wheel means a different robot.
The Brick screen
Shows rotations, distance and speed. That is three lines that mean something, not one that does not.
Measure the wheel carefully
Mark one spot on the tyre with a sticker or a dot of tape.
Line the mark up with zero on a ruler. Roll the robot forward until the mark comes round to the bottom again.
Read the distance. That is your circumference. Write it on your sheet and on the board.
Do it twice more. Do the three match, to a couple of millimetres? If not, roll more carefully. Every number today is built on this one.
Check it with maths. Circumference is π × diameter. The diameter is the distance across the middle of the wheel. Measure it, times it by 3.14, and see if it matches what you rolled. Two ways to the same number is how you know it is right.
Ports — and the rule 4 min
Sensors go in ports 1, 2, 3, 4. Motors go in ports A, B, C, D. You cannot swap them. If you do, nothing warns you. The robot just will not work.
Part
Port
Why this one
Left drive (Large)
B
B is left. B is also the one this lesson reads for its maths.
Right drive (Large)
C
C is right. The Movement blocks keep it in step with B. That is why reading only one of them is fair.
Sensors
none
Everything you measure today comes from inside the Brick and the motors.
Check your own build now:
Stand behind the robot. Left in B, right in C.
Find at least a metre of clear, flat floor. Mark a start line. On a short run, small timing mistakes count for a lot.
Use the same floor for every run today. Carpet and table give different answers. That is something you found out, not a mistake.
Connect the Brick 4 min
Two routes, and either is fine. USB is the reliable one and the one to fall back on when a room’s Bluetooth is busy; Bluetooth leaves the robot free to move, which some models need.
▶How to connect the BrickUSB and Bluetooth, step by step, with a photograph of every screen. Open it if you have not done this before — or if pairing is not working.Show meHide
USB — the reliable one
Switch the Brick on with the dark grey centre button.
Cable into the Brick’s PC port — the small square socket beside the numbered ports, not one of the numbered ones.
Other end into the computer.
Bluetooth — name it first
Do these in order. Naming the Brick after you go looking for it in the list is how groups end up driving each other’s robots.
Name your Brick. On the Brick: Settings (the spanner) → Brick Name. Type something nobody else will pick, then press the tick. Every Brick is called EV3 until somebody changes it.
Turn Bluetooth on. Settings → Bluetooth. Tick Bluetooth and Visibility. Leave iPhone/iPad/iPod unticked.
Connect from EV3 Classroom. Click the Brick icon at the top of the programming area, find your Brick by name, and click Connect.
Say yes on the Brick. It asks “Connect?” with the computer’s name — choose the tick, then accept the passkey, which is already 1234.
Where to read it. The name sits in the bar across the very top of the screen, on every screen — so you can check which Brick you are holding at any moment without going into a menu. This one is EV3VE. A Brick nobody has renamed says EV3.Step 3, and the reason step 1 exists. Three Bricks in range — read the name before you click Connect. Pairing with the wrong one is not an error: it works perfectly, on somebody else’s robot.
Step 2.Bluetooth switches the radio on; Visibility is what lets the computer find you. With Visibility off your Brick works perfectly and simply never appears in the list.Step 4. Look at the Brick. It asks whether to accept and names the computer. Choose the tick.Then the passkey, already 1234. Press the tick again and you are connected.
The two failures, every class, every time. The Brick has gone to sleep while you were building — press the centre button to wake it. Or you have paired with the group at the next table, which is why the name matters.
The long version, including Port View and how to read the port tiles, is in the Brick & Bluetooth guide.
Use Bluetooth. It matters today. A dragging cable slows the robot down. That changes the very number you are trying to measure.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
Two Large Motor tiles, on B and C.
Roll the robot one wheel turn by hand. Watch tile B. It should go up by about 360. Is it very different? Then your wheel is joined to the motor by gears, not fixed straight onto it. Every sum today then needs the gears in it.
Push it along your measured metre and see about what B reads. That is a guess you can check against the program.
Change it and test 8 min
Guess every number before you run, and write your guess down. If you did not guess, nothing can surprise you. Being surprised is how you find mistakes.
Add the speed line. Build it from the inside out. Take your working distance blocks. Drop them into the left side of a / block, with (timer) on the right. Write it to line 7.
Run at 40% and note the speed. Then run at 80%. Is the second number about twice the first? It is most often a bit less. Say why.
Change the trip to 10 rotations at the same speed. The distance doubles. The time about doubles. The speed should stay about the same. If your speed changed a lot, something in the sum is wrong.
Run the same program on carpet, not a table. You ask for the same rotations, but get a different real distance. Now you can measure how much the floor cost you.
Wrap the speed line in (round ()). It is easier to read, but you lose the decimals. Is that better here? You decide.
Step 3 is the best proof in the lesson. Speed should not change with how far you went. That is what makes it speed and not distance. If a longer trip doubles your “speed”, you divided by the wrong thing.
A formula that is right once might be luck. One that stays right when you change the trip is a real formula.
This is what you are building: the EV3 Speed Bot.
Build it 15 min
Build the model before you read any further. Everything after this is about making it do something, and none of it will make much sense with nothing on the table in front of you.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
Make it move 10 min
Drive a set trip. Then show it in rotations and centimetres. Speed comes in step 10, once these two are right.
when program starts :: events hat
set movement motors to [B v] and [C v] :: movement
clear display :: display
[B v] reset degrees counted :: motors
reset timer :: sensors
move [forward v] for (5) [rotations v] at (40) % speed :: movement
write [Turns:] at line (1) :: display
write (([B v] degrees counted) / (360)) at line (2) :: display
write [Distance cm:] at line (3) :: display
write ((([B v] degrees counted) / (360)) * (17.6)) at line (4) :: display
write [Time s:] at line (5) :: display
write (timer) at line (6) :: display
Change 17.6 to the circumference you measured. Everything else is the same for every robot in the room.
reset degrees counted and reset timer. Do both, just before the trip. If you start measuring too early, the numbers are wrong.
move forward for 5 rotations. This is the trip. It waits until it is done. So everything below runs after.
degrees ÷ 360. This should read very close to 5, because you asked for 5 rotations. This line checks that everything works.
× circumference. This gives centimetres. Now measure the real distance with a ruler and compare.
What success looks like: line 2 reads about 5. Line 4 matches what you measure on the floor, to a centimetre or two. If those two agree, you can trust every number you build on top of them.
Is the distance on screen bigger than the real one? Then the wheels slipped. The motor turned further than the robot went. Is it always too small, or too big, by the same share? Then your circumference is wrong. The same share each time is a maths mistake. A random difference is a grip problem.
Challenges 27 min
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Challenge 1
Measure a metre. Mark a start and a finish exactly one metre apart. Make the robot report a distance within two centimetres of that. You may change the rotations but not the formula. The formula is the sum the robot uses to work out the distance.
Challenge 2
Prove that speed stays the same. Run the same program on a short trip and a long one, at the same motor speed. The distances must be different. The speed it reports must not be. If it is, find out why before you go on.
Challenge 3
Make a speed table. Measure the robot's speed at 20, 40, 60, 80 and 100 percent. Do three runs at each. Write them all down. Does doubling the percentage double the speed? Say what you found.
Extra challenge
Turn the Speed Bot into a tool someone else can use.
A measuring tool is not just a robot that does sums. A stranger can pick it up, use it the right way, and trust it.
Start with the maths. Write your formula on paper, with your own measured circumference in it. Work out one trip by hand before the robot does it. Show your working. You are proving the tool is right. You cannot use the tool to do that.
Then make it easy to use. Decide what the screen should show, and where. Someone should be able to read the distance and speed at a glance. They should not need to know what degrees are. Decide how it starts. Decide how people know it has finished.
Then give it to another group. Do not explain it. Ask them to measure something with it.
When you show it, answer two questions. What did your tester read wrong? Was it the labels, or where things were on the screen? And your robot reports how far its wheels turned, not how far it really went. When could those two be very different? What would you add to spot it?