How the Robot Thinks
Every robot follows a recipe written in Python. Let's open up
simplified.py and see the whole plan — step by step —
and discover how a handful of variables work together to win the mission.
🤖 Meet the Robot's Body
Before the program can move anything, it tells the hub which device is plugged into which port. Each name below is a variable you'll use all through the code.
left_motorright_motorfrontbackfloorhub = the brain, timer = a stopwatch. The two wheels (left_motor + right_motor) drive the robot, while front and back are arms that grab and release blocks.
🗺️ The Mission Flowchart
The main() function is the boss. It calls each job in order, top to bottom.
Tap any job to peek at its Python code and see which parts it uses.
currentPosition = 6
taking = 0
currentDirection = -1
target = [blue, white, green]
while taking < 2:
move(60, 120)
currentPosition += currentDirection
while currentPosition != target[taking]:
move(60, 120)
currentPosition += currentDirection
front.dc(100) # grab!
taking += 1
move(40, 120)
turn(60, -90)
back.dc(65)
move(-60, 170)
back.dc(-65)
move(-40, 45)
move(80, 260)
turn(60, -115)
front.dc(100) # release
move(-100, 50)
move(-70, 230)
turn(60, 90)
front.dc(100)
move(-100, 80)
move(-80, 100)
back.dc(50)
move(-55, 150)
turn(60, 25)
move(60, 50)
currentPosition = red
taking = 0
target = [black, yellow]
currentDirection = -1
while taking < 2:
move(60, 120)
currentPosition += currentDirection
while currentPosition != target[taking]:
move(60, 120)
currentPosition += currentDirection
front.dc(100)
taking += 1
move(-100, 190)
turn(60, -90)
follow(60, 1650) # line-follow
turn(60, 39)
move(-80, 710)
back.dc(70)
move(50, 300)
turn(60, -39)
front.dc(100)
move(-100, 350)
move(100, 110)
turn(60, 90)
follow(60, 300)
move(100, 120)
turn(60, 15)
move(100, 480)
turn(60, -92)
move(100, 250)
move(100, 300)
turn(60, 90)
move(100, 2300)
stop() — brakes on. Mission complete!🧠 The Robot's Memory (Variables)
A variable is a labelled box that remembers a number. This program keeps just a few — but they do a lot of work. They split into three groups, each with its own job:
How hard to steer right now. Bigger number → sharper correction.
Calms down wobble. It reacts to sudden changes so the robot doesn't zig-zag.
Stores the mistake from the last moment. PD() compares it with the new mistake to stay smooth.
Which coloured spot the robot is lined up with right now — a number from 0 to 6.
How many blocks grabbed this trip. Counts 0 → 1 → 2, then the trip is done.
+1 = count up the line, −1 = count down. Decides which way to drive next.
blue
white
green
red
black
yellow
🔌 How It All Connects
Nothing works alone! Variables feed the toolbox functions, and the mission jobs call those tools. Tap any block to light up everything it touches.
currentPosition, then tap PD() — watch the connections glow.🎮 Trace the Counter
This is the clever part of TakeBlueWhite(). The robot starts at spot
6 and drives down the line (direction −1), checking each spot until
currentPosition matches the target. Pick a target and press Step!
📍 The Spot Counter
Each Step runs one loop: currentPosition += currentDirection,
then checks currentPosition != target.
This is why variables matter: the same six tiny functions can run the whole mission, but it's currentPosition, currentDirection and taking that make the robot smart enough to grab the correct block every time. Master these chunks and you can build your own PyBricks program!
📟 Live state
🎚 Calibration
🐍 Run steps
Pick a reusable chunk, drag the sliders, watch it react — then copy the Python straight into PyBricks.
🎚 Numbers
👀 What it does
🐍 Copy-ready Python
Tap jobs to add them to main(), reorder them, then Run to watch your mission on the mat.