The worksheetDownload the PDF
Answers

1.2 Driving by distance

Driving · Robot club · about 15 min

BugBotLab

What this lesson is about

Tell the robot how far, not how long. Where it thinks it is.

Questions 7 marks in all

  1. [1 mark]What changes when you add distance=20 to forward(60)?

    Tick every answer that is true.

    1. AThe robot stops itself when it has gone 20 cm
    2. BYour program waits until the move is done
    3. CThe robot drives for 20 seconds
    4. DThe robot drives at speed 20
    Answer: A, B. With a distance, the robot stops on its own and nothing after the line runs until the move has finished.
  2. [1 mark]How does the robot know how far it has gone?

    1. AAn optical-flow sensor underneath watches the mat slide past, like a computer mouse
    2. BIt counts how many times its wheels turn
    3. CIt times how long it has been driving
    4. DA camera on the front measures the mat
    Answer: A. BugBot has no wheels to count. The sensor underneath works like the one in a mouse and adds up how far the mat has moved.
  3. [1 mark]The robot starts at (0, 0) facing forward, drives forward 30 cm, then backward 10 cm. Roughly what does position() say?

    1. A(0, 20)
    2. B(20, 0)
    3. C(0, 40)
    4. D(40, 0)
    Answer: A. x is to the right and y is forward. 30 forward and 10 back leaves y at about 20, with x still about 0.
  4. [1 mark]When is driving on, not waiting printed?

    print("starting")
    forward(60, distance=25)
    print("arrived")
    forward(60)
    print("driving on, not waiting")
    wait(1)
    stop()
    1. AAs soon as the second drive starts, while the robot is still moving
    2. BAfter the robot has gone 25 cm more
    3. CAfter the one second wait
    4. DBefore "arrived"
    Answer: A. forward(60, distance=25) blocks until the move is done, but forward(60) returns straight away, so the next print happens at once.
  5. [1 mark]forward(100, distance=20) usually lands further from 20 than forward(30, distance=20). Why?

    1. AA faster robot coasts further after the motors stop, and the robot cannot allow for it perfectly
    2. BThe sensor cannot measure at high speed
    3. CSpeed 100 is not allowed with a distance
    4. DThe slow one drives for longer, so it is more tired
    Answer: A. The robot switches off early to allow for the slide, but not perfectly. Faster means more slide, so more to get wrong.
  6. [1 mark]The robot drives forward(60, distance=20) then forward(60, distance=40). Roughly how many centimetres forward of the start does it end? Give a whole number.

    Answer: 60 (accept within 1). Each move counts on from where the last one stopped, so 20 then 40 more is about 60 cm.
  7. [1 mark]There is a line 30 cm ahead that the robot must stop before. Which is the safest plan?

    1. Aforward(40, distance=27)
    2. Bforward(100, distance=30)
    3. Cforward(100) then wait(3) then stop()
    4. Dforward(40, distance=33)
    Answer: A. Leave a margin for coasting, and a lower speed coasts less. Driving by time does not know how far the robot has gone at all.

The task: twenty, then forty

Drive 20 cm, print after 20: followed by position(), then drive 40 cm more and stop inside the green band 60 cm from the start.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# drive forward at 60 for 20 cm, then stop
forward(60, distance=20)
print("after 20:", position())

The hint students can ask for: Drive 20 cm, print after 20: followed by position(), then drive 40 more and stop in the green band (60 cm from the start).

A solution

from bugbot import *
connect()
forward(60, distance=20)
print('after 20:', position())
forward(60, distance=40)

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.