Lesson 15: Obstacle course
تحتاج هذه الصفحة إلى متصفح حديث (يدعم SharedArrayBuffer). يرجى تحديث Chrome أو Edge أو Firefox أو Safari إلى أحدث إصدار.
English
Boxes in the way
- In the warehouse some boxes fell on the floor. The robot must still reach the green strip at the top.
- The boxes are in different places on every map, so the robot has to notice a box and go round it.
- The distance sensor looks straight ahead. A box close in front means: stop, and plan a detour.
Words for this lesson
| Word | Meaning |
|---|---|
| obstacle | something in your way |
| detour | a way round something, not straight through it |
| space | free room to drive |
| heading | the direction the robot faces: 0° up, 90° right, 180° down, 270° left |
English
A detour in three moves
| Move | Code | Robot faces |
|---|---|---|
| turn to the side | turn_for(RIGHT, 90, DEGREES) |
right (90°) |
| drive past the box | drive_for(FORWARD, 450, MM) |
right (90°) |
| face up again | turn_to_heading(0, DEGREES) |
up (0°) |
- A box here is 400 mm wide. 450 mm to the side is enough to pass it, even with the robot's own width.
English
Which way is the robot facing?
from vexcode_vr import *
def main():
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.print(drivetrain.heading())
brain.new_line()
drivetrain.turn_to_heading(0, DEGREES)
brain.print(drivetrain.heading())
vr_thread(main)
- The first number is 90.0: the robot faces right. After
turn_to_heading(0, DEGREES)it faces up again: 0.0.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Boxes fell off a shelf in the warehouse. Drive up to the green strip at the top (Y is 750 or more). Drive 50 mm at a time. When a box is closer than 80 mm, go round it: turn right, drive 450 mm, and face up again with turn_to_heading(0, DEGREES). On these maps there is always room on the right.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 4/5 · 280 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Now some boxes are near the right wall. Before you go round a box, look: turn right, and if there is less than 500 mm of space, turn left 180° and go round on the left side instead.
اضغط تشغيل لرؤية المخرجات هنا.