Servo Motor
Library
Import Library:
http://mbed.org/projects/cookbook/svn/Servo/trunk
Import Example program:
http://mbed.org/projects/cookbook/svn/Servo/examples/Servo
- For details on how to use this in the compiler, see Importing Projects and Libraries in to the Compiler
Hardware
|
|
Hello World!
|
|
| Schematic | Photo |
#include "mbed.h" #include "Servo.h" Servo myServo (p21); int main() { int i; while (1) { for (i=0 ; i<100 ; i++){ myServo = i/100.0; wait (0.01); } for (i=100 ; i>0 ; i--){ myServo = i/100.0; wait (0.01); } } } |
| Source Code |
API
| Servo | Abstraction on top of PwmOut to control the position of a servo motor |
| Functions | |
| Servo | Create a servo object connected to the specified PwmOut pin |
| write | Set the servo position, normalised to it’s full range |
| read | Read the servo motors current position |
| operator= | Shorthand for the write and read functions |
Abstraction on top of PwmOut to control the position of a servo motor
class Servo : public Base
Create a servo object connected to the specified PwmOut pin
Servo( PinName pin, const char* = NULL )
Set the servo position, normalised to it’s full range
void write( float percent )
Read the servo motors current position
float read()
Shorthand for the write and read functions
Servo& operator= ( float percent )
- Full api at http://mbed.org/projects/cookbook/api/Servo/trunk
- Full source at http://mbed.org/projects/cookbook/svn/Servo/trunk
Theory
A standard R/C servo uses a PWM signal with a 20ms period, and modulates the pulsewidth from 0.5ms to 2.5ms to give the full range of the servo, usually 180 degrees.
The servo requires a higher current than the USB port can safely provide, and so it is essential that you power the servo using an external supply, such as a 4xAA (6v) battery pack.
Resources
Datasheets
PCB Library and Footprint
The Eagle PCB repository can be found at the Eagle page.
The Library for the Servo is
