The worksheetDownload the PDF
Answers

7.3 Fetching a ball

Hands and feet · Robot club · about 20 min

BugBotLab

What this lesson is about

See it, approach it, grip it, bring it home.

Questions 7 marks in all

  1. [1 mark]Put the stages of a fetch in order.

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

    1. Stop and close the jaws once the ball is in reach
    2. Steer towards the blob, slowing as distance() falls
    3. Open the jaws
    4. Spin until a red blob is in view
    5. Drive home with go_to, holding the ball
    Answer:
    Spin until a red blob is in view
    Steer towards the blob, slowing as distance() falls
    Stop and close the jaws once the ball is in reach
    Drive home with go_to, holding the ball
    Open the jaws

    Find it, go to it, grip it, bring it home, let go. Each stage is something from an earlier lesson.

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

    def bearing_of(cx):
        return (cx - 160) * 120 / 320
    
    print(bearing_of(240))
    print(bearing_of(100))
    Answer:
    30.0
    -22.5

    The picture is 320 pixels across a 120 degree view, centred on 160. 240 is 80 pixels right, 30 degrees; 100 is 60 pixels left, -22.5 degrees.

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

    for d, error in [(30, 4), (30, 25), (8, 2)]:
        speed = 15 if d < 10 else (45 if abs(error) < 10 else 20)
        print(d, error, speed)
    Answer:
    30 4 45
    30 25 20
    8 2 15

    Far and centred gets 45, far but still turning gets 20, and anything under 10 cm gets 15 whatever the error.

  4. [1 mark]Why does fetch slow to 15 for the last few centimetres?

    1. AThe slow finish is what makes the grip reliable
    2. BThe distance sensor only works at low speed
    3. CThe jaws cannot close while the robot is moving
    4. DTo save the battery for the drive home
    Answer: A. Arrive fast and the ball gets nudged away or overshot. Arrive slowly and it is still there when the jaws close.
  5. [1 mark]Inside fetch, the jaws close but holding() is None. What happens next?

    1. AIt creeps forward at 15 and tries again on a later tick
    2. BIt returns False straight away
    3. CIt opens the jaws and spins to search again
    4. DIt returns True anyway
    Answer: A. A missed grip means the ball was just out of reach, so the loop moves a little closer and keeps going.
  6. [1 mark]fetch has used all 250 ticks without holding the ball. What does it do?

    1. AStops the motors and returns False
    2. BReturns True
    3. CStarts the 250 ticks again
    4. DKeeps driving forward at 15
    Answer: A. After the loop, stop() then return False: the caller can tell the fetch failed.
  7. [1 mark]fetch waits 0.1 s each tick for up to 250 ticks. Ignoring the time spent gripping, what is the longest it can take, in whole seconds?

    Answer: 25. 250 x 0.1 = 25 seconds, so a fetch can never hang forever.

The task: fetch the ball

Find the red ball, fetch it, and leave it in the home zone.

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