Sensing · Robot club · about 20 min
Detect, sidestep, continue: the first obstacle avoidance.
[1 mark]Put the steps for getting round a box in order.
Number the lines 1 to 5 to put them in the right order.
StopSlide right until distance() is over 60 cmDrive forward 35 cm to get pastSlide right 6 cm moreDrive forward until distance() is under 20 cm[1 mark]Why does the program slide another 6 cm after the sensor says the way is clear?
[1 mark]Why does sliding sideways, rather than turning, keep this program simple?
[1 mark]What does this loop do?
while distance() < 60:
right(50)
wait(0.1)
stop()[1 mark]What does this program print?
left_side = 25
right_side = 25
if right_side >= left_side:
print("stepping right")
else:
print("stepping left")[1 mark]What could go wrong if the robot always steps right?
Drive until the box is close, print box ahead, step sideways until the way is clear, go past, and finish in the green zone without touching the box.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# as long as the thing ahead is further than 20 cm
while distance() > 20:
# drive forward at 50 (keeps going until the next command)
forward(50)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()
print("box ahead")Plan your program here, then type it in and press Run.