Lesson 24: Sorting robot
Sort the metal
- Recycling centres use robots to sort things: each kind goes into its own bin.
- The robot reads the colour with the down eye, decides which bin, and carries the disk there with its magnet.
- Sorting is a decision (
if ... else) inside a loop: look, decide, carry, come back, look again.
Words for this lesson
| Word | Meaning |
|---|---|
| sort | put things into groups |
| bin | a box or place where things are put |
| recycling | using old material again |
| abs | the size of a number without its sign: abs(-5) is 5 |
Which way?
| Down eye sees | Turn to heading | Bin |
|---|---|---|
| RED | 270 (left) | red bin |
| BLUE | 90 (right) | blue bin |
turn_to_headingturns to a compass direction, wherever the robot faces now: 0 is up, 90 right, 180 down, 270 left.
Two colours in one condition
from vexcode_vr import *
def main():
colour = "blue"
if colour == "red" or colour == "blue":
brain.print("a disk!")
else:
brain.print("nothing here")
vr_thread(main)
oris true when one side is true, so the brain printsa disk!.
In the exam
Past paper 0478/11/M/J/23 Q9(a): factory robots make furniture. One characteristic of a robot is that it is programmable; state two others. Think of your sorting robot: it has a mechanical structure (wheels, body, magnet), sensors (the colour sensor, the distance sensor), and electrical components (motors, the magnet).
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
A recycling robot sorts metal disks. The red bin runs along the left wall, the blue bin along the right wall. Drive up until the down eye sees a red or a blue disk. Then face the right bin (red: heading 270, blue: heading 90), pick the disk up, drive until the wall is 100 mm away and put it down. The starter always goes left.
출력을 보려면 '실행'을 클릭하세요.
난이도 5/5 · 400코인 + 오늘 첫 완료 시 작은 보너스 추가
Now there are 3 or 4 disks on the middle line. Sort them all and count them: after each drop, turn round, drive back until the robot is on the middle line again (location.position(X, MM) is near 0), and face up (heading 0). At the end, print the counts like this: Red: 2, Blue: 1.
출력을 보려면 '실행'을 클릭하세요.