Vision · Robot club · about 25 min
Visit three tag cubes in order.
[1 mark]Why are the markers in this project on cubes instead of cards?
[1 mark]What does this program print?
tags = [[2, 100, 120, 40.0], [1, 250, 118, 65.0]] print([t[0] for t in tags])
[1 mark]Put the three lines of the marker trail in order.
Number the lines 1 to 3 to put them in the right order.
`for tag_id in [1, 2, 3]:`` find(tag_id)`` approach(tag_id, 10)`[1 mark]You want to visit the markers in the order 3, 1, 2. What do you change?
[3, 1, 2]find for each markerapproach for each markerset_cv for each marker[1 mark]What does this program print?
steps = []
def find(tag_id):
steps.append("find " + str(tag_id))
def approach(tag_id, stop_at):
steps.append("go " + str(tag_id))
for tag_id in [3, 1, 2]:
find(tag_id)
approach(tag_id, 10)
print(", ".join(steps))[1 mark]A student gets marker 1 working, then copies the whole search and approach code out twice more for markers 2 and 3. What is the main problem?
Visit markers 1, 2 and 3 in order, stopping close to each. Sixty seconds.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def bearing_of(cx):
return (cx - 160) * 120 / 320
def find(tag_id):
# again and again, for ever
while True:
tags = [t for t in apriltags() if t[0] == tag_id]
if tags:
# leave the loop
break
# spin clockwise on the spot at 40
turn_right(40)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
# pause 0.3 s (the robot keeps doing what it was told)
wait(0.3)
def approach(tag_id, stop_at):
# again and again, for ever
while True:
tags = [t for t in apriltags() if t[0] == tag_id]
if not tags:
# spin clockwise on the spot at 30
turn_right(30)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# back to the top of the loop
continue
cx, dist = tags[0][1], tags[0][3]
if dist <= stop_at:
# leave the loop
break
speed = max(20, min(70, (dist - stop_at) * 3))
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(speed, 0, bearing_of(cx) * 3)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
# camera: the tag detector
set_cv("apriltag")
find(1)
approach(1, 10)Plan your program here, then type it in and press Run.
wait calls or the t from the telemetry.find remember which way it turned to find the last tag and search that way first.