26 #include <RobotAPI/gui-plugins/HandUnitPlugin/ui_HandUnitConfigDialog.h>
33 #include <QPushButton>
36 #include <QMessageBox>
38 #include <QtWidgets/QSlider>
39 #include <QtWidgets/QTableWidgetItem>
48 addWidget<HandUnitWidget>();
52 leftHandName(
"NOT SET YET"),
53 rightHandName(
"NOT SET YET"),
54 leftHandUnitProxyName(
""),
55 rightHandUnitProxyName(
""),
56 setLeftHandJointAnglesFlag(false),
57 setRightHandJointAnglesFlag(false)
64 updateInfoTimer =
new QTimer(
this);
78 updateInfoTimer->start(50);
82 setLeftHandJointAngleUpdateTask->start();
84 leftHandUnitProxy = getProxy<HandUnitInterfacePrx>(leftHandUnitProxyName);
85 leftHandName = leftHandUnitProxy->getHandName();
87 if (leftHandName ==
"Hand L" || leftHandName ==
"TCP L")
89 leftHandConversionFactor *=
M_PI / 2;
91 else if (leftHandName !=
"Hand_L_EEF")
93 ARMARX_WARNING <<
"Left hand with name \"" << leftHandName <<
"\" is not supported.";
96 SingleTypeVariantListPtr leftHandPreshapeStrings = SingleTypeVariantListPtr::dynamicCast(leftHandUnitProxy->getShapeNames());
97 QStringList leftHandList;
98 int leftHandPreshapeCount = leftHandPreshapeStrings->getSize();
100 for (
int i = 0; i < leftHandPreshapeCount; ++i)
102 std::string shape = ((leftHandPreshapeStrings->getVariant(i))->get<std::string>());
104 leftHandList << QString::fromStdString(shape);
107 ui.comboLeftHandPreshapes->clear();
108 ui.comboLeftHandPreshapes->addItems(leftHandList);
112 setRightHandJointAngleUpdateTask->start();
114 rightHandUnitProxy = getProxy<HandUnitInterfacePrx>(rightHandUnitProxyName);
115 rightHandName = rightHandUnitProxy->getHandName();
117 if (rightHandName ==
"Hand R" || rightHandName ==
"TCP R")
119 rightHandConversionFactor *=
M_PI / 2;
121 else if (rightHandName !=
"Hand_R_EEF")
123 ARMARX_WARNING <<
"Right hand with name \"" << rightHandName <<
"\" is not supported.";
126 SingleTypeVariantListPtr rightHandPreshapeStrings = SingleTypeVariantListPtr::dynamicCast(rightHandUnitProxy->getShapeNames());
127 QStringList rightHandList;
128 int rightHandPreshapeCount = rightHandPreshapeStrings->getSize();
130 for (
int i = 0; i < rightHandPreshapeCount; ++i)
132 std::string shape = ((rightHandPreshapeStrings->getVariant(i))->get<std::string>());
134 rightHandList << QString::fromStdString(shape);
137 ui.comboRightHandPreshapes->clear();
138 ui.comboRightHandPreshapes->addItems(rightHandList);
145 displayJointAngleUpdateTask->start();
150 setLeftHandJointAngleUpdateTask->stop();
151 setRightHandJointAngleUpdateTask->stop();
152 displayJointAngleUpdateTask->stop();
153 updateInfoTimer->stop();
169 return qobject_cast<HandUnitConfigDialog*>(dialog);
174 leftHandUnitProxyName = dialog->proxyFinderLeftHand->getSelectedProxyName().toStdString();
175 rightHandUnitProxyName = dialog->proxyFinderRightHand->getSelectedProxyName().toStdString();
180 setLeftHandPreshape(
ui.comboLeftHandPreshapes->currentText().toUtf8().data());
185 setRightHandPreshape(
ui.comboRightHandPreshapes->currentText().toUtf8().data());
191 if (!leftHandUnitProxy)
197 if (!setLeftHandJointAnglesFlag)
202 setLeftHandJointAnglesFlag =
false;
205 NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues();
207 if (leftHandName ==
"Hand L" || leftHandName ==
"TCP L")
209 leftHandConversionFactor *=
M_PI / 2;
211 else if (leftHandName !=
"Hand_L_EEF")
213 ARMARX_WARNING <<
"Left hand with name \"" << leftHandName <<
"\" is not supported.";
217 for (
const auto& pair : currentLeftHandJointValues)
219 if (pair.first == currentLeftHandJoint)
221 value =
static_cast<float>(
ui.horizontalSliderLeftHandJointPos->value() * leftHandConversionFactor);
223 leftHandJa[pair.first] =
value;
229 ui.lcdNumberLeftHandJointValue->display(
value / leftHandConversionFactor);
230 leftHandUnitProxy->setJointAngles(leftHandJa);
236 if (!rightHandUnitProxy)
242 if (!setRightHandJointAnglesFlag)
247 setRightHandJointAnglesFlag =
false;
250 NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues();
252 if (rightHandName ==
"Hand R" || rightHandName ==
"TCP R")
254 rightHandConversionFactor *=
M_PI / 2;
256 else if (rightHandName !=
"Hand_R_EEF")
258 ARMARX_WARNING <<
"Right hand with name \"" << rightHandName <<
"\" is not supported.";
262 for (
const auto& pair : currentRightHandJointValues)
264 if (pair.first == currentRightHandJoint)
266 value =
static_cast<float>(
ui.horizontalSliderRightHandJointPos->value() * rightHandConversionFactor);
268 rightHandJa[pair.first] =
value;
274 ui.lcdNumberRightHandJointValue->display(
value / rightHandConversionFactor);
275 rightHandUnitProxy->setJointAngles(rightHandJa);
280 setLeftHandJointAnglesFlag =
true;
285 setRightHandJointAnglesFlag =
true;
290 setLeftHandPreshape(
"Open");
295 setRightHandPreshape(
"Open");
300 setLeftHandPreshape(
"Close");
305 setRightHandPreshape(
"Close");
310 setLeftHandPreshape(
"Relax");
315 setRightHandPreshape(
"Relax");
320 ui.labelInfoLeftHand->setText(QString::fromStdString(leftHandUnitProxyName +
" :: " + leftHandName +
" State: " + leftHandUnitProxy->describeHandState()));
321 ui.labelInfoRightHand->setText(QString::fromStdString(rightHandUnitProxyName +
" :: " + rightHandName +
" State: " + rightHandUnitProxy->describeHandState()));
326 NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues();
328 int frameLeftHandRowIdx = 0;
330 for (
const auto& pair : currentLeftHandJointValues)
333 QString name(pair.first.c_str());
334 QTableWidgetItem* newItem =
new QTableWidgetItem(QString::number(pair.second));
335 ui.tableWidgetLeftHand->setItem(frameLeftHandRowIdx, 1, newItem);
336 frameLeftHandRowIdx++;
341 NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues();
343 int frameRightHandRowIdx = 0;
345 for (
const auto& pair : currentRightHandJointValues)
348 QString name(pair.first.c_str());
349 QTableWidgetItem* newItem =
new QTableWidgetItem(QString::number(pair.second));
350 ui.tableWidgetRightHand->setItem(frameRightHandRowIdx, 1, newItem);
351 frameRightHandRowIdx++;
358 NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues();
361 for (
const auto& pair: currentLeftHandJointValues)
365 currentLeftHandJoint = pair.first;
366 int convertedValue =
static_cast<int>(pair.second / leftHandConversionFactor);
367 ui.horizontalSliderLeftHandJointPos->setSliderPosition(convertedValue);
368 ui.lcdNumberLeftHandJointValue->display(convertedValue);
379 NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues();
382 for (
const auto& pair: currentRightHandJointValues)
386 currentRightHandJoint = pair.first;
387 int convertedValue =
static_cast<int>(pair.second / rightHandConversionFactor);
388 ui.horizontalSliderRightHandJointPos->setSliderPosition(convertedValue);
389 ui.lcdNumberRightHandJointValue->display(convertedValue);
397 void HandUnitWidget::setLeftHandPreshape(std::string preshape)
400 leftHandUnitProxy->setShape(preshape);
403 void HandUnitWidget::setRightHandPreshape(std::string preshape)
406 rightHandUnitProxy->setShape(preshape);
411 leftHandUnitProxyName = settings->value(
"leftHandUnitProxyName", QString::fromStdString(leftHandUnitProxyName)).toString().toStdString();
412 leftHandName = settings->value(
"leftHandName", QString::fromStdString(leftHandName)).toString().toStdString();
413 rightHandUnitProxyName = settings->value(
"rightHandUnitProxyName", QString::fromStdString(rightHandUnitProxyName)).toString().toStdString();
414 rightHandName = settings->value(
"rightHandName", QString::fromStdString(rightHandName)).toString().toStdString();
419 settings->setValue(
"leftHandUnitProxyName", QString::fromStdString(leftHandUnitProxyName));
420 settings->setValue(
"leftHandName", QString::fromStdString(leftHandName));
421 settings->setValue(
"rightHandUnitProxyName", QString::fromStdString(rightHandUnitProxyName));
422 settings->setValue(
"rightHandName", QString::fromStdString(rightHandName));
428 NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues();
430 int frameLeftHandRowIdx = 0;
432 connect(
ui.buttonPreshapeLeftHand, SIGNAL(clicked()),
this, SLOT(
preshapeLeftHand()), Qt::UniqueConnection);
433 connect(
ui.buttonOpenLeftHand, SIGNAL(clicked()),
this, SLOT(
openLeftHand()), Qt::UniqueConnection);
434 connect(
ui.buttonCloseLeftHand, SIGNAL(clicked()),
this, SLOT(
closeLeftHand()), Qt::UniqueConnection);
435 connect(
ui.buttonRelaxLeftHand, SIGNAL(clicked()),
this, SLOT(
relaxLeftHand()), Qt::UniqueConnection);
436 ui.horizontalSliderLeftHandJointPos->setMaximum(100);
437 ui.horizontalSliderLeftHandJointPos->setMinimum(0);
439 connect(
ui.comboLeftHandJoints, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
selectLeftHandJoint(
int)), Qt::UniqueConnection);
441 ui.tableWidgetLeftHand->setRowCount(currentLeftHandJointValues.size());
442 ui.tableWidgetLeftHand->setColumnCount(2);
444 ui.comboLeftHandJoints->clear();
446 qRegisterMetaType<QVector<int> >(
"QVector<int>");
447 for (
const auto& pair : currentLeftHandJointValues)
450 QString name(pair.first.c_str());
451 QTableWidgetItem* newItem =
new QTableWidgetItem(name);
452 ui.tableWidgetLeftHand->setItem(frameLeftHandRowIdx, 0, newItem);
453 ui.comboLeftHandJoints->addItem(name);
454 frameLeftHandRowIdx++;
457 ui.comboLeftHandJoints->setCurrentIndex(-1);
461 NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues();
463 int frameRightHandRowIdx = 0;
465 connect(
ui.buttonPreshapeRightHand, SIGNAL(clicked()),
this, SLOT(
preshapeRightHand()), Qt::UniqueConnection);
466 connect(
ui.buttonOpenRightHand, SIGNAL(clicked()),
this, SLOT(
openRightHand()), Qt::UniqueConnection);
467 connect(
ui.buttonCloseRightHand, SIGNAL(clicked()),
this, SLOT(
closeRightHand()), Qt::UniqueConnection);
468 connect(
ui.buttonRelaxRightHand, SIGNAL(clicked()),
this, SLOT(
relaxRightHand()), Qt::UniqueConnection);
469 ui.horizontalSliderRightHandJointPos->setMaximum(100);
470 ui.horizontalSliderRightHandJointPos->setMinimum(0);
472 connect(
ui.comboRightHandJoints, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
selectRightHandJoint(
int)), Qt::UniqueConnection);
474 ui.tableWidgetRightHand->setRowCount(currentRightHandJointValues.size());
475 ui.tableWidgetRightHand->setColumnCount(2);
477 ui.comboRightHandJoints->clear();
479 qRegisterMetaType<QVector<int> >(
"QVector<int>");
480 for (
const auto& pair : currentRightHandJointValues)
483 QString name(pair.first.c_str());
484 QTableWidgetItem* newItem =
new QTableWidgetItem(name);
485 ui.tableWidgetRightHand->setItem(frameRightHandRowIdx, 0, newItem);
486 ui.comboRightHandJoints->addItem(name);
487 frameRightHandRowIdx++;
490 ui.comboRightHandJoints->setCurrentIndex(-1);