The worksheetDownload the PDF
Answers

6.4 Seeing other robots

Seeing more · Robot club · about 15 min

BugBotLab

What this lesson is about

Tags from 100 up say who and how far; LEDs say what.

Questions 7 marks in all

  1. [1 mark]The camera reads a tag with id 101. What is it?

    1. AA marker on the mat
    2. BAnother robot
    3. CA blob
    4. DA misread, because ids stop at 99
    Answer: A. Every tag is a marker on the mat. A robot wears none, so a tag reading is never another robot.
  2. [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))
    Answer:
    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.

  3. [1 mark]What does robots() give?

    1. AOnly the robots in view, each as [colour, cx, cy, distance]
    2. BEvery robot in the arena, seen or not
    3. CThe ids of the robots, as plain numbers
    4. DThe tags on the robots
    Answer: A. It reads the lit dome on each one, so a robot with its LED off is not in the list.
  4. [1 mark]Which of these are true?

    Tick every answer that is true.

    1. AA robot's dome colour says which robot it is
    2. BIts dome can also say what it is doing
    3. CA robot with its LED off is not in robots()
    4. DDomes are best told apart by shade, like light and dark green
    Answer: A, B, C. A lit dome washes out towards white in a camera, so tell robots apart by colour, not shade. About four colours is the limit.
  5. [1 mark]A robot's dome is at cx = 272. What is its bearing in degrees?

    Answer: 42 (accept within 0.5). 272 minus 160 is 112 pixels, and 112 times 0.375 is 42 degrees to the right.
  6. [1 mark]Your robot runs led("red"). What can the other robots see?

    1. AA red blob, if they look for red with the blob detector
    2. BA tag with a new id
    3. CNothing, the LED is only for people
    4. DA red line
    Answer: A. Light works both ways. A team could agree on what each colour means.
  7. [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])
    Answer:
    near: ['green', 'red']
    nearest: green

    robots() comes back nearest first, so the first one is the closest without any sorting of your own.

The task: spot the robot

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.

A solution

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.