The worksheetDownload the PDF
Answers

10.2 Racing the bots

Competing · Robot club · about 14 min

BugBotLab

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))
    Answer:
    gap 100 -> speed 90
    gap 30 -> speed 36
    gap 10 -> speed 20

    100 x 1.2 = 120 is capped at 90, 30 x 1.2 = 36 is inside the limits, and 10 x 1.2 = 12 is raised to the floor of 20.

  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?
    Answer:
    Did the robot do what you meant?
    Where did the time go?
    What did the bots do differently?

    Most losses are a program doing exactly what it was told, so watch the replay first.

  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
    Answer: A. Practice is free, on your own screen, as often as you like.
  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
    Answer: A. A robot at 30 the whole way loses to one at 90 that creeps at the end. It is proportional control used as a tactic.
  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
    Answer: A. The task wants you within 10 degrees of the way you started. Finish straight.
  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.

    Answer: 16.7 (accept within 0.1). gap x 1.2 = 20 when gap = 20 / 1.2, which is about 16.7 cm.

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

The hint students can ask for: Drive in fast while it is far, creep at the end, and check heading() before you stop: a quarter of a turn out is a fail.

A solution

from bugbot import *
connect()
forward(70, distance=25)
while position()[1] < 52:
    forward(25)
    wait(0.1)
stop()
print('heading', heading())

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