Skip to content

Commit 278ba15

Browse files
committed
admt: Fixed sequence configuration
- Added conversion restart on calibration - Fixed bug when deselect all graph channel in acquisition - Changed ramp mode variable for reset motor to zero - Remove unused methods Signed-off-by: John Lloyd Juanillo <[email protected]> Signed-off-by: JJuanill <[email protected]>
1 parent 4e1c570 commit 278ba15

File tree

2 files changed

+68
-62
lines changed

2 files changed

+68
-62
lines changed

plugins/admt/include/admt/harmoniccalibration.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ public Q_SLOTS:
319319
void stopWaitForVelocityReachedThread();
320320
void waitForVelocityReached(int mode, int sampleRate);
321321
int calculateContinuousCalibrationSampleRate(double motorRPS, int samplesPerCycle);
322-
void configureConversionType(int mode);
323-
void configureCalibrationSequenceSettings();
322+
void configureCalibrationSequenceSettings(int conversionMode);
324323
void startOneShotCalibration();
325324
void postCalibrateData();
326325
void resetAllCalibrationState();

plugins/admt/src/harmoniccalibration.cpp

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,38 +2372,41 @@ bool HarmonicCalibration::readSequence()
23722372

23732373
bool HarmonicCalibration::writeSequence(QMap<string, int> settings)
23742374
{
2375-
bool success = false;
2376-
2377-
uint32_t generalRegisterAddress =
2378-
m_admtController->getConfigurationRegister(ADMTController::ConfigurationRegister::GENERAL);
2379-
uint32_t *generalRegValue = new uint32_t;
2380-
if(m_admtController->readDeviceRegistry(m_admtController->getDeviceId(ADMTController::Device::ADMT4000),
2381-
generalRegisterAddress, generalRegValue) != 0)
2375+
if(!disableECC(true))
23822376
return false;
23832377

2384-
uint32_t newGeneralRegValue =
2385-
m_admtController->setGeneralRegisterBitMapping(*generalRegValue, settings.toStdMap());
23862378
uint8_t generalRegisterPage =
23872379
m_admtController->getConfigurationPage(ADMTController::ConfigurationRegister::GENERAL);
23882380

23892381
if(!changeCNVPage(generalRegisterPage))
23902382
return false;
23912383

2392-
convertStart(false);
2384+
bool success = false;
23932385

2394-
if(m_admtController->writeDeviceRegistry(m_admtController->getDeviceId(ADMTController::Device::ADMT4000),
2395-
generalRegisterAddress, newGeneralRegValue) != 0)
2396-
return false;
2386+
uint32_t generalRegisterAddress =
2387+
m_admtController->getConfigurationRegister(ADMTController::ConfigurationRegister::GENERAL);
2388+
uint32_t *generalRegValue = new uint32_t;
2389+
2390+
if(m_admtController->readDeviceRegistry(m_admtController->getDeviceId(ADMTController::Device::ADMT4000),
2391+
generalRegisterAddress, generalRegValue) == 0) {
2392+
uint32_t newGeneralRegValue =
2393+
m_admtController->setGeneralRegisterBitMapping(*generalRegValue, settings.toStdMap());
23972394

2398-
if(readSequence())
2399-
if(settings.value("Convert Synchronization") == GENERALRegisterMap.value("Convert Synchronization") &&
2395+
if(convertStart(false) && changeCNVPage(generalRegisterPage) &&
2396+
m_admtController->writeDeviceRegistry(
2397+
m_admtController->getDeviceId(ADMTController::Device::ADMT4000), generalRegisterAddress,
2398+
newGeneralRegValue) == 0 &&
2399+
readSequence() &&
2400+
settings.value("Convert Synchronization") == GENERALRegisterMap.value("Convert Synchronization") &&
24002401
settings.value("Angle Filter") == GENERALRegisterMap.value("Angle Filter") &&
24012402
settings.value("8th Harmonic") == GENERALRegisterMap.value("8th Harmonic") &&
24022403
settings.value("Sequence Type") == GENERALRegisterMap.value("Sequence Type") &&
2403-
settings.value("Conversion Type") == GENERALRegisterMap.value("Conversion Type"))
2404+
settings.value("Conversion Type") == GENERALRegisterMap.value("Conversion Type")) {
24042405
success = true;
2406+
}
2407+
}
24052408

2406-
convertStart(true);
2409+
delete generalRegValue;
24072410

24082411
return success;
24092412
}
@@ -2689,12 +2692,10 @@ bool HarmonicCalibration::updateChannelValues()
26892692
updateChannelValue(3);
26902693
} else if(readMode == 1) {
26912694
if(conversionMode == 1)
2692-
convertStart(true);
2695+
convertRestart();
26932696
updateSensorValue(ADMTController::SensorRegister::ANGLE);
26942697
updateSensorValue(ADMTController::SensorRegister::ABSANGLE);
26952698
updateSensorValue(ADMTController::SensorRegister::TMP0);
2696-
if(conversionMode == 1)
2697-
convertStart(false);
26982699
}
26992700

