dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
calibration.h
Go to the documentation of this file.
1 
8 /*
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, see <http://www.gnu.org/licenses/>
21  */
22 #ifndef CALIBRATION_H
23 #define CALIBRATION_H
24 
25 #include <config/config_global.h>
29 #include <uavobjects/uavobject.h>
30 #include <config/tempcompcurve.h>
31 
32 #include <QObject>
33 #include <QTimer>
34 #include <QString>
35 
46 class CONFIG_EXPORT Calibration : public QObject
47 {
48  Q_OBJECT
49 
50 public:
51  explicit Calibration();
52  ~Calibration();
53 
54  void initialize(bool calibrateAccels, bool calibrateMags);
55 
56 private:
57  enum CALIBRATION_STATE {
58  IDLE,
59  LEVELING,
60  YAW_ORIENTATION,
61  SIX_POINT_WAIT1,
62  SIX_POINT_COLLECT1,
63  SIX_POINT_WAIT2,
64  SIX_POINT_COLLECT2,
65  SIX_POINT_WAIT3,
66  SIX_POINT_COLLECT3,
67  SIX_POINT_WAIT4,
68  SIX_POINT_COLLECT4,
69  SIX_POINT_WAIT5,
70  SIX_POINT_COLLECT5,
71  SIX_POINT_WAIT6,
72  SIX_POINT_COLLECT6,
73  GYRO_TEMP_CAL
74  } calibration_state;
75 
76 public slots:
78  void doStartBiasAndLeveling();
79 
81  void doStartNoBiasLeveling();
82 
84  void doStartOrientation();
85 
87  void doStartSixPoint();
88 
90  void doCancelSixPoint();
91 
93  void doSaveSixPointPosition();
94 
96  void doStartTempCal();
97 
99  void doAcceptTempCal();
100 
102  void doCancelTempCalPoint();
103 
105  void configureTempCurves(TempCompCurve *x, TempCompCurve *y, TempCompCurve *z);
106 
107 private slots:
109  void dataUpdated(UAVObject *);
110 
112  void timeout();
113 
114 public slots:
116  void setTempCalRange(int r);
117 
118 signals:
120  void calibrationBusy(bool busy);
122  void toggleControls(bool enable);
123 
125  void toggleSavePosition(bool enable);
126 
128  void updatePlane(int position);
129 
131  void showSixPointMessage(QString message);
132 
134  void showYawOrientationMessage(QString message);
135 
137  void showLevelingMessage(QString message);
138 
140  void yawOrientationProgressChanged(int);
141 
143  void levelingProgressChanged(int);
144 
146  void sixPointProgressChanged(int);
147 
149  void showTempCalMessage(QString message);
150 
152  void tempCalProgressChanged(int);
153 
155  void calibrationCompleted();
156 
157 private:
159  void setMetadata(QMap<QString, UAVObject::Metadata> metaList);
160 
162  void doStartLeveling();
163 
165  UAVObjectManager *getObjectManager();
166 
168  UAVObjectUtilManager *getObjectUtilManager();
169 
171  void assignUpdateRate(UAVObject *obj, quint32 updatePeriod);
172 
173  QTimer timer;
174 
176  bool calibrateMags;
177 
179  bool calibrateAccels;
180 
182  bool zeroVertical;
183 
185  double accelLength;
186 
188  QMap<QString, UAVObject::Metadata> originalMetaData;
189 
191  QMap<QString, UAVObject::Metadata> slowedDownMetaDataList;
192 
193  QList<double> gyro_accum_x;
194  QList<double> gyro_accum_y;
195  QList<double> gyro_accum_z;
196  QList<double> gyro_accum_temp;
197  QList<double> accel_accum_x;
198  QList<double> accel_accum_y;
199  QList<double> accel_accum_z;
200  QList<double> mag_accum_x;
201  QList<double> mag_accum_y;
202  QList<double> mag_accum_z;
203 
204  double gyro_data_x[6], gyro_data_y[6], gyro_data_z[6];
205  double accel_data_x[6], accel_data_y[6], accel_data_z[6];
206  double mag_data_x[6], mag_data_y[6], mag_data_z[6];
207 
208  static const int NUM_SENSOR_UPDATES_LEVELING = 300;
209  static const int NUM_SENSOR_UPDATES_YAW_ORIENTATION = 300;
210  static const int NUM_SENSOR_UPDATES_SIX_POINT = 100;
211  static const int SENSOR_UPDATE_PERIOD = 25;
212  static const int NON_SENSOR_UPDATE_PERIOD = 0;
213 
214  double min_temperature_range;
215  double boardRotationMatrix[3][3];
216  double initialAccelsScale[3];
217  double initialAccelsBias[3];
218  double initialMagsScale[3];
219  double initialMagsBias[3];
220 
221  TempCompCurve *xCurve;
222  TempCompCurve *yCurve;
223  TempCompCurve *zCurve;
224 
225 protected:
226  enum sensor_type { ACCEL, GYRO, MAG };
227 
229  void connectSensor(sensor_type sensor, bool connect);
230 
232  bool storeSixPointMeasurement(UAVObject *obj, int position);
233 
235  bool storeYawOrientationMeasurement(UAVObject *obj);
236 
238  bool storeLevelingMeasurement(UAVObject *obj);
239 
241  int computeScaleBias();
242 
243  int SixPointInConstFieldCal(double ConstMag, double x[6], double y[6], double z[6], double S[3],
244  double b[3]);
245 
247  void rotate_vector(double R[3][3], const double vec[3], double vec_out[3], bool transpose);
248 
250  void Euler2R(double rpy[3], double Rbe[3][3]);
251 
253  static inline double listMean(QList<double> list)
254  {
255  return std::accumulate(list.begin(), list.end(), 0.0) / list.size();
256  }
257 
259  void resetSensorCalibrationToOriginalValues();
260 
262  bool storeTempCalMeasurement(UAVObject *obj);
263 
265  int computeTempCal();
266 
268  void updateTempCompCalibrationDisplay();
269 };
270 
271 #endif // CALIBRATION_H
The Calibration class is a UI free algorithm that can be connected to any interfaces. As such it only communicates with the UI via signals and slots, but has no direct handles to any particular controls or widgets.
Definition: calibration.h:46
static double listMean(QList< double > list)
Compute the mean value of a list.
Definition: calibration.h:253
z
Definition: OPPlots.m:102
x
Definition: OPPlots.m:100
y
Definition: OPPlots.m:101