Skip to content

Commit 3a54cd8

Browse files
committed
admt: Implemented continuous calibration
- Migrating styles to separate .qss - Changed status LED behavior Signed-off-by: John Lloyd Juanillo <[email protected]>
1 parent 53dac52 commit 3a54cd8

15 files changed

+1419
-664
lines changed

gui/style/json/Harmonic dark.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"interactive_primary_hover": "#C6D8F6",
1111
"interactive_primary_pressed": "#abc4ed",
1212
"interactive_primary_disabled": "#0067B9",
13+
"interactive_primary_faint": "#00549A",
1314
"interactive_secondary_idle": "#92BEFC",
1415
"interactive_secondary_hover": "#C6D8F6",
1516
"interactive_secondary_pressed": "#abc4ed",
1617
"interactive_secondary_disabled": "#4B545D",
18+
"interactive_silent_hover": "#3A424B",
1719
"content_default": "#FFFFFF",
1820
"content_subtle": "#B7BBC3",
1921
"content_silent": "#848B95",

gui/style/json/Harmonic light.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"interactive_primary_hover": "#00427A",
1111
"interactive_primary_pressed": "#003969",
1212
"interactive_primary_disabled": "#92BEFC",
13+
"interactive_primary_faint": "#C6D8F6",
1314
"interactive_secondary_idle": "#0067B9",
1415
"interactive_secondary_hover": "#00427A",
1516
"interactive_secondary_pressed": "#003969",
1617
"interactive_secondary_disabled": "#c1c3c7",
18+
"interactive_silent_hover": "#D5D8DC",
1719
"content_default": "#101820",
1820
"content_subtle": "#5E6773",
1921
"content_silent": "#9FA4AD",

gui/style/json/Scopy.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"interactive_primary_hover": "#697EFF",
1111
"interactive_primary_pressed": "#7084fa",
1212
"interactive_primary_disabled": "#2E3874",
13+
"interactive_primary_faint": "#00549A",
1314
"interactive_secondary_idle": "#5b5b6b",
1415
"interactive_secondary_hover": "#535361",
1516
"interactive_secondary_pressed": "#4c4c59",
1617
"interactive_secondary_disabled": "#35353d",
18+
"interactive_silent_hover": "#3A424B",
1719
"content_default": "#e1e1e3",
1820
"content_subtle": "#bac2cc",
1921
"content_silent": "#848491",

plugins/admt/include/admt/admtcontroller.h

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <QObject>
3131
#include <QString>
32+
#include <QElapsedTimer>
3233

3334
#include <iioutil/connectionprovider.h>
3435
#include <pluginbase/statusbarmanager.h>
@@ -53,7 +54,16 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
5354
ADMTController(QString uri, QObject *parent = nullptr);
5455
~ADMTController();
5556

56-
int HAR_MAG_1, HAR_MAG_2, HAR_MAG_3, HAR_MAG_8 ,HAR_PHASE_1 ,HAR_PHASE_2 ,HAR_PHASE_3 ,HAR_PHASE_8;
57+
int HAR_MAG_1, HAR_MAG_2, HAR_MAG_3, HAR_MAG_8 ,HAR_PHASE_1 ,HAR_PHASE_2 ,HAR_PHASE_3 ,HAR_PHASE_8,
58+
sampleCount = 0;
59+
60+
bool stopStream = false;
61+
62+
double streamedValue = 0.0;
63+
QVector<double> streamBufferedValues;
64+
QVector<uint32_t> streamBufferedIntervals;
65+
66+
QElapsedTimer elapsedStreamTimer;
5767

5868
vector<double> angle_errors_fft_pre,
5969
angle_errors_fft_phase_pre,
@@ -171,6 +181,15 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
171181
UNIQID_REGISTER_COUNT
172182
};
173183

184+
enum RampGeneratorDriverFeatureControlRegister
185+
{
186+
VDCMIN,
187+
SW_MODE,
188+
RAMP_STAT,
189+
XLATCH,
190+
RAMP_GENERATOR_DRIVER_FEATURE_CONTROL_REGISTER_COUNT
191+
};
192+
174193
const char* ChannelIds[CHANNEL_COUNT] = { "rot", "angl", "count", "temp" };
175194
const char* DeviceIds[DEVICE_COUNT] = { "admt4000", "tmc5240" };
176195
const char* DeviceAttributes[DEVICE_ATTR_COUNT] = { "page", "sequencer_mode", "angle_filt", "conversion_mode", "h8_ctrl", "sdp_gpio_ctrl", "sdp_gpio0_busy", "sdp_coil_rs", "regmap_dump" };
@@ -186,6 +205,8 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
186205
const uint32_t SensorRegisters[SENSOR_REGISTER_COUNT] = { 0x03, 0x05, 0x08, 0x10, 0x11, 0x12, 0x13, 0x18, 0x1D, 0x1E, 0x20, 0x23, 0x14 };
187206
const uint32_t SensorPages[SENSOR_REGISTER_COUNT] = { UINT32_MAX, UINT32_MAX, UINT32_MAX, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 };
188207

