The answersDownload the PDF
Worksheet

10.2 Racing the bots

Competing · Robot club · about 14 min

BugBotLab
NameClassDate

What this lesson is about

Practice, replay and the results board: why you lost, and the fast-then-careful pattern that wins.

Questions 6 marks in all

  1. [1 mark]What does this program print?

    for gap in [100, 30, 10]:
        speed = max(20, min(90, gap * 1.2))
        print("gap", gap, "-> speed", round(speed))
  2. [1 mark]After losing a race, put the three things to look at in order.

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

    1. Where did the time go?
    2. Did the robot do what you meant?
    3. What did the bots do differently?
  3. [1 mark]What are the built-in bots for?

    1. AA measuring stick you can race again and again
    2. BOpponents you only need to beat once
    3. CRobots that copy your program
    4. DHelpers that push you to the finish
  4. [1 mark]Which pattern wins nearly every game with a target?

    1. AFast while the target is far, slow as you arrive, stop before you overshoot
    2. BSlow and steady the whole way
    3. CFull speed until you touch the target
    4. DFast at the end to catch up
  5. [1 mark]Your robot stops inside the bay but facing 14 degrees off. What should you add?

    1. AA correction at the end that turns back to the starting heading
    2. BA faster approach
    3. CA longer wait before stopping
    4. DNothing, being in the bay is enough
  6. [1 mark]With speed = max(20, min(90, gap * 1.2)), below what gap does the speed stop falling and sit at 20? Give your answer to one decimal place.

The task: park square

Drive into the bay and stop inside it, facing the way you started, within 10 degrees. Being in the bay is not enough: finish straight.

from bugbot import *
connect()

forward(60, distance=35)
stop()
print("heading", heading())

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

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

Challenges

  1. Run the same program five times. How much do the finishing positions differ?
  2. Add a correction at the end: if the heading is out by more than 5 degrees, turn back.
  3. Try the speed rule above instead of two fixed speeds, and see which parks closer.