Exercise: Servo Sweep

Objective

Control a hobby servomotor module.

Hobby servos are feedback-controlled motors which move an output shaft to a specified position. Internally they use a potentiometer to measure the actual position. The internal circuit compares the actual and commanded position and generates positive and negative motor current pulses to operate a tiny gearmotor. They are a very convenient modular way to create controlled physical motion.

The commanded position is specified using a specific format of PWM in which pulses with duration approximately 1-2 ms repeat at approximately 50 Hz. The different pulse widths correspond to different positions. Note that this a significantly different waveform than the motor PWM, since the duty cycle is always very low, i.e., the pulse on-time is always much shorter than the cycle time.

../../../_images/servo-sweep.png

Steps and observations

  1. Wire up a servo to the Arduino. It is easiest just to use jumper wires directly from the servo connector to the Arduino heades.
  2. Load and run the ServoSweep sketch. This examples uses the Servo library included with the Arduino IDE.
  3. Observe the different demonstrations of servo motion.
  4. Observe the PWM command signal on the oscilloscope.
  5. Try varying the parameters controlling the motion limits and speeds.
  6. Determine the maximum speed possible.

Comments

Note that trajectories and speed control are only possible by issuing position commands at intervals.

As a challenge, rewrite the program to avoid delay() and operate two servos simultanously on different trajectories. This will be taken up in more detail in an upcoming exercise.

Suggested Layout

../../../_images/servo-sweep_img.jpg

Arduino Code

  1. Documentation: ServoSweep Arduino Sketch
  2. Sketch Folder: ServoSweep

Other Files

  1. EAGLE file: servo-sweep.sch

Table Of Contents