Skip to content

Lessons

The lessons live in their own place, built for students: each lesson mixes short explanations with live code cells. Press Run and the robot moves on the mat right there in the page, and the tasks are checked by the simulator, including what your program prints.

Open the lessons

Module 0: Python with a robot

The basics of Python, one idea at a time, taught by making a BugBot do things and print things. No experience needed. Sixteen lessons of 10 to 25 minutes.

Lesson New idea
0.1 What a program is instructions run top to bottom; Run; the console
0.2 Talking: print text in quotes, several things in one print
0.3 Calling functions brackets mean do it; arguments; telling versus asking
0.4 When things go wrong reading an error; the three mistakes everyone makes
0.5 Comments and tidy code #, blank lines, switching a line off
0.6 Numbers + - * / // %, integers and floats, round
0.7 Variables a name for a value, changing it, x = x + 1
0.8 Strings joining, str(), f-strings, reports
0.9 Blocks and indentation what a block is, the colon, IndentationError
0.10 Making decisions comparisons, True/False, if
0.11 More decisions else, elif, and/or/not
0.12 Repeating: for for and range, the loop variable
0.13 Repeating: while while, break, loops that never end
0.14 Lists making, reading, append, the depth grid, enumerate
0.15 Functions def, parameters, return
0.16 Project: the patrol a complete program, built a piece at a time

Game 0: Print race (after Module 0)

No driving. The arena asks every robot questions about what it senses (distance, position, heading, the depth grid, how many others there are) and the first correct answer takes the point. Game programs are written like lesson programs, with info() for what the game tells you. Play it.

Module 1: Driving

How BugBot moves: by time, by distance, by turning, and sideways. Six lessons.

Lesson What you learn
1.1 Your first move forward, wait, stop, the LED, the safety rule (motion deadman)
1.2 Driving by distance distance=, the optical-flow sensor, position(), blocking calls
1.3 Turning and heading turn(), clockwise is positive, heading(), spin_left/spin_right
1.4 Sideways left/right strafing, drive(fwd, lat, rot), why holonomic matters
1.5 Speed and precision coasting, why distance= lands accurately, fast then slow
1.6 Project: draw a letter plan strokes, drive them, leave a trail

Game 1: Sprint (after Module 1)

Eight lanes, one finish line, and robots that drift. Touch a lane line and you are out. Play it.

Module 2: Sensing

Knowing where you are and what is ahead. Six lessons.

Lesson What you learn
2.1 Where am I? position(), heading(), velocity(), resetting, estimates not truth
2.2 The distance sensor distance(), loops that react, slowing as you get close
2.3 The depth grid tof_grid(): 8 columns as directions, left and right
2.4 Getting round things detect, sidestep, continue
2.5 Drift and correction open loop versus closed loop, the first proportional correction
2.6 Project: the maze walls, corners and a goal, all of the above in one run

Game 2: Maze relay (after Module 2)

Four robots, one maze, one goal. The same three-leg plan as lesson 2.6, with three other robots in the way. Play it.

Module 3: Control

The error, and what to do with it. The robots in this module curve and leak on purpose. Six lessons.

Lesson What you learn
3.1 What a controller is error and its sign, wrapping headings, bang-bang, overshoot
3.2 Proportional control correct in proportion to the error, gain, sign, feedback
3.3 Tuning the gain sluggish, good, oscillating; loop speed and driving speed
3.4 Controlling speed speed from the remaining distance, dead band, clamping
3.5 Two loops at once heading and sideways controllers together
3.6 Project: precision parking round a box, into a bay, facing east

Game 3: Sumo (after Module 3)

Four robots in a ring 90 cm across, and they can shove each other. Aim with math.atan2, control with a P loop, and stay away from the edge. Play it.

Module 4: Vision

The camera as lists of what was found. Six lessons.

Lesson What you learn
4.1 What the camera sees set_cv, the AprilTag list [id, cx, cy, distance], empty lists
4.2 Where is it? pixels to degrees, a controller that turns to face a tag
4.3 Visual servoing rotation from cx, speed from distance, docking
4.4 Colour the blob detector, one colour at a time, box width as distance
4.5 Searching spin until in view; find and approach; list comprehensions
4.6 Project: the marker trail visit three tag cubes in order

Game 4: Capture the marker (after Module 4)

A tag cube that jumps to a new spot each time a robot reaches it. The cube is marker 0: marker_tags() finds it, and robot_tags() is everyone else. Play it.

Module 5: Behaviours

Programs that never stop. Six lessons.

