The answersDownload the PDF
Worksheet

2.4 Getting round things

Sensing · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

Detect, sidestep, continue: the first obstacle avoidance.

Questions 6 marks in all

  1. [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.

    1. Stop
    2. Slide right until distance() is over 60 cm
    3. Drive forward 35 cm to get past
    4. Slide right 6 cm more
    5. Drive forward until distance() is under 20 cm
  2. [1 mark]Why does the program slide another 6 cm after the sensor says the way is clear?

    1. AThe body is wider than the sensor's beam
    2. BThe sensor is always 6 cm wrong
    3. CTo make up for coasting forward
    4. DTo turn the robot back to heading 0
  3. [1 mark]Why does sliding sideways, rather than turning, keep this program simple?

    1. AThe robot never turns, so "ahead" still means the same direction
    2. BSliding is faster than turning
    3. CThe sensor does not work after a turn
    4. DTurning would reset position()
  4. [1 mark]What does this loop do?

    while distance() < 60:
        right(50)
        wait(0.1)
    stop()
    1. ASlides right for as long as something is closer than 60 cm ahead
    2. BSlides right exactly 60 cm
    3. CSlides right until something is closer than 60 cm
    4. DDrives forward for 60 cm
  5. [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")
  6. [1 mark]What could go wrong if the robot always steps right?

    1. AThere might be no room on the right
    2. BIt would turn round
    3. CThe distance sensor would stop working
    4. DNothing, stepping right always works

The task: dodge the box

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.

QR code
Do it on the robot
www.bugbotlab.com/learn/2-4-getting-round-things/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. After passing the box, step back to the original line so the robot ends where it would have without the box.
  2. Choose the side with more room using the grid.
  3. Handle two boxes in a row with a loop around the whole behaviour.