ppm
Dependents: Autonomous_quadcopter
Fork of PPM by
PpmRegen.cpp
- Committer:
- edy05
- Date:
- 2017-09-27
- Revision:
- 3:2d4d05f95c1a
- Child:
- 4:380e7c35e466
File content as of revision 3:2d4d05f95c1a:
#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]; }