Skip to main content

Lesson 3 · Turning on the Grid

Module 3 · Grid Driving

Lesson 3 · Turning on the Grid

40–50 minSequencingPaths & planning
👩‍🏫

Teacher mode is on. Toggle it off (bottom-right) to preview the student view.

You can drive straight down the grid. Now you'll turn corners — sequencing drives and turns to trace an L-shaped path. Any route across a grid is really just a sequence of "drive some segments, turn, drive some more."

Learning Objectives

By the end of this lesson you will be able to:

  • Sequence drive and turn operations into a path
  • Turn at intersections with turn_right() and turn_left()
  • Navigate an L-shaped path
  • Plan a path on paper before you write the code

Drive, turn, drive

Turning a corner on the grid is just like walking city streets: go to the intersection, then turn. In code that's drive_intersections(), then a turn, then drive_intersections() again:

drive_intersections(tracker, 2) # drive forward 2 intersections
tracker.turn_right() # turn right onto the crossing line
drive_intersections(tracker, 2) # drive 2 more, now sideways

print("L-shape complete!")
🖼️
Diagram — grid with an L-shaped path: 2 segments across, a right turn, 2 segments down
Add a src to drop in your image
An L-shape: drive two segments, turn right, drive two more.
Knowledge Check

Which sequence drives an L-shape — two segments, a right turn, then two more segments?

No clearing after a turn

There's a nice detail: after turn_right() or turn_left(), you go straight into the next drive — no clearing needed. That's because the turn methods already drive forward off the intersection as part of turning, so the robot is past the cross when the turn finishes.

Knowledge Check

After tracker.turn_right(), do you need to clear the intersection before the next drive_intersections()?

Activity · Plan on paper first

Before coding a path, sketch it: mark the start, the direction the robot faces, how many segments each leg is, and where the turns go. Then translate the sketch, one leg per line:

drive_intersections(tracker, 3) # leg 1
tracker.turn_left() # corner
drive_intersections(tracker, 1) # leg 2
Knowledge Check

Starting at the top-left facing right, the robot runs: drive_intersections(3), turn_right(), drive_intersections(2). Where does it end up?

Real-world connections

Turn-by-turn sequencing on a grid is exactly how routed navigation works:

Maps

Turn-by-turn directions

"Go 3 blocks, turn right, go 2 blocks" is the same drive/turn sequence you just wrote.

Warehouses

Pick routes

A warehouse robot's route is a list of segment-drives and turns between shelf intersections.

Manufacturing

Toolpaths

CNC and pick-and-place machines follow planned sequences of moves and direction changes.

Wrap-up

  • What's the basic shape of any grid path? (A sequence of drives and turns.)
  • Do you clear after a turn? (No — the turn already cleared the intersection.)
  • Where must the robot be to turn? (At an intersection.)

Resources