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:
Mon Oct 15 17:23:06 2012 +0000
Revision:
7:9d4313510646
Parent:
1:5a64632b1eb9
Child:
9:4e0c3936c756
RC vorgelegt und vor Tickereinbau

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 1:5a64632b1eb9 5 }
maetugr 1:5a64632b1eb9 6
maetugr 1:5a64632b1eb9 7 void Servo::initialize() {
maetugr 0:0c4fafa398b4 8 // initialize ESC
maetugr 0:0c4fafa398b4 9 Enable(2000,20000); // full throttle
maetugr 7:9d4313510646 10 wait(0.01); // for 0.01 secs
maetugr 0:0c4fafa398b4 11 SetPosition(1000); // low throttle
maetugr 0:0c4fafa398b4 12 }
maetugr 0:0c4fafa398b4 13
maetugr 0:0c4fafa398b4 14 void Servo::SetPosition(int Pos) {
maetugr 0:0c4fafa398b4 15 Position = Pos;
maetugr 0:0c4fafa398b4 16 }
maetugr 0:0c4fafa398b4 17
maetugr 0:0c4fafa398b4 18 void Servo::StartPulse() {
maetugr 0:0c4fafa398b4 19 ServoPin = 1;
maetugr 0:0c4fafa398b4 20 PulseStop.attach_us(this, &Servo::EndPulse, Position);
maetugr 0:0c4fafa398b4 21 }
maetugr 0:0c4fafa398b4 22
maetugr 0:0c4fafa398b4 23 void Servo::EndPulse() {
maetugr 0:0c4fafa398b4 24 ServoPin = 0;
maetugr 0:0c4fafa398b4 25 }
maetugr 0:0c4fafa398b4 26
maetugr 0:0c4fafa398b4 27 void Servo::Enable(int StartPos, int Period) {
maetugr 0:0c4fafa398b4 28 Position = StartPos;
maetugr 0:0c4fafa398b4 29 Pulse.attach_us(this, &Servo::StartPulse, Period);
maetugr 0:0c4fafa398b4 30 }
maetugr 0:0c4fafa398b4 31
maetugr 0:0c4fafa398b4 32 void Servo::Disable() {
maetugr 0:0c4fafa398b4 33 Pulse.detach();
maetugr 0:0c4fafa398b4 34 }
maetugr 0:0c4fafa398b4 35
maetugr 0:0c4fafa398b4 36 void Servo::operator=(int position) {
maetugr 0:0c4fafa398b4 37 SetPosition(position);
maetugr 0:0c4fafa398b4 38 }