Lesson 3 · Turning on the Grid
Lesson 3 · Turning on the Grid
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()andturn_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!")
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.
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
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:
Turn-by-turn directions
"Go 3 blocks, turn right, go 2 blocks" is the same drive/turn sequence you just wrote.
Pick routes
A warehouse robot's route is a list of segment-drives and turns between shelf intersections.
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.)