Lesson 10: Final challenges
Final challenges
- Now put it all together: loops, functions, sensors and
if. - First plan the route on paper. Then write it step by step and press Run often.
- In the second challenge the gap in the wall moves. Only a program that looks with its sensor works on every map.
Words for this lesson
| Word | Meaning |
|---|---|
| maze | walls with one way through |
| gap | an open space in a wall |
| break | leave a loop at once |
| while True | a loop that only break can end |
Look, then move
from vexcode_vr import *
def main():
while True:
if front_distance.get_distance(MM) < 300:
break
drivetrain.drive_for(FORWARD, 100, MM)
brain.print("wall ahead")
vr_thread(main)
- The loop drives 100 mm at a time. When a wall is closer than 300 mm,
breakends the loop.
In the exam
- 0478/12/O/N/23 Q7(b): a train door may close only when no passenger is in the doorway; explain how a sensor and a microprocessor check this (6 marks). Mark scheme points include: a proximity or infrared sensor; it sends data to the microprocessor; the microprocessor compares the data with a stored value; if it is safe, a signal goes to an actuator to close the door; if not, the door stays open; the process repeats. Your robot does the same:
front_distanceis the sensor, 300 mm is the stored value, and the loop repeats until it is safe to stop.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Drive through the zigzag to the goal in the top-right corner without touching a wall. The route: 1500 mm right, up 550, 1500 left, up 500, 1500 right, up 500. Use a function for one zig and one zag if you like.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
A wall crosses the playground with one gap, in a different place on each map. Face right and move 100 mm at a time; after each step, turn left and look up. When the distance is more than 1000 mm, the gap is in front: move 150 mm more to its middle, then drive 1300 mm up to the goal.
Cliquez sur Exécuter pour voir le résultat ici.