208+
const uint32_t RampGeneratorDriverFeatureControlRegisters[RAMP_GENERATOR_DRIVER_FEATURE_CONTROL_REGISTER_COUNT] = { 0x33, 0x34, 0x35, 0x36 };
209+
189210
const char* getChannelId(Channel channel);
190211
const char* getDeviceId(Device device);
191212
const char* getDeviceAttribute(DeviceAttribute attribute);
@@ -199,14 +220,16 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
199220
const uint32_t getSensorRegister(SensorRegister registerID);
200221
const uint32_t getSensorPage(SensorRegister registerID);
201222

223+
const uint32_t getRampGeneratorDriverFeatureControlRegister(RampGeneratorDriverFeatureControlRegister registerID);
224+
202225
void connectADMT();
203226
void disconnectADMT();
204227
int getChannelIndex(const char *deviceName, const char *channelName);
205228
double getChannelValue(const char *deviceName, const char *channelName, int bufferSize = 1);
206229
int getDeviceAttributeValue(const char *deviceName, const char *attributeName, double *returnValue);
207230
int getDeviceAttributeValueString(const char *deviceName, const char *attributeName, char *returnValue, size_t byteLength = 512);
208231
int setDeviceAttributeValue(const char *deviceName, const char *attributeName, double writeValue);
209-
QString calibrate(vector<double> PANG, int cycles = 11, int samplesPerCycle = 256);
232+
QString calibrate(vector<double> PANG, int cycles, int samplesPerCycle, bool CCW);
210233
int writeDeviceRegistry(const char *deviceName, uint32_t address, uint32_t value);
211234
int readDeviceRegistry(const char *deviceName, uint32_t address, uint32_t *returnValue);
212235
void computeSineCosineOfAngles(const vector<double>& angles);
@@ -221,7 +244,7 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
221244
map<string, double> getDiag1RegisterBitMapping_Afe(uint16_t registerValue, bool is5V);
222245
map<string, double> getDiag2RegisterBitMapping(uint16_t registerValue);
223246
uint16_t setGeneralRegisterBitMapping(uint16_t currentRegisterValue, map<string, int> settings);
224-
void postcalibrate(vector<double> PANG, int cycleCount, int samplesPerCycle);
247+
void postcalibrate(vector<double> PANG, int cycleCount, int samplesPerCycle, bool CCW);
225248
int getAbsAngleTurnCount(uint16_t registerValue);
226249
uint16_t setDIGIOENRegisterBitMapping(uint16_t currentRegisterValue, map<string, bool> settings);
227250
uint16_t setDIGIORegisterBitMapping(uint16_t currentRegisterValue, map<string, bool> settings);
@@ -235,7 +258,17 @@ class SCOPY_ADMT_EXPORT ADMTController : public QObject
235258
map<string, double> getSecAnglIRegisterBitMapping(uint16_t registerValue);
236259
map<string, double> getTmp1RegisterBitMapping(uint16_t registerValue, bool is5V);
237260
bool checkRegisterFault(uint16_t registerValue, bool isMode1);
238-
261+
int streamIO();
262+
void bufferedStreamIO(int totalSamples, int targetSampleRate);
263+
bool checkVelocityReachedFlag(uint16_t registerValue);
264+
public Q_SLOTS:
265+
void handleStreamData(double value);
266+
void handleStreamBufferedData(const QVector<double> &value);
267+
void handleStreamBufferedDataInterval(const QVector<uint32_t> &value);
268+
Q_SIGNALS:
269+
void streamData(double value);
270+
void streamBufferedData(const QVector<double> &value);
271+
void streamBufferedDataInterval(const QVector<uint32_t> &value);
239272
private:
240273
iio_context *m_iioCtx;
241274
iio_buffer *m_iioBuffer;

