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:
Fri Feb 14 14:17:32 2014 +0000
Revision:
40:2ca410923691
Parent:
29:8b7362a2ee14
now with MPU6050 before taking it too FlyBed2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 0:0c4fafa398b4 1 #include "Servo.h"
maetugr 0:0c4fafa398b4 2 #include "mbed.h"
maetugr 0:0c4fafa398b4 3
maetugr 0:0c4fafa398b4 4 Servo::Servo(PinName Pin) : ServoPin(Pin) {
maetugr 9:4e0c3936c756 5 initialize(); // TODO: Works?
maetugr 1:5a64632b1eb9 6 }
maetugr 1:5a64632b1eb9 7
maetugr 1:5a64632b1eb9 8 void Servo::initialize() {
maetugr 0:0c4fafa398b4 9 // initialize ESC
maetugr 29:8b7362a2ee14 10 Enable(1000,20000); // low throttle 50Hz TODO: Frequency modify
maetugr 0:0c4fafa398b4 11 }
maetugr 0:0c4fafa398b4 12
maetugr 0:0c4fafa398b4 13 void Servo::SetPosition(int Pos) {
maetugr 0:0c4fafa398b4 14 Position = Pos;
maetugr 0:0c4fafa398b4 15 }
maetugr 0:0c4fafa398b4 16
maetugr 0:0c4fafa398b4 17 void Servo::StartPulse() {
maetugr 0:0c4fafa398b4 18 ServoPin = 1;
maetugr 0:0c4fafa398b4 19 PulseStop.attach_us(this, &Servo::EndPulse, Position);
maetugr 0:0c4fafa398b4 20 }
maetugr 0:0c4fafa398b4 21
maetugr 0:0c4fafa398b4 22 void Servo::EndPulse() {
maetugr 9:4e0c3936c756 23 // my change
maetugr 9:4e0c3936c756 24 PulseStop.detach();
maetugr 9:4e0c3936c756 25 // my change
maetugr 0:0c4fafa398b4 26 ServoPin = 0;
maetugr 0:0c4fafa398b4 27 }
maetugr 0:0c4fafa398b4 28
maetugr 0:0c4fafa398b4 29 void Servo::Enable(int StartPos, int Period) {
maetugr 0:0c4fafa398b4 30 Position = StartPos;
maetugr 0:0c4fafa398b4 31 Pulse.attach_us(this, &Servo::StartPulse, Period);
maetugr 0:0c4fafa398b4 32 }
maetugr 0:0c4fafa398b4 33
maetugr 0:0c4fafa398b4 34 void Servo::Disable() {
maetugr 0:0c4fafa398b4 35 Pulse.detach();
maetugr 0:0c4fafa398b4 36 }
maetugr 0:0c4fafa398b4 37
maetugr 0:0c4fafa398b4 38 void Servo::operator=(int position) {
maetugr 0:0c4fafa398b4 39 SetPosition(position);
maetugr 0:0c4fafa398b4 40 }