Behaviours · Robot club · about 15 min
Two things at once, remembered ticks, timeouts.
[1 mark]Why can a program not blink the LED with wait(0.5) while it drives to the zone?
wait(0.5) holds up the whole loop, so the driving stops being updatedwait turns the LED offwait only accepts whole numbers[1 mark]What does this program print?
on = False
changes = 0
for ticks in range(20):
if ticks % 5 == 0:
on = not on
changes += 1
print(changes, on)[1 mark]The loop waits 0.1 s a tick. To toggle the LED every half second, every how many ticks should it toggle?
[1 mark]What does this program print?
started = None
for ticks in range(40):
if started is None and ticks == 20:
started = ticks
print("start", ticks)
elif started is not None and ticks - started >= 10:
print("stop", ticks)
started = None[1 mark]In started_turning = None, what does None mean?
[1 mark]A search spins while ticks < 30 and gives up if nothing is found. Why is this timeout important?
[1 mark]What is the advantage of clock() - started_at >= 1.0 over counting ticks?
Drive into the green zone while the LED blinks green and off every half second, at least eight changes.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# the LED: green
led("green")
# drive forward at 60 for 70 cm, then stop
forward(60, distance=70)
# the LED: off
led("off")Plan your program here, then type it in and press Run.