plugins/admt/include/admt/admtstylehelper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class SCOPY_ADMT_EXPORT ADMTStyleHelper : public QObject
5858
static void LineEditStyle(QLineEdit *widget, QString objectName = "");
5959
static void ColoredSquareCheckbox(QCheckBox *chk, QColor color, QString objectName = "");
6060
static void StartButtonStyle(QPushButton *btn, QString objectName = "");
61-
static void TabWidgetStyle(QTabWidget *widget, const QString& styleHelperColor = "ScopyBlue", QString objectName = "");
6261
static void TextStyle(QWidget *widget, const char *styleHelperColor = json::global::white, bool isBold = false, QString objectName = "");// void TextStyle(QWidget *widget, const QString& styleHelperColor, bool isBold = false, QString objectName = "");
6362
static void MenuSmallLabel(QLabel *label, QString objectName = "");
6463
static void LineStyle(QFrame *line, QString objectName = "");

plugins/admt/include/admt/harmoniccalibration.h

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,26 @@ public Q_SLOTS:
113113
void stop();
114114
void start();
115115
void restart();
116-
void commandLogWrite(QString message);
116+
void calibrationLogWrite(QString message = "");
117+
void commandLogWrite(QString message = "");
117118
void updateFaultStatus(bool value);
118119
void updateMotorPosition(double position);
119-
void updateDIGIOUI(uint32_t *registerValue);
120-
void updateFaultRegisterUI(uint32_t *registerValue);
121-
void updateMTDiagnosticRegisterUI(uint32_t *registerValue);
122-
void updateMTDiagnosticsUI(uint32_t *registerValue);
120+
void updateDIGIOUI(uint16_t *registerValue);
121+
void updateFaultRegisterUI(uint16_t *registerValue);
122+
void updateMTDiagnosticRegisterUI(uint16_t *registerValue);
123+
void updateMTDiagnosticsUI(uint16_t *registerValue);
123124
Q_SIGNALS:
124125
void runningChanged(bool);
125126
void canCalibrateChanged(bool);
126127
void updateUtilityUI();
128+
void calibrationLogWriteSignal(QString message);
127129
void commandLogWriteSignal(QString message);
128130
void updateFaultStatusSignal(bool value);
129131
void motorPositionChanged(double position);
130-
void DIGIORegisterChanged(uint32_t *registerValue);
131-
void FaultRegisterChanged(uint32_t *registerValue);
132-
void DIAG1RegisterChanged(uint32_t *registerValue);
133-
void DIAG2RegisterChanged(uint32_t *registerValue);
132+
void DIGIORegisterChanged(uint16_t *registerValue);
133+
void FaultRegisterChanged(uint16_t *registerValue);
134+
void DIAG1RegisterChanged(uint16_t *registerValue);
135+
void DIAG2RegisterChanged(uint16_t *registerValue);
134136
private:
135137
ADMTController *m_admtController;
136138
iio_context *m_ctx;
@@ -142,15 +144,16 @@ public Q_SLOTS:
142144

143145
const char *rotationChannelName, *angleChannelName, *countChannelName, *temperatureChannelName;
144146

145-
double rotation, angle, count, temp = 0.0, amax, rotate_vmax, dmax, disable, target_pos, current_pos, ramp_mode,
147+
double rotation, angle, count, temp = 0.0,
148+
motor_rpm, amax, rotate_vmax, dmax, disable, target_pos, current_pos, ramp_mode,
146149
afeDiag0, afeDiag1, afeDiag2;
147150

148151
QPushButton *openLastMenuButton, *calibrationStartMotorButton,
149152
*calibrateDataButton, *extractDataButton, *clearCalibrateDataButton,
150153
*clearCommandLogButton, *applySequenceButton, *readAllRegistersButton;
151154
QButtonGroup *rightMenuButtonGroup;
152155

153-
QLineEdit *motorTargetPositionLineEdit, *graphUpdateIntervalLineEdit, *displayLengthLineEdit,
156+
QLineEdit *acquisitionMotorRPMLineEdit, *calibrationMotorRPMLineEdit, *motorTargetPositionLineEdit, *graphUpdateIntervalLineEdit, *displayLengthLineEdit,
154157
*dataGraphSamplesLineEdit, *tempGraphSamplesLineEdit,
155158
*acquisitionMotorCurrentPositionLineEdit,
156159
*calibrationH1MagLineEdit, *calibrationH2MagLineEdit,
@@ -179,7 +182,8 @@ public Q_SLOTS:
179182
MenuSectionWidget *rightMenuSectionWidget;
180183
MenuCollapseSection *rotationCollapse, *angleCollapse, *countCollapse, *tempCollapse;
181184
MenuCombo *m_dataGraphChannelMenuCombo, *m_dataGraphDirectionMenuCombo, *m_tempGraphDirectionMenuCombo, *m_calibrationMotorRampModeMenuCombo,
182-
*sequenceTypeMenuCombo, *conversionTypeMenuCombo, *cnvSourceMenuCombo, *convertSynchronizationMenuCombo, *angleFilterMenuCombo, *eighthHarmonicMenuCombo;
185+
*sequenceTypeMenuCombo, *conversionTypeMenuCombo, *cnvSourceMenuCombo, *convertSynchronizationMenuCombo, *angleFilterMenuCombo, *eighthHarmonicMenuCombo,
186+
*calibrationModeMenuCombo;
183187

