NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Committer:
maetugr
Date:
Wed Sep 26 12:15:00 2012 +0000
Revision:
0:0c4fafa398b4
Child:
1:5a64632b1eb9
Sensor Test; Acc, Gyro working, result on LCD (servo lib included)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 0:0c4fafa398b4 1 // based on http://mbed.org/users/jdenkers/code/Servo/
maetugr 0:0c4fafa398b4 2
maetugr 0:0c4fafa398b4 3 #ifndef __SERVO_H
maetugr 0:0c4fafa398b4 4 #define __SERVO_H
maetugr 0:0c4fafa398b4 5
maetugr 0:0c4fafa398b4 6 #include "mbed.h"
maetugr 0:0c4fafa398b4 7
maetugr 0:0c4fafa398b4 8 /** Class to control a servo on any pin, without using pwm
maetugr 0:0c4fafa398b4 9 *
maetugr 0:0c4fafa398b4 10 * Example:
maetugr 0:0c4fafa398b4 11 * @code
maetugr 0:0c4fafa398b4 12 * // Keep sweeping servo from left to right
maetugr 0:0c4fafa398b4 13 * #include "mbed.h"
maetugr 0:0c4fafa398b4 14 * #include "Servo.h"
maetugr 0:0c4fafa398b4 15 *
maetugr 0:0c4fafa398b4 16 * Servo Servo1(p20);
maetugr 0:0c4fafa398b4 17 *
maetugr 0:0c4fafa398b4 18 * Servo1.Enable(1500,20000);
maetugr 0:0c4fafa398b4 19 *
maetugr 0:0c4fafa398b4 20 * while(1) {
maetugr 0:0c4fafa398b4 21 * for (int pos = 1000; pos < 2000; pos += 25) {
maetugr 0:0c4fafa398b4 22 * Servo1.SetPosition(pos);
maetugr 0:0c4fafa398b4 23 * wait_ms(20);
maetugr 0:0c4fafa398b4 24 * }
maetugr 0:0c4fafa398b4 25 * for (int pos = 2000; pos > 1000; pos -= 25) {
maetugr 0:0c4fafa398b4 26 * Servo1.SetPosition(pos);
maetugr 0:0c4fafa398b4 27 * wait_ms(20);
maetugr 0:0c4fafa398b4 28 * }
maetugr 0:0c4fafa398b4 29 * }
maetugr 0:0c4fafa398b4 30 * @endcode
maetugr 0:0c4fafa398b4 31 */
maetugr 0:0c4fafa398b4 32
maetugr 0:0c4fafa398b4 33 class Servo {
maetugr 0:0c4fafa398b4 34
maetugr 0:0c4fafa398b4 35 public:
maetugr 0:0c4fafa398b4 36 /** Create a new Servo object on any mbed pin
maetugr 0:0c4fafa398b4 37 *
maetugr 0:0c4fafa398b4 38 * @param Pin Pin on mbed to connect servo to
maetugr 0:0c4fafa398b4 39 */
maetugr 0:0c4fafa398b4 40 Servo(PinName Pin);
maetugr 0:0c4fafa398b4 41
maetugr 0:0c4fafa398b4 42 /** Change the position of the servo. Position in us
maetugr 0:0c4fafa398b4 43 *
maetugr 0:0c4fafa398b4 44 * @param NewPos The new value of the servos position (us)
maetugr 0:0c4fafa398b4 45 */
maetugr 0:0c4fafa398b4 46 void SetPosition(int NewPos);
maetugr 0:0c4fafa398b4 47
maetugr 0:0c4fafa398b4 48 /** Enable the servo. Without enabling the servo won't be running. Startposition and period both in us.
maetugr 0:0c4fafa398b4 49 *
maetugr 0:0c4fafa398b4 50 * @param StartPos The position of the servo to start (us)
maetugr 0:0c4fafa398b4 51 * @param Period The time between every pulse. 20000 us = 50 Hz(standard) (us)
maetugr 0:0c4fafa398b4 52 */
maetugr 0:0c4fafa398b4 53 void Enable(int StartPos, int Period);
maetugr 0:0c4fafa398b4 54
maetugr 0:0c4fafa398b4 55 //Disable the servo. After disabling the servo won't get any signal anymore
maetugr 0:0c4fafa398b4 56 void Disable();
maetugr 0:0c4fafa398b4 57
maetugr 0:0c4fafa398b4 58 //operator for confortable positioning
maetugr 0:0c4fafa398b4 59 void operator=(int position);
maetugr 0:0c4fafa398b4 60
maetugr 0:0c4fafa398b4 61 private:
maetugr 0:0c4fafa398b4 62 void StartPulse();
maetugr 0:0c4fafa398b4 63 void EndPulse();
maetugr 0:0c4fafa398b4 64
maetugr 0:0c4fafa398b4 65 int Position;
maetugr 0:0c4fafa398b4 66 DigitalOut ServoPin;
maetugr 0:0c4fafa398b4 67 Ticker Pulse;
maetugr 0:0c4fafa398b4 68 Timeout PulseStop;
maetugr 0:0c4fafa398b4 69 };
maetugr 0:0c4fafa398b4 70
maetugr 0:0c4fafa398b4 71 #endif