diff --git a/source/RobotAPI/components/units/HandUnit.cpp b/source/RobotAPI/components/units/HandUnit.cpp index 0b19a5566bbf07fdd4f6805ff0cbcedc181a150b..237ea2180bd5ec2ed68e6750f0f360984f0884d7 100644 --- a/source/RobotAPI/components/units/HandUnit.cpp +++ b/source/RobotAPI/components/units/HandUnit.cpp @@ -25,19 +25,19 @@ #include "HandUnit.h" -#include <ArmarXCore/core/system/ArmarXDataPath.h> +#include <vector> -#include <VirtualRobot/VirtualRobot.h> #include <VirtualRobot/EndEffector/EndEffector.h> +#include <VirtualRobot/VirtualRobot.h> #include <VirtualRobot/XML/RobotIO.h> -#include <vector> +#include <ArmarXCore/core/system/ArmarXDataPath.h> using namespace armarx; using namespace VirtualRobot; - -void HandUnit::onInitComponent() +void +HandUnit::onInitComponent() { std::string endeffectorFile = getProperty<std::string>("RobotFileName").getValue(); std::string endeffectorName = getProperty<std::string>("EndeffectorName").getValue(); @@ -50,7 +50,8 @@ void HandUnit::onInitComponent() try { - robot = VirtualRobot::RobotIO::loadRobot(endeffectorFile, VirtualRobot::RobotIO::eStructure); + robot = + VirtualRobot::RobotIO::loadRobot(endeffectorFile, VirtualRobot::RobotIO::eStructure); } catch (VirtualRobot::VirtualRobotException& e) { @@ -86,7 +87,7 @@ void HandUnit::onInitComponent() for (size_t i = 0; i < actors.size(); i++) { EndEffectorActorPtr a = actors[i]; - std::vector<EndEffectorActor::ActorDefinition> ads;// = a->getDefinition(); + std::vector<EndEffectorActor::ActorDefinition> ads; // = a->getDefinition(); for (size_t j = 0; j < ads.size(); j++) { @@ -99,7 +100,8 @@ void HandUnit::onInitComponent() } } - const std::vector<std::string> endeffectorPreshapes = robot->getEndEffector(endeffectorName)->getPreshapes(); + const std::vector<std::string> endeffectorPreshapes = + robot->getEndEffector(endeffectorName)->getPreshapes(); shapeNames = new SingleTypeVariantList(VariantType::String); std::vector<std::string>::const_iterator iter = endeffectorPreshapes.begin(); @@ -120,8 +122,8 @@ void HandUnit::onInitComponent() this->onInitHandUnit(); } - -void HandUnit::onConnectComponent() +void +HandUnit::onConnectComponent() { ARMARX_INFO << "setting report topic to " << listenerChannelName << flush; listenerPrx = getTopic<HandUnitListenerPrx>(listenerChannelName); @@ -129,45 +131,48 @@ void HandUnit::onConnectComponent() this->onStartHandUnit(); } - -void HandUnit::onExitComponent() +void +HandUnit::onExitComponent() { this->onExitHandUnit(); } - - -void HandUnit::setShape(const std::string& shapeName, const Ice::Current& c) +void +HandUnit::setShape(const std::string& shapeName, const Ice::Current& c) { } -void HandUnit::setShapeWithObjectInstance(const std::string& shapeName, const std::string& objectInstanceName, const Ice::Current& c) +void +HandUnit::setShapeWithObjectInstance(const std::string& shapeName, + const std::string& objectInstanceName, + const Ice::Current& c) { ARMARX_WARNING << "setShapeWithObjectInstance Function not implemented!"; } - -SingleTypeVariantListBasePtr HandUnit::getShapeNames(const Ice::Current& c) +SingleTypeVariantListBasePtr +HandUnit::getShapeNames(const Ice::Current& c) { return shapeNames; } - -PropertyDefinitionsPtr HandUnit::createPropertyDefinitions() +PropertyDefinitionsPtr +HandUnit::createPropertyDefinitions() { - return PropertyDefinitionsPtr(new HandUnitPropertyDefinitions( - getConfigIdentifier())); + return PropertyDefinitionsPtr(new HandUnitPropertyDefinitions(getConfigIdentifier())); } - -NameValueMap HandUnit::getShapeJointValues(const std::string& shapeName, const Ice::Current&) +NameValueMap +HandUnit::getShapeJointValues(const std::string& shapeName, const Ice::Current&) { - EndEffectorPtr efp = robot->getEndEffector(getProperty<std::string>("EndeffectorName").getValue()); + EndEffectorPtr efp = + robot->getEndEffector(getProperty<std::string>("EndeffectorName").getValue()); RobotConfigPtr rc = efp->getPreshape(shapeName); return rc->getRobotNodeJointValueMap(); } -NameValueMap HandUnit::getCurrentJointValues(const Ice::Current& c) +NameValueMap +HandUnit::getCurrentJointValues(const Ice::Current& c) { NameValueMap result; @@ -179,42 +184,44 @@ NameValueMap HandUnit::getCurrentJointValues(const Ice::Current& c) return result; } -void HandUnit::setObjectGrasped(const std::string& objectName, const Ice::Current&) +void +HandUnit::setObjectGrasped(const std::string& objectName, const Ice::Current&) { ARMARX_INFO << "Object grasped " << objectName << flush; graspedObject = objectName; } -void HandUnit::setObjectReleased(const std::string& objectName, const Ice::Current&) +void +HandUnit::setObjectReleased(const std::string& objectName, const Ice::Current&) { ARMARX_INFO << "Object released " << objectName << flush; graspedObject = ""; } - - -std::string armarx::HandUnit::getHandName(const Ice::Current&) +std::string +armarx::HandUnit::getHandName(const Ice::Current&) { return eef->getName(); } -void HandUnit::setJointForces(const NameValueMap& targetJointForces, const Ice::Current&) +void +HandUnit::setJointForces(const NameValueMap& targetJointForces, const Ice::Current&) { - } -void HandUnit::sendJointCommands(const NameCommandMap& targetJointCommands, const Ice::Current&) +void +HandUnit::sendJointCommands(const NameCommandMap& targetJointCommands, const Ice::Current&) { - } - -void armarx::HandUnit::setJointAngles(const armarx::NameValueMap& targetJointAngles, const Ice::Current& c) +void +armarx::HandUnit::setJointAngles(const armarx::NameValueMap& targetJointAngles, + const Ice::Current& c) { - } -std::string HandUnit::describeHandState(const Ice::Current&) +std::string +HandUnit::describeHandState(const Ice::Current&) { return "not implemented"; } @@ -224,3 +231,15 @@ armarx::HandUnit::reloadPreshapes(const Ice::Current&) { ARMARX_WARNING << "`reloadPreshapes` not implemented for this hand unit!"; } + +void +armarx::HandUnit::tare(const Ice::Current&) +{ + ARMARX_WARNING << "Taring is not supported by this hand."; +} + +void +armarx::HandUnit::resetFirmware(const Ice::Current&) +{ + ARMARX_WARNING << "Resetting firmware is not supported by this hand."; +} diff --git a/source/RobotAPI/components/units/HandUnit.h b/source/RobotAPI/components/units/HandUnit.h index c68f915579890d59fb96a1c4d811041477a13ec6..43fb4d00c9799905df3a063a8a51a50f727d6c5f 100644 --- a/source/RobotAPI/components/units/HandUnit.h +++ b/source/RobotAPI/components/units/HandUnit.h @@ -24,16 +24,14 @@ #pragma once -#include <RobotAPI/components/units/SensorActorUnit.h> - -#include <RobotAPI/interface/units/HandUnitInterface.h> +#include <VirtualRobot/VirtualRobot.h> #include <ArmarXCore/core/application/properties/Properties.h> #include <ArmarXCore/core/system/ImportExportComponent.h> #include <ArmarXCore/observers/variant/SingleTypeVariantList.h> -#include <VirtualRobot/VirtualRobot.h> - +#include <RobotAPI/components/units/SensorActorUnit.h> +#include <RobotAPI/interface/units/HandUnitInterface.h> namespace armarx { @@ -41,19 +39,20 @@ namespace armarx * \class HandUnitPropertyDefinitions * \brief Defines all necessary properties for armarx::HandUnit */ - class HandUnitPropertyDefinitions: - public ComponentPropertyDefinitions + class HandUnitPropertyDefinitions : public ComponentPropertyDefinitions { public: - HandUnitPropertyDefinitions(std::string prefix): - ComponentPropertyDefinitions(prefix) + HandUnitPropertyDefinitions(std::string prefix) : ComponentPropertyDefinitions(prefix) { - defineRequiredProperty<std::string>("RobotFileName", "VirtualRobot XML file in which the endeffector is is stored."); - defineRequiredProperty<std::string>("EndeffectorName", "Name of the endeffector as stored in the XML file (will publish values on EndeffectorName + 'State')"); + defineRequiredProperty<std::string>( + "RobotFileName", "VirtualRobot XML file in which the endeffector is is stored."); + defineRequiredProperty<std::string>( + "EndeffectorName", + "Name of the endeffector as stored in the XML file (will publish values on " + "EndeffectorName + 'State')"); } }; - /** * @ingroup Component-HandUnit HandUnit * \brief Base unit for high-level access to robot hands. @@ -68,13 +67,12 @@ namespace armarx * @brief The HandUnit class * @ingroup Component-HandUnit */ - class HandUnit : - virtual public HandUnitInterface, - virtual public SensorActorUnit + class HandUnit : virtual public HandUnitInterface, virtual public SensorActorUnit { public: // inherited from Component - std::string getDefaultName() const override + std::string + getDefaultName() const override { return "HandUnit"; } @@ -112,7 +110,8 @@ namespace armarx /** * Send command to the hand to form a specific shape position. The shapes are defined in the robot.xml file. */ - void setShape(const std::string& shapeName, const Ice::Current& c = Ice::emptyCurrent) override; + void setShape(const std::string& shapeName, + const Ice::Current& c = Ice::emptyCurrent) override; /** * @brief setShapeWithObjectInstance Send command to the hand to form a specific shape position. @@ -122,14 +121,18 @@ namespace armarx * @param shapeName Name of the well known shape that the hand should form * @param graspedObjectInstanceName name of the object instance which is used to check for collisions while setting the shape */ - void setShapeWithObjectInstance(const std::string& shapeName, const std::string& objectInstanceName, const Ice::Current& c = Ice::emptyCurrent) override; + void setShapeWithObjectInstance(const std::string& shapeName, + const std::string& objectInstanceName, + const Ice::Current& c = Ice::emptyCurrent) override; /** * \return a list of strings for shape positions which can be used together with HandUnit::shape(). */ - SingleTypeVariantListBasePtr getShapeNames(const Ice::Current& c = Ice::emptyCurrent) override; + SingleTypeVariantListBasePtr + getShapeNames(const Ice::Current& c = Ice::emptyCurrent) override; - NameValueMap getShapeJointValues(const std::string& shapeName, const Ice::Current& c = Ice::emptyCurrent) override; + NameValueMap getShapeJointValues(const std::string& shapeName, + const Ice::Current& c = Ice::emptyCurrent) override; NameValueMap getCurrentJointValues(const Ice::Current& c = Ice::emptyCurrent) override; void setObjectGrasped(const std::string& objectName, const Ice::Current&) override; @@ -145,6 +148,10 @@ namespace armarx void reloadPreshapes(const Ice::Current&) override; + void tare(const Ice::Current&) override; + + void resetFirmware(const Ice::Current&) override; + protected: /** * HandUnitListener proxy for publishing state updates @@ -167,7 +174,7 @@ namespace armarx std::string robotName; std::string tcpName; - std::map <std::string, float> handJoints; + std::map<std::string, float> handJoints; std::string graspedObject; @@ -176,6 +183,7 @@ namespace armarx public: std::string getHandName(const Ice::Current& = Ice::emptyCurrent) override; void setJointForces(const NameValueMap& targetJointForces, const Ice::Current&) override; - void sendJointCommands(const NameCommandMap& targetJointCommands, const Ice::Current&) override; + void sendJointCommands(const NameCommandMap& targetJointCommands, + const Ice::Current&) override; }; -} +} // namespace armarx diff --git a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.cpp b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.cpp index 72ff523b09b5e5282d1caff1b5ae92f559cbceee..fec96cb89cc635119afe1d1e260a805c7a850936 100644 --- a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.cpp +++ b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.cpp @@ -22,24 +22,27 @@ * GNU General Public License */ #include "HandUnitGuiPlugin.h" -#include "HandUnitConfigDialog.h" -#include <RobotAPI/gui-plugins/HandUnitPlugin/ui_HandUnitConfigDialog.h> + #include <ArmarXCore/core/system/ArmarXDataPath.h> #include <ArmarXCore/observers/variant/SingleTypeVariantList.h> +#include <RobotAPI/gui-plugins/HandUnitPlugin/ui_HandUnitConfigDialog.h> + +#include "HandUnitConfigDialog.h" + // Qt headers -#include <Qt> -#include <QtGlobal> -#include <QPushButton> +#include <cmath> + #include <QLabel> #include <QLineEdit> #include <QMessageBox> +#include <QPushButton> +#include <QString> #include <QTimer> +#include <Qt> +#include <QtGlobal> #include <QtWidgets/QSlider> #include <QtWidgets/QTableWidgetItem> -#include <QString> - -#include <cmath> namespace armarx { @@ -63,13 +66,15 @@ namespace armarx ARMARX_INFO << "Done: Setup UI"; - setLeftHandJointAngleUpdateTask = new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::setLeftHandJointAngles, 50); - setRightHandJointAngleUpdateTask = new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::setRightHandJointAngles, 50); + setLeftHandJointAngleUpdateTask = + new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::setLeftHandJointAngles, 50); + setRightHandJointAngleUpdateTask = + new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::setRightHandJointAngles, 50); updateInfoTimer = new QTimer(this); } - - void HandUnitWidget::onInitComponent() + void + HandUnitWidget::onInitComponent() { usingProxy(leftHandUnitProxyName); usingProxy(rightHandUnitProxyName); @@ -77,12 +82,12 @@ namespace armarx //ARMARX_WARNING << "Listening on Topic: " << handName + "State"; } - void HandUnitWidget::onConnectComponent() + void + HandUnitWidget::onConnectComponent() { updateInfoTimer->start(50); - setLeftHandJointAngleUpdateTask->start(); leftHandUnitProxy = getProxy<HandUnitInterfacePrx>(leftHandUnitProxyName); @@ -97,14 +102,15 @@ namespace armarx ARMARX_WARNING << "Left hand with name \"" << leftHandName << "\" is not supported."; } - SingleTypeVariantListPtr leftHandPreshapeStrings = SingleTypeVariantListPtr::dynamicCast(leftHandUnitProxy->getShapeNames()); + SingleTypeVariantListPtr leftHandPreshapeStrings = + SingleTypeVariantListPtr::dynamicCast(leftHandUnitProxy->getShapeNames()); QStringList leftHandList; int leftHandPreshapeCount = leftHandPreshapeStrings->getSize(); for (int i = 0; i < leftHandPreshapeCount; ++i) { std::string shape = ((leftHandPreshapeStrings->getVariant(i))->get<std::string>()); -// ARMARX_INFO << VAROUT(shape); + // ARMARX_INFO << VAROUT(shape); leftHandList << QString::fromStdString(shape); } @@ -112,7 +118,6 @@ namespace armarx ui.comboLeftHandPreshapes->addItems(leftHandList); - setRightHandJointAngleUpdateTask->start(); rightHandUnitProxy = getProxy<HandUnitInterfacePrx>(rightHandUnitProxyName); @@ -127,14 +132,15 @@ namespace armarx ARMARX_WARNING << "Right hand with name \"" << rightHandName << "\" is not supported."; } - SingleTypeVariantListPtr rightHandPreshapeStrings = SingleTypeVariantListPtr::dynamicCast(rightHandUnitProxy->getShapeNames()); + SingleTypeVariantListPtr rightHandPreshapeStrings = + SingleTypeVariantListPtr::dynamicCast(rightHandUnitProxy->getShapeNames()); QStringList rightHandList; int rightHandPreshapeCount = rightHandPreshapeStrings->getSize(); for (int i = 0; i < rightHandPreshapeCount; ++i) { std::string shape = ((rightHandPreshapeStrings->getVariant(i))->get<std::string>()); -// ARMARX_INFO << VAROUT(shape); + // ARMARX_INFO << VAROUT(shape); rightHandList << QString::fromStdString(shape); } @@ -142,14 +148,17 @@ namespace armarx ui.comboRightHandPreshapes->addItems(rightHandList); - -// ARMARX_INFO << "initGUIJointFrames"; + // ARMARX_INFO << "initGUIJointFrames"; initGUIJointFrames(); - displayJointAngleUpdateTask = new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::updateJointValueTable, 50); + displayJointAngleUpdateTask = + new PeriodicTask<HandUnitWidget>(this, &HandUnitWidget::updateJointValueTable, 50); displayJointAngleUpdateTask->start(); + + updateInfoLabel(); } - void HandUnitWidget::onDisconnectComponent() + void + HandUnitWidget::onDisconnectComponent() { setLeftHandJointAngleUpdateTask->stop(); setRightHandJointAngleUpdateTask->stop(); @@ -157,11 +166,13 @@ namespace armarx updateInfoTimer->stop(); } - void HandUnitWidget::onExitComponent() + void + HandUnitWidget::onExitComponent() { } - QPointer<QDialog> HandUnitWidget::getConfigDialog(QWidget* parent) + QPointer<QDialog> + HandUnitWidget::getConfigDialog(QWidget* parent) { if (!dialog) { @@ -173,29 +184,33 @@ namespace armarx return qobject_cast<HandUnitConfigDialog*>(dialog); } - void HandUnitWidget::configured() + void + HandUnitWidget::configured() { leftHandUnitProxyName = dialog->proxyFinderLeftHand->getSelectedProxyName().toStdString(); rightHandUnitProxyName = dialog->proxyFinderRightHand->getSelectedProxyName().toStdString(); } - void HandUnitWidget::preshapeLeftHand() + void + HandUnitWidget::preshapeLeftHand() { setLeftHandPreshape(ui.comboLeftHandPreshapes->currentText().toUtf8().data()); } - void HandUnitWidget::preshapeRightHand() + void + HandUnitWidget::preshapeRightHand() { setRightHandPreshape(ui.comboRightHandPreshapes->currentText().toUtf8().data()); } - void HandUnitWidget::reloadPreshapes() + void + HandUnitWidget::reloadPreshapes() { ARMARX_INFO << "Reloading preshapes in robot unit ..."; // left hand unit { - if(leftHandUnitProxy) + if (leftHandUnitProxy) { ARMARX_INFO << "Left hand unit: reloading preshapes."; leftHandUnitProxy->reloadPreshapes(); @@ -204,7 +219,7 @@ namespace armarx // right hand unit { - if(rightHandUnitProxy) + if (rightHandUnitProxy) { ARMARX_INFO << "Right hand unit: reloading preshapes."; rightHandUnitProxy->reloadPreshapes(); @@ -212,9 +227,10 @@ namespace armarx } } - void HandUnitWidget::setLeftHandJointAngles() - { -// ARMARX_INFO << "setLeftHandJointAngles"; + void + HandUnitWidget::setLeftHandJointAngles() + { + // ARMARX_INFO << "setLeftHandJointAngles"; if (!leftHandUnitProxy) { ARMARX_WARNING << "invalid proxy"; @@ -245,21 +261,23 @@ namespace armarx { if (pair.first == currentLeftHandJoint) { - value = static_cast<float>(ui.horizontalSliderLeftHandJointPos->value() * leftHandConversionFactor); -// ARMARX_INFO << VAROUT(value); + value = static_cast<float>(ui.horizontalSliderLeftHandJointPos->value() * + leftHandConversionFactor); + // ARMARX_INFO << VAROUT(value); leftHandJa[pair.first] = value; break; } } -// ARMARX_INFO << VAROUT(value / leftHandConversionFactor); + // ARMARX_INFO << VAROUT(value / leftHandConversionFactor); ui.lcdNumberLeftHandJointValue->display(value / leftHandConversionFactor); leftHandUnitProxy->setJointAngles(leftHandJa); } - void HandUnitWidget::setRightHandJointAngles() + void + HandUnitWidget::setRightHandJointAngles() { -// ARMARX_INFO << "setRightHandJointAngles"; + // ARMARX_INFO << "setRightHandJointAngles"; if (!rightHandUnitProxy) { ARMARX_WARNING << "invalid proxy"; @@ -290,73 +308,88 @@ namespace armarx { if (pair.first == currentRightHandJoint) { - value = static_cast<float>(ui.horizontalSliderRightHandJointPos->value() * rightHandConversionFactor); -// ARMARX_INFO << VAROUT(value); + value = static_cast<float>(ui.horizontalSliderRightHandJointPos->value() * + rightHandConversionFactor); + // ARMARX_INFO << VAROUT(value); rightHandJa[pair.first] = value; break; } } -// ARMARX_INFO << VAROUT(value / rightHandConversionFactor); + // ARMARX_INFO << VAROUT(value / rightHandConversionFactor); ui.lcdNumberRightHandJointValue->display(value / rightHandConversionFactor); rightHandUnitProxy->setJointAngles(rightHandJa); } - void HandUnitWidget::requestSetLeftHandJointAngles() + void + HandUnitWidget::requestSetLeftHandJointAngles() { setLeftHandJointAnglesFlag = true; } - void HandUnitWidget::requestSetRightHandJointAngles() + void + HandUnitWidget::requestSetRightHandJointAngles() { setRightHandJointAnglesFlag = true; } - void HandUnitWidget::openLeftHand() + void + HandUnitWidget::openLeftHand() { setLeftHandPreshape("Open"); } - void HandUnitWidget::openRightHand() + void + HandUnitWidget::openRightHand() { setRightHandPreshape("Open"); } - void HandUnitWidget::closeLeftHand() + void + HandUnitWidget::closeLeftHand() { setLeftHandPreshape("Close"); } - void HandUnitWidget::closeRightHand() + void + HandUnitWidget::closeRightHand() { setRightHandPreshape("Close"); } - void HandUnitWidget::relaxLeftHand() + void + HandUnitWidget::relaxLeftHand() { setLeftHandPreshape("Relax"); } - void HandUnitWidget::relaxRightHand() + void + HandUnitWidget::relaxRightHand() { setRightHandPreshape("Relax"); } - void HandUnitWidget::updateInfoLabel() + void + HandUnitWidget::updateInfoLabel() { - ui.labelInfoLeftHand->setText(QString::fromStdString(leftHandUnitProxyName + " :: " + leftHandName + " State: " + leftHandUnitProxy->describeHandState())); - ui.labelInfoRightHand->setText(QString::fromStdString(rightHandUnitProxyName + " :: " + rightHandName + " State: " + rightHandUnitProxy->describeHandState())); + ui.labelInfoLeftHand->setText( + QString::fromStdString(leftHandUnitProxyName + " :: " + leftHandName + + " State: " + leftHandUnitProxy->describeHandState())); + ui.labelInfoRightHand->setText( + QString::fromStdString(rightHandUnitProxyName + " :: " + rightHandName + + " State: " + rightHandUnitProxy->describeHandState())); } - void HandUnitWidget::updateJointValueTable() + void + HandUnitWidget::updateJointValueTable() { NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues(); -// ARMARX_INFO << VAROUT(leftHandUnitProxy->getCurrentJointValues()); + // ARMARX_INFO << VAROUT(leftHandUnitProxy->getCurrentJointValues()); int frameLeftHandRowIdx = 0; for (const auto& pair : currentLeftHandJointValues) { -// ARMARX_INFO << VAROUT(pair.first); + // ARMARX_INFO << VAROUT(pair.first); QString name(pair.first.c_str()); QTableWidgetItem* newItem = new QTableWidgetItem(QString::number(pair.second)); ui.tableWidgetLeftHand->setItem(frameLeftHandRowIdx, 1, newItem); @@ -364,14 +397,13 @@ namespace armarx } - NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues(); -// ARMARX_INFO << VAROUT(rightHandUnitProxy->getCurrentJointValues()); + // ARMARX_INFO << VAROUT(rightHandUnitProxy->getCurrentJointValues()); int frameRightHandRowIdx = 0; for (const auto& pair : currentRightHandJointValues) { -// ARMARX_INFO << VAROUT(pair.first); + // ARMARX_INFO << VAROUT(pair.first); QString name(pair.first.c_str()); QTableWidgetItem* newItem = new QTableWidgetItem(QString::number(pair.second)); ui.tableWidgetRightHand->setItem(frameRightHandRowIdx, 1, newItem); @@ -379,13 +411,73 @@ namespace armarx } } - void HandUnitWidget::selectLeftHandJoint(int i) + void + HandUnitWidget::setExpertMode(side side, int state) + { + bool const isExpert = state == Qt::Checked; + + if (side == side::left) + { + ui.leftTare->setEnabled(isExpert); + ui.leftReset->setEnabled(isExpert); + } + else if (side == side::right) + { + ui.rightTare->setEnabled(isExpert); + ui.rightReset->setEnabled(isExpert); + } + else + { + ARMARX_WARNING << "Invalid side to set expert mode."; + } + } + + void + HandUnitWidget::tareHand(side side) { -// ARMARX_INFO << "selectLeftHandJoint " << i; + if (side == side::left) + { + ARMARX_INFO << "Trigger taring left hand now..."; + leftHandUnitProxy->tare(); + } + else if (side == side::right) + { + ARMARX_INFO << "Trigger taring right hand now..."; + rightHandUnitProxy->tare(); + } + else + { + ARMARX_WARNING << "Invalid side to tare hand."; + } + } + + void + HandUnitWidget::resetHand(side side) + { + if (side == side::left) + { + ARMARX_INFO << "Trigger resetting left hand firmware now..."; + leftHandUnitProxy->resetFirmware(); + } + else if (side == side::right) + { + ARMARX_INFO << "Trigger resetting right hand firmware now..."; + rightHandUnitProxy->resetFirmware(); + } + else + { + ARMARX_WARNING << "Invalid side to reset hand firmware."; + } + } + + void + HandUnitWidget::selectLeftHandJoint(int i) + { + // ARMARX_INFO << "selectLeftHandJoint " << i; NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues(); int idx = 0; - for (const auto& pair: currentLeftHandJointValues) + for (const auto& pair : currentLeftHandJointValues) { if (idx == i) { @@ -393,20 +485,21 @@ namespace armarx int convertedValue = static_cast<int>(pair.second / leftHandConversionFactor); ui.horizontalSliderLeftHandJointPos->setSliderPosition(convertedValue); ui.lcdNumberLeftHandJointValue->display(convertedValue); -// ARMARX_INFO << "Found joint"; + // ARMARX_INFO << "Found joint"; break; } idx++; } } - void HandUnitWidget::selectRightHandJoint(int i) + void + HandUnitWidget::selectRightHandJoint(int i) { -// ARMARX_INFO << "selectRightHandJoint " << i; + // ARMARX_INFO << "selectRightHandJoint " << i; NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues(); int idx = 0; - for (const auto& pair: currentRightHandJointValues) + for (const auto& pair : currentRightHandJointValues) { if (idx == i) { @@ -414,68 +507,113 @@ namespace armarx int convertedValue = static_cast<int>(pair.second / rightHandConversionFactor); ui.horizontalSliderRightHandJointPos->setSliderPosition(convertedValue); ui.lcdNumberRightHandJointValue->display(convertedValue); -// ARMARX_INFO << "Found joint"; + // ARMARX_INFO << "Found joint"; break; } idx++; } } - void HandUnitWidget::setLeftHandPreshape(std::string preshape) + void + HandUnitWidget::setLeftHandPreshape(std::string preshape) { -// ARMARX_INFO << "Setting new left hand shape: " << preshape; + // ARMARX_INFO << "Setting new left hand shape: " << preshape; leftHandUnitProxy->setShape(preshape); } - void HandUnitWidget::setRightHandPreshape(std::string preshape) + void + HandUnitWidget::setRightHandPreshape(std::string preshape) { -// ARMARX_INFO << "Setting new right hand shape: " << preshape; + // ARMARX_INFO << "Setting new right hand shape: " << preshape; rightHandUnitProxy->setShape(preshape); } - void HandUnitWidget::loadSettings(QSettings* settings) + void + HandUnitWidget::loadSettings(QSettings* settings) { - leftHandUnitProxyName = settings->value("leftHandUnitProxyName", QString::fromStdString(leftHandUnitProxyName)).toString().toStdString(); - leftHandName = settings->value("leftHandName", QString::fromStdString(leftHandName)).toString().toStdString(); - rightHandUnitProxyName = settings->value("rightHandUnitProxyName", QString::fromStdString(rightHandUnitProxyName)).toString().toStdString(); - rightHandName = settings->value("rightHandName", QString::fromStdString(rightHandName)).toString().toStdString(); + leftHandUnitProxyName = + settings->value("leftHandUnitProxyName", QString::fromStdString(leftHandUnitProxyName)) + .toString() + .toStdString(); + leftHandName = settings->value("leftHandName", QString::fromStdString(leftHandName)) + .toString() + .toStdString(); + rightHandUnitProxyName = + settings + ->value("rightHandUnitProxyName", QString::fromStdString(rightHandUnitProxyName)) + .toString() + .toStdString(); + rightHandName = settings->value("rightHandName", QString::fromStdString(rightHandName)) + .toString() + .toStdString(); } - void HandUnitWidget::saveSettings(QSettings* settings) + void + HandUnitWidget::saveSettings(QSettings* settings) { settings->setValue("leftHandUnitProxyName", QString::fromStdString(leftHandUnitProxyName)); settings->setValue("leftHandName", QString::fromStdString(leftHandName)); - settings->setValue("rightHandUnitProxyName", QString::fromStdString(rightHandUnitProxyName)); + settings->setValue("rightHandUnitProxyName", + QString::fromStdString(rightHandUnitProxyName)); settings->setValue("rightHandName", QString::fromStdString(rightHandName)); } - - void HandUnitWidget::initGUIJointFrames() + void + HandUnitWidget::initGUIJointFrames() { ARMARX_INFO << "initGUIJointFrames"; - + NameValueMap currentLeftHandJointValues = leftHandUnitProxy->getCurrentJointValues(); -// ARMARX_INFO << VAROUT(leftHandUnitProxy->getCurrentJointValues()); + // ARMARX_INFO << VAROUT(leftHandUnitProxy->getCurrentJointValues()); int frameLeftHandRowIdx = 0; - connect(ui.buttonPreshapeLeftHand, SIGNAL(clicked()), this, SLOT(preshapeLeftHand()), Qt::UniqueConnection); - connect(ui.buttonOpenLeftHand, SIGNAL(clicked()), this, SLOT(openLeftHand()), Qt::UniqueConnection); - connect(ui.buttonCloseLeftHand, SIGNAL(clicked()), this, SLOT(closeLeftHand()), Qt::UniqueConnection); - connect(ui.buttonRelaxLeftHand, SIGNAL(clicked()), this, SLOT(relaxLeftHand()), Qt::UniqueConnection); + connect(ui.buttonPreshapeLeftHand, + SIGNAL(clicked()), + this, + SLOT(preshapeLeftHand()), + Qt::UniqueConnection); + connect(ui.buttonOpenLeftHand, + SIGNAL(clicked()), + this, + SLOT(openLeftHand()), + Qt::UniqueConnection); + connect(ui.buttonCloseLeftHand, + SIGNAL(clicked()), + this, + SLOT(closeLeftHand()), + Qt::UniqueConnection); + connect(ui.buttonRelaxLeftHand, + SIGNAL(clicked()), + this, + SLOT(relaxLeftHand()), + Qt::UniqueConnection); ui.horizontalSliderLeftHandJointPos->setMaximum(100); ui.horizontalSliderLeftHandJointPos->setMinimum(0); - connect(ui.horizontalSliderLeftHandJointPos, SIGNAL(sliderMoved(int)), this, SLOT(requestSetLeftHandJointAngles()), Qt::UniqueConnection); - connect(ui.comboLeftHandJoints, SIGNAL(currentIndexChanged(int)), this, SLOT(selectLeftHandJoint(int)), Qt::UniqueConnection); + connect(ui.horizontalSliderLeftHandJointPos, + SIGNAL(sliderMoved(int)), + this, + SLOT(requestSetLeftHandJointAngles()), + Qt::UniqueConnection); + connect(ui.comboLeftHandJoints, + SIGNAL(currentIndexChanged(int)), + this, + SLOT(selectLeftHandJoint(int)), + Qt::UniqueConnection); + connect(ui.leftExpertMode, + &QCheckBox::stateChanged, + [&](int state) { setExpertMode(side::left, state); }); + connect(ui.leftTare, &QPushButton::clicked, [&] { tareHand(side::left); }); + connect(ui.leftReset, &QPushButton::clicked, [&] { resetHand(side::left); }); ui.tableWidgetLeftHand->setRowCount(currentLeftHandJointValues.size()); ui.tableWidgetLeftHand->setColumnCount(2); ui.comboLeftHandJoints->clear(); - qRegisterMetaType<QVector<int> >("QVector<int>"); + qRegisterMetaType<QVector<int>>("QVector<int>"); for (const auto& pair : currentLeftHandJointValues) { -// ARMARX_INFO << VAROUT(pair.first); + // ARMARX_INFO << VAROUT(pair.first); QString name(pair.first.c_str()); QTableWidgetItem* newItem = new QTableWidgetItem(name); ui.tableWidgetLeftHand->setItem(frameLeftHandRowIdx, 0, newItem); @@ -486,29 +624,57 @@ namespace armarx ui.comboLeftHandJoints->setCurrentIndex(-1); - NameValueMap currentRightHandJointValues = rightHandUnitProxy->getCurrentJointValues(); -// ARMARX_INFO << VAROUT(rightHandUnitProxy->getCurrentJointValues()); + // ARMARX_INFO << VAROUT(rightHandUnitProxy->getCurrentJointValues()); int frameRightHandRowIdx = 0; - connect(ui.buttonPreshapeRightHand, SIGNAL(clicked()), this, SLOT(preshapeRightHand()), Qt::UniqueConnection); - connect(ui.buttonOpenRightHand, SIGNAL(clicked()), this, SLOT(openRightHand()), Qt::UniqueConnection); - connect(ui.buttonCloseRightHand, SIGNAL(clicked()), this, SLOT(closeRightHand()), Qt::UniqueConnection); - connect(ui.buttonRelaxRightHand, SIGNAL(clicked()), this, SLOT(relaxRightHand()), Qt::UniqueConnection); + connect(ui.buttonPreshapeRightHand, + SIGNAL(clicked()), + this, + SLOT(preshapeRightHand()), + Qt::UniqueConnection); + connect(ui.buttonOpenRightHand, + SIGNAL(clicked()), + this, + SLOT(openRightHand()), + Qt::UniqueConnection); + connect(ui.buttonCloseRightHand, + SIGNAL(clicked()), + this, + SLOT(closeRightHand()), + Qt::UniqueConnection); + connect(ui.buttonRelaxRightHand, + SIGNAL(clicked()), + this, + SLOT(relaxRightHand()), + Qt::UniqueConnection); ui.horizontalSliderRightHandJointPos->setMaximum(100); ui.horizontalSliderRightHandJointPos->setMinimum(0); - connect(ui.horizontalSliderRightHandJointPos, SIGNAL(sliderMoved(int)), this, SLOT(requestSetRightHandJointAngles()), Qt::UniqueConnection); - connect(ui.comboRightHandJoints, SIGNAL(currentIndexChanged(int)), this, SLOT(selectRightHandJoint(int)), Qt::UniqueConnection); + connect(ui.horizontalSliderRightHandJointPos, + SIGNAL(sliderMoved(int)), + this, + SLOT(requestSetRightHandJointAngles()), + Qt::UniqueConnection); + connect(ui.comboRightHandJoints, + SIGNAL(currentIndexChanged(int)), + this, + SLOT(selectRightHandJoint(int)), + Qt::UniqueConnection); + connect(ui.rightExpertMode, + &QCheckBox::stateChanged, + [&](int state) { setExpertMode(side::right, state); }); + connect(ui.rightTare, &QPushButton::clicked, [&] { tareHand(side::right); }); + connect(ui.rightReset, &QPushButton::clicked, [&] { resetHand(side::right); }); ui.tableWidgetRightHand->setRowCount(currentRightHandJointValues.size()); ui.tableWidgetRightHand->setColumnCount(2); ui.comboRightHandJoints->clear(); - qRegisterMetaType<QVector<int> >("QVector<int>"); + qRegisterMetaType<QVector<int>>("QVector<int>"); for (const auto& pair : currentRightHandJointValues) { -// ARMARX_INFO << VAROUT(pair.first); + // ARMARX_INFO << VAROUT(pair.first); QString name(pair.first.c_str()); QTableWidgetItem* newItem = new QTableWidgetItem(name); ui.tableWidgetRightHand->setItem(frameRightHandRowIdx, 0, newItem); @@ -520,31 +686,38 @@ namespace armarx // reloading of preshapes - connect(ui.reloadPreshapesButton, SIGNAL(clicked()), this, SLOT(reloadPreshapes()), Qt::UniqueConnection); - + connect(ui.reloadPreshapesButton, + SIGNAL(clicked()), + this, + SLOT(reloadPreshapes()), + Qt::UniqueConnection); } - - - - - void armarx::HandUnitWidget::reportHandShaped(const std::string& handName, const std::string& handShapeName, const Ice::Current&) + void + armarx::HandUnitWidget::reportHandShaped(const std::string& handName, + const std::string& handShapeName, + const Ice::Current&) { ARMARX_IMPORTANT << handName << ": " << handShapeName; } - void armarx::HandUnitWidget::reportNewHandShapeName(const std::string& handName, const std::string& handShapeName, const Ice::Current&) + void + armarx::HandUnitWidget::reportNewHandShapeName(const std::string& handName, + const std::string& handShapeName, + const Ice::Current&) { ARMARX_IMPORTANT << handName << ": " << handShapeName; } - void armarx::HandUnitWidget::reportJointAngles(const armarx::NameValueMap& actualJointAngles, const Ice::Current& c) + void + armarx::HandUnitWidget::reportJointAngles(const armarx::NameValueMap& actualJointAngles, + const Ice::Current& c) { - } - void armarx::HandUnitWidget::reportJointPressures(const armarx::NameValueMap& actualJointPressures, const Ice::Current& c) + void + armarx::HandUnitWidget::reportJointPressures(const armarx::NameValueMap& actualJointPressures, + const Ice::Current& c) { - } -} +} // namespace armarx diff --git a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.h b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.h index dd68d856fad0cfbf0aa215d607826683927ad9f4..a4be90635175282654b604fa7a25c561debe8101 100644 --- a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.h +++ b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.h @@ -24,20 +24,20 @@ #pragma once /* ArmarX headers */ -#include <RobotAPI/gui-plugins/HandUnitPlugin/ui_HandUnitGuiPlugin.h> #include <ArmarXCore/core/Component.h> -#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h> + #include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXComponentWidgetController.h> +#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h> +#include <RobotAPI/gui-plugins/HandUnitPlugin/ui_HandUnitGuiPlugin.h> #include <RobotAPI/interface/units/HandUnitInterface.h> /* Qt headers */ -#include <QMainWindow> - #include <string> -#include <ArmarXCore/core/services/tasks/PeriodicTask.h> +#include <QMainWindow> +#include <ArmarXCore/core/services/tasks/PeriodicTask.h> namespace armarx { @@ -48,15 +48,16 @@ namespace armarx \brief This plugin offers a widget witch which the HandUnit can be controlled. \see HandUnitWidget */ - class HandUnitGuiPlugin : - public ArmarXGuiPlugin + class HandUnitGuiPlugin : public ArmarXGuiPlugin { Q_OBJECT Q_INTERFACES(ArmarXGuiInterface) Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00") public: HandUnitGuiPlugin(); - QString getPluginName() override + + QString + getPluginName() override { return "HandUnitGuiPlugin"; } @@ -81,8 +82,10 @@ namespace armarx Q_OBJECT public: HandUnitWidget(); + ~HandUnitWidget() override - {} + { + } // inherited from Component void onInitComponent() override; @@ -92,15 +95,19 @@ namespace armarx // HandUnitListener interface void reportHandShaped(const std::string&, const std::string&, const Ice::Current&) override; - void reportNewHandShapeName(const std::string&, const std::string&, const Ice::Current&) override; - + void reportNewHandShapeName(const std::string&, + const std::string&, + const Ice::Current&) override; // inherited of ArmarXWidget - static QString GetWidgetName() + static QString + GetWidgetName() { return "RobotControl.HandUnitGUI"; } - static QIcon GetWidgetIcon() + + static QIcon + GetWidgetIcon() { return QIcon("://icons/hand.svg"); } @@ -110,6 +117,12 @@ namespace armarx void saveSettings(QSettings* settings) override; void configured() override; + enum class side + { + left, + right + }; + public slots: void preshapeLeftHand(); @@ -126,6 +139,9 @@ namespace armarx void relaxRightHand(); void updateInfoLabel(); void updateJointValueTable(); + void setExpertMode(side side, int state); + void tareHand(side side); + void resetHand(side side); void selectLeftHandJoint(int i); void selectRightHandJoint(int i); @@ -161,14 +177,17 @@ namespace armarx bool setRightHandJointAnglesFlag; std::basic_string<char> currentLeftHandJoint; std::basic_string<char> currentRightHandJoint; - double leftHandConversionFactor= 1.0 / 100.0; + double leftHandConversionFactor = 1.0 / 100.0; double rightHandConversionFactor = 1.0 / 100.0; // HandUnitListener interface public: - void reportJointAngles(const::armarx::NameValueMap& actualJointAngles, const Ice::Current&) override; - void reportJointPressures(const::armarx::NameValueMap& actualJointPressures, const Ice::Current&) override; + void reportJointAngles(const ::armarx::NameValueMap& actualJointAngles, + const Ice::Current&) override; + void reportJointPressures(const ::armarx::NameValueMap& actualJointPressures, + const Ice::Current&) override; }; + using HandUnitGuiPluginPtr = std::shared_ptr<HandUnitWidget>; -} +} // namespace armarx diff --git a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.ui b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.ui index 79ffd00e83b842c062a61e9860f92f92eeda7d5b..031253abc93df81d1c27531bd4e07be27535a0eb 100644 --- a/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.ui +++ b/source/RobotAPI/gui-plugins/HandUnitPlugin/HandUnitGuiPlugin.ui @@ -57,7 +57,6 @@ </property> <property name="font"> <font> - <weight>75</weight> <bold>true</bold> </font> </property> @@ -154,6 +153,40 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="leftExpertMode"> + <property name="text"> + <string>I know what I'm doing</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="leftTare"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>tare</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="leftReset"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>reset</string> + </property> + </widget> + </item> + </layout> + </item> <item> <widget class="QTableWidget" name="tableWidgetLeftHand"/> </item> @@ -171,7 +204,6 @@ </property> <property name="font"> <font> - <weight>75</weight> <bold>true</bold> </font> </property> @@ -268,6 +300,40 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QCheckBox" name="rightExpertMode"> + <property name="text"> + <string>I know what I'm doing</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="rightTare"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>tare</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="rightReset"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>reset</string> + </property> + </widget> + </item> + </layout> + </item> <item> <widget class="QTableWidget" name="tableWidgetRightHand"/> </item> diff --git a/source/RobotAPI/interface/units/HandUnitInterface.ice b/source/RobotAPI/interface/units/HandUnitInterface.ice index 76a1000820a4f85b0fd21194aa72b13cb88bcc75..2badb58fdedf6ac7052ff0a4738deab7d5393314 100644 --- a/source/RobotAPI/interface/units/HandUnitInterface.ice +++ b/source/RobotAPI/interface/units/HandUnitInterface.ice @@ -24,25 +24,25 @@ #pragma once -#include <RobotAPI/interface/units/UnitInterface.ice> -#include <RobotAPI/interface/units/KinematicUnitInterface.ice> - -#include <ArmarXCore/interface/core/UserException.ice> #include <ArmarXCore/interface/core/BasicTypes.ice> -#include <ArmarXCore/interface/observers/VariantContainers.ice> +#include <ArmarXCore/interface/core/UserException.ice> #include <ArmarXCore/interface/observers/ObserverInterface.ice> +#include <ArmarXCore/interface/observers/VariantContainers.ice> + +#include <RobotAPI/interface/units/KinematicUnitInterface.ice> +#include <RobotAPI/interface/units/UnitInterface.ice> module armarx { dictionary<string, string> NameCommandMap; - /** + /** * Implements an interface to a HandUnit. */ interface HandUnitInterface extends SensorActorUnitInterface { - /** + /** * setShape sets the name of a known hand shape for the hand unit. * @param shapeName Name of the hand shape. */ @@ -71,7 +71,7 @@ module armarx * E.g. a state that verifies if a grasp was successful can call this routine. */ void setObjectReleased(string objectName); - /** + /** * setJointAngles controls the joints of the hand unit. * @param targetJointAngles Map of joint names and corresponding joint angle values. */ @@ -82,13 +82,35 @@ module armarx void sendJointCommands(NameCommandMap targetJointCommands); void reloadPreshapes(); + + /** + * @brief Will tare the relative encoders of the hand. + * + * For hands with relative encoders that support this function. No-op if not supported. + * + * This will change the relative encoder calibration! Make sure the hand is fully opened + * before taring. + */ + void tare(); + + /** + * @brief Will reset the firmware of the hand, enforcing a reboot. + * + * For hands that support this function. No-op if not supported. + * + * This is a very disruptive operation and will result in the firmware rebooting for up to + * several seconds, potentially dropping objects in the hand or homing procedures of the + * hand motors. This is only meant to be used in cases where the hand is lost due to + * connection issues and reconnections. + */ + void resetFirmware(); }; - /** + /** * Implements an interface to a HandUnitListener. */ interface HandUnitListener { - /** + /** * reportNewHandShapeName reports the current hand shape name. * @param handName Name of the hand to be controlled. * @param handName Name of the current hand shape name. @@ -110,13 +132,9 @@ module armarx * @param actualJointPressures Map of joint names and corresponding sensed pressure values. **/ void reportJointPressures(NameValueMap actualJointPressures); - }; - /** + /** * Implements an interface to a HandUnitObserver. */ - interface HandUnitObserverInterface extends ObserverInterface, HandUnitListener - { - }; - + interface HandUnitObserverInterface extends ObserverInterface, HandUnitListener{}; };