Colin Stearns
/
qcControl
QC Control software
Fork of dgps by
flight/flightControl.cpp@66:5d43988d100c, 2014-05-05 (annotated)
- Committer:
- dylanembed123
- Date:
- Mon May 05 13:20:35 2014 +0000
- Revision:
- 66:5d43988d100c
- Parent:
- 9:da906eeac51e
Final Project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dylanembed123 | 9:da906eeac51e | 1 | #include "flightControl.h" |
stearnsc | 8:28b866df62cf | 2 | |
stearnsc | 8:28b866df62cf | 3 | PwmOut throttle(p21); |
stearnsc | 8:28b866df62cf | 4 | PwmOut roll(p22); |
stearnsc | 8:28b866df62cf | 5 | PwmOut pitch(p23); |
stearnsc | 8:28b866df62cf | 6 | //PwmOut yaw(p24); |
stearnsc | 8:28b866df62cf | 7 | PwmOut arm(p25); |
stearnsc | 8:28b866df62cf | 8 | PwmOut baroHold(p26); |
stearnsc | 8:28b866df62cf | 9 | |
dylanembed123 | 9:da906eeac51e | 10 | //TODO see if pwm output gets initialized |
dylanembed123 | 9:da906eeac51e | 11 | void FlightControl::startPwm(){ |
dylanembed123 | 9:da906eeac51e | 12 | throttle.period_ms(20); |
dylanembed123 | 9:da906eeac51e | 13 | roll.period_ms(20); |
dylanembed123 | 9:da906eeac51e | 14 | pitch.period_ms(20); |
dylanembed123 | 9:da906eeac51e | 15 | // yaw.period_ms(20); |
dylanembed123 | 9:da906eeac51e | 16 | arm.period_ms(20); |
dylanembed123 | 9:da906eeac51e | 17 | } |
dylanembed123 | 9:da906eeac51e | 18 | |
dylanembed123 | 9:da906eeac51e | 19 | void FlightControl::stopPwm(){ |
dylanembed123 | 9:da906eeac51e | 20 | throttle.pulsewidth_us(0); |
dylanembed123 | 9:da906eeac51e | 21 | roll.pulsewidth_us(0); |
dylanembed123 | 9:da906eeac51e | 22 | pitch.pulsewidth_us(0); |
stearnsc | 8:28b866df62cf | 23 | // yaw.pulsewidth_us(0); |
dylanembed123 | 9:da906eeac51e | 24 | throttle.pulsewidth_us(0); |
dylanembed123 | 9:da906eeac51e | 25 | } |
dylanembed123 | 9:da906eeac51e | 26 | |
dylanembed123 | 9:da906eeac51e | 27 | //-500 means full back; 500 means full forward |
dylanembed123 | 9:da906eeac51e | 28 | void FlightControl::setPitch(int val){ |
dylanembed123 | 9:da906eeac51e | 29 | if (val > 500) val = 500; |
dylanembed123 | 9:da906eeac51e | 30 | else if (val < -500) val = 0; |
dylanembed123 | 9:da906eeac51e | 31 | pitch.pulsewidth_us(1500 + val); |
dylanembed123 | 9:da906eeac51e | 32 | } |
stearnsc | 8:28b866df62cf | 33 | |
dylanembed123 | 9:da906eeac51e | 34 | //-500 means full left; 500 means full right |
dylanembed123 | 9:da906eeac51e | 35 | void FlightControl::setRoll(int val){ |
dylanembed123 | 9:da906eeac51e | 36 | if (val > 500) val = 500; |
dylanembed123 | 9:da906eeac51e | 37 | else if (val < -500) val = 0; |
dylanembed123 | 9:da906eeac51e | 38 | roll.pulsewidth_us(1500 + val); |
dylanembed123 | 9:da906eeac51e | 39 | } |
dylanembed123 | 9:da906eeac51e | 40 | |
dylanembed123 | 9:da906eeac51e | 41 | //0 means no throttle, 1000 means full throttle |
dylanembed123 | 9:da906eeac51e | 42 | void FlightControl::setThrottle(int val){ |
dylanembed123 | 9:da906eeac51e | 43 | if (val > 1000) val = 1000; |
dylanembed123 | 9:da906eeac51e | 44 | else if (val < 0) val = 0; |
dylanembed123 | 9:da906eeac51e | 45 | throttle.pulsewidth_us(1000 + val); |
dylanembed123 | 9:da906eeac51e | 46 | } |
dylanembed123 | 9:da906eeac51e | 47 | |
dylanembed123 | 9:da906eeac51e | 48 | void FlightControl::setArmState(bool armState){ |
dylanembed123 | 9:da906eeac51e | 49 | if (armState) arm.pulsewidth_us(2000); |
dylanembed123 | 9:da906eeac51e | 50 | else arm.pulsewidth_us(1000); |
dylanembed123 | 9:da906eeac51e | 51 | } |
dylanembed123 | 9:da906eeac51e | 52 | |
dylanembed123 | 9:da906eeac51e | 53 | void FlightControl::setHoldAltitude(bool hold){ |
dylanembed123 | 9:da906eeac51e | 54 | if (hold) baroHold.pulsewidth_us(2000); |
dylanembed123 | 9:da906eeac51e | 55 | else baroHold.pulsewidth_us(1000); |
dylanembed123 | 9:da906eeac51e | 56 | } |