The worksheetDownload the PDF
Answers

7.1 Servos

Hands and feet · Robot club · about 15 min

BugBotLab

What this lesson is about

Angles, speed, what a servo can and cannot do.

Questions 7 marks in all

  1. [1 mark]What does the number 90 mean in servo(0, 90)?

    1. AThe angle for servo 0 to go to and hold
    2. BHow fast servo 0 should spin
    3. CHow many seconds servo 0 should run for
    4. DHow many degrees to turn from where it is now
    Answer: A. A servo goes to an angle between 0 and 180 and stays there. You say where to be, not how fast.
  2. [1 mark]Which servo works which attachment on BugBot?

    1. AServo 0 the gripper, servo 1 the kicker
    2. BServo 0 the kicker, servo 1 the gripper
    3. CServo 1 the gripper, servo 2 the kicker
    4. DBoth servos work the gripper together
    Answer: A. Servo 0 opens and closes the jaws; servo 1 winds the kicker.
  3. [1 mark]What does this program print?

    for angle in range(0, 181, 45):
        print("servo 0 at", angle)
    Answer:
    servo 0 at 0
    servo 0 at 45
    servo 0 at 90
    servo 0 at 135
    servo 0 at 180

    The third number in range is the step. Stopping at 181 rather than 180 is what lets 180 itself be included.

  4. [1 mark]A hobby servo turns about 60 degrees in a tenth of a second. About how many seconds does it take to swing from 0 to 180? Give your answer to one decimal place.

    Answer: 0.3 (accept within 0.05). 180 degrees is three lots of 60, and each takes 0.1 s, so about 0.3 s. That is why wait sits between moves.
  5. [1 mark]A program runs servo(0, 180) and on the very next line servo(0, 0), with no wait between. What does servo 0 do?

    1. AIt barely moves, because it is sent back to 0 before it gets anywhere near 180
    2. BIt goes all the way to 180, then back to 0
    3. CPython stops with an error
    4. DIt waits at 180 until you call wait
    Answer: A. servo does not wait for the move to finish. Without a wait, the second command arrives while the first is still starting.
  6. [1 mark]Which of these can a normal (not continuous-rotation) servo NOT do?

    Tick every answer that is true.

    1. ASpin round and round
    2. BTell you what it touched
    3. CPush harder than its small gearbox allows
    4. DHold an angle once it gets there
    5. EGo to 45 degrees
    Answer: A, B, C. 0 to 180 is the whole range, it has no sense of touch, and forcing it strains the gears. Holding an angle is exactly what it is for.
  7. [1 mark]What does this program print?

    for angle in range(180, -1, -60):
        print(angle)
    Answer:
    180
    120
    60
    0

    A negative step counts down. Stopping at -1 means 0 is the last value printed.

The task: servo sweep

Move servo 0 to 0, 45, 90, 135 and 180 in turn, printing servo 0 at <angle> each time. Do not drive.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# servo 0 to 90 degrees
servo(0, 90)
print("servo 0 at", 90)

The hint students can ask for: Move servo 0 to 0, 45, 90, 135 and 180 degrees in turn, printing servo 0 at <angle> each time, with a short wait between. Do not drive.

A solution

from bugbot import *
connect()
for angle in [0, 45, 90, 135, 180]:
    servo(0, angle)
    print('servo 0 at', angle)
    wait(0.5)

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