First published 16 Nov 2009, with 4 revisions since.
Last update: 10 Feb 2010.
View history
Last change message: N/A
ethernet,
http,
monitor,
webserver
Simon Ford
Debci Geek
derby,
pinewood
Dan Minear
Marc Bax
Marc Bax
Marc Bax
avc,
robomagellan
Michael Shimniok
mbed,
ServoCam,
servos,
uart samera
Toby Baumgartner
camera,
geeksessionlab,
get,
http,
motor,
pan,
position,
rest,
rpc,
Servo,
tilt,
webinterface
Nelson Neves
RoboArm
Giancarlo R.
Junichi Katsu
00001 /* mbed R/C Servo 00002 * Copyright (c) 2007-2009 sford, cstyles 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 */ 00005 00006 #ifndef MBED_SERVO_H 00007 #define MBED_SERVO_H 00008 00009 #include "mbed.h" 00010 00011 /* Class: Servo 00012 * Abstraction on top of PwmOut to control the position of a servo motor 00013 * 00014 * Example: 00015 * > // Continuously sweep the servo through it's full range 00016 * > #include "mbed.h" 00017 * > #include "Servo.h" 00018 * > 00019 * > Servo myservo(p21); 00020 * > 00021 * > int main() { 00022 * > while(1) { 00023 * > for(int i=0; i<100; i++) { 00024 * > myservo = i/100.0; 00025 * > wait(0.01); 00026 * > } 00027 * > for(int i=100; i>0; i--) { 00028 * > myservo = i/100.0; 00029 * > wait(0.01); 00030 * > } 00031 * > } 00032 * > } 00033 */ 00034 class Servo { 00035 00036 public: 00037 /* Constructor: Servo 00038 * Create a servo object connected to the specified PwmOut pin 00039 * 00040 * Variables: 00041 * pin - PwmOut pin to connect to 00042 */ 00043 Servo(PinName pin); 00044 00045 /* Function: write 00046 * Set the servo position, normalised to it's full range 00047 * 00048 * Variables: 00049 * percent - A normalised number 0.0-1.0 to represent the full range. 00050 */ 00051 void write(float percent); 00052 00053 /* Function: read 00054 * Read the servo motors current position 00055 * 00056 * Variables: 00057 * returns - A normalised number 0.0-1.0 representing the full range. 00058 */ 00059 float read(); 00060 00061 /* Function: position 00062 * Set the servo position 00063 * 00064 * Variables: 00065 * degrees - Servo position in degrees 00066 */ 00067 void position(float degrees); 00068 00069 /* Function: calibrate 00070 * Allows calibration of the range and angles for a particular servo 00071 * 00072 * 00073 * Variables: 00074 * range - Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds 00075 * degrees - Angle from centre to maximum/minimum position in degrees 00076 */ 00077 void calibrate(float range = 0.0005, float degrees = 45.0); 00078 00079 /* Function: operator= 00080 * Shorthand for the write and read functions 00081 */ 00082 Servo& operator= (float percent); 00083 Servo& operator= (Servo& rhs); 00084 operator float(); 00085 00086 protected: 00087 PwmOut _pwm; 00088 float _range; 00089 float _degrees; 00090 float _p; 00091 }; 00092 00093 00094 00095 #endif