From 68597d51cc9d85dc465f6d2ddf7dd06aeedb676f Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Sun, 2 Jul 2017 01:27:33 +0200 Subject: [PATCH] LP-399 Add GUI to Autotune module --- ground/gcs/src/plugins/config/autotune.ui | 2183 ++++++++++++----- ground/gcs/src/plugins/config/config.pro | 3 + .../plugins/config/configautotunewidget.cpp | 207 +- .../src/plugins/config/configautotunewidget.h | 38 +- .../src/plugins/config/configgadgetwidget.cpp | 18 +- .../src/plugins/config/configgadgetwidget.h | 2 +- 6 files changed, 1665 insertions(+), 786 deletions(-) diff --git a/ground/gcs/src/plugins/config/autotune.ui b/ground/gcs/src/plugins/config/autotune.ui index 2cfadba55..7498b10ef 100644 --- a/ground/gcs/src/plugins/config/autotune.ui +++ b/ground/gcs/src/plugins/config/autotune.ui @@ -1,7 +1,7 @@ - AutotuneWidget - + AutoTuneWidget + 0 @@ -10,131 +10,23 @@ 688 - - - 0 - 0 - - Form - - - 6 - - - 12 - - - 12 - - - 12 - - - 12 - + - - - 0 + + + Qt::NoFocus - + - 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,470 +41,64 @@ 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 - 0 + -74 0 - 526 - 510 + 925 + 724 - - - 0 - 0 - - - - true - - - - 12 - - - 12 - - - 12 - - - 12 - - - 12 - - - - - Tuning Aggressiveness - - - - - - 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 - - - - - - - - - - - Measured Properties - - - - - - Roll: - - - - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - objname:RelayTuning - fieldname:Period - 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 + Module Control - - - - - RateKi - - - - - - - AttitudeKp - - - - - - - 0 - - - - - - - Pitch - - - - - - - RateKp - - - - - - - 0 - - - - - - - AttitudeKi - - - - - - - Roll - - - - - - - 0 - - - - - - - 0 - - - - - - - 0 - - - - - - - 0 - - - - - - - 0 - - - - - - - 0 - - - - - - - - - - - - + - - - - - - - - Apply Computed Values - - - - - - - Step Size - - - Qt::AlignCenter - - - - - - - Qt::Horizontal - - - - objname:RelayTuningSettings - fieldname:Amplitude - scale:0.01 - haslimits:no - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - The Apply and Save buttons below save the autotuning settings which -will alter settings for the next autotuning flight - - - Qt::AlignCenter - - - - + + + + 900 + 16777215 + + + + Qt::StrongFocus + + + Allow AutoTune module to be started all time, without any AutoTune set in one FlightMode. + + + Enable AutoTune module + + + + + + + After enabling the module, you must power cycle before using and configuring. + + + true + + - + Qt::Vertical @@ -620,7 +106,1496 @@ will alter settings for the next autotuning flight 20 - 77 + 40 + + + + + + + + + 430 + 0 + + + + + 900 + 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 + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Bias + element:Roll + + + + + + + + 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 + + + + + + + + Tau + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Bias Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Yaw + + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Bias + element:Pitch + + + + + + + + Beta Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Bias Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Noise Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Bias Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Roll + + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Yaw + + + + + + + + Beta Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Bias + element:Yaw + + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Pitch + + + + + + + + Noise Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Noise + element:Roll + + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentState + fieldname:Beta + element:Pitch + + + + + + + + Beta Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Noise Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Number of gyro samples that were dropped (should be zero) + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0 + + + 0.000000000000000 + + + 99999.000000000000000 + + + + objname:SystemIdentState + fieldname:NumSpilledPts + + + + + + + + Gyro Dropped + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 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 + + + + + + + + Gyro Samples + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Measured delay from gyro read to inner loop in seconds + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 6 + + + 0.000000000000000 + + + 10.000000000000000 + + + + objname:SystemIdentState + fieldname:GyroReadTimeAverage + + + + + + + + Gyro Average + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Period (ms) + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0.000000000000000 + + + 10.000000000000000 + + + + objname:SystemIdentState + fieldname:Period + + + + + + + + Period + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + HoverThrottle + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Throttle level to hover (%) + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + 0.000000000000000 + + + 1.000000000000000 + + + + objname:SystemIdentState + fieldname:HoverThrottle + + + + + + + + Complete + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 25 + + + + False + + + true + + + Qt::AlignCenter + + + true + + + + + + + + + + + 430 + 0 + + + + + 900 + 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 + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Roll + + + + + + + + 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:SystemIdentSettings + fieldname:Tau + scale:1 + + + + + + + + Tau + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Beta Roll + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Yaw + + + + + + + + Beta Pitch + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + (Natural log of) Measured control gain + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1000.000000000000000 + + + 1000.000000000000000 + + + + objname:SystemIdentSettings + fieldname:Beta + element:Pitch + + + + + + + + Beta Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + true + + + + 0 + 0 + + + + + 900 + 16777215 + + + + + 50 + false + + + + Configuration + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Reset Yaw factors to default values + + + false + + + + + + Default + + + + button:default + buttongroup:20 + + + + + + + + Manual is direct control, AltitudeVario helps to maintain altitude. + + + + objname:SystemIdentSettings + fieldname:ThrustControl + buttongroup:20 + + + + + + + + + + Minimum Yaw to Pitch/Roll ratio limit. + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + + objname:SystemIdentSettings + fieldname:YawToRollPitchPIDRatioMin + buttongroup:20 + + + + + + + + Maximum Yaw to Pitch/Roll ratio limit. + + + 1 + + + 10.000000000000000 + + + 0.100000000000000 + + + + objname:SystemIdentSettings + fieldname:YawToRollPitchPIDRatioMax + buttongroup:20 + + + + + + + + + + Thrust Control + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + OuterLoop Kp Limit + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 50 + false + + + + Calculate Yaw + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Set a limiting upper value for the OuterLoop Kp. + + + 1 + + + + objname:SystemIdentSettings + fieldname:OuterLoopKpSoftClamp + buttongroup:20 + + + + + + + + 0 + + + 4 + + + + + + 60 + 22 + + + + + 60 + 22 + + + + Smooth - Quick value 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 + + + + 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; + + + Smooth + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 120 + 29 + + + + + 120 + 16777215 + + + + 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 + 30 + + + + Smooth - Quick value for PID calc based on AutoTune measurements. + + + -10 + + + 10 + + + 1 + + + 5 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 5 + + + + objname:SystemIdentSettings + fieldname:SmoothQuickValue + scale:0.1 + buttongroup:20 + + + + + + + + + 0 + 0 + + + + + 120 + 29 + + + + + 120 + 16777215 + + + + 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 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 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 + + + + + + + + + 250 + 0 + + + + Yaw to Roll/Pitch PID Ratio Limits + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Choose Accessory or FMS 3x toggle method with 3, 5, 7 positions. + + + + 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 + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::MinimumExpanding + + + + 40 + 20 @@ -634,22 +1609,19 @@ will alter settings for the next autotuning flight - + 4 - + Qt::Horizontal - - QSizePolicy::Expanding - - 13 - 25 + 40 + 5 @@ -664,8 +1636,8 @@ will alter settings for the next autotuning flight - 25 - 25 + 0 + 0 @@ -674,6 +1646,9 @@ will alter settings for the next autotuning flight 25 + + Qt::NoFocus + @@ -687,82 +1662,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 +1705,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..2e077bf64 100644 --- a/ground/gcs/src/plugins/config/configautotunewidget.cpp +++ b/ground/gcs/src/plugins/config/configautotunewidget.cpp @@ -1,173 +1,100 @@ +/** + **************************************************************************************** + * + * @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 #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"); addAutoBindings(); + addUAVObject("HwSettings"); + 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 +ConfigAutoTuneWidget::~ConfigAutoTuneWidget() +{ + // Do nothing +} + +/* + * 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::saveStabilization() +void ConfigAutoTuneWidget::refreshWidgetsValuesImpl(UAVObject *obj) { - StabilizationSettings *stabilizationSettings = StabilizationSettings::GetInstance(getObjectManager()); + if (obj == systemIdentStateObj) { + m_autotune->stateComplete->setText((systemIdentStateObj->getComplete() == SystemIdentState::COMPLETE_TRUE) ? tr("True") : tr("False")); + } else { + HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); - Q_ASSERT(stabilizationSettings); - if (!stabilizationSettings) { - return; + m_autotune->AutotuneEnable->setChecked(hwSettings->getOptionalModules(HwSettings::OPTIONALMODULES_AUTOTUNE) == HwSettings::OPTIONALMODULES_ENABLED); } - - // 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(); } -/** - * Called whenever the gain ratios or measured values - * are changed +/* + * This overridden function updates UAVObjects which have no direct relation + * to any of widgets. */ -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::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()); - if (obj == hwSettings) { - bool enabled = (hwSettings->getOptionalModules(HwSettings::OPTIONALMODULES_AUTOTUNE) == HwSettings::OPTIONALMODULES_ENABLED); - m_autotune->enableAutoTune->setChecked(enabled); - } -} - -void ConfigAutotuneWidget::updateObjectsFromWidgetsImpl() -{ - 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..5af5c076f 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, CameraStabilization, TxPid, AutoTune, OPLink }; ConfigGadgetWidget(QWidget *parent = 0); ~ConfigGadgetWidget();