184188
QTabWidget *tabWidget, *calibrationDataGraphTabWidget, *resultDataTabWidget;
185189

@@ -213,7 +217,7 @@ public Q_SLOTS:
213217

214218
HorizontalSpinBox *motorMaxVelocitySpinBox, *motorAccelTimeSpinBox, *motorMaxDisplacementSpinBox, *motorTargetPositionSpinBox;
215219

216-
CustomSwitch *calibrationDisplayFormatSwitch,
220+
CustomSwitch *acquisitionMotorDirectionSwitch, *calibrationMotorDirectionSwitch, *calibrationDisplayFormatSwitch,
217221
*DIGIO0ENToggleSwitch, *DIGIO0FNCToggleSwitch,
218222
*DIGIO1ENToggleSwitch, *DIGIO1FNCToggleSwitch,
219223
*DIGIO2ENToggleSwitch, *DIGIO2FNCToggleSwitch,
@@ -226,10 +230,12 @@ public Q_SLOTS:
226230

227231
QFuture<void> m_deviceStatusThread, m_currentMotorPositionThread,
228232
m_acquisitionUIThread, m_acquisitionDataThread, m_acquisitionGraphThread,
229-
m_calibrationUIThread, m_utilityUIThread, m_utilityThread;
233+
m_calibrationUIThread, m_calibrationStreamThread, m_calibrationWaitVelocityThread, m_calibrationContinuousThread,
234+
m_resetMotorToZeroThread, m_utilityUIThread, m_utilityThread;
230235
QFutureWatcher<void> m_deviceStatusWatcher, m_currentMotorPositionWatcher,
231236
m_acquisitionUIWatcher, m_acquisitionDataWatcher, m_acquisitionGraphWatcher,
232-
m_calibrationUIWatcher, m_utilityUIWatcher, m_utilityWatcher;
237+
m_calibrationUIWatcher, m_calibrationStreamWatcher, m_calibrationWaitVelocityWatcher, m_calibrationContinuousWatcher,
238+
m_resetMotorToZeroWatcher, m_utilityUIWatcher, m_utilityWatcher;
233239

234240
ToolTemplate* createAcquisitionWidget();
235241
ToolTemplate* createCalibrationWidget();
@@ -239,6 +245,7 @@ public Q_SLOTS:
239245
void readDeviceProperties();
240246
void initializeADMT();
241247
bool readSequence();
248+
bool writeSequence(const map<string, int> &settings);
242249
void applySequence();
243250
bool changeCNVPage(uint32_t page);
244251
void initializeMotor();
@@ -256,6 +263,8 @@ public Q_SLOTS:
256263
void updateLineEditValues();
257264
void startAcquisition();
258265
void stopAcquisition();
266+
void updateAcquisitionMotorRPM();
267+
void updateAcquisitionMotorRotationDirection();
259268
void getAcquisitionSamples(int sampleRate);
260269
double getAcquisitionParameterValue(const AcquisitionDataKey &key);
261270
void plotAcquisition(QVector<double>& list, PlotChannel* channel);
@@ -276,30 +285,43 @@ public Q_SLOTS:
276285
void startCalibrationUITask();
277286
void stopCalibrationUITask();
278287
void calibrationUITask(int sampleRate);
288+
void updateCalibrationMotorRPM();
289+
void updateCalibrationMotorRotationDirection();
279290
void getCalibrationSamples();
280291
void startCalibration();
281292
void stopCalibration();
282-
void startMotor();
283-
void startMotorContinuous();
293+
void startContinuousCalibration();
294+
void stopContinuousCalibration();
295+
void startCalibrationStreamThread();
296+
void stopCalibrationStreamThread();
297+
void startWaitForVelocityReachedThread(int mode);
298+
void stopWaitForVelocityReachedThread();
299+
void waitForVelocityReached(int mode, int sampleRate);
300+
int calculateContinuousCalibrationSampleRate(double motorRPS, int samplesPerCycle);
301+
void configureConversionType(int mode);
302+
void configureCalibrationSequenceSettings();
303+
void getStreamedCalibrationSamples(int microSampleRate);
304+
void startOneShotCalibration();
284305
void postCalibrateData();
285306
void resetAllCalibrationState();
286307
void computeSineCosineOfAngles(QVector<double> graphDataList);
287308
void populateAngleErrorGraphs();
288309
void populateCorrectedAngleErrorGraphs();
310+
void clearHarmonicRegisters();
289311
void flashHarmonicValues();
290312
void calculateHarmonicValues();
291313
void updateCalculatedCoeffAngle();
292314
void updateCalculatedCoeffHex();
293315
void resetCalculatedCoeffAngle();
294316
void resetCalculatedCoeffHex();
295317
void displayCalculatedCoeff();
296-
void calibrationLogWrite(QString message = "");
297318
void importCalibrationData();
298319
void extractCalibrationData();
299320
void toggleTabSwitching(bool value);
321+
void toggleCalibrationButtonState(int state);
300322
void canStartMotor(bool value);
301323
void canCalibrate(bool);
302-
void toggleMotorControls(bool value);
324+
void toggleCalibrationControls(bool value);
303325
void clearCalibrationSamples();
304326
void clearCalibrationSineCosine();
305327
void clearPostCalibrationSamples();
@@ -309,10 +331,17 @@ public Q_SLOTS:
309331

