Skip to main content

Lesson 3-3 · Turning on the Grid

Module 3 · Grid Driving

Lesson 3-3 · Turning on the Grid

40–50 minSequencingPaths & planningSlides (PowerPoint)
👩‍🏫

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

You can drive straight along 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_clockwise() and turn_counterclockwise(), and say why the turn pivots on the intersection
  • Navigate an L-shaped path, as a test function written from a description
  • Plan a path on paper before you write the code

This lesson's skeleton​

Paste this into robot.py above RUN, at the end of the GRID DRIVING section. No new function this time — a path is calls to what you have — so it's two tests.

# --- Lesson 3-3: turning on the grid ---
# No new function: a path is drive_intersections(), a turn,
# drive_intersections() again. The turn works because the
# helper leaves the wheels parked on the intersection.

def test_l_shape():
# drive 2 intersections, turn right, drive 2 more, then
# print that the L is complete
pass

def test_my_path():
# the path you planned on paper, one leg per line
pass

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 — three lines for an L, one per leg or corner.

The 3×3 grid with an L-shaped route. The robot starts parked on the bottom-left intersection, the corner nearest you, facing away from you. Leg 1 arrives at two intersections, numbered 1 and 2, up the left-hand column; at 2 it turns right; leg 2 arrives at intersections 3 and 4 along the top row, and it ends parked on 4 facing right. Beside it, the plan as written on paper: leg 1: 2 intersections; corner: turn right; leg 2: 2 intersections.
An L-shape: two intersections, a right turn, two more. The plan beside it is the paper sketch from Step 2.
Knowledge Check

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

Why the turn lands on the new line​

Look at what drive_intersections() leaves behind: the robot parked with its center over the last intersection, sensors just past it. That is exactly the position a turn needs. The robot pivots about its center of rotation (Lesson 2-8), so with that point on the cross it spins on the intersection, and the blind 60° plus the sensor-ended finish from Lesson 2-9 bring the sensors down on the crossing line. After the turn, the next drive_intersections() starts with a line to follow — no extra step in between.

Knowledge Check

After turn_clockwise(), what has to happen before the next drive_intersections()?

Activity · The L, then a path of your own​

An animation, seen from above, on a 4 by 4 taped grid. In step 1 the robot starts on a segment facing away from you, arrives at two intersections, turns right on the second, and arrives at two more along the crossing line, ending parked on the fourth. Then it follows an example plan from a different start: three intersections, a left turn, one intersection. Beside it, the plan for each run, with the leg or corner being driven highlighted.
The L from step 1, then the example plan from step 2: three intersections, a left turn, one more. Your own plan will draw something else.

Step 1 · test_l_shape()​

Write the body from its comment — three calls and a print — set the run line to test_l_shape(), and run it. Start the robot on a line segment with at least two intersections ahead and room to the right. It should drive two segments, pivot on the second intersection, drive two more along the crossing line, and stop parked on the fourth intersection it met. Don't go on until it does.

Step 2 · Plan on paper, then test_my_path()​

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. A plan reads like directions — leg 1: three segments; corner: left; leg 2: one segment — and translates one leg or corner per line, with a comment saying which is which. Write that into test_my_path(), set the run line to it, and run. Did the robot end where your sketch says? If not, the sketch and the code disagree somewhere; find the line.

Knowledge Check

Starting at the bottom-left corner facing away from you, the robot runs: drive_intersections(3), turn_clockwise(), 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.)
  • What has to come before a turn? (An arrival — the robot parked on the intersection.)
  • What comes after a turn? (The next drive — a sensor is already on the new line.)

Resources​