2 #include "ui_calibrationwindow.h"
6 #include <QtConcurrent/QtConcurrent>
11 #define CHANNEL_COUNT 6
12 #define HEX_VALC 0x8000
13 #define RANGE32K 32768
15 #define COL_CURRMEASURE 0
20 #define COL_REGISTERS 3
22 #define COL_CALIBBIAS 0
24 #define COL_FULLSCALE 0
26 #define COL_MAXMEASURE 0
27 #define COL_MINMEASURE 1
28 #define COL_DIFFMEASURE 2
29 #define COL_NEWTONMEASURE 3
31 #define MATRIX_COUNT 1
38 return static_cast<int>(v)-32768;
43 return static_cast<std::int16_t
>(v&0xffff);
67 const uint16_t CalibrationWindow::defaultStrain2AmplOffsets[6] =
69 32767, 32767, 32767, 32767, 32767, 32767
72 const uint16_t CalibrationWindow::defaultStrain1DACoffsets[6] =
74 511, 511, 511, 511, 511, 511
79 QMainWindow(parent),mutex(QMutex::Recursive),
83 setWindowModality(Qt::ApplicationModal);
90 calibration_value = 32767;
91 #if defined(MARCO_ACCAME_19SEP2018)
100 serial_number_changed =
false;
101 matrix_changed[0] =
false;
102 matrix_changed[1] =
false;
103 matrix_changed[2] =
false;
104 fullScaleChanged =
false;
107 eeprom_saved_status=
true;
109 refresh_serialnumber =
true;
123 offsetSliderPressed[i] =
false;
127 strncpy(serial_no,
"UNDEF",8);
131 full_scale_const[m][i] = 0;
135 if(icubCanProto_boardType__strain == boardtype){
136 ui->tableParamters->hideColumn(
COL_GAIN);
142 QWidget *container =
new QWidget(ui->tableParamters);
145 slider_offset.append(spinner);
147 ui->tableParamters->setCellWidget(i,
COL_OFFSET,spinner);
148 ui->tableParamters->cellWidget(i,
COL_OFFSET)->setEnabled(
false);
152 ui->tableParamters->setCellWidget(i,
COL_GAIN,gainCombo);
153 ui->tableParamters->cellWidget(i,
COL_GAIN)->setEnabled(
false);
157 QSpinBox *spinnerTarget =
new QSpinBox(container);
158 spinnerTarget->setMinimum(0);
159 spinnerTarget->setMaximum(32767);
160 spinnerTarget->setMinimum(-32768);
161 spinnerTarget->setValue(0);
162 ui->tableParamters->setCellWidget(i,
COL_TARGET,spinnerTarget);
164 if(icubCanProto_boardType__strain == boardtype && i > 0){
165 spinnerTarget->setEnabled(
false);
166 }
else if(icubCanProto_boardType__strain == boardtype && i == 0){
167 connect(spinnerTarget,SIGNAL(valueChanged(
int)),
this,SLOT(onTargetValueChanged(
int)));
174 QTableWidgetItem *item =
new QTableWidgetItem(
"-");
175 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
178 ui->tableCurr->setHorizontalHeaderItem(0,
new QTableWidgetItem(
"ADC"));
181 QTableWidgetItem *item1 =
new QTableWidgetItem(
"-");
182 item1->setFlags(item1->flags() ^ Qt::ItemIsEditable);
186 QTableWidgetItem *item2 =
new QTableWidgetItem(
"-");
187 item2->setFlags(item2->flags() ^ Qt::ItemIsEditable);
191 QTableWidgetItem *item3 =
new QTableWidgetItem(
"-");
192 item3->setFlags(item3->flags() ^ Qt::ItemIsEditable);
196 QTableWidgetItem *item4 =
new QTableWidgetItem(
"-");
197 item4->setFlags(item4->flags() ^ Qt::ItemIsEditable);
201 QTableWidgetItem *item =
new QTableWidgetItem(
"-");
202 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
203 ui->matrixA->setItem(i,j,item);
214 QTableWidgetItem *item001 =
new QTableWidgetItem(
"-");
215 item001->setFlags(item001->flags() ^ Qt::ItemIsEditable);
216 ui->tableParamters->setItem(i,
COL_GAIN,item001);
219 QTableWidgetItem *item5 =
new QTableWidgetItem(
"-");
220 item5->setFlags(item5->flags() ^ Qt::ItemIsEditable);
221 ui->tableParamters->setItem(i,
COL_TARGET,item5);
228 QTableWidgetItem *item6 =
new QTableWidgetItem(
"-");
229 item6->setFlags(item6->flags() ^ Qt::ItemIsEditable);
232 QTableWidgetItem *item7 =
new QTableWidgetItem(
"-");
233 item7->setFlags(item7->flags() ^ Qt::ItemIsEditable);
244 fullScales.append(ui->tableFullScaleA);
250 ui->tableParamters->setColumnWidth(
COL_OFFSET,150);
255 progress =
new QProgressBar(
this);
256 progress->setFixedWidth(100);
257 progress->setMinimum(0);
258 progress->setMaximum(100);
259 progress->setVisible(
false);
260 ui->statusbar->addWidget(progress);
266 matrices.append(ui->matrixA);
270 if(boardtype == icubCanProto_boardType__strain){
271 ui->comboRegSet->setEnabled(
false);
272 ui->comboRegSetBoot->setEnabled(
false);
277 connect(ui->comboRegSet,SIGNAL(currentIndexChanged(
int)),
this,SLOT(onChangeRegSet(
int)));
278 connect(ui->comboRegSetBoot,SIGNAL(currentIndexChanged(
int)),
this,SLOT(onChangeRegSetBoot(
int)));
279 connect(
this,SIGNAL(
applyDone()),
this,SLOT(onApplyDone()));
280 connect(ui->btnClose,SIGNAL(clicked(
bool)),
this,SLOT(close()));
281 connect(ui->edit_serial,SIGNAL(textEdited(QString)),
this,SLOT(onSerialChanged(QString)));
282 connect(
this,SIGNAL(
loading(
bool)),
this,SLOT(onLoading(
bool)),Qt::QueuedConnection);
283 connect(
this,SIGNAL(
setText(QLineEdit*,QString)),
this,SLOT(onSetText(QLineEdit*,QString)),Qt::QueuedConnection);
284 connect(
this,SIGNAL(
setText(QTableWidgetItem*,QString)),
this,SLOT(onSetText(QTableWidgetItem*,QString)),Qt::QueuedConnection);
285 connect(
this,SIGNAL(
setTableVisible(QTableWidget*,
bool)),
this,SLOT(onSetTableVisible(QTableWidget*,
bool)),Qt::QueuedConnection);
288 connect(ui->btnParametersClear,SIGNAL(clicked(
bool)),
this,SLOT(onParametersClear(
bool)));
289 connect(ui->btnParametersApply,SIGNAL(clicked(
bool)),
this,SLOT(onParametersApply(
bool)));
290 connect(ui->checkAutoTune,SIGNAL(toggled(
bool)),
this,SLOT(onCheckAutoTune(
bool)));
291 connect(ui->btnSetCalibBias,SIGNAL(clicked(
bool)),
this,SLOT(onSetCalibBias(
bool)));
292 connect(ui->btnResetCalibBias,SIGNAL(clicked(
bool)),
this,SLOT(onResetCalibBias(
bool)));
294 connect(ui->btnSetSerial,SIGNAL(clicked(
bool)),
this,SLOT(onSetSerial(
bool)),Qt::QueuedConnection);
295 connect(
this,SIGNAL(
setSerialChanged(
bool)),
this,SLOT(onSetSerialChanged(
bool)));
297 connect(
this,SIGNAL(
setFullScale()),
this,SLOT(onSetFullScale()),Qt::QueuedConnection);
298 connect(
this,SIGNAL(
setMatrix(
int)),
this,SLOT(onSetMatrix(
int)),Qt::QueuedConnection);
299 connect(ui->actionSave_To_Eproom,SIGNAL(triggered(
bool)),
this,SLOT(onSaveToEeprom(
bool)),Qt::QueuedConnection);
300 connect(ui->actionClear_Statistics,SIGNAL(triggered(
bool)),
this,SLOT(onClear_Statistics(
bool)),Qt::QueuedConnection);
301 connect(ui->actionClear_the_full_regulation,SIGNAL(triggered(
bool)),
this,SLOT(onClear_FullRegulation(
bool)),Qt::QueuedConnection);
302 connect(ui->actionClear_the_regulation_set_in_use,SIGNAL(triggered(
bool)),
this,SLOT(onClear_Regulation(
bool)),Qt::QueuedConnection);
303 connect(ui->btnSetCalibration,SIGNAL(clicked(
bool)),
this,SLOT(onSetCalibration(
bool)),Qt::QueuedConnection);
304 connect(
this,SIGNAL(
resetMatrices(
int)),
this,SLOT(resetMatricesState(
int)),Qt::QueuedConnection);
305 connect(
this,SIGNAL(
updateTitle()),
this,SLOT(onUpdateTitle()),Qt::QueuedConnection);
306 connect(
this,SIGNAL(
appendLogMsg(QString)),
this,SLOT(onAppendLogMsg(QString)),Qt::QueuedConnection);
307 connect(ui->btnClearLog,SIGNAL(clicked(
bool)),
this,SLOT(onClearLog()));
308 connect(ui->btnLoadCalibFile,SIGNAL(clicked(
bool)),
this,SLOT(onLoadCalibrationFile(
bool)));
309 connect(ui->btnSaveCalibFile,SIGNAL(clicked(
bool)),
this,SLOT(onSaveCalibrationFile(
bool)));
310 connect(ui->btnImportCalibMatrix,SIGNAL(clicked(
bool)),
this,SLOT(onImportCalibrationFile(
bool)));
314 ui->actionImport_Calib_Matrix->setEnabled(
false);
315 ui->actionLoad_Calibration_File->setEnabled(
false);
316 ui->actionSave_Calibration_File->setEnabled(
false);
323 QtConcurrent::run(
this,&CalibrationWindow::onTimeout);
338 void CalibrationWindow::onTargetValueChanged(
int v)
342 if(boardtype == icubCanProto_boardType__strain){
344 QSpinBox *spinnerTarget = (QSpinBox*)ui->tableParamters->cellWidget(i,
COL_TARGET);
345 spinnerTarget->setValue(v);
351 void CalibrationWindow::onChangeRegSet(
int regSet)
356 void CalibrationWindow::onChangeRegSetBoot(
int regSet)
362 void CalibrationWindow::onDigitalRegulation(
bool checked)
364 ui->digitalContainer->setEnabled(checked);
378 void CalibrationWindow::onCheckAutoTune(
bool checked)
382 if(icubCanProto_boardType__strain == boardtype){
384 ui->tableParamters->cellWidget(i,
COL_TARGET)->setEnabled(
true);
387 ui->tableParamters->cellWidget(i,
COL_TARGET)->setEnabled(
true);
389 ui->tableParamters->cellWidget(i,
COL_OFFSET)->setEnabled(
false);
390 ui->tableParamters->cellWidget(i,
COL_GAIN)->setEnabled(
false);
394 ui->tableParamters->cellWidget(i,
COL_TARGET)->setEnabled(
false);
395 ui->tableParamters->cellWidget(i,
COL_OFFSET)->setEnabled(
true);
396 ui->tableParamters->cellWidget(i,
COL_GAIN)->setEnabled(
true);
401 void CalibrationWindow::onParametersClear(
bool click)
407 if(icubCanProto_boardType__strain2 == boardtype || icubCanProto_boardType__strain2c == boardtype)
420 void CalibrationWindow::onParametersApply(
bool click)
422 if(ui->checkAutoTune->isChecked()){
429 void CalibrationWindow::onOffsetEditingFinished()
431 qDebug() <<
"EDIT FINISH FOR " << sender();
434 void CalibrationWindow::onTabMatrixCahnged(
int index)
439 ui->btnLoadCalibFile->setEnabled(
true);
440 ui->btnSaveCalibFile->setEnabled(
true);
441 ui->btnImportCalibMatrix->setEnabled(
true);
443 ui->btnSetCalibration->setEnabled(
true);
446 ui->btnLoadCalibFile->setEnabled(
false);
447 ui->btnSaveCalibFile->setEnabled(
false);
448 ui->btnImportCalibMatrix->setEnabled(
false);
450 ui->btnSetCalibration->setEnabled(
false);
456 void CalibrationWindow::onOffsetSliderPressed()
459 offsetSliderPressed[index] =
true;
462 void CalibrationWindow::onOffsetSliderReleased()
468 offsetSliderPressed[index] =
false;
523 std::vector<strain2_ampl_discretegain_t> gains(0);
524 std::vector<int16_t> targets(0);
525 if(icubCanProto_boardType__strain == boardtype)
528 std::int16_t target = spin->value();
530 targets.push_back(target);
536 QComboBox *combo = (QComboBox*)ui->tableParamters->cellWidget(i,
COL_GAIN);
539 targets.push_back(spin->value());
560 QComboBox *combo = (QComboBox*)ui->tableParamters->cellWidget(i,
COL_GAIN);
563 if(icubCanProto_boardType__strain2 == boardtype || icubCanProto_boardType__strain2c == boardtype)
565 int lastOffset = spin->value();
566 uint16_t offset = lastOffset;
567 int g = combo->itemData(combo->currentIndex(),
GAINAMPROLE).toInt();
576 int lastOffset = spin->value();
577 uint16_t offset = lastOffset;
597 serial_number_changed =
false;
627 const bool alsoserialnumber =
true;
628 if((icubCanProto_boardType__strain2 == boardtype) || (icubCanProto_boardType__strain2c == boardtype))
641 refresh_serialnumber = alsoserialnumber;
650 const bool alsoserialnumber =
false;
652 refresh_serialnumber = alsoserialnumber;
658 void CalibrationWindow::resetMatricesState(
int index)
662 matrix_changed[i] =
false;
668 QTableWidget *table = matrices.at(i);
674 table->item(r,c)->setTextColor(
"");
693 if(matrix_changed[0]){
704 if(fullScaleChanged){
754 printf (
"Calibration file applied with no errors\n");
755 appendLogMsg(QString(
"Calibration file applied with no errors"));
756 matrix_changed[0]=
false;
757 fullScaleChanged =
false;
785 setText(ui->edit_serial,QString(buffer));
786 serial_number_changed=
false;
793 sprintf(buffer,
"%x",matrix[index - 1][ri][ci]);
806 if (calib_matrix[index][ri][ci]==matrix[index][ri][ci]){
809 QString s = QString(
"Found 1 error on element %1,%2 !!").arg(ri).arg(ci);
815 QString s = QString(
"Calibration file applied with no errors");
817 matrix_changed[index]=
false;
819 QString s = QString(
"Found %1 errors applying the calibration file!!").arg(36-count_ok);
826 fullScaleChanged =
false;
832 void CalibrationWindow::onLoadCalibrationFile(
bool click)
834 QString filename = QFileDialog::getOpenFileName(
this,
"Choose File",
QDir::home().absolutePath(),
"dat(*.dat)");
836 if(filename.isEmpty()){
849 char path[256] = { 0 };
850 snprintf(path,
sizeof(path),
"%s", filePath.toLatin1().data());
851 std::string filename = std::string(path);
853 filename +=
"/calibrationData";
854 filename += serial_no;
862 if((icubCanProto_boardType__strain2 == boardtype || icubCanProto_boardType__strain2c == boardtype))
865 filestr<<
"File version:"<<endl;
868 filestr<<
"Board type:"<<endl;
869 filestr<<
"strain2"<<endl;
871 filestr<<
"Serial number:"<<endl;
872 sprintf (buffer,
"%s",serial_no);
873 filestr<<buffer<<endl;
875 filestr<<
"Amplifier registers:"<<endl;
877 sprintf (buffer,
"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
878 amp_registers[i].
data[0], amp_registers[i].
data[1], amp_registers[i].
data[2],
879 amp_registers[i].
data[3], amp_registers[i].
data[4], amp_registers[i].
data[5]);
880 filestr<<buffer<<endl;
886 filestr<<
"File version:"<<endl;
890 filestr<<
"Serial number:"<<endl;
891 sprintf (buffer,
"%s",serial_no);
892 filestr<<buffer<<endl;
895 filestr<<
"Offsets:"<<endl;
897 sprintf (buffer,
"%d",offset[i]);
898 filestr<<buffer<<endl;
905 filestr<<
"Calibration matrix:"<<endl;
907 sprintf (buffer,
"%x",matrix[index][i/6][i%6]);
908 filestr<<buffer<<endl;
913 filestr<<
"Matrix gain:"<<endl;
914 sprintf (buffer,
"%d",calib_const[index]);
915 filestr<<buffer<<endl;
919 filestr<<
"Tare:"<<endl;
921 sprintf (buffer,
"%d",calib_bias[i]);
922 filestr<<buffer<<endl;
926 filestr<<
"Full scale values:"<<endl;
928 sprintf (buffer,
"%d",full_scale_const[index][i]);
929 filestr<<buffer<<endl;
934 printf (
"Calibration file saved!\n");
941 void CalibrationWindow::onSaveCalibrationFile(
bool click)
943 QString filePath = QFileDialog::getExistingDirectory(
this,
"Choose File",
QDir::home().absolutePath());
945 if(filePath.isEmpty()){
959 char* buff = fileName.toLatin1().data();
962 yError(
"File not found!\n");
970 QFile filestr(fileName);
972 if (!filestr.open (QIODevice::ReadOnly)){
973 yError(
"Error opening calibration file!\n");
982 QByteArray line = filestr.readLine();
983 #if defined(MARCO_ACCAME_19SEP2018)
984 if(line.at(0) !=
'#')
994 while(!line.isEmpty() && line.at(0) ==
'#' && !filestr.atEnd()){
995 line = filestr.readLine();
1002 printf (
"No calib file loaded!\n");
1010 QString s = QString(line);
1017 t >> val[0] >> val[1] >> val[2] >> val[3] >> val[4] >> val[5];
1023 calib_matrix[index][i][j] = value;
1024 matrix[index][i][j] = value;
1027 line = filestr.readLine();
1033 matrix_changed[index]=
true;
1036 while(!line.isEmpty() && line.at(0) ==
'#' && !filestr.atEnd()){
1037 line = filestr.readLine();
1043 if(filestr.atEnd()){
1046 something_changed=
true;
1047 matrix_changed[index]=
true;
1049 printf (
"Calibration Matrix loaded! - No Fullscale found\n");
1050 appendLogMsg(
"Calibration Matrix loaded! - No Fullscale found!");
1061 t >> val[0] >> val[1] >> val[2] >> val[3] >> val[4] >> val[5];
1067 full_scale_calib[index][i] = value;
1073 fullScaleChanged =
true;
1076 something_changed=
true;
1079 printf (
"Calibration file loaded!\n");
1128 void CalibrationWindow::onImportCalibrationFile(
bool click)
1130 QString fileName = QFileDialog::getOpenFileName(
this,
"Choose File",
QDir::home().absolutePath());
1132 if(fileName.isEmpty()){
1140 void CalibrationWindow::onSetCalibration(
bool click)
1145 void CalibrationWindow::onSaveToEeprom(
bool click)
1150 void CalibrationWindow::onClear_Statistics(
bool click)
1155 void CalibrationWindow::onClear_FullRegulation(
bool click)
1160 void CalibrationWindow::onClear_Regulation(
bool click)
1165 void CalibrationWindow::onSetCalibBias(
bool click)
1170 void CalibrationWindow::onResetCalibBias(
bool click)
1175 void CalibrationWindow::onSetCurrBias(
bool click)
1180 void CalibrationWindow::onResetCurrBias(
bool click)
1186 void CalibrationWindow::onSetSerial(
bool)
1191 void CalibrationWindow::onLoading(
bool loading)
1194 ui->centralwidget->setEnabled(
false);
1195 progress->setVisible(
true);
1196 progress->setMaximum(0);
1198 ui->centralwidget->setEnabled(
true);
1199 progress->setVisible(
false);
1200 progress->setMaximum(100);
1204 void CalibrationWindow::onUpdateTitle()
1206 QString title =
"Calibration";
1207 if(!eeprom_saved_status){
1208 title +=
" - ****** Not saved *****";
1210 setWindowTitle(title);
1216 if(!eeprom_saved_status){
1217 if(
QMessageBox::warning(
this,
"The regulation set changed on the RAM of the board ",
"Do you want to save the values to EEPROM?", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes){
1218 onSaveToEeprom(
true);
1223 keepRunning =
false;
1224 QMainWindow::closeEvent(
e);
1227 void CalibrationWindow::onMatrixChanged(QTableWidgetItem *item)
1233 if(item->text() ==
"-"){
1236 QTableWidget *table = (QTableWidget*)sender();
1237 matrix_changed[matrices.indexOf(table)] =
true;
1240 table->item(i,j)->setTextColor(
"red");
1246 void CalibrationWindow::onSerialChanged(QString text)
1251 serial_number_changed =
true;
1254 void CalibrationWindow::onSetSerialChanged(
bool changed)
1257 ui->edit_serial->setStyleSheet(
"background-color: rgb(255,0,0)");
1259 ui->edit_serial->setStyleSheet(
"");
1263 void CalibrationWindow::onClearLog()
1265 ui->logText->clear();
1268 void CalibrationWindow::onAppendLogMsg(QString msg)
1271 ui->logText->appendPlainText(msg);
1275 void CalibrationWindow::onResetCalibMatrix(
bool click)
1287 for (
int ri=0; ri<6; ri++){
1288 for (
int ci=0; ci<6; ci++){
1290 matrix[index][ri][ci] = 32767;
1291 calib_matrix[index][ri][ci] = 32767;
1293 matrix[index][ri][ci] = 0;
1294 calib_matrix[index][ri][ci] = 0;
1298 calib_const[index]=1;
1301 matrix_changed[index] =
true;
1339 int regsetInUseTMP = index + 1;
1361 offset[chan] = value;
1369 void CalibrationWindow::onSetText(QLineEdit *edit,QString text)
1371 edit->setText(text);
1374 void CalibrationWindow::onSetText(QTableWidgetItem *item ,QString text)
1376 item->setText(text);
1379 void CalibrationWindow::onSetTableVisible(QTableWidget *item,
bool visible)
1381 item->setVisible(visible);
1384 void CalibrationWindow::onApplyDone()
1392 void CalibrationWindow::onOffsetSpinnerValue(
CustomSpinBox *spinner,
int value)
1397 void CalibrationWindow::onSetFullScale()
1399 QTableWidget *table = fullScales.first();
1406 sprintf(tempbuf,
"%f",v);
1407 QTableWidgetItem *item = table->item(ri,0);
1408 item->setText(tempbuf);
1416 void CalibrationWindow::onSetMatrix(
int index)
1418 QTableWidget *table = matrices.at(index);
1426 sprintf(tempbuf,
"%f",v);
1427 QTableWidgetItem *item = table->item(ri,ci);
1428 item->setText(tempbuf);
1437 void CalibrationWindow::onTimeout()
1442 qDebug() <<
"STARTING....";
1447 int bUseCalibration = ui->checkDigital->isChecked();
1449 bool skip_display_calib=
false;
1453 if(bUseCalibration) {
1466 ui->comboRegSet->blockSignals(
true);
1467 ui->comboRegSet->setCurrentIndex(regsetInUse - 1);
1468 ui->comboRegSet->blockSignals(
false);
1470 ui->comboRegSetBoot->blockSignals(
true);
1471 ui->comboRegSetBoot->setCurrentIndex(bootRegset - 1);
1472 ui->comboRegSetBoot->blockSignals(
false);
1482 if((icubCanProto_boardType__strain2 == boardtype) || (icubCanProto_boardType__strain2c == boardtype))
1498 ui->comboRegSet->blockSignals(
true);
1499 ui->comboRegSet->setCurrentIndex(regsetInUseTMP - 1);
1500 ui->comboRegSet->blockSignals(
false);
1502 ui->comboRegSetBoot->blockSignals(
true);
1503 ui->comboRegSetBoot->setCurrentIndex(bootRegsetTMP - 1);
1504 ui->comboRegSetBoot->blockSignals(
false);
1515 if(b.
bus == bus && b.
pid ==
id){
1523 if(refresh_serialnumber)
1525 refresh_serialnumber =
false;
1530 setText(ui->edit_serial,serial_no);
1537 &eeprom_saved_status,&msg);
1540 qDebug() <<
"debug: message 'strain_get_eeprom_saved' lost";
1553 qDebug() <<
"debug: message 'strain_get_offset' lost.";
1567 qDebug() <<
"debug: message 'strain_get_adc' lost.";
1581 if (matrix_changed[mi] ==
false){
1606 QTableWidget *table = matrices.at(mi);
1609 table->item(i,j)->setTextColor(
"");
1613 QTableWidget *table = matrices.first();
1616 table->item(i,j)->setTextColor(
"red");
1620 if(!fullScaleChanged){
1622 fullScales.at(mi)->item(ri,0)->setTextColor(
"");
1625 sprintf(tempbuf,
"%d",full_scale_const[mi][ri]);
1626 QTableWidgetItem *item2 = fullScales.at(mi)->item(ri,
COL_FULLSCALE);
1633 fullScales.first()->item(i,0)->setTextColor(
"red");
1653 if (!bUseCalibration){
1678 if(ui->tableCurr->horizontalHeaderItem(0)->text() !=
"ForceTorque"){
1679 setText(ui->tableCurr->horizontalHeaderItem(0),
"ForceTorque");
1689 setText(ui->tableUseMatrix->verticalHeaderItem(i),QString(
"%1").arg(i==0 ?
"Fx"
1695 setText(ui->tableCurr->verticalHeaderItem(i),QString(
"%1").arg(i==0 ?
"Fx"
1711 if(ui->tableCurr->horizontalHeaderItem(0)->text() !=
"ADC"){
1712 setText(ui->tableCurr->horizontalHeaderItem(0),
"ADC");
1719 setText(ui->tableUseMatrix->verticalHeaderItem(i),QString(
"Ch:%1").arg(i));
1720 setText(ui->tableCurr->verticalHeaderItem(i),QString(
"Ch:%1").arg(i));
1733 if((icubCanProto_boardType__strain2 == boardtype) || (icubCanProto_boardType__strain2c == boardtype))
1747 for(
int k=0;k<combo->count();k++){
1748 if(combo->itemData(k).toInt() == amp_gains[i]){
1762 amp_gains[i] = 1.0f;
1772 sprintf(tempbuf,
"%d",
showasQ15(calib_bias[i]));
1774 QTableWidgetItem *item = ui->tableBias->item(i,
COL_CALIBBIAS);
1797 QTableWidgetItem *item3 = NULL;
1798 if(bUseCalibration){
1808 if(bUseCalibration){
1810 sprintf(tempbuf,
"%d",maxft[i]);
1811 QTableWidgetItem *item = ui->tableUseMatrix->item(i,
COL_MAXMEASURE);
1814 sprintf(tempbuf,
"%d",minft[i]);
1815 QTableWidgetItem *item1 = ui->tableUseMatrix->item(i,
COL_MINMEASURE);
1818 sprintf(tempbuf,
"%d",maxft[i]-minft[i]);
1819 QTableWidgetItem *item2 = ui->tableUseMatrix->item(i,
COL_DIFFMEASURE);
1822 if (full_scale_const[currentMatrixIndex][i]==0){
1823 qDebug() <<
"Error getting the full scale "<< i <<
" from the sensor";
1824 skip_display_calib=
true;
1829 if (skip_display_calib==
false){
1845 sprintf(tempbuf,
"%d",maxadc[i]);
1846 QTableWidgetItem *item = ui->tableUseMatrix->item(i,
COL_MAXMEASURE);
1850 sprintf(tempbuf,
"%d",minadc[i]);
1851 QTableWidgetItem *item1 = ui->tableUseMatrix->item(i,
COL_MINMEASURE);
1855 sprintf(tempbuf,
"%d",maxadc[i]-minadc[i]);
1856 QTableWidgetItem *item2 = ui->tableUseMatrix->item(i,
COL_DIFFMEASURE);
1884 QThread::msleep(500);
1892 if (filename==NULL){
1893 yError(
"File not found!\n");
1897 if (selected_id <1 || selected_id >= 15){
1898 yError(
"Invalid board address!\n");
1905 filestr.open (filename, fstream::in);
1906 if (!filestr.is_open()){
1907 yError(
"Error opening calibration file!\n");
1916 filestr.getline (buffer,256);
1917 filestr.getline (buffer,256);
1918 sscanf (buffer,
"%d",&file_version);
1921 if( ( (icubCanProto_boardType__strain2 == boardtype) || (icubCanProto_boardType__strain2c == boardtype) ) && (3 != file_version))
1923 yError(
"Wrong file. Calibration version not supported for strain2: %d\n", file_version);
1924 appendLogMsg(
"Wrong file. Calibration version not supported for strain2");
1927 else if((icubCanProto_boardType__strain == boardtype) && (2 != file_version))
1929 yError(
"Wrong file. Calibration version not supported: %d\n", file_version);
1930 appendLogMsg(
"Wrong file. Calibration version not supported");
1934 if(3 == file_version)
1937 filestr.getline (buffer,256);
1938 filestr.getline (buffer,256);
1939 if(0 != strcmp(buffer,
"strain2"))
1941 yError(
"Wrong file. Board type not supported: %s\n", buffer);
1947 filestr.getline (buffer,256);
1948 filestr.getline (buffer,256);
1949 sprintf(serial_no,
"%s", buffer);
1954 filestr.getline (buffer,256);
1957 filestr.getline (buffer,256);
1959 unsigned int t08[6] = {0};
1960 sscanf (buffer,
"0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", &t08[0], &t08[1], &t08[2], &t08[3], &t08[4], &t08[5]);
1961 for(
int j=0; j<6; j++) amp_registers[i].
data[j] = t08[j];
1977 filestr.getline (buffer,256);
1978 filestr.getline (buffer,256);
1979 sprintf(serial_no,
"%s", buffer);
1983 filestr.getline (buffer,256);
1986 filestr.getline (buffer,256);
1987 sscanf (buffer,
"%d",&offset[i]);
1995 filestr.getline (buffer,256);
1996 for (i=0;i<36; i++){
1999 filestr.getline (buffer,256);
2000 sscanf (buffer,
"%x",&calib_matrix[index][ri][ci]);
2001 printf(
"%d %x\n", calib_matrix[index][ri][ci],calib_matrix[index][ri][ci]);
2008 filestr.getline (buffer,256);
2009 filestr.getline (buffer,256);
2011 sscanf (buffer,
"%d",&cc);
2015 filestr.getline (buffer,256);
2017 filestr.getline (buffer,256);
2018 sscanf (buffer,
"%d",&calib_bias[i]);
2023 filestr.getline (buffer,256);
2025 filestr.getline (buffer,256);
2026 sscanf (buffer,
"%d",&full_scale_const[index][i]);
2035 matrix_changed[0]=
true;
2036 matrix_changed[1]=
true;
2037 matrix_changed[2]=
true;
2038 something_changed=
true;
2039 printf (
"Calibration file loaded!\n");
2046 bool CalibrationWindow::calibration_load_v2 (
char* filename,
int selected_bus,
int selected_id,
int index)
2050 if (filename==NULL){
2051 yError(
"File not found!\n");
2055 if (selected_id <1 || selected_id >= 15){
2056 yError(
"Invalid board address!\n");
2063 filestr.open (filename, fstream::in);
2064 if (!filestr.is_open()){
2065 yError(
"Error opening calibration file!\n");
2074 filestr.getline (buffer,256);
2075 filestr.getline (buffer,256);
2076 sscanf (buffer,
"%d",&file_version);
2077 if (file_version!=2){
2078 yError(
"Wrong file. Calibration version != 2\n");
2084 filestr.getline (buffer,256);
2085 filestr.getline (buffer,256);
2086 sprintf(serial_no,
"%s", buffer);
2090 filestr.getline (buffer,256);
2093 filestr.getline (buffer,256);
2094 sscanf (buffer,
"%d",&offset[i]);
2101 filestr.getline (buffer,256);
2102 for (i=0;i<36; i++){
2105 filestr.getline (buffer,256);
2106 sscanf (buffer,
"%x",&calib_matrix[index][ri][ci]);
2107 printf(
"%d %x\n", calib_matrix[index][ri][ci],calib_matrix[index][ri][ci]);
2114 filestr.getline (buffer,256);
2115 filestr.getline (buffer,256);
2117 sscanf (buffer,
"%d",&cc);
2121 filestr.getline (buffer,256);
2123 filestr.getline (buffer,256);
2124 sscanf (buffer,
"%d",&calib_bias[i]);
2129 filestr.getline (buffer,256);
2131 filestr.getline (buffer,256);
2132 sscanf (buffer,
"%d",&full_scale_const[index][i]);
2141 matrix_changed[0]=
true;
2142 matrix_changed[1]=
true;
2143 matrix_changed[2]=
true;
2144 something_changed=
true;
2145 printf (
"Calibration file loaded!\n");
2153 #if defined(MARCO_ACCAME_19SEP2018)
2158 const int index = 0;
2162 char* buff = fileName.toLatin1().data();
2166 yError(
"File not found!\n");
2174 filestr.open (buff, fstream::in);
2175 if (!filestr.is_open()){
2176 yError(
"Error opening MATLAB matrix-fullscale file!\n");
2177 appendLogMsg(
"Error opening MATLAB matrix-fullscale file!");
2183 printf(
"Importing MATLAB matrix-fullscale file.\n");
2185 printf(
"matrix[6][6] = \n");
2186 unsigned int mat0[6][6] = {0};
2189 for (i=0;i<36; i++){
2192 filestr.getline (buffer,256);
2193 sscanf (buffer,
"%x",&mat0[ri][ci]);
2200 filestr.getline (buffer,256);
2202 sscanf (buffer,
"%d",&cc);
2206 printf(
"gain = %d [BUT IT IS UNUSED]\n", cc);
2208 printf(
"fullscales[6] = \n");
2210 filestr.getline (buffer,256);
2211 sscanf (buffer,
"%d",&cc);
2220 printf (
"MATLAB matrix-fullscale file loaded!\n");
2226 unsigned int mat1[6][6] = {0};
2238 for (i=0;i<36; i++){
2241 if (mat0[ri][ci]==mat1[ri][ci]) {
2244 printf (
"Found 1 error on element %d,%d !!\n",ri, ci);
2250 printf (
"MATLAB matrix-fullscale file %s applied with no errors\n", buff);
2251 appendLogMsg(QString(
"MATLAB matrix-fullscale file %1 applied with no errors").arg(buff));
2254 printf (
"Found %d errors applying the MATLAB matrix-fullscale file!!\n",36-count_ok);
2255 appendLogMsg(QString(
"Found %1 errors applying the MATLAB matrix-fullscale file!!").arg(36-count_ok));
2258 matrix_changed[index] =
false;
2259 fullScaleChanged =
false;
2260 something_changed =
false;
2281 if(alsoserialnumber)
2284 char my_serial_no[8] =
"SN0000";
2288 if((icubCanProto_boardType__strain2 == boardtype) || (icubCanProto_boardType__strain2c == boardtype))
2313 unsigned int value = 0;
int convert_to_signed32k(unsigned int v)
#define COL_NEWTONMEASURE
int showBias(unsigned int v)
unsigned int q15_from(int v)
bool SetDefaultRegulationSet(int regset, bool alsoserialnumber=false)
void setMatrix(int index)
void appendLogMsg(QString)
void Clear_AllRegulations()
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 setText(QLineEdit *, QString text)
CalibrationWindow(FirmwareUpdaterCore *core, icubCanProto_boardType_t b, CustomTreeWidgetItem *item, QWidget *parent=0)
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)
void addCustomValue(float val)
void setIndexFromAmpGain(int g)
void setCurrentValue(int v)
cDownloader * getDownloader()
int strain_get_serial_number(int bus, int target_id, char *serial_number, string *errorstring=NULL)
int strain_set_matrix_gain(int bus, int target_id, unsigned int gain, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_get_offset(int bus, int target_id, char channel, unsigned int &offset, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_get_full_scale(int bus, int target_id, unsigned char channel, unsigned int &full_scale, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_get_calib_bias(int bus, int target_id, char channel, signed int &bias, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_reset_curr_bias(int bus, int target_id, string *errorstring=NULL)
int strain_set_offset(int bus, int target_id, char channel, unsigned int offset, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_serial_number(int bus, int target_id, const char *serial_number, string *errorstring=NULL)
int strain_get_regulationset(int bus, int target_id, int ®set, const int regsetmode=strain_regsetmode_temporary, string *errorstring=NULL)
int strain_save_to_eeprom(int bus, int target_id, string *errorstring=NULL)
int strain_get_adc(int bus, int target_id, char channel, unsigned int &adc, int type, string *errorstring=NULL)
int strain_get_eeprom_saved(int bus, int target_id, bool *status, string *errorstring=NULL)
int strain_reset_calib_bias(int bus, int target_id, string *errorstring=NULL)
int strain_get_matrix_rc(int bus, int target_id, char r, char c, unsigned int &elem, int regset=strain_regset_inuse, string *errorstring=NULL)
void set_external_logger(void *caller=NULL, void(*logger)(void *, const std::string &)=NULL)
int strain_set_full_scale(int bus, int target_id, unsigned char channel, unsigned int full_scale, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_regulationset(int bus, int target_id, int regset=strain_regset_one, int regsetmode=strain_regsetmode_temporary, string *errorstring=NULL)
@ strain_regsetmode_permanent
@ strain_regsetmode_temporary
int strain_set_calib_bias(int bus, int target_id, string *errorstring=NULL)
int strain_get_amplifier_regs(int bus, int target_id, unsigned char channel, strain2_ampl_regs_t &regs, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_curr_bias(int bus, int target_id, string *errorstring=NULL)
int strain_get_amplifier_gain_offset(int bus, int target_id, unsigned char channel, float &gain, uint16_t &offset, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_matrix_rc(int bus, int target_id, char r, char c, unsigned int elem, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_amplifier_regs(int bus, int target_id, unsigned char channel, const strain2_ampl_regs_t &regs, int regset=strain_regset_inuse, string *errorstring=NULL)
int strain_set_amplifier_gain_offset(int bus, int target_id, unsigned char channel, float gain, uint16_t offset, int regset=strain_regset_inuse, string *errorstring=NULL)
float strain_amplifier_discretegain2float(strain2_ampl_discretegain_t c)
int strain_calibrate_offset2(int bus, int target_id, icubCanProto_boardType_t boardtype, const std::vector< strain2_ampl_discretegain_t > &gains, const std::vector< int16_t > &targets, string *errorstring=NULL)
void drv_sleep(double time)
strain2_ampl_discretegain_t
home
store as home position
Gain convert(const DiscreteGain dg)
Q15 convert(const double v, bool &saturated)