Sensing · Robot club · about 25 min
Walls, corners and a goal. Everything in this module in one run.
[1 mark]Put the maze legs in order.
Number the lines 1 to 5 to put them in the right order.
Drive along the top until the right-hand wall is closeTurn rightDrive down the middle channel into the goalDrive up the left channel until the top wall is closeTurn right again[1 mark]What does this program print?
def drive_to_wall(gap):
reading = 50
while reading > gap:
reading = reading - 10
print("stopped at", reading)
drive_to_wall(15)[1 mark]In the side-wall check, left_side is 6 cm. What does the program set sideways to, and why?
sideways = 0
if left_side < 8:
sideways = 30
elif right_side < 8:
sideways = -30[1 mark]Why write one leg as drive_to_wall(gap)?
[1 mark]Which ideas from Module 2 does the maze use?
Tick every answer that is true.
[1 mark]What does this program print?
legs = [("up", 15), ("right", 15), ("down", 15)]
for leg in legs:
print(leg[0], "until", leg[1], "cm")[1 mark]How does the left-hand rule get a robot through a maze it has not seen?
Up the left channel, right along the top, down the middle channel into the goal, without touching either wall. Forty-five seconds.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def drive_to_wall(gap):
while distance() > gap:
# drive forward at 60 (keeps going until the next command)
forward(60)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
drive_to_wall(15)
# turn, second leg, turn, third legPlan your program here, then type it in and press Run.
[("up", 15), ("right", 15), ("down", 15)] and a loop that drives them.