A simple library for driving RC servos without using the mbed's PWM functions. This allows the mbed to drive as many servos as there are DigitalOut pins, and additionally allows for the PWM functions to be used at a different frequency than the 50Hz used for servos.

Committer:
pclary
Date:
Wed Jan 09 21:08:53 2013 +0000
Revision:
14:0eff26aa0d17
Parent:
13:896410a1b594
Parent:
11:79862bf306c1
Child:
15:55221f9de707
Merged branches

Who changed what in which revision?

UserRevisionLine numberNew contents of line
UCSBRobotics 7:ff85ac12e11b 1 #ifndef SERVO_H
UCSBRobotics 7:ff85ac12e11b 2 #define SERVO_H
UCSBRobotics 7:ff85ac12e11b 3
UCSBRobotics 7:ff85ac12e11b 4 #include "mbed.h"
UCSBRobotics 7:ff85ac12e11b 5
UCSBRobotics 7:ff85ac12e11b 6
UCSBRobotics 7:ff85ac12e11b 7
UCSBRobotics 7:ff85ac12e11b 8 class Servo
UCSBRobotics 7:ff85ac12e11b 9 {
UCSBRobotics 7:ff85ac12e11b 10 public:
pclary 9:6bfea9af4dcb 11 Servo(PinName pin);
pclary 13:896410a1b594 12 bool calibrate(unsigned int plus45, unsigned int minus45, float upperLimit, float lowerLimit);
pclary 9:6bfea9af4dcb 13 void write(float degrees);
pclary 9:6bfea9af4dcb 14 void writeWidth(unsigned int width);
pclary 9:6bfea9af4dcb 15 float read();
pclary 9:6bfea9af4dcb 16 int readWidth();
pclary 9:6bfea9af4dcb 17 void operator=(float degrees);
pclary 9:6bfea9af4dcb 18 operator float();
UCSBRobotics 7:ff85ac12e11b 19 operator int();
UCSBRobotics 7:ff85ac12e11b 20
pclary 11:79862bf306c1 21 unsigned int center;
pclary 11:79862bf306c1 22 float usPerDegree;
pclary 11:79862bf306c1 23 float upperLimit;
pclary 11:79862bf306c1 24 float lowerLimit;
pclary 11:79862bf306c1 25
UCSBRobotics 7:ff85ac12e11b 26 protected:
UCSBRobotics 7:ff85ac12e11b 27 static unsigned int numServos;
UCSBRobotics 7:ff85ac12e11b 28 static Servo *servos[];
UCSBRobotics 7:ff85ac12e11b 29 static const unsigned int period = 20000;
UCSBRobotics 7:ff85ac12e11b 30 static Ticker* refreshTicker;
UCSBRobotics 7:ff85ac12e11b 31 Timeout servoTimeout;
UCSBRobotics 7:ff85ac12e11b 32 unsigned int pulseWidth;
UCSBRobotics 7:ff85ac12e11b 33 DigitalOut signalPin;
UCSBRobotics 7:ff85ac12e11b 34
pclary 11:79862bf306c1 35
pclary 9:6bfea9af4dcb 36
UCSBRobotics 7:ff85ac12e11b 37 static void refresh();
UCSBRobotics 7:ff85ac12e11b 38 void timeout();
UCSBRobotics 7:ff85ac12e11b 39 };
UCSBRobotics 7:ff85ac12e11b 40
UCSBRobotics 2:19f995979c6a 41 #endif // SERVO_H