diff --git a/flight/modules/AutoTune/autotune.c b/flight/modules/AutoTune/autotune.c index b4fc4924b..f118cafe4 100644 --- a/flight/modules/AutoTune/autotune.c +++ b/flight/modules/AutoTune/autotune.c @@ -9,7 +9,7 @@ * @{ * * @file AutoTune/autotune.c - * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016. + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2017. * dRonin, http://dRonin.org/, Copyright (C) 2015-2016 * Tau Labs, http://taulabs.org, Copyright (C) 2013-2014 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. @@ -69,43 +69,39 @@ #undef STACK_SIZE_BYTES // Pull Request version tested on Sparky2. 292 bytes of stack left when configured with 1340 // Beware that Nano needs 156 bytes more stack than Sparky2 -#define STACK_SIZE_BYTES 1340 -#define TASK_PRIORITY (tskIDLE_PRIORITY + 1) +#define STACK_SIZE_BYTES 1340 +#define TASK_PRIORITY (tskIDLE_PRIORITY + 1) -#define AF_NUMX 13 -#define AF_NUMP 43 +#define AF_NUMX 13 +#define AF_NUMP 43 #if !defined(AT_QUEUE_NUMELEM) -#define AT_QUEUE_NUMELEM 18 +#define AT_QUEUE_NUMELEM 18 #endif -#define TASK_STARTUP_DELAY_MS 250 /* delay task startup this much, waiting on accessory valid */ -#define NOT_AT_MODE_DELAY_MS 50 /* delay this many ms if not in autotune mode */ -#define NOT_AT_MODE_RATE (1000.0f / NOT_AT_MODE_DELAY_MS) /* this many loops per second if not in autotune mode */ -#define SMOOTH_QUICK_FLUSH_DELAY 0.5f /* wait this long after last change to flush to permanent storage */ -#define SMOOTH_QUICK_FLUSH_TICKS (SMOOTH_QUICK_FLUSH_DELAY * NOT_AT_MODE_RATE) /* this many ticks after last change to flush to permanent storage */ +#define TASK_STARTUP_DELAY_MS 250 /* delay task startup this much, waiting on accessory valid */ +#define NOT_AT_MODE_DELAY_MS 50 /* delay this many ms if not in autotune mode */ +#define NOT_AT_MODE_RATE (1000.0f / NOT_AT_MODE_DELAY_MS) /* this many loops per second if not in autotune mode */ +#define SMOOTH_QUICK_FLUSH_DELAY 0.5f /* wait this long after last change to flush to permanent storage */ +#define SMOOTH_QUICK_FLUSH_TICKS (SMOOTH_QUICK_FLUSH_DELAY * NOT_AT_MODE_RATE) /* this many ticks after last change to flush to permanent storage */ -#define MAX_PTS_PER_CYCLE 4 /* max gyro updates to process per loop see YIELD_MS and consider gyro rate */ -#define INIT_TIME_DELAY_MS 100 /* delay to allow stab bank, etc. to be populated after flight mode switch change detection */ -#define SYSTEMIDENT_TIME_DELAY_MS 2000 /* delay before starting systemident (shaking) flight mode */ -#define INIT_TIME_DELAY2_MS 2500 /* delay before starting to capture data */ -#define YIELD_MS 2 /* delay this long between processing sessions see MAX_PTS_PER_CYCLE and consider gyro rate */ +#define MAX_PTS_PER_CYCLE 4 /* max gyro updates to process per loop see YIELD_MS and consider gyro rate */ +#define INIT_TIME_DELAY_MS 100 /* delay to allow stab bank, etc. to be populated after flight mode switch change detection */ +#define SYSTEMIDENT_TIME_DELAY_MS 2000 /* delay before starting systemident (shaking) flight mode */ +#define INIT_TIME_DELAY2_MS 2500 /* delay before starting to capture data */ +#define YIELD_MS 2 /* delay this long between processing sessions see MAX_PTS_PER_CYCLE and consider gyro rate */ // CheckSettings() returned error bits -#define TAU_NAN 1 -#define BETA_NAN 2 -#define ROLL_BETA_LOW 4 -#define PITCH_BETA_LOW 8 -#define YAW_BETA_LOW 16 -#define TAU_TOO_LONG 32 -#define TAU_TOO_SHORT 64 -#define CPU_TOO_SLOW 128 - -// smooth-quick modes -#define SMOOTH_QUICK_DISABLED 0 -#define SMOOTH_QUICK_ACCESSORY_BASE 10 -#define SMOOTH_QUICK_TOGGLE_BASE 20 +#define TAU_NAN 1 +#define BETA_NAN 2 +#define ROLL_BETA_LOW 4 +#define PITCH_BETA_LOW 8 +#define YAW_BETA_LOW 16 +#define TAU_TOO_LONG 32 +#define TAU_TOO_SHORT 64 +#define CPU_TOO_SLOW 128 +#define FMS_TOGGLE_STEP_DISABLED 0.0f // Private types enum AUTOTUNE_STATE { AT_INIT, AT_INIT_DELAY, AT_INIT_DELAY2, AT_START, AT_RUN, AT_FINISHED, AT_WAITING }; @@ -136,11 +132,11 @@ static float gyroReadTimeAverageAlpha; static float gyroReadTimeAverageAlphaAlpha; static float alpha; static float smoothQuickValue; +static float flightModeSwitchToggleStepValue; static volatile uint32_t atPointsSpilled; static uint32_t throttleAccumulator; static uint8_t rollMax, pitchMax; static int8_t accessoryToUse; -static int8_t flightModeSwitchTogglePosition; static bool moduleEnabled; @@ -288,13 +284,13 @@ static void AutoTuneTask(__attribute__((unused)) void *parameters) savePidNeeded = false; // Save PIDs to permanent settings switch (systemIdentSettings.DestinationPidBank) { - case 1: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK1: UAVObjSave(StabilizationSettingsBank1Handle(), 0); break; - case 2: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK2: UAVObjSave(StabilizationSettingsBank2Handle(), 0); break; - case 3: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK3: UAVObjSave(StabilizationSettingsBank3Handle(), 0); break; } @@ -306,13 +302,13 @@ static void AutoTuneTask(__attribute__((unused)) void *parameters) // and the autotune data gathering is complete // and the autotune data gathered is good // note: CheckFlightModeSwitchForPidRequest(mode) only returns true if current mode is not autotune - if (flightModeSwitchTogglePosition != -1 && CheckFlightModeSwitchForPidRequest(flightStatus.FlightMode) + if (flightModeSwitchToggleStepValue > FMS_TOGGLE_STEP_DISABLED && CheckFlightModeSwitchForPidRequest(flightStatus.FlightMode) && systemIdentSettings.Complete && !CheckSettings()) { if (flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED) { // if user toggled while armed set PID's to next in sequence // if you assume that smoothest is -1 and quickest is +1 // this corresponds to 0,+.50,+1.00,-1.00,-.50 (for 5 position toggle) - smoothQuickValue += 1.0f / (float)flightModeSwitchTogglePosition; + smoothQuickValue += flightModeSwitchToggleStepValue; if (smoothQuickValue > 1.001f) { smoothQuickValue = -1.0f; } @@ -746,39 +742,45 @@ static void InitSystemIdent(bool loadDefaults) // Update SmoothQuickSource to be used static void UpdateSmoothQuickSource(uint8_t smoothQuickSource, bool loadDefaults) { + // disable PID changing with accessory0-3 and flight mode switch toggle + accessoryToUse = -1; + flightModeSwitchToggleStepValue = FMS_TOGGLE_STEP_DISABLED; + switch (smoothQuickSource) { - case SMOOTH_QUICK_ACCESSORY_BASE + 0: // use accessory0 - case SMOOTH_QUICK_ACCESSORY_BASE + 1: // use accessory1 - case SMOOTH_QUICK_ACCESSORY_BASE + 2: // use accessory2 - case SMOOTH_QUICK_ACCESSORY_BASE + 3: // use accessory3 - // leave smoothQuickValue alone since it is always controlled by knob - // disable PID changing with flight mode switch - flightModeSwitchTogglePosition = -1; - // enable PID changing with accessory0-3 - accessoryToUse = smoothQuickSource - SMOOTH_QUICK_ACCESSORY_BASE; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_ACCESSORY0: + accessoryToUse = 0; break; - case SMOOTH_QUICK_TOGGLE_BASE + 3: // use flight mode switch toggle with 3 points - case SMOOTH_QUICK_TOGGLE_BASE + 5: // use flight mode switch toggle with 5 points - case SMOOTH_QUICK_TOGGLE_BASE + 7: // use flight mode switch toggle with 7 points - // don't allow init of current toggle position in the middle of 3x fms toggle - if (loadDefaults) { - // set toggle to middle of range - smoothQuickValue = 0.0f; - } - // enable PID changing with flight mode switch - flightModeSwitchTogglePosition = (smoothQuickSource - 1 - SMOOTH_QUICK_TOGGLE_BASE) / 2; - // disable PID changing with accessory0-3 - accessoryToUse = -1; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_ACCESSORY1: + accessoryToUse = 1; break; - case SMOOTH_QUICK_DISABLED: + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_ACCESSORY2: + accessoryToUse = 2; + break; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_ACCESSORY3: + accessoryToUse = 3; + break; + // enable PID changing with flight mode switch + // -1 to +1 give a range = 2, define step value for desired positions: 3, 5, 7 + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_FMSTOGGLE3POS: + flightModeSwitchToggleStepValue = 1.0f; + break; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_FMSTOGGLE5POS: + flightModeSwitchToggleStepValue = 0.5f; + break; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_FMSTOGGLE7POS: + flightModeSwitchToggleStepValue = 0.33f; + break; + case SYSTEMIDENTSETTINGS_SMOOTHQUICKSOURCE_DISABLED: default: - // leave smoothQuickValue alone so user can set it to a different value and have it stay that value - // disable PID changing with flight mode switch - flightModeSwitchTogglePosition = -1; - // disable PID changing with accessory0-3 accessoryToUse = -1; + flightModeSwitchToggleStepValue = FMS_TOGGLE_STEP_DISABLED; break; } + // don't allow init of current toggle position in the middle of 3x fms toggle + if (loadDefaults && (flightModeSwitchToggleStepValue > FMS_TOGGLE_STEP_DISABLED)) { + // set toggle to middle of range + smoothQuickValue = 0.0f; + } } @@ -928,13 +930,13 @@ static void ComputeStabilizationAndSetPidsFromDampAndNoise(float dampRate, float _Static_assert(sizeof(StabilizationSettingsBank1Data) == sizeof(StabilizationBankData), "sizeof(StabilizationSettingsBank1Data) != sizeof(StabilizationBankData)"); StabilizationBankData volatile stabSettingsBank; switch (systemIdentSettings.DestinationPidBank) { - case 1: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK1: StabilizationSettingsBank1Get((void *)&stabSettingsBank); break; - case 2: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK2: StabilizationSettingsBank2Get((void *)&stabSettingsBank); break; - case 3: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK3: StabilizationSettingsBank3Get((void *)&stabSettingsBank); break; } @@ -1161,13 +1163,13 @@ static void ComputeStabilizationAndSetPidsFromDampAndNoise(float dampRate, float // Save PIDs to UAVO RAM (not permanently yet) switch (systemIdentSettings.DestinationPidBank) { - case 1: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK1: StabilizationSettingsBank1Set((void *)&stabSettingsBank); break; - case 2: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK2: StabilizationSettingsBank2Set((void *)&stabSettingsBank); break; - case 3: + case SYSTEMIDENTSETTINGS_DESTINATIONPIDBANK_BANK3: StabilizationSettingsBank3Set((void *)&stabSettingsBank); break; } diff --git a/ground/gcs/src/plugins/config/autotune.ui b/ground/gcs/src/plugins/config/autotune.ui index 2cfadba55..4d931e4a2 100644 --- a/ground/gcs/src/plugins/config/autotune.ui +++ b/ground/gcs/src/plugins/config/autotune.ui @@ -1,140 +1,38 @@ - AutotuneWidget - + AutoTuneWidget + 0 0 - 739 - 688 + 979 + 794 - - - 0 - 0 - - Form - - - 6 - - - 12 - - - 12 - - - 12 - - - 12 - + - - - 0 + + + Qt::NoFocus - + + + + 0 + 0 + + - Pre-Autotune + AutoTune Configuration - - - 12 + + + 0 - - 12 - - - 12 - - - 12 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Sunken - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:20pt; font-weight:600; color:#ff0000;">WARNING:</span></p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Lucida Grande'; font-size:13pt;"><br /></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:13pt;"><br /></span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:13pt;"><br /></span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Lucida Grande'; font-size:13pt;">This is an experimental plugin for the GCS that is going to make your aircraft shake, etc, so test with lots of space and be </span><span style=" font-family:'Lucida Grande'; font-size:13pt; font-weight:600;">very very wary</span><span style=" font-family:'Lucida Grande'; font-size:13pt;"> for it creating bad tuning values.  Basically there is no reason to think this will work at all.<br /><br />To use autotuning, here are the steps:<br /></span></p> -<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">On the <span style=" font-style:italic;">Input configuration</span> tab, <span style=" font-style:italic;">Flight Mode Switch Settings</span>, set one of your flight modes to &quot;Autotune&quot;.<br /></li> -<li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Take off, change flight mode to autotune, keep it in the air while it's shaking.<br /></li> -<li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Land and disarm.  (note - you <span style=" font-weight:600;">MUST</span> stay in autotune mode through this point, leaving autotune before disarming aborts the process)<br /></li> -<li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">We'd recommend checking your stabilization settings before trying them out (ie: compare to what you currently use, if they are VASTLY different, probably a good indication bad things will happen).<br /></li> -<li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Test fly the new settings.</li> -<li style=" font-family:'Lucida Grande'; font-size:13pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">If you're ready to proceed, click the <span style=" font-style:italic;">Enable Autotune Module</span> checkbox above this text, click <span style=" font-style:italic;">save</span> and go to the next tab.</li></ul></body></html> - - - - - - - Module Control - - - - - - Enable Autotune Module - - - true - - - - - - - After enabling the module, you must power cycle before using and configuring. - - - - - - - - - - - Autotune Setup - - 0 @@ -149,76 +47,12 @@ p, li { white-space: pre-wrap; } - - - - - - - 255 - 255 - 255 - - - - - - - 232 - 232 - 232 - - - - - - - - - 255 - 255 - 255 - - - - - - - 232 - 232 - 232 - - - - - - - - - 232 - 232 - 232 - - - - - - - 232 - 232 - 232 - - - - - + + Qt::NoFocus QFrame::NoFrame - - QFrame::Plain - true @@ -227,367 +61,1834 @@ p, li { white-space: pre-wrap; } 0 0 - 526 - 510 + 957 + 706 - - - 0 - 0 - - - - true - - - - 12 - - - 12 - - - 12 - - - 12 - - - 12 - - - - - Tuning Aggressiveness + + + + + Qt::Vertical - - - - - Rate Tuning: - - - - - - - Attitude Tuning: - - - - - - - 100 - - - Qt::Horizontal - - - - objname:RelayTuningSettings - fieldname:RateGain - scale:0.01 - haslimits:no - - - - - - - - 100 - - - Qt::Horizontal - - - - objname:RelayTuningSettings - fieldname:AttitudeGain - scale:0.01 - haslimits:no - - - - - - + + QSizePolicy::Expanding + + + + 20 + 0 + + + - - - - Measured Properties + + + + + 430 + 0 + - - - - - Roll: + + + 16777215 + 16777215 + + + + + 50 + false + + + + Qt::LeftToRight + + + QLineEdit { + border: none; + border-radius: 1px; + padding: 0 4px; + background: rgba(0, 0, 0, 16); + /* background: transparent; */ + /* selection-background-color: darkgray;*/ + } + + + Status + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 0 + 0 + - - - - - - 0 + + Measured amount and direction of control stick that stabilization automatically adds for motionless hover. + + + true Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + - objname:RelayTuning - fieldname:Period + objname:SystemIdentState + fieldname:Bias element:Roll - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - objname:RelayTuning - fieldname:Gain - element:Roll - - - - - - - - Period (ms) - - - - - - - Gain (deg/s) / output - - - - - - - Pitch - - - - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - objname:RelayTuning - fieldname:Period - element:Pitch - - - - - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - objname:RelayTuning - fieldname:Gain - element:Pitch - - - - - - - - - - - Computed Values - - - - - - RateKi - - - - - - - AttitudeKp - - - - - - - 0 - - - - - - - Pitch - - - - - - - RateKp - - - - - - - 0 - - - - - - - AttitudeKi - - - - - - - Roll - - - - - - - 0 - - - - + + + + 0 + 0 + + + + Measured delay between inner loop and detected gyro response ln(sec). + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -100.000000000000000 + + + 100.000000000000000 + + + + objname:SystemIdentState + fieldname:Tau + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Number of Gyro samples that were dropped (should be zero). + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0 + + + 0.000000000000000 + + + 100.000000000000000 + + + + objname:SystemIdentState + fieldname:NumSpilledPts + + + + + + + + + 0 + 0 + + + + Number of Gyro samples that were counted. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0 + + + 0.000000000000000 + + + 99999.000000000000000 + + + + objname:SystemIdentState + fieldname:NumAfPredicts + + + + + + + + + 0 + 0 + + + + Measured delay from Gyro read to inner loop in milliseconds. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 2 + + + 0.000000000000000 + + + 10.000000000000000 + + + 0.010000000000000 + + + + objname:SystemIdentState + fieldname:GyroReadTimeAverage + scale:0.001 + + + + + + - 0 + Bias Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Beta Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + (Natural log of) Measured control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Pitch + + + + + + + + + 0 + 0 + + + + Measured vibration: Usually 10's to 1000's. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Roll + + + + + + + + Bias Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + (Natural log of) Measured control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Yaw + + + + + + + + + 0 + 0 + + + + Measured amount and direction of control stick that stabilization automatically adds for motionless hover. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Bias + element:Yaw + + + + + + + + Noise Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Throttle level needed to hover, in percent. How the multirotor is under/over powered. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0.000000000000000 + + + 1.000000000000000 + + + + objname:SystemIdentState + fieldname:HoverThrottle + + + + + + + + + 0 + 0 + + + + Period (ms) + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0.000000000000000 + + + 10.000000000000000 + + + + objname:SystemIdentState + fieldname:Period + + + + + + + + + 0 + 0 + + + + Dropped + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Measured amount and direction of control stick that stabilization automatically adds for motionless hover. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Bias + element:Pitch + + + + + + + + + 0 + 0 + + + + Measured vibration: Usually 10's to 1000's. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Pitch + + + + + + + + Noise Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Samples + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Noise Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Beta Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Measured vibration: Usually 10's to 1000's. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Yaw + + + + + + + + Bias Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Beta Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + (Natural log of) Measured control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Roll + + + + + + + + + 0 + 0 + + + + Gyro Avg + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Period + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + 0 + 0 + + - 0 + Tau + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 110 + 0 + + - 0 + HoverThrottle + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + Automatically checked for a good complete tune or unchecked for incomplete or bad tune. + + + Qt::LeftToRight + - 0 + + + + true + + + + objname:SystemIdentState + fieldname:Complete + - - + + - 0 + Complete + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + + + + true - - - - - - - + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + 50 + false + + + + Configuration + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Reset AutoTune settings to default values. + + + false + + + + + + Default + + + + button:default + buttongroup:20 + + + + + + + + + 0 + 0 + + + + + 50 + false + + + + Calculate Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + 4 + + + + + + 60 + 28 + - - Apply Computed Values + + + 60 + 16777215 + + + + Smooth - Normal - Quick PID response desired for PID calc based on AutoTune measurements. + + + 1 + + + -1.000000000000000 + + + 1.000000000000000 + + + 0.100000000000000 + + + 0.000000000000000 + + + + objname:SystemIdentSettings + fieldname:SmoothQuickValue + scale:1 + buttongroup:20 + - - + + + + + 0 + 0 + + + + + 120 + 29 + + + + + 120 + 16777215 + + + + Smooth PID response, preferred for photography. + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +margin:1px; +font:bold; + - Step Size + Smooth Qt::AlignCenter - - + + + + + 0 + 0 + + + + + 120 + 29 + + + + + 120 + 16777215 + + + + Quick PID response, preferred for racing. + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +margin:1px; +font:bold; + + + Quick + + + Qt::AlignCenter + + + + + + + + 0 + 28 + + + + Smooth - Normal - Quick PID response desired for PID calc based on AutoTune measurements. + + + -10 + + + 10 + + + 1 + + + 5 + + + 0 + Qt::Horizontal + + QSlider::TicksBelow + + + 5 + - objname:RelayTuningSettings - fieldname:Amplitude - scale:0.01 - haslimits:no + objname:SystemIdentSettings + fieldname:SmoothQuickValue + scale:0.1 + buttongroup:20 - - + + + + + 0 + 0 + + + + + 120 + 29 + + + + + 120 + 16777215 + + + + Normal PID response. + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +margin:1px; +font:bold; + + + Normal + + + Qt::AlignCenter + + + + + Qt::Horizontal - 40 + 10 20 - + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Whether to calculate yaw and whether to use Yaw to Roll/Pitch PID Ratios limits bellow. + + + Qt::LeftToRight + + + 0 + + + + objname:SystemIdentSettings + fieldname:CalculateYaw + buttongroup:20 + + + + + + + + How the SmoothQuick slider is controlled, using Accessory or FMS 3x toggle method with 3, 5, 7 positions. Allow testing smooth/quick PID sets after a AutoTune flight. + + + + objname:SystemIdentSettings + fieldname:SmoothQuickSource + buttongroup:20 + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + SmoothQuick Source + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + PID Bank Destination + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Which bank the calculated PIDs will be stored in after tuning. + + + + objname:SystemIdentSettings + fieldname:DestinationPidBank + buttongroup:20 + + + + + + + + Thrust Control + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Manual is direct control, AltitudeVario helps to maintain altitude. + + + + objname:SystemIdentSettings + fieldname:ThrustControl + buttongroup:20 + + + + + + + + OuterLoop Kp Limit + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Yaw to Roll/Pitch PID Ratio Limits + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 10 + 20 + + + + + + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Minimum Yaw to Pitch/Roll ratio limit. + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + + objname:SystemIdentSettings + fieldname:YawToRollPitchPIDRatioMin + buttongroup:20 + + + + + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Maximum Yaw to Pitch/Roll ratio limit. + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + + objname:SystemIdentSettings + fieldname:YawToRollPitchPIDRatioMax + buttongroup:20 + + + + + + + + + + + 0 + 0 + + + + Set a limiting upper value for the OuterLoop Kp. + + + 1 + + + + objname:SystemIdentSettings + fieldname:OuterLoopKpSoftClamp + buttongroup:20 + + + + + + + + + + + + 0 + 0 + + + + + 430 + 0 + + + + + 16777215 + 16777215 + + + + + 50 + false + + + + Qt::LeftToRight + + + QLineEdit { + border: none; + border-radius: 1px; + padding: 0 4px; + background: rgba(0, 0, 0, 16); + /* background: transparent; */ + /* selection-background-color: darkgray;*/ + } + + + Tuning Results Stored + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 0 + 0 + + + + (Natural log of) Stored control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Roll + buttongroup:30 + + + + + + + + + 0 + 0 + + + + Stored delay between inner loop and detected gyro response ln(sec). + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + QAbstractSpinBox::NoButtons + + + -100.000000000000000 + + + 100.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Tau + scale:1 + buttongroup:30 + + + + + + + + + 0 + 0 + + + + + 110 + 0 + + + + + 16777215 + 16777215 + + + + Tau + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Beta Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + (Natural log of) Stored control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Yaw + buttongroup:30 + + + + + + + + + 0 + 0 + + + + Beta Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + (Natural log of) Stored control gain. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + QAbstractSpinBox::NoButtons + + + -999.000000000000000 + + + 999.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Pitch + buttongroup:30 + + + + + + + + + 0 + 0 + + + + Beta Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Measured delay from Gyro read to inner loop in milliseconds. + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + QAbstractSpinBox::NoButtons + + + 2 + + + 0.000000000000000 + + + 10.000000000000000 + + + 0.010000000000000 + + + + objname:SystemIdentSettings + fieldname:GyroReadTimeAverage + scale:0.001 + buttongroup:30 + + + + + + + + + 0 + 0 + + + + Gyro Avg + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + Qt::Horizontal + + QSizePolicy::MinimumExpanding + 40 @@ -596,11 +1897,199 @@ p, li { white-space: pre-wrap; } - - + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Clear results of previous AutoTune flight. + + + Qt::LeftToRight + + + false + + + + - The Apply and Save buttons below save the autotuning settings which -will alter settings for the next autotuning flight + Default + + + + button:default + buttongroup:30 + + + + + + + + + + Automatically checked for a good complete tune or unchecked for incomplete or bad tune. + + + Qt::LeftToRight + + + + + + true + + + + objname:SystemIdentSettings + fieldname:Complete + + + + + + + + Complete + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 6 + + + 0 + + + + + + 0 + 0 + + + + Module Control + + + + 0 + + + 9 + + + + + + 900 + 16777215 + + + + Qt::StrongFocus + + + Allow AutoTune module to be started all time, without any AutoTune set in one FlightMode. + + + Enable AutoTune module + + + + + + + + 0 + 0 + + + + After enabling the module, you must power cycle before using and configuring. + + + true + + + + + + + + + + + 0 + 0 + + + + Module Status + + + + 9 + + + + + true + + + + 0 + 0 + + + + + 200 + 30 + + + + + 200 + 200 + + + + + + + border: 1px solid grey; +border-radius: 5; +margin:1px; +font:bold; + + + Stopped Qt::AlignCenter @@ -608,22 +2097,9 @@ will alter settings for the next autotuning flight - - - - - - - - Qt::Vertical - - - - 20 - 77 - - - + + + @@ -634,22 +2110,19 @@ will alter settings for the next autotuning flight - + 4 - + Qt::Horizontal - - QSizePolicy::Expanding - - 13 - 25 + 40 + 5 @@ -664,8 +2137,8 @@ will alter settings for the next autotuning flight - 25 - 25 + 0 + 0 @@ -674,6 +2147,9 @@ will alter settings for the next autotuning flight 25 + + Qt::NoFocus + @@ -687,82 +2163,42 @@ will alter settings for the next autotuning flight 25 - - button:help - - - - - - - - 0 - 0 - - - - Reloads the saved settings into GCS. -Useful if you have accidentally changed some settings. - - - - - - Reload Board Data + + true - button:reload - buttongroup:10 + button:help - - - 0 - 0 - - - Send settings to the board but do not save to the non-volatile memory - - - + Send settings to the board but do not save to the non-volatile memory. Apply - - button:apply - + button:apply - - - 0 - 0 - - - Send settings to the board and save to the non-volatile memory - - - + Send settings to the board and save to the non-volatile memory. Save + + false + - - button:save - + button:save @@ -770,6 +2206,10 @@ Useful if you have accidentally changed some settings. + + applyButton + saveButton + diff --git a/ground/gcs/src/plugins/config/config.pro b/ground/gcs/src/plugins/config/config.pro index 4f923923b..6de77a22d 100644 --- a/ground/gcs/src/plugins/config/config.pro +++ b/ground/gcs/src/plugins/config/config.pro @@ -64,6 +64,7 @@ HEADERS += \ calibration/levelcalibrationmodel.h \ calibration/gyrobiascalibrationmodel.h \ calibration/calibrationuiutils.h \ + configautotunewidget.h \ configoplinkwidget.h \ configrevonanohwwidget.h \ configsparky2hwwidget.h \ @@ -106,6 +107,7 @@ SOURCES += \ calibration/sixpointcalibrationmodel.cpp \ calibration/levelcalibrationmodel.cpp \ calibration/gyrobiascalibrationmodel.cpp \ + configautotunewidget.cpp \ configoplinkwidget.cpp \ configrevonanohwwidget.cpp \ configsparky2hwwidget.cpp \ @@ -133,6 +135,7 @@ FORMS += \ mixercurve.ui \ configrevohwwidget.ui \ configspracingf3hwwidget.ui \ + autotune.ui \ oplink.ui \ configrevonanohwwidget.ui \ configsparky2hwwidget.ui \ diff --git a/ground/gcs/src/plugins/config/configautotunewidget.cpp b/ground/gcs/src/plugins/config/configautotunewidget.cpp index 670e7a134..2944fa818 100644 --- a/ground/gcs/src/plugins/config/configautotunewidget.cpp +++ b/ground/gcs/src/plugins/config/configautotunewidget.cpp @@ -1,173 +1,133 @@ +/** + **************************************************************************************** + * + * @file configautotunewidget.cpp + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015-2017. + * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup ConfigPlugin Config Plugin + * @{ + * @brief The Configuration Gadget used to configure autotune module + ***************************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #include "configautotunewidget.h" #include "ui_autotune.h" -#include "relaytuningsettings.h" -#include "relaytuning.h" -#include "stabilizationsettings.h" +#include + +#include +#include #include "hwsettings.h" +#include "taskinfo.h" +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -ConfigAutotuneWidget::ConfigAutotuneWidget(QWidget *parent) : - ConfigTaskWidget(parent) +ConfigAutoTuneWidget::ConfigAutoTuneWidget(QWidget *parent) : ConfigTaskWidget(parent) { - m_autotune = new Ui_AutotuneWidget(); + m_autotune = new Ui_AutoTuneWidget(); m_autotune->setupUi(this); // must be done before auto binding ! - // setWikiURL(""); + setWikiURL("AutoTune+Configuration"); + + // Add HwSettings before auto binding to give priority while saving + addUAVObject("HwSettings"); addAutoBindings(); disableMouseWheelEvents(); - // Whenever any value changes compute new potential stabilization settings - connect(m_autotune->rateTuning, SIGNAL(valueChanged(int)), this, SLOT(recomputeStabilization())); - connect(m_autotune->attitudeTuning, SIGNAL(valueChanged(int)), this, SLOT(recomputeStabilization())); + systemIdentStateObj = dynamic_cast(getObject("SystemIdentState")); + Q_ASSERT(systemIdentStateObj); - addUAVObject("HwSettings"); - addWidget(m_autotune->enableAutoTune); + systemIdentSettingsObj = dynamic_cast(getObject("SystemIdentSettings")); + Q_ASSERT(systemIdentSettingsObj); - RelayTuning *relayTuning = RelayTuning::GetInstance(getObjectManager()); - Q_ASSERT(relayTuning); - if (relayTuning) { - connect(relayTuning, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(recomputeStabilization())); - } - - // Connect the apply button for the stabilization settings - connect(m_autotune->useComputedValues, SIGNAL(pressed()), this, SLOT(saveStabilization())); + addWidget(m_autotune->AutotuneEnable); } -/** - * Apply the stabilization settings computed - */ -void ConfigAutotuneWidget::saveStabilization() +ConfigAutoTuneWidget::~ConfigAutoTuneWidget() { - StabilizationSettings *stabilizationSettings = StabilizationSettings::GetInstance(getObjectManager()); - - Q_ASSERT(stabilizationSettings); - if (!stabilizationSettings) { - return; - } - - // Make sure to recompute in case the other stab settings changed since - // the last time - recomputeStabilization(); - - // Apply this data to the board - stabilizationSettings->setData(stabSettings); - stabilizationSettings->updated(); + // Do nothing } -/** - * Called whenever the gain ratios or measured values - * are changed +/* + * This overridden function refreshes widgets which have no direct relation + * to any of UAVObjects. It saves their dirty state first because update comes + * from UAVObjects, and then restores it. */ -void ConfigAutotuneWidget::recomputeStabilization() -{ - RelayTuningSettings *relayTuningSettings = RelayTuningSettings::GetInstance(getObjectManager()); - - Q_ASSERT(relayTuningSettings); - if (!relayTuningSettings) { - return; - } - - RelayTuning *relayTuning = RelayTuning::GetInstance(getObjectManager()); - Q_ASSERT(relayTuning); - if (!relayTuning) { - return; - } - - StabilizationSettings *stabilizationSettings = StabilizationSettings::GetInstance(getObjectManager()); - Q_ASSERT(stabilizationSettings); - if (!stabilizationSettings) { - return; - } - - RelayTuning::DataFields relayTuningData = relayTuning->getData(); - RelayTuningSettings::DataFields tuningSettingsData = relayTuningSettings->getData(); - stabSettings = stabilizationSettings->getData(); - - // Need to divide these by 100 because that is what the .ui file does - // to get the UAVO - const double gain_ratio_r = m_autotune->rateTuning->value() / 100.0; - const double zero_ratio_r = m_autotune->rateTuning->value() / 100.0; - const double gain_ratio_p = m_autotune->attitudeTuning->value() / 100.0; - const double zero_ratio_p = m_autotune->attitudeTuning->value() / 100.0; - - // For now just run over roll and pitch - for (int i = 0; i < 2; i++) { - if (relayTuningData.Period[i] == 0 || relayTuningData.Gain[i] == 0) { - continue; - } - - double wu = 1000.0 * 2 * M_PI / relayTuningData.Period[i]; // ultimate freq = output osc freq (rad/s) - - double wc = wu * gain_ratio_r; // target openloop crossover frequency (rad/s) - double zc = wc * zero_ratio_r; // controller zero location (rad/s) - double kpu = 4.0f / M_PI / relayTuningData.Gain[i]; // ultimate gain, i.e. the proportional gain for instablity - double kp = kpu * gain_ratio_r; // proportional gain - double ki = zc * kp; // integral gain - - // Now calculate gains for the next loop out knowing it is the integral of - // the inner loop -- the plant is position/velocity = scale*1/s - double wc2 = wc * gain_ratio_p; // crossover of the attitude loop - double kp2 = wc2; // kp of attitude - double ki2 = wc2 * zero_ratio_p * kp2; // ki of attitude - - switch (i) { - case 0: // Roll - - stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KP] = kp; - stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KI] = ki; - stabSettings.RollPI[StabilizationSettings::ROLLPI_KP] = kp2; - stabSettings.RollPI[StabilizationSettings::ROLLPI_KI] = ki2; - break; - case 1: // Pitch - stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP] = kp; - stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI] = ki; - stabSettings.PitchPI[StabilizationSettings::PITCHPI_KP] = kp2; - stabSettings.PitchPI[StabilizationSettings::PITCHPI_KI] = ki2; - break; - } - } - - // Display these computed settings - m_autotune->rollRateKp->setText(QString().number(stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KP])); - m_autotune->rollRateKi->setText(QString().number(stabSettings.RollRatePID[StabilizationSettings::ROLLRATEPID_KI])); - m_autotune->rollAttitudeKp->setText(QString().number(stabSettings.RollPI[StabilizationSettings::ROLLPI_KP])); - m_autotune->rollAttitudeKi->setText(QString().number(stabSettings.RollPI[StabilizationSettings::ROLLPI_KI])); - m_autotune->pitchRateKp->setText(QString().number(stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KP])); - m_autotune->pitchRateKi->setText(QString().number(stabSettings.PitchRatePID[StabilizationSettings::PITCHRATEPID_KI])); - m_autotune->pitchAttitudeKp->setText(QString().number(stabSettings.PitchPI[StabilizationSettings::PITCHPI_KP])); - m_autotune->pitchAttitudeKi->setText(QString().number(stabSettings.PitchPI[StabilizationSettings::PITCHPI_KI])); -} - -void ConfigAutotuneWidget::refreshWidgetsValuesImpl(UAVObject *obj) +void ConfigAutoTuneWidget::refreshWidgetsValuesImpl(UAVObject *obj) { HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); - if (obj == hwSettings) { - bool enabled = (hwSettings->getOptionalModules(HwSettings::OPTIONALMODULES_AUTOTUNE) == HwSettings::OPTIONALMODULES_ENABLED); - m_autotune->enableAutoTune->setChecked(enabled); + TaskInfo *taskInfo = TaskInfo::GetInstance(getObjectManager()); + + bool moduleEnabled = (hwSettings->getOptionalModules(HwSettings::OPTIONALMODULES_AUTOTUNE) == HwSettings::OPTIONALMODULES_ENABLED); + bool moduleRunning = (taskInfo->runningAutoTune() == TaskInfo_Running::True); + + if (obj == systemIdentStateObj) { + QString message; + QString tooltip_message; + QString color; + if (moduleRunning && moduleEnabled) { + message = tr("Running"); + tooltip_message = tr("Module is running because it is enabled to be started at all times"); + color = "green"; + } else if (moduleRunning && !moduleEnabled) { + message = tr("Running"); + tooltip_message = tr("Module is running, due to a Flightmode setup with Autotune on it."); + color = "green"; + } else if (!moduleRunning && moduleEnabled) { + message = tr("Please Reboot"); + tooltip_message = tr("Module is enabled but not running yet, needs a reboot."); + color = "orange"; + } else { + message = tr("Stopped"); + tooltip_message = tr("Module is stopped. It can be enabled by adding an AutoTune flightmode or force the module to be started at all times."); + color = "gray"; + } + + QString style = QString("QLabel { background-color: %1; color: rgb(255, 255, 255); \ + border: 1px solid grey; border-radius: 5; margin:1px; font:bold;}").arg(color); + m_autotune->autotuneModuleStatus->setStyleSheet(style); + m_autotune->autotuneModuleStatus->setText(message); + m_autotune->autotuneModuleStatus->setToolTip(tooltip_message); + } else { + m_autotune->AutotuneEnable->setChecked(moduleEnabled); + // Request TaskInfo update at start + taskInfo->requestUpdate(); } } -void ConfigAutotuneWidget::updateObjectsFromWidgetsImpl() +/* + * This overridden function updates UAVObjects which have no direct relation + * to any of widgets. + */ +void ConfigAutoTuneWidget::updateObjectsFromWidgetsImpl() { + // Save state of the module enable checkbox first. + // Do not use setData() member on whole object, if possible, since it triggers unnecessary UAVObect update. + quint8 enableModule = m_autotune->AutotuneEnable->isChecked() ? + HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED; HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); - quint8 enableModule = (m_autotune->enableAutoTune->isChecked()) ? HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED; - hwSettings->setOptionalModules(HwSettings::OPTIONALMODULES_AUTOTUNE, enableModule); - ; } diff --git a/ground/gcs/src/plugins/config/configautotunewidget.h b/ground/gcs/src/plugins/config/configautotunewidget.h index 7e1d9391a..ba0cf358a 100644 --- a/ground/gcs/src/plugins/config/configautotunewidget.h +++ b/ground/gcs/src/plugins/config/configautotunewidget.h @@ -2,12 +2,13 @@ ****************************************************************************** * * @file configautotunewidget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017. + * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup ConfigPlugin Config Plugin * @{ - * @brief The Configuration Gadget used to adjust or recalculate autotuning + * @brief The Configuration Gadget used to configure autotune module *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify @@ -27,36 +28,29 @@ #ifndef CONFIGAUTOTUNE_H #define CONFIGAUTOTUNE_H -#include "../uavobjectwidgetutils/configtaskwidget.h" -#include "extensionsystem/pluginmanager.h" -#include "uavobjectmanager.h" -#include "uavobject.h" +#include "configtaskwidget.h" -#include "stabilizationsettings.h" -#include "relaytuningsettings.h" -#include "relaytuning.h" +class SystemIdentState; +class SystemIdentSettings; -#include -#include +class Ui_AutoTuneWidget; -class Ui_AutotuneWidget; - -class ConfigAutotuneWidget : public ConfigTaskWidget { +class ConfigAutoTuneWidget : public ConfigTaskWidget { Q_OBJECT -public: - explicit ConfigAutotuneWidget(QWidget *parent = 0); -private: - Ui_AutotuneWidget *m_autotune; - StabilizationSettings::DataFields stabSettings; +public: + ConfigAutoTuneWidget(QWidget *parent = 0); + ~ConfigAutoTuneWidget(); protected: virtual void refreshWidgetsValuesImpl(UAVObject *obj); virtual void updateObjectsFromWidgetsImpl(); -private slots: - void recomputeStabilization(); - void saveStabilization(); +private: + Ui_AutoTuneWidget *m_autotune; + + SystemIdentState *systemIdentStateObj; + SystemIdentSettings *systemIdentSettingsObj; }; #endif // CONFIGAUTOTUNE_H diff --git a/ground/gcs/src/plugins/config/configgadgetwidget.cpp b/ground/gcs/src/plugins/config/configgadgetwidget.cpp index 03ae0cd23..b83f0a582 100644 --- a/ground/gcs/src/plugins/config/configgadgetwidget.cpp +++ b/ground/gcs/src/plugins/config/configgadgetwidget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configgadgetwidget.cpp - * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015-2017. * E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @addtogroup GCSPlugins GCS Plugins * @{ @@ -37,6 +37,7 @@ #include "configtxpidwidget.h" #include "configrevohwwidget.h" #include "config_cc_hw_widget.h" +#include "configautotunewidget.h" #include "configoplinkwidget.h" #include "configrevowidget.h" #include "configrevonanohwwidget.h" @@ -130,6 +131,12 @@ ConfigGadgetWidget::ConfigGadgetWidget(QWidget *parent) : QWidget(parent) static_cast(widget)->bind(); stackWidget->insertTab(ConfigGadgetWidget::TxPid, widget, *icon, QString("TxPID")); + icon = new QIcon(); + icon->addFile(":/configgadget/images/autotune_normal.png", QSize(), QIcon::Normal, QIcon::Off); + icon->addFile(":/configgadget/images/autotune_selected.png", QSize(), QIcon::Selected, QIcon::Off); + widget = new DefaultConfigWidget(this, tr("AutoTune Configuration")); + stackWidget->insertTab(ConfigGadgetWidget::AutoTune, widget, *icon, QString("AutoTune")); + icon = new QIcon(); icon->addFile(":/configgadget/images/pipx-normal.png", QSize(), QIcon::Normal, QIcon::Off); icon->addFile(":/configgadget/images/pipx-selected.png", QSize(), QIcon::Selected, QIcon::Off); @@ -223,6 +230,9 @@ void ConfigGadgetWidget::onAutopilotConnect() widget = new ConfigRevoWidget(this); widget->bind(); stackWidget->replaceTab(ConfigGadgetWidget::Sensors, widget); + widget = new ConfigAutoTuneWidget(this); + widget->bind(); + stackWidget->replaceTab(ConfigGadgetWidget::AutoTune, widget); if (board == 0x0903 || board == 0x0904) { widget = new ConfigRevoHWWidget(this); } else if (board == 0x0905) { @@ -236,6 +246,9 @@ void ConfigGadgetWidget::onAutopilotConnect() widget = new ConfigRevoWidget(this); widget->bind(); stackWidget->replaceTab(ConfigGadgetWidget::Sensors, widget); + widget = new ConfigAutoTuneWidget(this); + widget->bind(); + stackWidget->replaceTab(ConfigGadgetWidget::AutoTune, widget); widget = new ConfigSparky2HWWidget(this); widget->bind(); stackWidget->replaceTab(ConfigGadgetWidget::Hardware, widget); @@ -278,6 +291,9 @@ void ConfigGadgetWidget::onAutopilotDisconnect() widget = new DefaultConfigWidget(this, tr("Hardware")); stackWidget->replaceTab(ConfigGadgetWidget::Hardware, widget); + + widget = new DefaultConfigWidget(this, tr("AutoTune")); + stackWidget->replaceTab(ConfigGadgetWidget::AutoTune, widget); } void ConfigGadgetWidget::onOPLinkConnect() diff --git a/ground/gcs/src/plugins/config/configgadgetwidget.h b/ground/gcs/src/plugins/config/configgadgetwidget.h index 9997ba8d4..dc9bfac5e 100644 --- a/ground/gcs/src/plugins/config/configgadgetwidget.h +++ b/ground/gcs/src/plugins/config/configgadgetwidget.h @@ -38,7 +38,7 @@ class ConfigGadgetWidget : public QWidget { Q_OBJECT public: - enum WidgetTabs { Hardware = 0, Aircraft, Input, Output, Sensors, Stabilization, CameraStabilization, TxPid, OPLink }; + enum WidgetTabs { Hardware = 0, Aircraft, Input, Output, Sensors, Stabilization, AutoTune, CameraStabilization, TxPid, OPLink }; ConfigGadgetWidget(QWidget *parent = 0); ~ConfigGadgetWidget(); diff --git a/shared/uavobjectdefinition/systemidentsettings.xml b/shared/uavobjectdefinition/systemidentsettings.xml index c6aa3d880..b86e8e963 100644 --- a/shared/uavobjectdefinition/systemidentsettings.xml +++ b/shared/uavobjectdefinition/systemidentsettings.xml @@ -56,23 +56,19 @@ - + - - - - + + - - - - - - - + + + + + diff --git a/shared/uavobjectdefinition/systemidentstate.xml b/shared/uavobjectdefinition/systemidentstate.xml index b0269c201..a23d339c7 100644 --- a/shared/uavobjectdefinition/systemidentstate.xml +++ b/shared/uavobjectdefinition/systemidentstate.xml @@ -12,7 +12,7 @@ - +