|
|
@ -37,6 +37,10 @@ int16_t gyroADCprevious[3] = {0,0,0}; |
|
|
|
int16_t gyroADCinter[3]; |
|
|
|
uint32_t timeInterleave = 0; |
|
|
|
|
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
char debug_str[512]; |
|
|
|
#endif
|
|
|
|
|
|
|
|
flags_struct_t flags; |
|
|
|
|
|
|
|
// Common variables
|
|
|
@ -604,7 +608,7 @@ void taskMeasurements(void *pvParameters) { |
|
|
|
// sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Cycle: %d Bat: %.2fv Temp: %.2fC Alt: %dcm T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, cycleTime, battery.volt, baro.temperature, baro.altitude, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]);
|
|
|
|
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Cycle: %d Bat: %.2fv Temp: %.2fC Alt: %dcm T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, cycleTime, battery.volt, baro.temperature, alt.EstAlt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]); |
|
|
|
#else
|
|
|
|
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Motor: %d Cycle: %d RC: %d Bat: %.2fv T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, motors.counts, cycleTime, rc_counts, battery.volt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]); |
|
|
|
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Motor: %d Cycle: %d RC: %d Bat: %.2fv T: %d Y: %d P: %d R: %d FS: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, motors.counts, cycleTime, rc_counts, battery.volt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL], failsafeCnt); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Reset counter
|
|
|
@ -1060,9 +1064,7 @@ bool process_rc(void) { |
|
|
|
#endif
|
|
|
|
} else { |
|
|
|
#if defined(FAILSAFE)
|
|
|
|
if(rc_counts == 0) { |
|
|
|
failsafeCnt++; |
|
|
|
} |
|
|
|
failsafeCnt++; |
|
|
|
#endif
|
|
|
|
} |
|
|
|
// rx.stopListening();
|
|
|
@ -1906,18 +1908,33 @@ void process_data(void) { |
|
|
|
if(rcDelayCommand == 20) { |
|
|
|
if(flags.ARMED) { // actions during armed
|
|
|
|
#ifdef ALLOW_ARM_DISARM_VIA_TX_YAW
|
|
|
|
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE) |
|
|
|
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "DISARM VIA TX YAW"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
go_disarm(); // Disarm via YAW
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef ALLOW_ARM_DISARM_VIA_TX_ROLL
|
|
|
|
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO) |
|
|
|
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "DISARM VIA TX ROLL"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
go_disarm(); // Disarm via ROLL
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
} else { // actions during not armed
|
|
|
|
} else { // actions during not armed
|
|
|
|
i=0; |
|
|
|
if(rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) { // GYRO calibration
|
|
|
|
calibratingG = 512; |
|
|
|
|
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "GYRO CLIBRATING"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO: Focus on basic function before proceed to GPS
|
|
|
|
#if GPS
|
|
|
|
//// GPS_reset_home_position();
|
|
|
@ -1929,9 +1946,20 @@ void process_data(void) { |
|
|
|
#if defined(INFLIGHT_ACC_CALIBRATION)
|
|
|
|
else if(rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_HI) { // Inflight ACC calibration START/STOP
|
|
|
|
if(AccInflightCalibrationMeasurementDone) { // trigger saving into eeprom after landing
|
|
|
|
|
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "INFLIGHT ACC CALIBRATION DONE"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
|
|
|
|
AccInflightCalibrationMeasurementDone = 0; |
|
|
|
AccInflightCalibrationSavetoEEProm = 1; |
|
|
|
} else { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "INFLIGHT ACC CALIBRATION BEGIN"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
|
|
|
|
AccInflightCalibrationArmed = !AccInflightCalibrationArmed; |
|
|
|
#if defined(BUZZER)
|
|
|
|
if(AccInflightCalibrationArmed) |
|
|
@ -1943,13 +1971,17 @@ void process_data(void) { |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef MULTIPLE_CONFIGURATION_PROFILES
|
|
|
|
if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO) |
|
|
|
if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO) |
|
|
|
i = 1; // ROLL left -> Profile 1
|
|
|
|
else if(rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_CE) |
|
|
|
i = 2; // PITCH up -> Profile 2
|
|
|
|
else if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_HI) |
|
|
|
i = 3; // ROLL right -> Profile 3
|
|
|
|
if(i){ |
|
|
|
if(i) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "Profile: %d", i); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
global_conf.currentSet = i-1; |
|
|
|
writeGlobalSet(0); |
|
|
|
// readEEPROM();
|
|
|
@ -1961,16 +1993,26 @@ void process_data(void) { |
|
|
|
if(rcSticks == THR_LO + YAW_HI + PIT_HI + ROL_CE) { // Enter LCD config
|
|
|
|
#if defined(LCD_CONF)
|
|
|
|
configurationLoop(); // beginning LCD configuration
|
|
|
|
#endif
|
|
|
|
previousTime = micros(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
#ifdef ALLOW_ARM_DISARM_VIA_TX_YAW
|
|
|
|
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE) |
|
|
|
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "ARM VIA TX YAW"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
go_arm(); // Arm via YAW
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef ALLOW_ARM_DISARM_VIA_TX_ROLL
|
|
|
|
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI) |
|
|
|
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "ARM VIA TX ROLL"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
go_arm(); // Arm via ROLL
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef LCD_TELEMETRY_AUTO
|
|
|
|
else if(rcSticks == THR_LO + YAW_CE + PIT_HI + ROL_LO) { // Auto telemetry ON/OFF
|
|
|
@ -1996,12 +2038,24 @@ void process_data(void) { |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#if USE_ACC
|
|
|
|
else if(rcSticks == THR_HI + YAW_LO + PIT_LO + ROL_CE) |
|
|
|
else if(rcSticks == THR_HI + YAW_LO + PIT_LO + ROL_CE) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "ACC CALIBRATION"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
|
|
|
|
calibratingA = 512; // throttle=max, yaw=left, pitch=min
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
#if USE_MAG
|
|
|
|
else if(rcSticks == THR_HI + YAW_HI + PIT_LO + ROL_CE) |
|
|
|
else if(rcSticks == THR_HI + YAW_HI + PIT_LO + ROL_CE) { |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "MAG CALIBRATION"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
|
|
|
|
flags.CALIBRATE_MAG = 1; // throttle=max, yaw=right, pitch=min
|
|
|
|
} |
|
|
|
#endif
|
|
|
|
i = 0; |
|
|
|
if(rcSticks == THR_HI + YAW_CE + PIT_HI + ROL_CE) { |
|
|
@ -2287,6 +2341,10 @@ void process_data(void) { |
|
|
|
void go_disarm(void) { |
|
|
|
if(flags.ARMED) { |
|
|
|
flags.ARMED = 0; |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "DISARMED"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
#ifdef LOG_PERMANENT
|
|
|
|
plog.disarm++; // #disarm events
|
|
|
|
plog.armed_time = armedTime ; // lifetime in seconds
|
|
|
@ -2309,7 +2367,7 @@ void go_arm(void) { |
|
|
|
&& flags.ACC_CALIBRATED |
|
|
|
#endif
|
|
|
|
#if defined(FAILSAFE)
|
|
|
|
&& failsafeCnt < 2 |
|
|
|
&& failsafeCnt < 50 |
|
|
|
#endif
|
|
|
|
#if GPS && defined(ONLY_ALLOW_ARM_WITH_GPS_3DFIX)
|
|
|
|
&& (flags.GPS_FIX && GPS_numSat >= 5) |
|
|
@ -2317,6 +2375,10 @@ void go_arm(void) { |
|
|
|
) { |
|
|
|
if(!flags.ARMED && !flags.BARO_MODE) { // arm now!
|
|
|
|
flags.ARMED = 1; |
|
|
|
#ifdef DEBUG_MODE
|
|
|
|
sprintf(debug_str, "ARMED"); |
|
|
|
Serial.println(debug_str); |
|
|
|
#endif
|
|
|
|
#if defined(HEADFREE)
|
|
|
|
headFreeModeHold = att.heading; |
|
|
|
#endif // defined(HEADFREE)
|
|
|
|