ppm
Dependents: Autonomous_quadcopter
Fork of PPM by
Diff: PpmRegen.cpp
- Revision:
- 3:2d4d05f95c1a
- Child:
- 4:380e7c35e466
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PpmRegen.cpp Wed Sep 27 17:05:59 2017 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "PpmRegen.h" + +PpmRegen::PpmRegen(PinName InterruptPort, PinName roll, PinName pitch, PinName yaw, PinName throttle, PinName aux1, PinName aux2): +ppmPin(InterruptPort), _roll(roll), _pitch(pitch), _yaw(yaw), _throttle(throttle), _aux1(aux1), _aux2(aux2){ + current_channel = 0; + first_reading = true; + timer.start(); + ppmPin.fall(this, &PpmRegen::fall); +} + + +void PpmRegen::getAllChannels(uint16_t all_channels[]){ + for(int i = 0; i < CHANNELS; i++){ + all_channels[i] = channels[i]; + } + +} + +void PpmRegen::fall(){ + //__disable_irq(); + uint16_t time = timer.read_us(); + + // we are in synchro zone + if(time > 2500) + { + if(first_reading){ + //channel_correction(); + first_reading = false; + } + + current_channel = 0; + + _roll.pulsewidth_us( channels[0]); + _pitch.pulsewidth_us( channels[1]); + _yaw.pulsewidth_us( channels[2]); + _throttle.pulsewidth_us(channels[3]); + _aux1.pulsewidth_us( channels[4]); + _aux2.pulsewidth_us( channels[5]); + } + else + { + channels[current_channel] = timer.read_us(); + current_channel += 1; + } + + timer.reset(); + + //__enable_irq(); +} + +void PpmRegen::channel_correction(){ + corrections[0] = 1500 - channels[0]; + corrections[1] = 1500 - channels[1]; + corrections[2] = 1500 - channels[2]; + corrections[3] = 1010 - channels[3]; + corrections[4] = 1010 - channels[4]; + corrections[5] = 1010 - channels[5]; +} \ No newline at end of file