Seeing more · Robot club · about 15 min
Tags from 100 up say who and how far; LEDs say what.
[1 mark]The camera reads a tag with id 101. What is it?
[1 mark]What does this program print?
seen = [['green', 60, 120, 55.0], ['red', 240, 110, 42.0]]
for colour, cx, cy, dist in seen:
print(colour, dist, round((cx - 160) * 120 / 320, 1))green 55.0 -37.5 red 42.0 30.0
The green one is 100 pixels left, -37.5 degrees. The red one is 80 pixels right, 30 degrees.
[1 mark]What does robots() give?
[colour, cx, cy, distance][1 mark]Which of these are true?
Tick every answer that is true.
robots()[1 mark]A robot's dome is at cx = 272. What is its bearing in degrees?
[1 mark]Your robot runs led("red"). What can the other robots see?
[1 mark]What does this program print?
seen = [['green', 90, 120, 30.0], ['red', 200, 115, 42.0], ['blue', 20, 110, 80.0]]
near = [r[0] for r in seen if r[3] < 50]
print("near:", near)
print("nearest:", seen[0][0])near: ['green', 'red'] nearest: green
robots() comes back nearest first, so the first one is the closest without any sorting of your own.
Print robot at <cm> cm, bearing <degrees> and dome: <colour>, both from robots(). Do not drive.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # every robot in view, nearest first print(robots())
The hint students can ask for: Another robot is ahead to the right with its dome lit. robots() gives you every robot in view as [colour, cx, cy, distance]. Turn cx into a bearing the way lesson 4.2 did, then print both lines. Do not drive.
from bugbot import *
connect()
seen = robots()[0]
bearing = (seen[1] - 160) * 120 / 320
print(f'robot at {seen[3]} cm, bearing {round(bearing, 1)}')
print('dome:', seen[0])
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.