dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
configautotunewidget.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 #ifndef CONFIGAUTOTUNE_H
28 #define CONFIGAUTOTUNE_H
29 
30 #include "../uavobjectwidgetutils/configtaskwidget.h"
33 #include "uavobjects/uavobject.h"
34 #include "actuatorsettings.h"
35 #include "stabilizationsettings.h"
36 #include "systemident.h"
37 
38 #include <QChart>
39 #include <QLineSeries>
40 #include <QTimer>
41 #include <QWidget>
42 #include <QWizardPage>
43 #include <QtNetwork/QNetworkReply>
44 
45 QT_CHARTS_USE_NAMESPACE
46 
47 #include "ui_autotune.h"
48 #include "ui_autotunebeginning.h"
49 #include "ui_autotuneproperties.h"
50 #include "ui_autotunesliders.h"
51 #include "ui_autotunefinalpage.h"
52 #include "configgadgetwidget.h"
53 
55 {
56  bool valid;
57 
58  QByteArray data;
59 
60  // Parameters
61  float tau[3];
62  float beta[3];
63  float bias[3];
64  float noise[3];
65 
66  // Inputs
67  float damping;
68  float noiseSens;
69 
70  // Computation status
71  bool converged;
73 
74  // Results...
75  // -1 means "not calculated"; (don't change)
76  float kp[3];
77  float ki[3];
78  float kd[3];
79 
81  float naturalFreq;
82 
83  float outerKp;
84  float outerKi;
85 
86  float vertSpeedKp;
87  float vertSpeedKi;
88  float vertPosKp;
89 
90  QLineSeries *model[3];
91  QLineSeries *actual[3];
92 };
93 
94 class AutotuneBeginningPage : public QWizardPage, private Ui::AutotuneBeginning
95 {
96  Q_OBJECT
97 
98 public:
99  explicit AutotuneBeginningPage(QWidget *parent, bool autoOpened,
100  AutotunedValues *autoValues);
101 
102  void initializePage();
103 
104  bool isComplete() const;
105 
106 private:
107  QString tuneValid(bool *okToContinue) const;
108 
109  AutotunedValues *tuneState;
110  bool autoOpened;
111  bool dataValid;
112 
113  /* Need a better place for all of these implementation things. But
114  * for now this is at least encapsulated and won't get tainted
115  * elsewhere
116  */
117  const uint64_t ATFLASH_MAGIC = 0x656e755480008041;
118 
119  struct at_flash_header
120  {
121  uint64_t magic;
122  uint16_t wiggle_points;
123  uint16_t aux_data_len;
124  uint16_t sample_rate;
125 
126  // Consider total number of averages here
127  uint16_t resv;
128  };
129 
130  struct at_measurement
131  {
132  float y[3]; /* Gyro measurements */
133  float u[3]; /* Actuator desired */
134  };
135 
136  struct at_flash
137  {
138  struct at_flash_header hdr;
139 
140  struct at_measurement data[];
141  };
142 
143  bool processAutotuneData();
144  void biquadFilter(float cutoff, int pts, QVector<float> &data);
145  float getSampleDelay(int pts, const QVector<float> &delayed,
146  const QVector<float> &orig, int seriesCutoff = 4);
147 
148 private slots:
149  void doDownloadAndProcess();
150 
151 };
152 
153 class AutotuneMeasuredPropertiesPage : public QWizardPage, private Ui::AutotuneProperties
154 {
155  Q_OBJECT
156 
157 public:
158  explicit AutotuneMeasuredPropertiesPage(QWidget *parent,
159  AutotunedValues *autoValues);
160  void initializePage();
161 
162 private:
163  AutotunedValues *tuneState;
164  QChart *makeChart(int axis);
165 };
166 
167 class AutotuneSlidersPage : public QWizardPage, private Ui::AutotuneSliders
168 {
169  Q_OBJECT
170 
171 public:
172  explicit AutotuneSlidersPage(QWidget *parent,
173  AutotunedValues *autoValues);
174 
175  bool isComplete() const;
176 
177  void initializePage();
178 
179 private:
180  AutotunedValues *tuneState;
181 
182  void setText(QLabel *lbl, double value, int precision);
183 
184 private slots:
185  void computeThrust();
186  void compute();
187  void resetSliders();
188 };
189 
190 class AutotuneFinalPage : public QWizardPage, public Ui::AutotuneFinalPage
191 {
192  Q_OBJECT
193 
194 public:
195  explicit AutotuneFinalPage(QWidget *parent);
196 };
197 
199 {
200  Q_OBJECT
201 public:
202  explicit ConfigAutotuneWidget(ConfigGadgetWidget *parent = nullptr);
203 
204 private:
205  Ui_AutotuneWidget *m_autotune;
206  UAVObjectUtilManager *utilMngr;
207  ConfigGadgetWidget *parentConfigWidget;
208  static const QString databaseUrl;
209 
210  QString tuneValid(AutotunedValues &data, bool *okToContinue) const;
211 
212  QJsonDocument getResultsJson(AutotuneFinalPage *autotuneShareForm, AutotunedValues *av);
213 
214  void stuffShareForm(AutotuneFinalPage *autotuneShareForm);
215  void persistShareForm(AutotuneFinalPage *autotuneShareForm);
216  void checkNewAutotune();
217 
218 private slots:
219  void openAutotuneDialog();
220  void openAutotuneDialog(bool autoOpened, AutotunedValues *precalc_vals = nullptr);
221 
222  void openAutotuneFile();
223 
224  void atConnected();
225  void atDisconnected();
226 };
227 
228 #endif // CONFIGAUTOTUNE_H
AutotuneSlidersPage(QWidget *parent, AutotunedValues *autoValues)
QLineSeries * model[3]
DataFields data
AutotuneFinalPage(QWidget *parent)
ConfigAutotuneWidget(ConfigGadgetWidget *parent=nullptr)
AutotuneBeginningPage(QWidget *parent, bool autoOpened, AutotunedValues *autoValues)
AutotuneMeasuredPropertiesPage(QWidget *parent, AutotunedValues *autoValues)
QLineSeries * actual[3]
y
Definition: OPPlots.m:101