Lesson 14: Rescue mission
Search and rescue
- A person is lost in a big, dark hall. The robot has to find them and bring them home to the green base.
- The robot cannot see far. Its down eye only sees the floor under it, so it has to drive over every part of the hall.
- A good search pattern misses nothing and does not drive the same lane twice.
Words for this lesson
| Word | Meaning |
|---|---|
| rescue | save someone who is in danger |
| search pattern | a plan for looking everywhere |
| lane | one long strip of the floor |
| position | where the robot is: X (right) and Y (up), in mm |
| base | the home place where a mission starts and ends |
Lane by lane
- Drive up a lane to the wall. Turn right, move 250 mm, turn right again: now you drive down the next lane.
- At the bottom you must turn left twice, or you go back into the old lane.
- A variable remembers the side: swap it after every wall.
| Wall | Turns | Then |
|---|---|---|
| top | right, right | drive down |
| bottom | left, left | drive up |
| top | right, right | drive down |
Where am I?
from vexcode_vr import *
def main():
drivetrain.drive_for(FORWARD, 500, MM)
x = location.position(X, MM)
y = location.position(Y, MM)
brain.print("x = " + str(x) + ", y = " + str(y))
vr_thread(main)
- The robot starts at (0, −800) and drives 500 mm up, so it prints
x = 0.0, y = -300.0. - To go home, the robot works out how far it is from the base: y − (−875) = y + 875 down, and x − (−875) = x + 875 to the left.
drivetrain.turn_to_heading(180, DEGREES)turns until the robot faces down, wherever it faced before.
ความยาก 4/5 · 280 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Someone is lost in a dark hall: the red square. Search the whole hall, lane by lane, like mowing a lawn. Drive 50 mm at a time until a wall is 60 mm away. Then move over to the next lane: turn, drive 250 mm, turn again. Change the turning side at every wall: right, left, right... Stop on red and print Found!.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 4/5 · 280 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Now bring the person home to the green base in the bottom-left corner. When the robot finds red, read its position with location.position(X, MM) และ location.position(Y, MM). The base is at (-875, -875). Face down (heading 180°) and drive y + 875 mm. Then face left (heading 270°) and drive x + 875 mm.
คลิก Run เพื่อดูผลลัพธ์ที่นี่