NRC 2026
🐍 Python · PyBricks · Robot Brain

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.

⏱️ 1 mission 🧩 11 jobs 📦 6 colour blocks 🛠️ 7 reusable chunks
Part 1 · The Body

🤖 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.

🛞
Port A
Left Wheel
left_motor
🛞
Port E
Right Wheel
right_motor
🦾
Port F
Front Arm
front
🦾
Port B
Back Arm
back
👁️
Port C
Colour Eye
floor
💡

hub = 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.

Part 2 · The Plan

🗺️ 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.

1 Collect Set 1 & Deliver blue · white · green
currentPosition currentDirection taking turn move front arm
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 turn back arm
move(40, 120)
turn(60, -90)
back.dc(65)
move(-60, 170)
back.dc(-65)
move(-40, 45)
move turn front arm back arm
move(80, 260)
turn(60, -115)
front.dc(100)   # release
move(-100, 50)
move(-70, 230)
turn(60, 90)
front.dc(100)
2 Collect Set 2 red · black · yellow
move turn back arm
move(-100, 80)
move(-80, 100)
back.dc(50)
move(-55, 150)
turn(60, 25)
move(60, 50)
currentPosition currentDirection taking turn move front arm
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
3 The Big Delivery follow the line
move turn follow colour eye
move(-100, 190)
turn(60, -90)
follow(60, 1650)   # line-follow
turn move back arm front arm
turn(60, 39)
move(-80, 710)
back.dc(70)
move(50, 300)
turn(60, -39)
front.dc(100)
4 Final Tasks cables · mic · instruments
move turn follow
move(-100, 350)
move(100, 110)
turn(60, 90)
follow(60, 300)
move turn
move(100, 120)
turn(60, 15)
move(100, 480)
turn move
turn(60, -92)
move(100, 250)
move turn
move(100, 300)
turn(60, 90)
move(100, 2300)
🏁 stop() — brakes on. Mission complete!
Part 3 · The Memory

🧠 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:

🎯
Group 1 · Smart Steering (PD)
These three numbers keep the robot driving straight and turning cleanly.
kP= 0.6

How hard to steer right now. Bigger number → sharper correction.

kD= 8

Calms down wobble. It reacts to sudden changes so the robot doesn't zig-zag.

last_errorremembers

Stores the mistake from the last moment. PD() compares it with the new mistake to stay smooth.

📍
Group 2 · Where Am I?
These count spots along the line so the robot grabs the right block.
currentPosition

Which coloured spot the robot is lined up with right now — a number from 0 to 6.

taking

How many blocks grabbed this trip. Counts 0 → 1 → 2, then the trip is done.

currentDirection

+1 = count up the line, −1 = count down. Decides which way to drive next.

🌈
Group 3 · The Colour Map
Each colour is given a spot number, so the code can compare positions with simple maths.
0
blue
1
white
2
green
3
red
4
black
5
yellow
Part 4 · The Connections

🔌 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.

👆 Tap currentPosition, then tap PD() — watch the connections glow.
📦 Variables
🛠️ Toolbox
🎯 Mission Jobs
Part 5 · Try It

🎮 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.

currentPosition = 6 currentDirection = -1 target = 0
Ready — robot is parked at spot 6.
🏆

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!