Successful acro and level mode now! Relying on MPU9250 as base sensor. I'm working continuously on tuning and features :) NEWEST VERSION ON: https://github.com/MaEtUgR/FlyBed (CODE 100% compatible/copyable)
Servo/Servo.cpp@0:37f0c1e8fa66, 2015-09-08 (annotated)
- Committer:
- maetugr
- Date:
- Tue Sep 08 13:38:10 2015 +0000
- Revision:
- 0:37f0c1e8fa66
MPU9250 on the new Board works fine over SPI; RC is broken and works with FlyBed2 :(
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 0:37f0c1e8fa66 | 1 | #include "Servo.h" |
maetugr | 0:37f0c1e8fa66 | 2 | #include "mbed.h" |
maetugr | 0:37f0c1e8fa66 | 3 | |
maetugr | 0:37f0c1e8fa66 | 4 | Servo::Servo(PinName Pin, int frequency) : ServoPin(Pin) { |
maetugr | 0:37f0c1e8fa66 | 5 | Enable(1000,1000000/frequency); // low throttle 50Hz TODO: Frequency modify |
maetugr | 0:37f0c1e8fa66 | 6 | } |
maetugr | 0:37f0c1e8fa66 | 7 | |
maetugr | 0:37f0c1e8fa66 | 8 | void Servo::SetFrequency(int frequency) { |
maetugr | 0:37f0c1e8fa66 | 9 | Pulse.detach(); |
maetugr | 0:37f0c1e8fa66 | 10 | Pulse.attach_us(this, &Servo::StartPulse, 1/frequency); |
maetugr | 0:37f0c1e8fa66 | 11 | } |
maetugr | 0:37f0c1e8fa66 | 12 | |
maetugr | 0:37f0c1e8fa66 | 13 | void Servo::SetPosition(int Pos) { |
maetugr | 0:37f0c1e8fa66 | 14 | if (Pos > 1000) |
maetugr | 0:37f0c1e8fa66 | 15 | Pos = 1000; |
maetugr | 0:37f0c1e8fa66 | 16 | if (Pos < 0) |
maetugr | 0:37f0c1e8fa66 | 17 | Pos = 0; |
maetugr | 0:37f0c1e8fa66 | 18 | Position = Pos+1000; |
maetugr | 0:37f0c1e8fa66 | 19 | } |
maetugr | 0:37f0c1e8fa66 | 20 | |
maetugr | 0:37f0c1e8fa66 | 21 | void Servo::StartPulse() { |
maetugr | 0:37f0c1e8fa66 | 22 | ServoPin = 1; |
maetugr | 0:37f0c1e8fa66 | 23 | PulseStop.attach_us(this, &Servo::EndPulse, Position); |
maetugr | 0:37f0c1e8fa66 | 24 | } |
maetugr | 0:37f0c1e8fa66 | 25 | |
maetugr | 0:37f0c1e8fa66 | 26 | void Servo::EndPulse() { |
maetugr | 0:37f0c1e8fa66 | 27 | // my change |
maetugr | 0:37f0c1e8fa66 | 28 | PulseStop.detach(); |
maetugr | 0:37f0c1e8fa66 | 29 | // my change |
maetugr | 0:37f0c1e8fa66 | 30 | ServoPin = 0; |
maetugr | 0:37f0c1e8fa66 | 31 | } |
maetugr | 0:37f0c1e8fa66 | 32 | |
maetugr | 0:37f0c1e8fa66 | 33 | void Servo::Enable(int StartPos, int Period) { |
maetugr | 0:37f0c1e8fa66 | 34 | Position = StartPos; |
maetugr | 0:37f0c1e8fa66 | 35 | Pulse.attach_us(this, &Servo::StartPulse, Period); |
maetugr | 0:37f0c1e8fa66 | 36 | } |
maetugr | 0:37f0c1e8fa66 | 37 | |
maetugr | 0:37f0c1e8fa66 | 38 | void Servo::Disable() { |
maetugr | 0:37f0c1e8fa66 | 39 | Pulse.detach(); |
maetugr | 0:37f0c1e8fa66 | 40 | } |
maetugr | 0:37f0c1e8fa66 | 41 | |
maetugr | 0:37f0c1e8fa66 | 42 | void Servo::operator=(int position) { |
maetugr | 0:37f0c1e8fa66 | 43 | SetPosition(position); |
maetugr | 0:37f0c1e8fa66 | 44 | } |