Unit 7: Wheels
Two motors, and how to ease off.
Unit 7 of 8 in Robotics coding for kids. Its 4 lessons are Two Motors, Curves, Easing Off and Docking — below is everything each one explains, and a question or two from it to try.
Every program on this page was driven round the simulated room before it shipped, and prints exactly what it says it prints.
This unit opens with a fortnight’s trial of everything — no card needed — or with a family plan, bought in the iPhone app. The first two units of every track are free for ever. Try it in the app.
⚙️ Two Motors
What forward was really doing
Bolt has one motor per wheel. robot.wheels(left, right) sets both, from -10 to 10, and runs them for a tenth of a second.
Power 10 is 20 cm a second, so one call at full power moves 2 cm. Equal powers on both sides drive dead straight.
Python
for tick in range(15):
robot.wheels(10, 10)
robot.say(robot.y())
It prints
150.0
Try it yourself
What makes a two-wheeled robot turn?
- One wheel running faster than the other
- A steering wheel at the front
- Turning the whole body
- Nothing — it can only go straight
Power 5 is 10 cm a second, and each call lasts a tenth of a second. What does this print?
Python
for tick in range(20):
robot.wheels(5, 5)
robot.say(robot.y())
Answer them in the app
🌗 Curves
Unequal wheels draw a circle
Run the left wheel a little faster than the right and the robot swings right — not in a corner, but in a smooth arc. The bigger the difference, the tighter the circle.
Make them exactly opposite and the circle shrinks to nothing: the robot spins where it stands. That is all robot.right(90) ever was.
Python
for tick in range(10):
robot.wheels(6, 4)
robot.say(robot.heading())
It prints
19.1
Try it yourself
Opposite powers spin the robot on the spot. What heading does this end on?
Python
for tick in range(6):
robot.wheels(5, -5)
robot.say(robot.heading())
Which pair of powers makes the tightest turn?
- wheels(10, -10)
- wheels(10, 9)
- wheels(10, 10)
- wheels(5, 5)
Answer them in the app
🐢 Easing Off
Big steps overshoot
This asks the robot to stop 30 cm from the wall, and it stops at 22. It never had the chance to stop at 30 — it was 47 away, took a 25 cm stride, and landed past the mark.
A robot that always moves the same amount can only ever be as accurate as its stride.
Python
while robot.distance() > 30:
robot.forward(25)
robot.say(robot.distance())
It prints
22.0
Let the mistake set the speed
Work out how wrong you are — the error — and drive that much harder:
error = robot.distance() - 30
Miles away, the error is big, so the power is big and the robot hurries. Nearly there, the error is tiny, so it creeps. It cannot overshoot, because as it closes in it slows down on its own.
This is called proportional control, and it steers real robots.
Python
while abs(robot.distance() - 30) > 0.5:
error = robot.distance() - 30
robot.wheels(error * 0.2, error * 0.2)
robot.say(robot.distance())
It prints
30.5
Try it yourself
How would you make that stop closer to 30?
- Take smaller steps the nearer it gets
- Take bigger steps
- Check the sensor less often
- Nothing can be done about it
Answer it in the app
🏆 Docking
Try it yourself
What is the error in a proportional controller?
- How far the robot is from where you want it to be
- A mistake in the program
- The robot’s top speed
- How long the loop has run
Answer it in the app