The worksheetDownload the PDF
Answers

7.7 Project: clear the mat

Hands and feet · Robot club · about 30 min

BugBotLab

What this lesson is about

Every ball into the home zone.

Questions 6 marks in all

  1. [1 mark]The first ball is home. On the second trip, what goes wrong with a plain find_ball("red")?

    1. AIt can find the red ball already sitting in the home zone
    2. BThe gripper only works once per run
    3. Cblobs() can only see one ball per run
    4. Dfetch always returns False after the first ball
    Answer: A. A ball at home is still red. balls_out works out where each blob is and ignores the ones already home.
  2. [1 mark]What does this program print?

    def at_home(bx, by):
        return abs(bx) < 15 and by < 16
    
    for bx, by in [(5, 10), (-20, 10), (0, 40)]:
        print(bx, by, "home" if at_home(bx, by) else "still out")
    Answer:
    5 10 home
    -20 10 still out
    0 40 still out

    Home needs x within 15 cm of the start on either side and y under 16. (-20, 10) is too far left and (0, 40) too far up.

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

    import math
    px, py = 0, 0
    heading = 90
    bearing = 0
    dist = 4 * 92 / 23
    h = math.radians(heading + bearing)
    print(round(px + math.sin(h) * dist), round(py + math.cos(h) * dist))
    Answer:
    16 0

    The ball is 16 cm away. Heading 90 faces right (clockwise from up the mat), so the ball is 16 cm along x and 0 along y.

  4. [1 mark]After opening the jaws at home, put the moves in order so the robot never drives through the ball it just dropped.

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

    1. gripper("open")
    2. backward(50, distance=8)
    3. forward(50, distance=20)
    4. right(50, distance=14)
    Answer:
    gripper("open")
    backward(50, distance=8)
    right(50, distance=14)
    forward(50, distance=20)

    Let go, step back, step aside, and only then drive off for the next search.

  5. [1 mark]Why step back and then sideways before driving away?

    1. ASo the robot's body never passes through the spot where it left the ball
    2. BTo reset the gripper servo
    3. CSo the camera can count the balls at home
    4. DBecause go_to only works facing sideways
    Answer: A. Driving straight off can shove the ball back out of the zone.
  6. [1 mark]Three balls must be home within two minutes. On average, how many seconds can each ball take?

    Answer: 40. 120 seconds divided by 3 balls is 40 seconds each.

The task: clear the mat

Bring all three red balls into the home zone within two minutes.

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