From 50ae5b2519443209bff453c5f71499e754cfad0a Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Mon, 1 Sep 2014 15:28:07 +0900 Subject: [PATCH] InertialSensor: reorder .cpp file to match .h No functional changes --- .../AP_InertialSensor/AP_InertialSensor.cpp | 440 +++++++++--------- 1 file changed, 220 insertions(+), 220 deletions(-) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor.cpp b/libraries/AP_InertialSensor/AP_InertialSensor.cpp index d1bbac8333..3cb39d5b35 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor.cpp @@ -131,126 +131,6 @@ AP_InertialSensor::init( Start_style style, } } -// save parameters to eeprom -void AP_InertialSensor::_save_parameters() -{ - _product_id.save(); - for (uint8_t i=0; iprint_P(PSTR("Init Gyro")); - - // flash leds to tell user to keep the IMU still - AP_Notify::flags.initialising = true; - - // remove existing gyro offsets - for (uint8_t k=0; kdelay(5); - update(); - } - - // the strategy is to average 50 points over 0.5 seconds, then do it - // again and see if the 2nd average is within a small margin of - // the first - - uint8_t num_converged = 0; - - // we try to get a good calibration estimate for up to 10 seconds - // if the gyros are stable, we should get it in 1 second - for (int16_t j = 0; j <= 20 && num_converged < num_gyros; j++) { - Vector3f gyro_sum[INS_MAX_INSTANCES], gyro_avg[INS_MAX_INSTANCES], gyro_diff[INS_MAX_INSTANCES]; - float diff_norm[INS_MAX_INSTANCES]; - uint8_t i; - - memset(diff_norm, 0, sizeof(diff_norm)); - - hal.console->print_P(PSTR("*")); - - for (uint8_t k=0; kdelay(5); - } - for (uint8_t k=0; kprintln(); - for (uint8_t k=0; kprintf_P(PSTR("gyro[%u] did not converge: diff=%f dps\n"), - (unsigned)k, ToDeg(best_diff[k])); - _gyro_offset[k] = best_avg[k]; - } - } -} - - void AP_InertialSensor::init_accel() { @@ -260,106 +140,6 @@ AP_InertialSensor::init_accel() _save_parameters(); } -void -AP_InertialSensor::_init_accel() -{ - uint8_t num_accels = min(get_accel_count(), INS_MAX_INSTANCES); - uint8_t flashcount = 0; - Vector3f prev[INS_MAX_INSTANCES]; - Vector3f accel_offset[INS_MAX_INSTANCES]; - float total_change[INS_MAX_INSTANCES]; - float max_offset[INS_MAX_INSTANCES]; - - memset(max_offset, 0, sizeof(max_offset)); - memset(total_change, 0, sizeof(total_change)); - - // cold start - hal.scheduler->delay(100); - - hal.console->print_P(PSTR("Init Accel")); - - // flash leds to tell user to keep the IMU still - AP_Notify::flags.initialising = true; - - // clear accelerometer offsets and scaling - for (uint8_t k=0; kdelay(20); - update(); - - // low pass filter the offsets - for (uint8_t k=0; k= 10) { - hal.console->print_P(PSTR("*")); - flashcount = 0; - } - flashcount++; - } - - for (uint8_t k=0; k accel_offset[k].y) ? accel_offset[k].x : accel_offset[k].y; - max_offset[k] = (max_offset[k] > accel_offset[k].z) ? max_offset[k] : accel_offset[k].z; - } - - uint8_t num_converged = 0; - for (uint8_t k=0; kdelay(500); - } - - // set the global accel offsets - for (uint8_t k=0; kprint_P(PSTR(" ")); - -} - #if !defined( __AVR_ATmega1280__ ) // calibrate_accel - perform accelerometer calibration including providing user // instructions and feedback Gauss-Newton accel calibration routines borrowed @@ -489,6 +269,7 @@ failed: } return false; } +#endif /// calibrated - returns true if the accelerometers have been calibrated /// @note this should not be called while flying because it reads from the eeprom which can be slow @@ -504,6 +285,215 @@ bool AP_InertialSensor::calibrated() return true; } +void +AP_InertialSensor::init_gyro() +{ + _init_gyro(); + + // save calibration + _save_parameters(); +} + +void +AP_InertialSensor::_init_accel() +{ + uint8_t num_accels = min(get_accel_count(), INS_MAX_INSTANCES); + uint8_t flashcount = 0; + Vector3f prev[INS_MAX_INSTANCES]; + Vector3f accel_offset[INS_MAX_INSTANCES]; + float total_change[INS_MAX_INSTANCES]; + float max_offset[INS_MAX_INSTANCES]; + + memset(max_offset, 0, sizeof(max_offset)); + memset(total_change, 0, sizeof(total_change)); + + // cold start + hal.scheduler->delay(100); + + hal.console->print_P(PSTR("Init Accel")); + + // flash leds to tell user to keep the IMU still + AP_Notify::flags.initialising = true; + + // clear accelerometer offsets and scaling + for (uint8_t k=0; kdelay(20); + update(); + + // low pass filter the offsets + for (uint8_t k=0; k= 10) { + hal.console->print_P(PSTR("*")); + flashcount = 0; + } + flashcount++; + } + + for (uint8_t k=0; k accel_offset[k].y) ? accel_offset[k].x : accel_offset[k].y; + max_offset[k] = (max_offset[k] > accel_offset[k].z) ? max_offset[k] : accel_offset[k].z; + } + + uint8_t num_converged = 0; + for (uint8_t k=0; kdelay(500); + } + + // set the global accel offsets + for (uint8_t k=0; kprint_P(PSTR(" ")); + +} + +void +AP_InertialSensor::_init_gyro() +{ + uint8_t num_gyros = min(get_gyro_count(), INS_MAX_INSTANCES); + Vector3f last_average[INS_MAX_INSTANCES], best_avg[INS_MAX_INSTANCES]; + float best_diff[INS_MAX_INSTANCES]; + bool converged[INS_MAX_INSTANCES]; + + // cold start + hal.console->print_P(PSTR("Init Gyro")); + + // flash leds to tell user to keep the IMU still + AP_Notify::flags.initialising = true; + + // remove existing gyro offsets + for (uint8_t k=0; kdelay(5); + update(); + } + + // the strategy is to average 50 points over 0.5 seconds, then do it + // again and see if the 2nd average is within a small margin of + // the first + + uint8_t num_converged = 0; + + // we try to get a good calibration estimate for up to 10 seconds + // if the gyros are stable, we should get it in 1 second + for (int16_t j = 0; j <= 20 && num_converged < num_gyros; j++) { + Vector3f gyro_sum[INS_MAX_INSTANCES], gyro_avg[INS_MAX_INSTANCES], gyro_diff[INS_MAX_INSTANCES]; + float diff_norm[INS_MAX_INSTANCES]; + uint8_t i; + + memset(diff_norm, 0, sizeof(diff_norm)); + + hal.console->print_P(PSTR("*")); + + for (uint8_t k=0; kdelay(5); + } + for (uint8_t k=0; kprintln(); + for (uint8_t k=0; kprintf_P(PSTR("gyro[%u] did not converge: diff=%f dps\n"), + (unsigned)k, ToDeg(best_diff[k])); + _gyro_offset[k] = best_avg[k]; + } + } +} + +#if !defined( __AVR_ATmega1280__ ) // _calibrate_model - perform low level accel calibration // accel_sample are accelerometer samples collected in 6 different positions // accel_offsets are output from the calibration routine @@ -679,3 +669,13 @@ void AP_InertialSensor::_calculate_trim(Vector3f accel_sample, float& trim_roll, #endif // __AVR_ATmega1280__ +// save parameters to eeprom +void AP_InertialSensor::_save_parameters() +{ + _product_id.save(); + for (uint8_t i=0; i