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:06:59 2013 +0000
Revision:
13:896410a1b594
Parent:
9:6bfea9af4dcb
Child:
14:0eff26aa0d17
Changed +/-60 degree calibration parameter to +/- 45

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
UCSBRobotics 7:ff85ac12e11b 21 protected:
UCSBRobotics 7:ff85ac12e11b 22 static unsigned int numServos;
UCSBRobotics 7:ff85ac12e11b 23 static Servo *servos[];
UCSBRobotics 7:ff85ac12e11b 24 static const unsigned int period = 20000;
UCSBRobotics 7:ff85ac12e11b 25 static Ticker* refreshTicker;
UCSBRobotics 7:ff85ac12e11b 26 Timeout servoTimeout;
UCSBRobotics 7:ff85ac12e11b 27 unsigned int pulseWidth;
UCSBRobotics 7:ff85ac12e11b 28 DigitalOut signalPin;
UCSBRobotics 7:ff85ac12e11b 29
pclary 9:6bfea9af4dcb 30 unsigned int center;
pclary 9:6bfea9af4dcb 31 float usPerDegree;
pclary 9:6bfea9af4dcb 32 float upperLimit;
pclary 9:6bfea9af4dcb 33 float lowerLimit;
pclary 9:6bfea9af4dcb 34
UCSBRobotics 7:ff85ac12e11b 35 static void refresh();
UCSBRobotics 7:ff85ac12e11b 36 void timeout();
UCSBRobotics 7:ff85ac12e11b 37 };
UCSBRobotics 7:ff85ac12e11b 38
UCSBRobotics 2:19f995979c6a 39 #endif // SERVO_H