Lesson What you learn
5.1 The loop look, decide, act, wait, repeat; one action per tick; counting ticks
5.2 States a plan as a state variable, transitions, drawing the machine
5.3 Timers two things at once, remembered ticks, timeouts
5.4 Priorities avoid beats seek: behaviours that take over and run to completion
5.5 Brains the behaviour as a function the arena calls, think(me) and me.memory: how the built-in bots are written, with a practice arena in the lesson
5.6 Project: rescue search, approach, return: camera, servoing and states in one machine

Game 5: King of the hill (after Module 5)

Most time on the green square in 45 seconds wins, and robots can shove each other. Play it.

Module 6: Seeing more

The camera, part two. Eight lessons.

Lesson What you learn
6.1 Lines the line detector: cx and angle, the empty list
6.2 Following a line cx to rotation, the angle as a look-ahead
6.3 Losing the line gaps: carry on, then search
6.4 Seeing other robots tags from 100 up say who and how far; LEDs say what
6.5 Following a robot chase a moving tag at a set distance
6.6 Bumps and stalls bumped(), stalls from velocity, back off and go round
6.7 Where will it be two sightings give a velocity; give way to a crossing robot
6.8 Project: the delivery a line to a marker and back through traffic

Game 6: Line race (after Module 6)

Two laps of a taped loop with six checkpoints; off the line you crawl. Play it.

Module 7: Hands and feet

The attachments. Seven lessons.

Lesson What you learn
7.1 Servos angles, speed, what a servo can and cannot do
7.2 The gripper servo(0, 90) closes the jaws, servo(0, 0) opens them, holding(); writing grip() and release()
7.3 Fetching a ball see it, approach it, grip it, bring it home
7.4 The kicker a continuous-rotation servo and a spring: one turn, one strength, aiming by heading
7.5 Ball physics rolling, friction, bouncing, measuring the kick, carrying for short distances
7.6 Passing aim at a team mate's tag, get to kicking range first
7.7 Project: clear the mat every ball into the home zone

Game 7: Netball (after Module 7)

Two against two, no contact, no moving with the ball: turn, then pass or shoot for the goal. Play it.

Module 8: Learning

Teaching the robot instead of programming it. Eight lessons.

Lesson What you learn
8.1 See as numbers a model only sees numbers; the level rows as features
8.2 Collecting data samples with labels, and why bad data makes bad robots
8.3 Nearest neighbour the simplest classifier, and where it goes wrong
8.4 A tiny network weights, loss, gradient descent, trained in the browser
8.5 Learning by reward Q-learning: states, actions, rewards, the table
8.6 Tuning itself the robot finds its own gain by trial
8.7 Models as text saving and loading a model with JSON
8.8 Project: situations a classifier decides what the robot does next

Game 8: The trained race (after Module 8)

A long sprint on robots that drift badly and all differently. Programs that measure their own robot and adapt beat programs with fixed numbers. Play it.

Module 9: Talking to each other

The radio. Seven lessons.

Lesson What you learn
9.1 Sending send(): a broadcast everyone hears; numbers into text
9.2 Listening messages(): what arrived since you last asked, and who sent it
9.3 Protocols agreeing what a message looks like; words and numbers
9.4 Asking a question, a reply, a timeout; going where you are told
9.5 Taking turns one robot at a time through a corridor
9.6 Sharing what you see telling a robot without a camera where the ball is
9.7 Project: the relay drive to the handover, then and only then say go

Game 9: The radio relay (after Module 9)

Teams of two. Leg 1 drives to the handover zone and radios; leg 2 may not move until the message arrives. Play it.

That is the course: ten modules and ten games (plus a competitions-only maze), from a first print to robots that learn and talk to each other.

For the classroom: competitions

Every game can be run as a class competition at bugbot-competitions. The teacher opens a game on the projector and a room code appears on the screen. Students open the same game, type the code, and submit their brain; their robot appears on the projector's mat. The teacher presses Start and every screen in the room plays the same race. A class session keeps a points table across the day's competitions. Students can practise any game on their own against the built-in bots first.

A robot that drives into a wall or another robot can stay wedged for the rest of a game. The built-in bots have a reflex for that in the arena; a student's program handles it itself, and every driving game's starter carries a short unstick() helper (back off and step aside after half a second of going nowhere) that students can read and change.

One competition is not in the lessons at all: the Maze time trial. A random maze nobody has seen, different every race. The robots run it one at a time, each on its own clock; turn, look with the depth sensor, decide. The fastest to the far corner wins.

Nothing to install and no account. Progress is saved in your browser. A room code lets a class race in one shared arena. The same code runs on a real BugBot.

For teachers: lessons are Markdown files in the bugbot-lessons repository, and a task is a small JSON scene with goals, which can include the exact output the program must print. Writing a new one needs no code.