type bool and inflight acc calib

This commit is contained in:
treymarc 2014-04-16 14:39:34 +00:00
parent 45b74bf0b6
commit e276665b32
2 changed files with 17 additions and 17 deletions

View File

@ -58,11 +58,11 @@ uint8_t GPS_svinfo_quality[16]; // Bitfield Qualtity
uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength) uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength)
// Automatic ACC Offset Calibration // Automatic ACC Offset Calibration
bool AccInflightCalibrationArmed = false;
bool AccInflightCalibrationMeasurementDone = false;
bool AccInflightCalibrationSavetoEEProm = false;
bool AccInflightCalibrationActive = false;
uint16_t InflightcalibratingA = 0; uint16_t InflightcalibratingA = 0;
int16_t AccInflightCalibrationArmed;
uint16_t AccInflightCalibrationMeasurementDone = 0;
uint16_t AccInflightCalibrationSavetoEEProm = 0;
uint16_t AccInflightCalibrationActive = 0;
// Battery monitoring stuff // Battery monitoring stuff
uint8_t batteryCellCount = 3; // cell count uint8_t batteryCellCount = 3; // cell count
@ -560,8 +560,8 @@ void loop(void)
// Inflight ACC Calibration // Inflight ACC Calibration
} else if (feature(FEATURE_INFLIGHT_ACC_CAL) && (rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_HI)) { } else if (feature(FEATURE_INFLIGHT_ACC_CAL) && (rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_HI)) {
if (AccInflightCalibrationMeasurementDone) { // trigger saving into eeprom after landing if (AccInflightCalibrationMeasurementDone) { // trigger saving into eeprom after landing
AccInflightCalibrationMeasurementDone = 0; AccInflightCalibrationMeasurementDone = false;
AccInflightCalibrationSavetoEEProm = 1; AccInflightCalibrationSavetoEEProm = true;
} else { } else {
AccInflightCalibrationArmed = !AccInflightCalibrationArmed; AccInflightCalibrationArmed = !AccInflightCalibrationArmed;
if (AccInflightCalibrationArmed) { if (AccInflightCalibrationArmed) {
@ -623,14 +623,15 @@ void loop(void)
if (feature(FEATURE_INFLIGHT_ACC_CAL)) { if (feature(FEATURE_INFLIGHT_ACC_CAL)) {
if (AccInflightCalibrationArmed && f.ARMED && rcData[THROTTLE] > mcfg.mincheck && !rcOptions[BOXARM]) { // Copter is airborne and you are turning it off via boxarm : start measurement if (AccInflightCalibrationArmed && f.ARMED && rcData[THROTTLE] > mcfg.mincheck && !rcOptions[BOXARM]) { // Copter is airborne and you are turning it off via boxarm : start measurement
InflightcalibratingA = 50; InflightcalibratingA = 50;
AccInflightCalibrationArmed = 0; AccInflightCalibrationArmed = false;
} }
if (rcOptions[BOXCALIB]) { // Use the Calib Option to activate : Calib = TRUE Meausrement started, Land and Calib = 0 measurement stored if (rcOptions[BOXCALIB]) { // Use the Calib Option to activate : Calib = TRUE Meausrement started, Land and Calib = 0 measurement stored
if (!AccInflightCalibrationActive && !AccInflightCalibrationMeasurementDone) if (!AccInflightCalibrationActive && !AccInflightCalibrationMeasurementDone)
InflightcalibratingA = 50; InflightcalibratingA = 50;
AccInflightCalibrationActive = true;
} else if (AccInflightCalibrationMeasurementDone && !f.ARMED) { } else if (AccInflightCalibrationMeasurementDone && !f.ARMED) {
AccInflightCalibrationMeasurementDone = 0; AccInflightCalibrationMeasurementDone = false;
AccInflightCalibrationSavetoEEProm = 1; AccInflightCalibrationSavetoEEProm = true;
} }
} }

View File

@ -8,10 +8,9 @@ uint16_t acc_1G = 256; // this is the 1G measured acceleration.
int16_t heading, magHold; int16_t heading, magHold;
extern uint16_t InflightcalibratingA; extern uint16_t InflightcalibratingA;
extern int16_t AccInflightCalibrationArmed; extern bool AccInflightCalibrationMeasurementDone;
extern uint16_t AccInflightCalibrationMeasurementDone; extern bool AccInflightCalibrationSavetoEEProm;
extern uint16_t AccInflightCalibrationSavetoEEProm; extern bool AccInflightCalibrationActive;
extern uint16_t AccInflightCalibrationActive;
extern uint16_t batteryWarningVoltage; extern uint16_t batteryWarningVoltage;
extern uint8_t batteryCellCount; extern uint8_t batteryCellCount;
extern float magneticDeclination; extern float magneticDeclination;
@ -213,8 +212,8 @@ static void ACC_Common(void)
} }
// all values are measured // all values are measured
if (InflightcalibratingA == 1) { if (InflightcalibratingA == 1) {
AccInflightCalibrationActive = 0; AccInflightCalibrationActive = false;
AccInflightCalibrationMeasurementDone = 1; AccInflightCalibrationMeasurementDone = true;
toggleBeep = 2; // buzzer for indicatiing the end of calibration toggleBeep = 2; // buzzer for indicatiing the end of calibration
// recover saved values to maintain current flight behavior until new values are transferred // recover saved values to maintain current flight behavior until new values are transferred
mcfg.accZero[ROLL] = accZero_saved[ROLL]; mcfg.accZero[ROLL] = accZero_saved[ROLL];
@ -226,8 +225,8 @@ static void ACC_Common(void)
InflightcalibratingA--; InflightcalibratingA--;
} }
// Calculate average, shift Z down by acc_1G and store values in EEPROM at end of calibration // Calculate average, shift Z down by acc_1G and store values in EEPROM at end of calibration
if (AccInflightCalibrationSavetoEEProm == 1) { // the copter is landed, disarmed and the combo has been done again if (AccInflightCalibrationSavetoEEProm) { // the copter is landed, disarmed and the combo has been done again
AccInflightCalibrationSavetoEEProm = 0; AccInflightCalibrationSavetoEEProm = false;
mcfg.accZero[ROLL] = b[ROLL] / 50; mcfg.accZero[ROLL] = b[ROLL] / 50;
mcfg.accZero[PITCH] = b[PITCH] / 50; mcfg.accZero[PITCH] = b[PITCH] / 50;
mcfg.accZero[YAW] = b[YAW] / 50 - acc_1G; // for nunchuk 200=1G mcfg.accZero[YAW] = b[YAW] / 50 - acc_1G; // for nunchuk 200=1G