Lesson 23: Disk mover
Pick and place
- In factories and scrapyards, robots move metal parts with an electromagnet: a magnet that you can switch on and off with electricity.
- Magnet on: the metal sticks. Magnet off: it falls.
- The down eye sees the blue disk on the floor, so the robot knows when it is on top of one.
Words for this lesson
| Word | Meaning |
|---|---|
| electromagnet | a magnet that works only while electricity flows |
| disk | a flat round piece of metal |
| BOOST | switch the magnet on: pick up |
| DROP | switch the magnet off: put down |
| break | leave a loop at once |
The magnet commands
| Command | What happens |
|---|---|
energize(BOOST) |
pick up the disk below |
energize(DROP) |
put the disk down here |
- Write them with the magnet's name:
magnet.energize(BOOST). - The robot can carry one disk at a time.
- BOOST only works when the robot is on a disk: check with
down_eye.detect(BLUE)first.
A loop with two ways out
from vexcode_vr import *
def main():
n = 0
while True:
n = n + 1
if n == 4:
break
brain.print(n)
brain.new_line()
brain.print("done")
vr_thread(main)
- The brain prints 1, 2, 3 and then
done:while Trueruns untilbreak.
In the exam
Past paper 0478/11/M/J/25 Q8: a robot moves car parts in a factory.
- (a) It has a mechanical structure. Another characteristic: it has sensors and electrical components (your down eye, the magnet), or it is programmable (your Python program).
- (b) Firmware is the program stored in the robot's ROM that controls its hardware: it starts when the robot is switched on.
- (c) Interrupts while it works: a sensor finds an object in the way, a part is dropped, the emergency stop button is pressed.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The robot has an electromagnet. A blue metal disk lies somewhere in front of the robot (in a different place on each map). Drive forward 25 mm at a time until the down eye sees BLUE, pick the disk up with magnet.energize(BOOST), carry it on until the wall is 150 mm away, and put it down in the goal with magnet.energize(DROP).
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 5/5 · 400 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Now there are 2, 3 or 4 disks in a line, and the robot can carry only one at a time. Repeat: look for a disk on the way up (stop looking when the wall is 300 mm away), carry it to the goal, drive back down to the start wall, and turn round. When the robot reaches 300 mm from the top wall without finding a disk, the job is done: break. Count the disks and print Disks: and the number.
คลิก Run เพื่อดูผลลัพธ์ที่นี่