Ian Hua / Quadcopter-mbedRTOS
Committer:
pHysiX
Date:
Thu May 08 13:00:50 2014 +0000
Revision:
24:54a8cdf17378
Parent:
22:ef8aa9728013
Child:
25:a7cfe421cb4a
Stable mode works. Already begun to start implementing MODE SWITCHING

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pHysiX 22:ef8aa9728013 1 /* File: Task3.cpp
pHysiX 22:ef8aa9728013 2 * Author: Trung Tin Ian HUA
pHysiX 22:ef8aa9728013 3 * Date: May 2014
pHysiX 22:ef8aa9728013 4 * Purpose: Thread3: RC & BT Command, and Telemetry
pHysiX 22:ef8aa9728013 5 * Settings: 50Hz
pHysiX 24:54a8cdf17378 6 */
pHysiX 2:ab967d7b4346 7
pHysiX 21:b642c18eccd1 8 #define STICK_GAIN 2
pHysiX 24:54a8cdf17378 9 #define STICK_GAIN_YAW 8
pHysiX 21:b642c18eccd1 10
pHysiX 1:43f8ac7ca6d7 11 #include "tasks.h"
pHysiX 1:43f8ac7ca6d7 12 #include "setup.h"
pHysiX 4:01921a136f58 13 #include "PwmIn.h"
pHysiX 1:43f8ac7ca6d7 14
pHysiX 1:43f8ac7ca6d7 15 float ypr_offset[3];
pHysiX 21:b642c18eccd1 16
pHysiX 3:605fbcb54e75 17 bool box_demo = false;
pHysiX 5:4879ef0e6d41 18 bool rc_out = false;
pHysiX 5:4879ef0e6d41 19 bool gyro_out = false;
pHysiX 21:b642c18eccd1 20 bool command_check = false;
pHysiX 21:b642c18eccd1 21 bool adjust_check = false;
pHysiX 3:605fbcb54e75 22
pHysiX 4:01921a136f58 23 PwmIn rxModule[] = {p14, p15, p16, p17, p18};
pHysiX 12:953d25061417 24 AnalogIn voltageSense(p20);
pHysiX 12:953d25061417 25
pHysiX 12:953d25061417 26 float vIn = 0.0;
pHysiX 3:605fbcb54e75 27
pHysiX 3:605fbcb54e75 28 /* [YAW PITCH ROLL THROTTLE AUX] */
pHysiX 3:605fbcb54e75 29 int RCCommand[5] = {0, 0, 0, 0, 0};
pHysiX 22:ef8aa9728013 30 /* Decoded input: [YAW PITCH ROLL] */
pHysiX 21:b642c18eccd1 31 int inputYPR[3];
pHysiX 1:43f8ac7ca6d7 32
pHysiX 24:54a8cdf17378 33 //typedef enum {
pHysiX 24:54a8cdf17378 34 enum FLIGHT_MODE {
pHysiX 24:54a8cdf17378 35 RATE,
pHysiX 24:54a8cdf17378 36 STABLE
pHysiX 24:54a8cdf17378 37 };
pHysiX 24:54a8cdf17378 38
pHysiX 24:54a8cdf17378 39 FLIGHT_MODE mode;
pHysiX 24:54a8cdf17378 40
pHysiX 1:43f8ac7ca6d7 41 void Task3(void const *argument)
pHysiX 1:43f8ac7ca6d7 42 {
pHysiX 1:43f8ac7ca6d7 43 if (BT.readable()) {
pHysiX 1:43f8ac7ca6d7 44 char data = BT.getc();
pHysiX 20:b193a50a2ba3 45
pHysiX 21:b642c18eccd1 46 switch (data) {
pHysiX 21:b642c18eccd1 47 case '9':
pHysiX 21:b642c18eccd1 48 case '0':
pHysiX 21:b642c18eccd1 49 armed = false;
pHysiX 21:b642c18eccd1 50 box_demo = false;
pHysiX 21:b642c18eccd1 51 rc_out = false;
pHysiX 21:b642c18eccd1 52 gyro_out = false;
pHysiX 21:b642c18eccd1 53 ESC_check = false;
pHysiX 21:b642c18eccd1 54 command_check = false;
pHysiX 21:b642c18eccd1 55 calibration_mode = false;
pHysiX 21:b642c18eccd1 56 adjust_check = false;
pHysiX 21:b642c18eccd1 57
pHysiX 21:b642c18eccd1 58 pitchPIDstable.reset();
pHysiX 21:b642c18eccd1 59 rollPIDstable.reset();
pHysiX 21:b642c18eccd1 60 yawPIDrate.reset();
pHysiX 21:b642c18eccd1 61 pitchPIDrate.reset();
pHysiX 21:b642c18eccd1 62 rollPIDrate.reset();
pHysiX 21:b642c18eccd1 63
pHysiX 21:b642c18eccd1 64 armed? BT.printf("ARMED\n") : BT.printf("DISARMED\n");
pHysiX 21:b642c18eccd1 65 break;
pHysiX 21:b642c18eccd1 66
pHysiX 21:b642c18eccd1 67 case 'D':
pHysiX 21:b642c18eccd1 68 case 'd':
pHysiX 21:b642c18eccd1 69 armed = false;
pHysiX 21:b642c18eccd1 70 box_demo = false;
pHysiX 21:b642c18eccd1 71 rc_out = false;
pHysiX 21:b642c18eccd1 72 gyro_out = false;
pHysiX 21:b642c18eccd1 73 ESC_check = false;
pHysiX 21:b642c18eccd1 74 command_check = false;
pHysiX 21:b642c18eccd1 75 calibration_mode = false;
pHysiX 21:b642c18eccd1 76 adjust_check = false;
pHysiX 21:b642c18eccd1 77
pHysiX 21:b642c18eccd1 78 ypr_offset[0] = ypr[0];
pHysiX 21:b642c18eccd1 79 ypr_offset[1] = ypr[1];
pHysiX 21:b642c18eccd1 80 ypr_offset[2] = ypr[2];
pHysiX 21:b642c18eccd1 81
pHysiX 21:b642c18eccd1 82 pitchPIDstable.reset();
pHysiX 21:b642c18eccd1 83 rollPIDstable.reset();
pHysiX 21:b642c18eccd1 84 yawPIDrate.reset();
pHysiX 21:b642c18eccd1 85 pitchPIDrate.reset();
pHysiX 21:b642c18eccd1 86 rollPIDrate.reset();
pHysiX 21:b642c18eccd1 87
pHysiX 21:b642c18eccd1 88 armed? BT.printf("DISARM FAIL\n") : BT.printf("DISARMED\n");
pHysiX 21:b642c18eccd1 89 break;
pHysiX 21:b642c18eccd1 90
pHysiX 21:b642c18eccd1 91 case 'B':
pHysiX 21:b642c18eccd1 92 box_demo = true;
pHysiX 21:b642c18eccd1 93 rc_out = false;
pHysiX 21:b642c18eccd1 94 gyro_out = false;
pHysiX 21:b642c18eccd1 95 ESC_check = false;
pHysiX 21:b642c18eccd1 96 command_check = false;
pHysiX 21:b642c18eccd1 97 calibration_mode = false;
pHysiX 21:b642c18eccd1 98 adjust_check = false;
pHysiX 21:b642c18eccd1 99 break;
pHysiX 21:b642c18eccd1 100
pHysiX 21:b642c18eccd1 101 case 'Z':
pHysiX 21:b642c18eccd1 102 ypr_offset[0] = ypr[0];
pHysiX 21:b642c18eccd1 103 ypr_offset[1] = ypr[1];
pHysiX 21:b642c18eccd1 104 ypr_offset[2] = ypr[2];
pHysiX 21:b642c18eccd1 105 break;
pHysiX 21:b642c18eccd1 106
pHysiX 21:b642c18eccd1 107 case 'R':
pHysiX 21:b642c18eccd1 108 box_demo = false;
pHysiX 21:b642c18eccd1 109 rc_out = false;
pHysiX 21:b642c18eccd1 110 gyro_out = false;
pHysiX 21:b642c18eccd1 111 ESC_check = false;
pHysiX 21:b642c18eccd1 112 command_check = true;
pHysiX 21:b642c18eccd1 113 calibration_mode = false;
pHysiX 21:b642c18eccd1 114 adjust_check = false;
pHysiX 21:b642c18eccd1 115 break;
pHysiX 21:b642c18eccd1 116
pHysiX 21:b642c18eccd1 117 case 'r':
pHysiX 21:b642c18eccd1 118 box_demo = false;
pHysiX 21:b642c18eccd1 119 rc_out = true;
pHysiX 21:b642c18eccd1 120 gyro_out = false;
pHysiX 21:b642c18eccd1 121 ESC_check = false;
pHysiX 21:b642c18eccd1 122 command_check = false;
pHysiX 21:b642c18eccd1 123 calibration_mode = false;
pHysiX 21:b642c18eccd1 124 adjust_check = false;
pHysiX 21:b642c18eccd1 125 break;
pHysiX 21:b642c18eccd1 126
pHysiX 21:b642c18eccd1 127 case 'G':
pHysiX 21:b642c18eccd1 128 case 'g':
pHysiX 21:b642c18eccd1 129 box_demo = false;
pHysiX 21:b642c18eccd1 130 rc_out = false;
pHysiX 21:b642c18eccd1 131 gyro_out = true;
pHysiX 21:b642c18eccd1 132 ESC_check = false;
pHysiX 21:b642c18eccd1 133 command_check = false;
pHysiX 21:b642c18eccd1 134 calibration_mode = false;
pHysiX 21:b642c18eccd1 135 adjust_check = false;
pHysiX 21:b642c18eccd1 136 break;
pHysiX 21:b642c18eccd1 137
pHysiX 21:b642c18eccd1 138 case '1':
pHysiX 21:b642c18eccd1 139 box_demo = false;
pHysiX 21:b642c18eccd1 140 rc_out = false;
pHysiX 21:b642c18eccd1 141 gyro_out = false;
pHysiX 21:b642c18eccd1 142 ESC_check = false;
pHysiX 21:b642c18eccd1 143 KP_YAW_RATE += 0.1;
pHysiX 21:b642c18eccd1 144 yawPIDrate.setTunings(KP_YAW_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 145 BT.printf("KP Y rate: %2.5f\n", KP_YAW_RATE);
pHysiX 21:b642c18eccd1 146 break;
pHysiX 21:b642c18eccd1 147 case 'Q':
pHysiX 21:b642c18eccd1 148 case 'q':
pHysiX 21:b642c18eccd1 149 box_demo = false;
pHysiX 21:b642c18eccd1 150 rc_out = false;
pHysiX 21:b642c18eccd1 151 gyro_out = false;
pHysiX 21:b642c18eccd1 152 ESC_check = false;
pHysiX 21:b642c18eccd1 153 KP_YAW_RATE -= 0.1;
pHysiX 21:b642c18eccd1 154 yawPIDrate.setTunings(KP_YAW_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 155 BT.printf("KP Y rate: %2.5f\n", KP_YAW_RATE);
pHysiX 21:b642c18eccd1 156 break;
pHysiX 20:b193a50a2ba3 157
pHysiX 21:b642c18eccd1 158 case '2':
pHysiX 21:b642c18eccd1 159 box_demo = false;
pHysiX 21:b642c18eccd1 160 rc_out = false;
pHysiX 21:b642c18eccd1 161 gyro_out = false;
pHysiX 21:b642c18eccd1 162 ESC_check = false;
pHysiX 21:b642c18eccd1 163 KP_PITCH_RATE += 0.1;
pHysiX 21:b642c18eccd1 164 pitchPIDrate.setTunings(KP_PITCH_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 165 BT.printf("KP P rate: %2.5f\n", KP_PITCH_RATE);
pHysiX 21:b642c18eccd1 166 break;
pHysiX 21:b642c18eccd1 167 case 'W':
pHysiX 21:b642c18eccd1 168 case 'w':
pHysiX 21:b642c18eccd1 169 box_demo = false;
pHysiX 21:b642c18eccd1 170 rc_out = false;
pHysiX 21:b642c18eccd1 171 gyro_out = false;
pHysiX 21:b642c18eccd1 172 ESC_check = false;
pHysiX 21:b642c18eccd1 173 KP_PITCH_RATE -= 0.1;
pHysiX 21:b642c18eccd1 174 pitchPIDrate.setTunings(KP_PITCH_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 175 BT.printf("KP P rate: %3.4f\n", KP_PITCH_RATE);
pHysiX 21:b642c18eccd1 176 break;
pHysiX 21:b642c18eccd1 177
pHysiX 21:b642c18eccd1 178 case '3':
pHysiX 21:b642c18eccd1 179 box_demo = false;
pHysiX 21:b642c18eccd1 180 rc_out = false;
pHysiX 21:b642c18eccd1 181 gyro_out = false;
pHysiX 21:b642c18eccd1 182 ESC_check = false;
pHysiX 21:b642c18eccd1 183 KP_ROLL_RATE += 0.1;
pHysiX 21:b642c18eccd1 184 rollPIDrate.setTunings(KP_ROLL_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 185 BT.printf("KP R rate: %3.4f\n", KP_ROLL_RATE);
pHysiX 21:b642c18eccd1 186 break;
pHysiX 21:b642c18eccd1 187 case 'E':
pHysiX 21:b642c18eccd1 188 case 'e':
pHysiX 21:b642c18eccd1 189 box_demo = false;
pHysiX 21:b642c18eccd1 190 rc_out = false;
pHysiX 21:b642c18eccd1 191 gyro_out = false;
pHysiX 21:b642c18eccd1 192 ESC_check = false;
pHysiX 21:b642c18eccd1 193 KP_ROLL_RATE -= 0.1;
pHysiX 21:b642c18eccd1 194 rollPIDrate.setTunings(KP_ROLL_RATE, PID_TI_RATE, 0.0);
pHysiX 21:b642c18eccd1 195 BT.printf("KP R rate: %2.5f\n", KP_ROLL_RATE);
pHysiX 21:b642c18eccd1 196 break;
pHysiX 24:54a8cdf17378 197
pHysiX 24:54a8cdf17378 198 case '6':
pHysiX 24:54a8cdf17378 199 box_demo = false;
pHysiX 24:54a8cdf17378 200 rc_out = false;
pHysiX 24:54a8cdf17378 201 gyro_out = false;
pHysiX 24:54a8cdf17378 202 ESC_check = false;
pHysiX 24:54a8cdf17378 203 KP_PITCH_STABLE += 0.1;
pHysiX 24:54a8cdf17378 204 pitchPIDstable.setTunings(KP_PITCH_STABLE, PID_TI_STABLE, 0.0);
pHysiX 24:54a8cdf17378 205 BT.printf("KP P stable: %2.5f\n", KP_PITCH_STABLE);
pHysiX 24:54a8cdf17378 206 break;
pHysiX 24:54a8cdf17378 207 case 'Y':
pHysiX 24:54a8cdf17378 208 case 'y':
pHysiX 24:54a8cdf17378 209 box_demo = false;
pHysiX 24:54a8cdf17378 210 rc_out = false;
pHysiX 24:54a8cdf17378 211 gyro_out = false;
pHysiX 24:54a8cdf17378 212 ESC_check = false;
pHysiX 24:54a8cdf17378 213 KP_PITCH_STABLE -= 0.1;
pHysiX 24:54a8cdf17378 214 pitchPIDstable.setTunings(KP_PITCH_STABLE, PID_TI_STABLE, 0.0);
pHysiX 24:54a8cdf17378 215 BT.printf("KP P stable: %2.5f\n", KP_PITCH_STABLE);
pHysiX 24:54a8cdf17378 216 break;
pHysiX 24:54a8cdf17378 217
pHysiX 24:54a8cdf17378 218 case '7':
pHysiX 24:54a8cdf17378 219 box_demo = false;
pHysiX 24:54a8cdf17378 220 rc_out = false;
pHysiX 24:54a8cdf17378 221 gyro_out = false;
pHysiX 24:54a8cdf17378 222 ESC_check = false;
pHysiX 24:54a8cdf17378 223 KP_ROLL_STABLE += 0.1;
pHysiX 24:54a8cdf17378 224 rollPIDstable.setTunings(KP_ROLL_STABLE, PID_TI_STABLE, 0.0);
pHysiX 24:54a8cdf17378 225 BT.printf("KP R stable: %2.5f\n", KP_ROLL_STABLE);
pHysiX 24:54a8cdf17378 226 break;
pHysiX 24:54a8cdf17378 227 case 'U':
pHysiX 24:54a8cdf17378 228 case 'u':
pHysiX 24:54a8cdf17378 229 box_demo = false;
pHysiX 24:54a8cdf17378 230 rc_out = false;
pHysiX 24:54a8cdf17378 231 gyro_out = false;
pHysiX 24:54a8cdf17378 232 ESC_check = false;
pHysiX 24:54a8cdf17378 233 KP_ROLL_STABLE -= 0.1;
pHysiX 24:54a8cdf17378 234 rollPIDstable.setTunings(KP_ROLL_STABLE, PID_TI_STABLE, 0.0);
pHysiX 24:54a8cdf17378 235 BT.printf("KP R stable: %2.5f\n", KP_ROLL_STABLE);
pHysiX 24:54a8cdf17378 236 break;
pHysiX 24:54a8cdf17378 237
pHysiX 21:b642c18eccd1 238 case 'A':
pHysiX 21:b642c18eccd1 239 if (!armed) {
pHysiX 21:b642c18eccd1 240 pitchPIDstable.reset();
pHysiX 21:b642c18eccd1 241 rollPIDstable.reset();
pHysiX 21:b642c18eccd1 242 yawPIDrate.reset();
pHysiX 21:b642c18eccd1 243 pitchPIDrate.reset();
pHysiX 21:b642c18eccd1 244 rollPIDrate.reset();
pHysiX 21:b642c18eccd1 245
pHysiX 21:b642c18eccd1 246 ypr_offset[0] = ypr[0];
pHysiX 21:b642c18eccd1 247 ypr_offset[1] = ypr[1];
pHysiX 21:b642c18eccd1 248 ypr_offset[2] = ypr[2];
pHysiX 21:b642c18eccd1 249
pHysiX 21:b642c18eccd1 250 armed = true;
pHysiX 21:b642c18eccd1 251 } else {
pHysiX 21:b642c18eccd1 252 BT.printf("ALREADY ARMED!!!\n");
pHysiX 21:b642c18eccd1 253 }
pHysiX 21:b642c18eccd1 254 box_demo = false;
pHysiX 21:b642c18eccd1 255 rc_out = false;
pHysiX 21:b642c18eccd1 256 gyro_out = false;
pHysiX 21:b642c18eccd1 257 ESC_check = false;
pHysiX 21:b642c18eccd1 258 command_check = false;
pHysiX 21:b642c18eccd1 259 calibration_mode = false;
pHysiX 21:b642c18eccd1 260 adjust_check = false;
pHysiX 21:b642c18eccd1 261 armed? BT.printf("ARMED\n"): BT.printf("ARM FAIL\n");
pHysiX 21:b642c18eccd1 262 break;
pHysiX 21:b642c18eccd1 263 case 'a':
pHysiX 21:b642c18eccd1 264 if (armed) {
pHysiX 21:b642c18eccd1 265 armed = false;
pHysiX 21:b642c18eccd1 266 BT.printf("DISARMED\n");
pHysiX 21:b642c18eccd1 267 ypr_offset[0] = ypr[0];
pHysiX 21:b642c18eccd1 268 ypr_offset[1] = ypr[1];
pHysiX 21:b642c18eccd1 269 ypr_offset[2] = ypr[2];
pHysiX 21:b642c18eccd1 270 pitchPIDstable.reset();
pHysiX 21:b642c18eccd1 271 rollPIDstable.reset();
pHysiX 21:b642c18eccd1 272 } else {
pHysiX 21:b642c18eccd1 273 BT.printf("ALREADY DISARMED!!!\n");
pHysiX 21:b642c18eccd1 274 }
pHysiX 21:b642c18eccd1 275 box_demo = false;
pHysiX 21:b642c18eccd1 276 rc_out = false;
pHysiX 21:b642c18eccd1 277 gyro_out = false;
pHysiX 21:b642c18eccd1 278 ESC_check = false;
pHysiX 21:b642c18eccd1 279 command_check = false;
pHysiX 21:b642c18eccd1 280 calibration_mode = false;
pHysiX 21:b642c18eccd1 281 adjust_check = false;
pHysiX 21:b642c18eccd1 282
pHysiX 21:b642c18eccd1 283 yawPIDrate.reset();
pHysiX 21:b642c18eccd1 284 pitchPIDrate.reset();
pHysiX 21:b642c18eccd1 285 rollPIDrate.reset();
pHysiX 21:b642c18eccd1 286
pHysiX 21:b642c18eccd1 287 armed? BT.printf("DISARM FAIL\n") : BT.printf("DISARMED\n");
pHysiX 21:b642c18eccd1 288 break;
pHysiX 21:b642c18eccd1 289
pHysiX 21:b642c18eccd1 290 case 'P':
pHysiX 21:b642c18eccd1 291 box_demo = false;
pHysiX 21:b642c18eccd1 292 rc_out = false;
pHysiX 21:b642c18eccd1 293 gyro_out = false;
pHysiX 21:b642c18eccd1 294 ESC_check = false;
pHysiX 21:b642c18eccd1 295 command_check = false;
pHysiX 21:b642c18eccd1 296 calibration_mode = false;
pHysiX 21:b642c18eccd1 297 adjust_check = true;
pHysiX 21:b642c18eccd1 298 break;
pHysiX 21:b642c18eccd1 299
pHysiX 21:b642c18eccd1 300 case 'p':
pHysiX 21:b642c18eccd1 301 box_demo = false;
pHysiX 21:b642c18eccd1 302 rc_out = false;
pHysiX 21:b642c18eccd1 303 gyro_out = false;
pHysiX 21:b642c18eccd1 304 ESC_check = true;
pHysiX 21:b642c18eccd1 305 command_check = false;
pHysiX 21:b642c18eccd1 306 calibration_mode = false;
pHysiX 21:b642c18eccd1 307 adjust_check = false;
pHysiX 21:b642c18eccd1 308 break;
pHysiX 21:b642c18eccd1 309
pHysiX 21:b642c18eccd1 310 case 'C':
pHysiX 21:b642c18eccd1 311 case 'c':
pHysiX 21:b642c18eccd1 312 box_demo = false;
pHysiX 21:b642c18eccd1 313 rc_out = true;
pHysiX 21:b642c18eccd1 314 gyro_out = false;
pHysiX 21:b642c18eccd1 315 ESC_check = false;
pHysiX 21:b642c18eccd1 316 calibration_mode = true;
pHysiX 21:b642c18eccd1 317 command_check = false;
pHysiX 21:b642c18eccd1 318 adjust_check = false;
pHysiX 21:b642c18eccd1 319
pHysiX 21:b642c18eccd1 320 BT.printf("Calibration mode...\n");
pHysiX 21:b642c18eccd1 321 armed? BT.printf("ARMED\n") : BT.printf("ARM FAILED\n");
pHysiX 21:b642c18eccd1 322 break;
pHysiX 21:b642c18eccd1 323
pHysiX 21:b642c18eccd1 324 default:
pHysiX 21:b642c18eccd1 325 break;
pHysiX 1:43f8ac7ca6d7 326 }
pHysiX 1:43f8ac7ca6d7 327 }
pHysiX 12:953d25061417 328
pHysiX 5:4879ef0e6d41 329 RCCommand[2] = rxModule[0].pulsewidth(); // Roll
pHysiX 21:b642c18eccd1 330 RCCommand[1] = rxModule[1].pulsewidth(); // Pitch
pHysiX 21:b642c18eccd1 331 RCCommand[3] = rxModule[2].pulsewidth(); // Throttle
pHysiX 5:4879ef0e6d41 332 RCCommand[0] = rxModule[3].pulsewidth(); // Yaw
pHysiX 5:4879ef0e6d41 333 RCCommand[4] = rxModule[4].pulsewidth(); // AUX
pHysiX 3:605fbcb54e75 334
pHysiX 24:54a8cdf17378 335 if (RCCommand[4] > 1500)
pHysiX 24:54a8cdf17378 336 mode = RATE;
pHysiX 24:54a8cdf17378 337
pHysiX 21:b642c18eccd1 338 inputYPR[0] = (RCCommand[0]-1500)*9/100*STICK_GAIN_YAW;
pHysiX 21:b642c18eccd1 339 inputYPR[1] = (RCCommand[1]-1500)*-1*9/100*STICK_GAIN;
pHysiX 24:54a8cdf17378 340 inputYPR[2] = (RCCommand[2]-1500)*-1*9/100*STICK_GAIN;
pHysiX 21:b642c18eccd1 341
pHysiX 5:4879ef0e6d41 342 if (rxModule[1].stallTimer.read_us() > 18820) {
pHysiX 21:b642c18eccd1 343 //armed = false;
pHysiX 5:4879ef0e6d41 344 for (int i = 0; i < 5; i++)
pHysiX 4:01921a136f58 345 RCCommand[i] = 0;
pHysiX 17:18c3bd016e49 346 } else {
pHysiX 17:18c3bd016e49 347 for (int i = 0; i < 5; i++)
pHysiX 17:18c3bd016e49 348 RCCommand[i] = constrainRCCommand(RCCommand[i]);
pHysiX 3:605fbcb54e75 349 }
pHysiX 5:4879ef0e6d41 350
pHysiX 12:953d25061417 351 if (box_demo) {
pHysiX 12:953d25061417 352 BT.printf("\nV%2.2f\n", voltageSense*VOLTAGE_SCALE);
pHysiX 12:953d25061417 353 BT.printf("\nA%3.2f\nT%2.2f\n", altimeter.Altitude_m(), altimeter.Temp_C());
pHysiX 12:953d25061417 354 } else if (rc_out)
pHysiX 5:4879ef0e6d41 355 BT.printf("%5d %5d %5d %5d %5d\n", RCCommand[0], RCCommand[1], RCCommand[2], RCCommand[3], RCCommand[4]);
pHysiX 21:b642c18eccd1 356 else if (command_check)
pHysiX 21:b642c18eccd1 357 BT.printf("%3d %3d %3d\n", inputYPR[0], inputYPR[1], inputYPR[2]);
pHysiX 1:43f8ac7ca6d7 358 }
pHysiX 17:18c3bd016e49 359
pHysiX 17:18c3bd016e49 360 int constrainRCCommand(int input)
pHysiX 17:18c3bd016e49 361 {
pHysiX 17:18c3bd016e49 362 if (input < 1000)
pHysiX 17:18c3bd016e49 363 return 1000;
pHysiX 17:18c3bd016e49 364 else if (input > 2000)
pHysiX 17:18c3bd016e49 365 return 2000;
pHysiX 17:18c3bd016e49 366 else
pHysiX 17:18c3bd016e49 367 return input;
pHysiX 17:18c3bd016e49 368 }