The answersDownload the PDF
Worksheet

3.4 Controlling speed

Control · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Speed from the remaining distance, the dead band, clamping.

Questions 6 marks in all

  1. [1 mark]The bang-bang park drives at 60 until distance() is 22 or less, then stops. Where does it end?

    1. ACloser than 22 cm, because it coasts
    2. BExactly 22 cm
    3. CFurther than 22 cm
    4. DTouching the wall every time
  2. [1 mark]Target 22, gain 4, and distance() reads 32. What speed does speed = (distance() - target) * 4 ask for?

  3. [1 mark]The plain proportional park stalls a little short of the target. Why?

    1. ANear the target it asks for speeds below about 15, which do not move the robot
    2. BThe gain is too high
    3. CThe sensor cannot see closer than 25 cm
    4. DThe loop runs out of ticks too early
  4. [1 mark]What does this program print?

    for value in [4, 30, 250]:
        print(max(16, min(60, value)))
  5. [1 mark]In the clamped park, the robot overshoots and distance() reads 18. What does it do?

    error = distance() - target
    speed = max(16, min(60, abs(error) * 4))
    if error > 0:
        forward(speed)
    else:
        backward(speed)
    1. ABacks up slowly, at speed 16
    2. BStops, because it is past the target
    3. CDrives forward at speed 16
    4. DBacks up at speed 60
  6. [1 mark]Put the three lines of every P controller in order.

    Number the lines 1 to 3 to put them in the right order.

    1. output = clamp(error * gain)
    2. apply(output)
    3. error = target - measured

The task: park at twenty

Stop with the front of the robot 20 to 24 cm from the wall, the green band, without touching the wall.

# 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 22 cm
while distance() > 22:
    # 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()

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

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

Challenges

  1. Park at 40 cm, then at 10 cm, with the same loop and a different target.
  2. Print the speed every tick and watch it fall as the robot approaches.
  3. Start the robot *closer* than the target (edit the loop to drive there first) and check it backs up.