The answersDownload the PDF
Worksheet

1.2 Driving by distance

Driving · Robot club · about 15 min

BugBotLab
NameClassDate

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
  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
  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)
  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"
  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
  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.

  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)

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())

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/1-2-driving-by-distance/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Drive 10 cm five times with a loop, printing position() each time. How much does the error grow?
  2. Drive out 30 cm and back 30 cm. How far from (0, 0) do you end up?
  3. Find the speed at which forward(speed, distance=20) lands closest to 20.