Seeing more · Robot club · about 30 min
Follow a line to a marker and back through traffic.
[1 mark]Why does the delivery program keep calling set_cv inside the loop?
set_cv refreshes the picture[1 mark]Put the delivery states in order.
Number the lines 1 to 4 to put them in the right order.
turndonehomeout[1 mark]The give way check comes after the state logic in each tick. Why there?
stop() overrides whatever the state asked forset_cv("line")[1 mark]What does this program print?
def facing_back(h, h0):
return abs((h - h0 - 180 + 180) % 360 - 180) < 20
for h in [0, 90, 170, 185, 200]:
print(h, facing_back(h, 0))[1 mark]What is h0 for?
[1 mark]A student reads the tags with set_cv("apriltag") but forgets to switch back to set_cv("line"). What will follow_step do?
False every tick, because the line detector is offFollow the line to marker 7, print found 7, and follow it home without touching the red robot.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def follow_step(speed=60, gain=0.4):
# [cx, angle] of the line ahead, or [] if none
seen = line()
if not seen:
return False
cx, angle = seen
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(speed, 0, (cx - 160) * gain)
return True
# camera: the line detector
set_cv("line")
# again and again, for ever
while True:
if not follow_step(55, 0.4):
# leave the loop
break
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()Plan your program here, then type it in and press Run.