Behaviours · Robot club · about 15 min
Look, decide, act, wait, repeat. One action per tick. Counting ticks.
[1 mark]What does every behaviour do, again and again?
[1 mark]Which call suits a behaviour loop, because it does not block?
forward(60)forward(60, distance=20)turn_right(30, angle=90)wait(5)[1 mark]A student leaves wait(0.1) out of a while True behaviour loop. What goes wrong?
[1 mark]What does this program print?
for tick in [0, 9, 10, 19, 20, 35]:
print(tick, "green" if tick % 20 < 10 else "off")[1 mark]What does this program print?
def choose(d):
if d < 15:
return "back"
elif d < 30:
return "turn"
else:
return "forward"
for d in [10, 15, 29, 30, 80]:
print(d, choose(d))[1 mark]In one tick a program calls forward(60) and then turn_right(60). What does the robot do?
[1 mark]A behaviour loop waits 0.1 s each tick. How many ticks is five seconds?
Keep moving for the whole twenty seconds, at least 120 cm in total, without touching a box or the edge of the mat.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # drive forward at 60 (keeps going until the next command) forward(60) # pause 5 s (the robot keeps doing what it was told) wait(5) # all motors off stop()
Plan your program here, then type it in and press Run.