Lesson 4: Plan a route
Plan a route
- Before you code, plan the path: how far to drive, which way to turn.
- Use the floor squares: each one is 250 mm. Four squares are 1000 mm.
- The robot must not touch the walls or the grey boxes. A red star shows where it crashed.
Words for this lesson
| Word | Meaning |
|---|---|
| route | the way the robot goes, step by step |
| checkpoint | a numbered circle the robot must drive over |
| obstacle | a wall or box in the way |
| crash | the robot hits a wall |
Count the squares
from vexcode_vr import *
def main():
drivetrain.drive_for(FORWARD, 750, MM) # 3 squares up
drivetrain.turn_for(LEFT, 90, DEGREES)
drivetrain.drive_for(FORWARD, 500, MM) # 2 squares left
vr_thread(main)
- A
#starts a comment: a note for people. The robot ignores it.
In the exam
Past paper 0478/21/M/J/23 Q1: (a) match each description to a stage of the program development life cycle. Your route lesson goes through all four:
| Stage | In this lesson |
|---|---|
| analysis: identify the problem and its requirements | reach every checkpoint, touch no wall |
| design: develop an algorithm (structure diagram, flowchart or pseudocode) | plan the route in squares on paper |
| coding: write and implement the instructions | type the drive and turn lines |
| testing: detect and fix the errors | press Check; a red star shows a crash |
(b) Name three parts of a problem after it is decomposed. Mark scheme: inputs, processes, outputs and storage.
Сложность 2/5 · 140 монет + небольшой бонус за первое завершение сегодня
Drive over checkpoints 1, 2 and 3 in order, without touching the grey box. Checkpoint 1 is 1000 mm up, 2 is 1000 mm right of it, 3 is 800 mm below 2.
Нажмите Запустить, чтобы увидеть результат здесь.
Сложность 2/5 · 140 монет + небольшой бонус за первое завершение сегодня
A wall is between the robot and the goal. Go round its right end: turn right, drive 1250 mm, turn left, drive 1200 mm, turn left, drive 1250 mm.
Нажмите Запустить, чтобы увидеть результат здесь.