27002701
if(rotation == UINT32_MAX)
@@ -2730,10 +2731,6 @@ bool HarmonicCalibration::updateSensorValue(ADMTController::SensorRegister senso
27302731
break;
27312732
case ADMTController::SensorRegister::ANGLE:
27322733
angle = m_admtController->getAngle(static_cast<uint16_t>(*registerValue));
2733-
if(angle < 5) {
2734-
qInfo() << angle;
2735-
qInfo() << *registerValue;
2736-
}
27372734
break;
27382735
case ADMTController::SensorRegister::TMP0:
27392736
temp = m_admtController->getTemperature(static_cast<uint16_t>(*registerValue));
@@ -2896,37 +2893,61 @@ void HarmonicCalibration::updateAcquisitionMotorRotationDirection()
28962893
void HarmonicCalibration::getAcquisitionSamples(QMap<SensorData, bool> dataMap)
28972894
{
28982895
QMap<SensorData, double> sensorDataMap;
2896+
bool dataChanged = false;
28992897
while(isStartAcquisition) {
29002898
if(updateChannelValues()) {
2901-
if(dataMap.value(ANGLE))
2899+
dataChanged = false;
2900+
2901+
if(dataMap.value(ANGLE)) {
29022902
sensorDataMap[ANGLE] = angle;
2903-
if(dataMap.value(ABSANGLE))
2903+
dataChanged = true;
2904+
}
2905+
if(dataMap.value(ABSANGLE)) {
29042906
sensorDataMap[ABSANGLE] = rotation;
2905-
if(dataMap.value(TMP0))
2907+
dataChanged = true;
2908+
}
2909+
if(dataMap.value(TMP0)) {
29062910
sensorDataMap[TMP0] = temp;
2907-
if(dataMap.value(SINE))
2911+
dataChanged = true;
2912+
}
2913+
if(dataMap.value(SINE)) {
29082914
sensorDataMap[SINE] =
29092915
getSensorDataAcquisitionValue(ADMTController::SensorRegister::SINE);
2910-
if(dataMap.value(COSINE))
2916+
dataChanged = true;
2917+
}
2918+
if(dataMap.value(COSINE)) {
29112919
sensorDataMap[COSINE] =
29122920
getSensorDataAcquisitionValue(ADMTController::SensorRegister::COSINE);
2913-
if(dataMap.value(RADIUS))
2921+
dataChanged = true;
2922+
}
2923+
if(dataMap.value(RADIUS)) {
29142924
sensorDataMap[RADIUS] =
29152925
getSensorDataAcquisitionValue(ADMTController::SensorRegister::RADIUS);
2916-
if(dataMap.value(ANGLESEC))
2926+
dataChanged = true;
2927+
}
2928+
if(dataMap.value(ANGLESEC)) {
29172929
sensorDataMap[ANGLESEC] =
29182930
getSensorDataAcquisitionValue(ADMTController::SensorRegister::ANGLESEC);
2919-
if(dataMap.value(SECANGLI))
2931+
dataChanged = true;
2932+
}
2933+
if(dataMap.value(SECANGLI)) {
29202934
sensorDataMap[SECANGLI] =
29212935
getSensorDataAcquisitionValue(ADMTController::SensorRegister::SECANGLI);
2922-
if(dataMap.value(SECANGLQ))
2936+
dataChanged = true;
2937+
}
2938+
if(dataMap.value(SECANGLQ)) {
29232939
sensorDataMap[SECANGLQ] =
29242940
getSensorDataAcquisitionValue(ADMTController::SensorRegister::SECANGLQ);
2925-
if(dataMap.value(TMP1))
2941+
dataChanged = true;
2942+
}
2943+
if(dataMap.value(TMP1)) {
29262944
sensorDataMap[TMP1] =
29272945
getSensorDataAcquisitionValue(ADMTController::SensorRegister::TMP1);
2946+
dataChanged = true;
2947+
}
29282948

2929-
Q_EMIT acquisitionDataChanged(sensorDataMap);
2949+
if(dataChanged)
2950+
Q_EMIT acquisitionDataChanged(sensorDataMap);
29302951
}
29312952
}
29322953
}
@@ -3327,18 +3348,16 @@ void HarmonicCalibration::startCalibration()
33273348
graphDataList.reserve(totalSamplesCount);
33283349
graphDataList.squeeze();
33293350

3330-
configureConversionType(calibrationMode);
3331-
3332-
configureCalibrationSequenceSettings();
3333-
clearHarmonicRegisters();
3334-
3335-
toggleTabSwitching(false);
3336-
toggleCalibrationControls(false);
3337-
33383351
calibrationDataGraphTabWidget->setCurrentIndex(0);
33393352
calibrationRawDataXPlotAxis->setInterval(0, totalSamplesCount);
33403353

3354+
toggleTabSwitching(false);
3355+
toggleCalibrationControls(false);
33413356
toggleCalibrationButtonState(1);
3357+
3358+
configureCalibrationSequenceSettings(calibrationMode);
3359+
clearHarmonicRegisters();
3360+
convertRestart();
33423361
if(calibrationMode == 0)
33433362
startContinuousCalibration();
33443363
else
@@ -3399,7 +3418,7 @@ void HarmonicCalibration::resetMotorToZero()
33993418
{
34003419
if(readMotorAttributeValue(ADMTController::MotorAttribute::CURRENT_POS, current_pos) == 0) {
34013420
if(current_pos != 0) {
3402-
setRampMode(true); // Write to ramp mode in case of motor disable
3421+
setRampMode(isMotorRotationClockwise); // Write to ramp mode in case of motor disable
34033422
writeMotorAttributeValue(ADMTController::MotorAttribute::ROTATE_VMAX,
34043423
convertRPStoVMAX(convertRPMtoRPS(fast_motor_rpm)));
34053424
writeMotorAttributeValue(ADMTController::MotorAttribute::TARGET_POS, 0);
@@ -3490,27 +3509,15 @@ int HarmonicCalibration::calculateContinuousCalibrationSampleRate(double motorRP
34903509
return static_cast<int>(floor(1 / motorRPS / samplesPerCycle * 1000 * 1000 * 1000)); // In nanoseconds
34913510
}
34923511

3493-
void HarmonicCalibration::configureConversionType(int mode)
3494-
{
3495-
readSequence();
3496-
if(!GENERALRegisterMap.contains("Conversion Type")) {
3497-
StatusBarManager::pushMessage("Failed to configure calibration conversion type");
3498-
return;
3499-
}
3500-
3501-
GENERALRegisterMap["Conversion Type"] = mode;
3502-
writeSequence(GENERALRegisterMap);
3503-
}
3504-
3505-
void HarmonicCalibration::configureCalibrationSequenceSettings()
3512+
void HarmonicCalibration::configureCalibrationSequenceSettings(int conversionMode)
35063513
{
3507-
readSequence();
3508-
if(!GENERALRegisterMap.contains("8th Harmonic")) {
3514+
if(!readSequence()) {
35093515
StatusBarManager::pushMessage("Failed to configure calibration sequence settings");
35103516
return;
35113517
}
35123518

3513-
GENERALRegisterMap["8th Harmonic"] = 1; // User-supplied 8th Harmonic
3519+
GENERALRegisterMap["Conversion Type"] = conversionMode; // 0: One-shot Conversion, 1: Continuous Conversion
3520+
GENERALRegisterMap["8th Harmonic"] = 1; // Always use user-supplied 8th Harmonic
35143521
writeSequence(GENERALRegisterMap);
35153522
}
35163523

0 commit comments

Comments
 (0)