The worksheetDownload the PDF
Answers

10.6 Project: enter a hard game

Competing · Robot club · about 25 min

BugBotLab

What this lesson is about

Light Cycles, Rescue Line or Capture the Flag: how to practise one properly, and the line and gripper rehearsal.

Questions 6 marks in all

  1. [1 mark]Which game do you play on your own, after Module 7, using the line and the gripper at once?

    1. ARescue Line
    2. BLight Cycles
    3. CCapture the Flag
    4. DShuttle Relay
    Answer: A. Follow the line, pick up the casualties, and carry them to safety without losing the line.
  2. [1 mark]Put the steps for getting good at a game in order.

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

    1. Change one thing at a time
    2. Then play people
    3. Print, race, read
    4. Beat one bot
    5. Read the game page
    Answer:
    Read the game page
    Beat one bot
    Print, race, read
    Change one thing at a time
    Then play people

    Know the rules and what info() gives, beat the bot that beats you most, learn from your log, and only then take it to a room.

  3. [1 mark]You change your top speed and your turning gain together, and the next race is better. What have you learned?

    1. AVery little: you cannot tell which change helped
    2. BBoth changes helped
    3. CThe speed change helped
    4. DYou should always change two things
    Answer: A. Change one thing at a time, so a better result tells you why.
  4. [1 mark]What does this program print?

    for cx in [200, 160, 100]:
        print(cx, round((cx - 160) * 0.35, 1))
    Answer:
    200 14.0
    160 0.0
    100 -21.0

    The turn is how far the line is from the middle of the picture times 0.35. Right of centre gives a positive, clockwise turn; left gives a negative one.

  5. [1 mark]In the carry-home task, when should the jaws close?

    1. AOnce the robot has stopped with the ball in reach
    2. BAt the very start, so they are ready
    3. CAs soon as the line comes into view
    4. DWhen the robot reaches the green zone
    Answer: A. Jaws closed at the start shut on nothing. Arrive, stop, then grip, and keep them closed until the zone.
  6. [1 mark]In the rehearsal, line() sees nothing and the robot runs drive(25, 0, 40). What is it doing?

    1. ACreeping forward while turning clockwise to find the line again
    2. BStopping until the line comes back
    3. CReversing along its path
    4. DSliding sideways
    Answer: A. Slow forward speed with a turn sweeps the camera round, looking for the line.

The task: carry it home

Follow the black line to the red ball, pick it up with the gripper, and carry it into the green zone at the end without dropping it. The line bends to the right, so driving straight up the mat misses the ball by 15 cm: the line is the only way to it.

from bugbot import *
connect()
set_cv('line')

gripper("open")

# follow the line first: steer by where it is and where it is going,
# and slide sideways onto it if you drift
while position()[1] < 40:
    seen = line()
    if seen:
        cx, angle = seen
        drive(35, (cx - 160) * 0.15, (cx - 160) * 0.15 + angle * 1.5)
    else:
        forward(20)
    wait(0.1)

stop()

The hint students can ask for: The line bends to the right, and the ball is at its end, 15 cm to the side of where you start: drive straight and you miss it. Follow the line all the way, steering with where it is going as well as where it is, and slide sideways onto it if you drift. Close the gripper on the ball, then carry it into the green zone without letting go.

A solution

from bugbot import *
connect()
set_cv('line')
gripper('open')
# follow the line, using where it is going as well as where it is, until the ball is in the jaws
while not holding() and position()[1] < 56:
    seen = line()
    if seen:
        cx, angle = seen
        drive(35, (cx - 160) * 0.15, (cx - 160) * 0.15 + angle * 1.5)
    else:
        forward(20)
    wait(0.1)
stop()
gripper('close')
wait(0.6)
# carry it home, holding the heading straight up the mat
while position()[1] < 78:
    err = (0 - heading() + 180) % 360 - 180
    drive(45, 0, max(-30, min(30, err * 1.5)))
    wait(0.1)
stop()
print('holding:', holding())

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