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.
点击“运行”查看此处输出。