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 againDrive up the left channel until the top wall is close Turn right Drive along the top until the right-hand wall is close Turn right again Drive down the middle channel into the goal
Three legs and two corners. Each leg is a "drive until distance() is small" loop.
[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)stopped at 10
The reading goes 50, 40, 30, 20, 10. The loop only checks between steps, so it stops at the first reading that is not over 15, which is 10.
[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")up until 15 cm right until 15 cm down until 15 cm
Each item in the list is a pair. leg[0] is the first part and leg[1] the second, just like position()[0].
[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 legThe hint students can ask for: Up the left channel, right along the top, down the middle channel into the goal. Use distance() to find each wall and turn_right(30, angle=90) at the corners.
from bugbot import *
connect()
def drive_to_wall(gap):
while distance() > gap:
forward(60)
wait(0.1)
stop()
drive_to_wall(15)
turn_right(30, angle=90)
drive_to_wall(15)
turn_right(30, angle=90)
drive_to_wall(12)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.