310332
#pragma region Motor Methods
311333
bool moveMotorToPosition(double& position, bool validate = true);
334+
void moveMotorContinuous();
312335
bool resetCurrentPositionToZero();
313336
void stopMotor();
314337
int readMotorAttributeValue(ADMTController::MotorAttribute attribute, double& value);
315338
int writeMotorAttributeValue(ADMTController::MotorAttribute attribute, double value);
339+
int readMotorRegisterValue(uint32_t address, uint32_t *value);
340+
void setRampMode(bool motorRotationClockwise);
341+
void getRampMode();
342+
void startResetMotorToZero();
343+
void stopResetMotorToZero();
344+
void resetMotorToZero();
316345
#pragma endregion
317346

318347
#pragma region Utility Methods
@@ -345,12 +374,7 @@ public Q_SLOTS:
345374
void updateLineEditValue(QLineEdit* lineEdit, double value);
346375
void toggleWidget(QPushButton *widget, bool value);
347376
void changeCustomSwitchLabel(CustomSwitch *customSwitch, QString onLabel, QString offLabel);
348-
void changeStatusLEDColor(MenuControlButton *menuControlButton, QColor color, bool checked = true);
349-
void changeStatusLEDColor(QCheckBox *widget, const char *colorAttribute);
350-
void updateFaultStatusLEDColor(MenuControlButton *widget, bool value);
351-
void toggleStatusLEDColor(QCheckBox *widget, const char *trueAttribute, const char* falseAttribute, bool value);
352-
MenuControlButton *createStatusLEDWidget(const QString title, QColor color, QWidget *parent = nullptr);
353-
QCheckBox *createStatusLEDWidget(const QString &text, const char *colorAttribute, bool checked = false, QWidget *parent = nullptr);
377+
QCheckBox *createStatusLEDWidget(const QString &text, QVariant variant = true, bool checked = false, QWidget *parent = nullptr);
354378
MenuControlButton *createChannelToggleWidget(const QString title, QColor color, QWidget *parent = nullptr);
355379
#pragma endregion
356380

@@ -364,13 +388,16 @@ public Q_SLOTS:
364388
void connectLineEditToRPSConversion(QLineEdit* lineEdit, double& vmax);
365389
void connectLineEditToAMAXConversion(QLineEdit* lineEdit, double& amax);
366390
void connectRegisterBlockToRegistry(RegisterBlockWidget* widget);
391+
void connectLineEditToRPM(QLineEdit* lineEdit, double& variable);
367392
#pragma endregion
368393

369394
#pragma region Convert Methods
370395
double convertRPStoVMAX(double rps);
371396
double convertVMAXtoRPS(double vmax);
372397
double convertAccelTimetoAMAX(double accelTime);
373398
double convertAMAXtoAccelTime(double amax);
399+
double convertRPMtoRPS(double rpm);
400+
double convertRPStoRPM(double rps);
374401
#pragma endregion
375402

376403
#pragma region Debug Methods

plugins/admt/include/admt/widgets/registerblockwidget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ namespace scopy::admt {
6565

6666
void addReadButton(QWidget *parent);
6767
void addWriteButton(QWidget *parent);
68-
void applyLineEditStyle(QLineEdit *widget);
69-
void applySpinBoxStyle(QSpinBox *widget);
7068
};
7169

7270
class SCOPY_ADMT_EXPORT PaddedSpinBox : public QSpinBox

0 commit comments

Comments
 (0)