iCub-main
calibrationwindow.h
Go to the documentation of this file.
1 #ifndef CALIBRATIONWINDOW_H
2 #define CALIBRATIONWINDOW_H
3 
4 #include <QMainWindow>
5 #include <QSlider>
6 #include <QLineEdit>
7 #include <QTimer>
8 #include <downloader.h>
9 #include "firmwareupdatercore.h"
10 #include <QTableWidgetItem>
11 #include <QProgressBar>
12 #include "customtreewidgetitem.h"
13 #include "customspinbox.h"
14 #include "customcombobox.h"
15 
16 #define MARCO_ACCAME_19SEP2018
17 
18 namespace Ui {
19 class CalibrationWindow;
20 }
21 
22 class CalibrationWindow : public QMainWindow
23 {
24  Q_OBJECT
25 
26 public:
27  explicit CalibrationWindow(FirmwareUpdaterCore *core, icubCanProto_boardType_t b, CustomTreeWidgetItem *item, QWidget *parent = 0);
29 
30 
31 protected:
32  void closeEvent(QCloseEvent *e);
33  void setCalibBias();
34  void resetCalibBias();
35  void setCurrBias();
36  void resetCurrBias();
37  void applyParameters();
38  void autoAdjust();
39  void setSerial();
40  void saveToEeprom();
41  void Clear_Statistics();
42  void setOffset(int chan, int value);
43  void setCalibration();
44  void loadCalibrationFile(QString fileName);
45  void saveCalibrationFile(QString filePath);
46  void importCalibrationFile(QString fileName);
47  //bool calibration_load_v2 (char* filename, int selected_bus, int selected_id, int index);
48  bool calibration_load_v3 (char* filename, int selected_bus, int selected_id, int index, int regset);
49  void useMatrix(int, bool boot);
50  void resetCalibration();
51 
52  bool SetDefaultRegulationSet(int regset, bool alsoserialnumber = false);
53  void Clear_AllRegulations();
54  void Clear_Regulation();
55 
56 #if defined(MARCO_ACCAME_19SEP2018)
57  void importCalibrationFileHEX(QString fileName);
58 #endif
59 
60  static void logger(void *caller, const std::string &msg);
61 
62 private:
63 
64  static const strain2_ampl_discretegain_t defaultStrain2AmplGains[6];
65  static const uint16_t defaultStrain2AmplOffsets[6];
66  static const uint16_t defaultStrain1DACoffsets[6];
67 
68  const int currentMatrixIndex = 0;
69  Ui::CalibrationWindow *ui;
71  FirmwareUpdaterCore *core;
72  icubCanProto_boardType_t boardtype;
73  bool offsetSliderPressed[6];
74  unsigned int adc[6];
75  signed int maxadc[6];
76  signed int minadc[6];
77  signed int maxft[6];
78  signed int minft[6];
79  bool first_time;
80  bool refresh_serialnumber;
81  unsigned int offset[6];
82  unsigned int amp_gain1[6];
83  unsigned int amp_gain2[6];
84  int ch[6];
85  int calib_bias[6];
86  int curr_bias[6];
87  uint16_t amp_offsets[6];
88  float amp_gains[6];
89  strain2_ampl_regs_t amp_registers[6];
90  unsigned int matrix[3][6][6];
91  unsigned int calib_matrix[3][6][6];
92  unsigned int full_scale_calib[3][6];
93  unsigned int calibration_value;
94  unsigned int calib_const[3];
95  unsigned int full_scale_const[3][6];
96  char serial_no[8];
97  int selected;
98  bool fullScaleChanged;
99  bool matrix_changed[3];
100  bool serial_number_changed;
101  bool something_changed;
102  bool eeprom_saved_status;
103  //QList<QSlider*>slider_offset;
104  QList<CustomSpinBox*>slider_offset;
105  QList<QLineEdit*>matrixGain;
106  QList<QTableWidget*>matrices;
107  QList<QTableWidget*>fullScales;
108  QTimer *timer;
109  int bus;
110  int id;
111  QMutex mutex;
112  QMutex sliderMutex;
113  QProgressBar *progress;
114  bool keepRunning;
115  volatile bool clearStats;
116 private slots:
117  void onTargetValueChanged(int);
118  void onTabMatrixCahnged(int);
119  void onTimeout();
120  void onMatrixChanged(QTableWidgetItem*);
121  void onSerialChanged(QString);
122  void onLoading(bool);
123  void onSetText(QLineEdit*,QString text);
124  void onSetText(QTableWidgetItem*,QString text);
125  void onOffsetSpinnerValue(CustomSpinBox *spinner, int value);
126  void onSetCalibBias(bool click);
127  void onResetCalibBias(bool click);
128  void onSetCurrBias(bool click);
129  void onResetCurrBias(bool click);
130  void onSetSerial(bool click);
131  void onSetSerialChanged(bool);
132  void onResetCalibMatrix(bool);
133  //void onUseMatrixChanged(int);
134  void onSetMatrix(int index);
135  void onSetFullScale();
136  void onSaveToEeprom(bool click);
137  void onClear_Statistics(bool click);
138  void onClear_FullRegulation(bool click);
139  void onClear_Regulation(bool click);
140  void onSetCalibration(bool click);
141  void onLoadCalibrationFile(bool click);
142  void onSaveCalibrationFile(bool click);
143  void onImportCalibrationFile(bool click);
144  void resetMatricesState(int index = -1);
145  void onUpdateTitle();
146  void onOffsetSliderPressed();
147  void onOffsetSliderReleased();
148  void onClearLog();
149  void onAppendLogMsg(QString);
150  void onOffsetEditingFinished();
151  void onParametersApply(bool);
152  void onParametersClear(bool);
153  void onCheckAutoTune(bool);
154  void onApplyDone();
155  void onDigitalRegulation(bool);
156  void onChangeRegSet(int regSet);
157  void onChangeRegSetBoot(int regset);
158  void onSetTableVisible(QTableWidget*,bool);
159 signals:
160  void loading(bool = true);
161  void setText(QLineEdit*,QString text);
162  void setText(QTableWidgetItem*,QString text);
163  void setTableVisible(QTableWidget*,bool);
165  void setSerialChanged(bool);
166  void setMatrix(int index);
167  void setFullScale();
168  void resetMatrices(int index = -1);
169  void updateTitle();
170  void appendLogMsg(QString);
171  void applyDone();
172 
173 
174 
175 };
176 
177 #endif // CALIBRATIONWINDOW_H
bool SetDefaultRegulationSet(int regset, bool alsoserialnumber=false)
void setMatrix(int index)
void appendLogMsg(QString)
void setTableVisible(QTableWidget *, bool)
void resetMatrices(int index=-1)
bool calibration_load_v3(char *filename, int selected_bus, int selected_id, int index, int regset)
void setOffsetSliderValue(CustomSpinBox *, int value)
void setOffset(int chan, int value)
void closeEvent(QCloseEvent *e)
void importCalibrationFile(QString fileName)
void loading(bool=true)
void setText(QLineEdit *, QString text)
CalibrationWindow(FirmwareUpdaterCore *core, icubCanProto_boardType_t b, CustomTreeWidgetItem *item, QWidget *parent=0)
void setText(QTableWidgetItem *, QString text)
void setSerialChanged(bool)
void importCalibrationFileHEX(QString fileName)
void loadCalibrationFile(QString fileName)
void useMatrix(int, bool boot)
static void logger(void *caller, const std::string &msg)
void saveCalibrationFile(QString filePath)
strain2_ampl_discretegain_t
Definition: downloader.h:105