Project: enter a hard game
Light Cycles, Rescue Line or Capture the Flag: how to practise one properly, and the line and gripper rehearsal.
Do this lesson in the simulatorEverything in this course now points at one of three games. Pick one, practise against the bots until you beat them, then take it to a room with other people.
The three
Light Cycles, free for all, after Module 6. Trails everywhere, your own included. Won by turning early and keeping to the outside, and by never standing still. Lesson 10.4 is the rehearsal.
Rescue Line, on your own, after Module 7. Follow the line, pick up the casualty with the gripper, carry it home without losing the line. Two skills you know separately, used at once, which is the whole difficulty.
Capture the Flag, teams, after Module 9. Take the other team's flag home while they try the same. Roles, radio, and knowing when to defend. Lesson 10.5 is the rehearsal.
How to get good at any of them
- Read the game page. It lists exactly what
info()gives you, and describes each built-in bot. - Beat one bot. Not all of them. Pick the one that beats you most and work out what it does differently.
- Print, race, read. One line per loop with your state and the numbers you decided on. The log is where the answer is.
- Change one thing at a time. Two changes and a better result tells you nothing.
- Then play people. Rooms are on the competitions site: one screen hosts, everyone else joins with the code.
The rehearsal
This is Rescue Line's hardest moment on its own: the line, a ball to carry, and a zone to reach.
from bugbot import *
connect()
set_cv('line')
while True:
seen = line()
if seen:
# line() gives [cx, angle]: steer by how far the line is from the middle of the picture
cx, angle = seen
drive(45, 0, (cx - 160) * 0.35)
else:
drive(25, 0, 40)
wait(0.1)
Task: carry it home
Follow the black line to the red ball, pick it up with the gripper, and carry it into the green zone at the end without dropping it.
from bugbot import *
connect()
set_cv('line')
gripper("open")
# follow the line first: position() counts from the start
while position()[1] < 40:
seen = line()
if seen:
cx, angle = seen
drive(40, 0, (cx - 160) * 0.3)
else:
forward(30)
wait(0.1)
stop()
Where next
That is Robot club, from your first line of Python to a hard game. Three things to do now:
- Play in a room. The competitions site takes a class, a club or four friends on one screen.
- Go deeper. The A level course covers the computer science under all of this: algorithms, data structures and how the machine works.
- Put it on a real robot. Everything you have written runs on a BugBot without a single change.