diff --git a/ArduCopter/compassmot.pde b/ArduCopter/compassmot.pde index 3d9a089893..61cb11473a 100644 --- a/ArduCopter/compassmot.pde +++ b/ArduCopter/compassmot.pde @@ -8,14 +8,14 @@ static uint8_t mavlink_compassmot(mavlink_channel_t chan) { int8_t comp_type; // throttle or current based compensation - Vector3f compass_base; // compass vector when throttle is zero - Vector3f motor_impact; // impact of motors on compass vector - Vector3f motor_impact_scaled; // impact of motors on compass vector scaled with throttle - Vector3f motor_compensation; // final compensation to be stored to eeprom + Vector3f compass_base[COMPASS_MAX_INSTANCES]; // compass vector when throttle is zero + Vector3f motor_impact[COMPASS_MAX_INSTANCES]; // impact of motors on compass vector + Vector3f motor_impact_scaled[COMPASS_MAX_INSTANCES]; // impact of motors on compass vector scaled with throttle + Vector3f motor_compensation[COMPASS_MAX_INSTANCES]; // final compensation to be stored to eeprom float throttle_pct; // throttle as a percentage 0.0 ~ 1.0 float throttle_pct_max = 0.0f; // maximum throttle reached (as a percentage 0~1.0) float current_amps_max = 0.0f; // maximum current reached - float interference_pct = 0.0f; // interference as a percentage of total mag field (for reporting purposes only) + float interference_pct[COMPASS_MAX_INSTANCES]; // interference as a percentage of total mag field (for reporting purposes only) uint32_t last_run_time; uint32_t last_send_time; bool updated = false; // have we updated the compensation vector at least once @@ -38,10 +38,12 @@ static uint8_t mavlink_compassmot(mavlink_channel_t chan) // check compass health compass.read(); - if (!compass.healthy(0)) { - gcs[chan-MAVLINK_COMM_0].send_text_P(SEVERITY_HIGH, PSTR("check compass")); - ap.compass_mot = false; - return 1; + for (uint8_t i=0; i= 3.0f ) { - motor_compensation = motor_compensation * 0.99f - motor_impact_scaled * 0.01f; - updated = true; + // adjust the motor compensation to negate the impact if drawing over 3amps + if (battery.current_amps() >= 3.0f) { + motor_compensation[i] = motor_compensation[i] * 0.99f - motor_impact_scaled[i] * 0.01f; + updated = true; + } } } // calculate interference percentage at full throttle as % of total mag field if (comp_type == AP_COMPASS_MOT_COMP_THROTTLE) { - // interference is impact@fullthrottle / mag field * 100 - interference_pct = motor_compensation.length() / (float)COMPASS_MAGFIELD_EXPECTED * 100.0f; + for (uint8_t i=0; i