Maze Runner

SPIKE Prime Robotics Camp — Day 2

 

 

 

 

Name your moves, then string them together

The Camp

  1. First Drive
  2. Maze Runner (today!)
  3. Gyro Precision
  4. Obstacle Avoidance
  5. Line Following + Showcase

Each day upgrades our robot.

Today's Mission

Get your robot through a maze by:

  • Giving moves names (functions)
  • Putting them in a sequence
  • Solving a maze without hitting walls

A solved maze is just a list of moves in order.

Catch-Up

New today? Welcome!

Quick recap so everyone can drive:

  • Open code.pybricks.com, connect to your hub by name
  • robot.straight(200) drives forward
  • robot.turn(90) turns right

Rule of the Week

Bugs are sensor data.

The robot did exactly what the code said.
What did the code actually say?

Maze on Paper

Draw a path through a grid, start to finish.

Write it as a list: "forward, turn right, forward, forward."

That List Is a Sequence

A program runs top to bottom, one step at a time.

Solving a maze = writing the right steps in the right order.

Naming a Move

Last time we typed straight() and turn() over and over.

Let's give those moves names.

Define a Function


def forward_one_cell():
    robot.straight(250)   # one maze cell

def turn_right():
    robot.turn(90)

def turn_left():
    robot.turn(-90)
					

def name(): defines a function.

Call a Function


forward_one_cell()
turn_right()
					

Writing the name with () calls it — the robot runs that move.

Solve the Maze

String your named moves into a readable sequence.

A Readable Path


forward_one_cell()
turn_right()
forward_one_cell()
forward_one_cell()
					

Reads like instructions — that's the whole point.

Bumped a Wall?

  • Find the step where it went wrong
  • Fix that step
  • Run again

The robot did exactly what the sequence said.

Calibrate the Cell

How far is one cell in your maze?

Measure, Then Set

  1. Run forward_one_cell() once
  2. Did it land in the next cell?
  3. Adjust the mm inside the function and try again

The cell size is a guess you measure — not a correct answer.

Energizer + Snack

Get up, move, refuel.

Keep food away from the kits and laptops!

Build It

Tape a maze, then solve someone else's.

The Loop That Matters

  1. Plan the path on paper
  2. Write the named moves in order
  3. Run
  4. Fix the step that bumped a wall

A completed maze is the win.

Demo + Wrap-Up

What We Learned

  • A program is a sequence — top to bottom
  • def name(): defines a function
  • name() calls it
  • Named moves make a long path readable

Coming Up Next

Gyro Precision

Your turns mostly landed —
but tomorrow we'll give the robot an inner compass,
the gyro, so its turns stay accurate.

Questions?

Maze solved!