TCPMover.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "TCPMover.h"
24
25#include <RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ui_TCPMover.h>
26
27
28//VirtualRobot
29#include <VirtualRobot/IK/DifferentialIK.h>
30#include <VirtualRobot/LinkedCoordinate.h>
31#include <VirtualRobot/Nodes/RobotNode.h>
32#include <VirtualRobot/Robot.h>
33#include <VirtualRobot/RobotNodeSet.h>
34#include <VirtualRobot/XML/RobotIO.h>
35
37
38// C++ includes
39#include <sstream>
40
41// Qt includes
42#include <QDialogButtonBox>
43#include <QLineEdit>
44#include <QScrollBar>
45
46using namespace armarx;
47using namespace VirtualRobot;
48
49TCPMover::TCPMover() : robotRequested(false), ui(std::make_unique<Ui::TCPMover>())
50
51{
52
53 // handData[selectedTCP][0] = handData[selectedTCP][1] = handData[selectedTCP][2] = 0.0f;
54 // handData[selectedTCP][3] = handData[selectedTCP][4] = handData[selectedTCP][5] = 0.0f;
55 ui->setupUi(getWidget());
56 ui->gridLayout->setEnabled(false);
57 // SIGNALS AND SLOTS CONNECTIONS
58 connect(ui->cbselectedTCP, SIGNAL(currentIndexChanged(int)), this, SLOT(selectHand(int)));
59 connect(ui->BtnRequestControl, SIGNAL(clicked(bool)), this, SLOT(robotControl(bool)));
60 connect(ui->btnUp, SIGNAL(clicked()), this, SLOT(moveUp()));
61 connect(ui->btnDown, SIGNAL(clicked()), this, SLOT(moveDown()));
62 connect(ui->btnZUp, SIGNAL(clicked()), this, SLOT(moveZUp()));
63 connect(ui->btnZDown, SIGNAL(clicked()), this, SLOT(moveZDown()));
64 connect(ui->btnLeft, SIGNAL(clicked()), this, SLOT(moveRight()));
65 connect(ui->btnRight, SIGNAL(clicked()), this, SLOT(moveLeft()));
66 connect(ui->btnIncreaseAlpha, SIGNAL(clicked()), this, SLOT(increaseAlpha()));
67 connect(ui->btnDecreaseAlpha, SIGNAL(clicked()), this, SLOT(decreaseAlpha()));
68 connect(ui->btnIncreaseBeta, SIGNAL(clicked()), this, SLOT(increaseBeta()));
69 connect(ui->btnDecreaseBeta, SIGNAL(clicked()), this, SLOT(decreaseBeta()));
70 connect(ui->btnIncreaseGamma, SIGNAL(clicked()), this, SLOT(increaseGamma()));
71 connect(ui->btnDecreaseGamma, SIGNAL(clicked()), this, SLOT(decreaseGamma()));
72
73 connect(ui->btnRight, SIGNAL(clicked()), this, SLOT(moveLeft()));
74 connect(ui->btnStop, SIGNAL(clicked()), this, SLOT(stopMoving()));
75 connect(ui->btnResetJoinAngles, SIGNAL(clicked()), this, SLOT(reset()));
76}
77
81
82void
84{
86 settings->value("TCPControlUnitName", "TCPControlUnit").toString().toStdString();
87}
88
89void
91{
92 settings->setValue("TCPControlUnitName", tcpMoverUnitName.c_str());
93}
94
95QPointer<QDialog>
97{
98 if (!configDialog)
99 {
101 }
102
103 return qobject_cast<TCPMoverConfigDialog*>(configDialog);
104}
105
106void
108{
109 tcpMoverUnitName = qobject_cast<TCPMoverConfigDialog*>(getConfigDialog())
110 ->proxyFinder->getSelectedProxyName()
111 .toStdString();
112}
113
114void
116{
117 // kinematicUnitFile = getProperty<std::string>("RobotFileName", KINEMATIC_UNIT_FILE_DEFAULT).getValueOrDefault();
118 // kinematicUnitName = getProperty<std::string>("RobotNodeSetName",KINEMATIC_UNIT_NAME_DEFAULT).getValueOrDefault();
119
120 // // Load Robot
121 // ARMARX_VERBOSE << ": Loading KinematicUnit " << kinematicUnitName << " from '" << kinematicUnitFile << "' ..." << flush;
122 // robot = RobotIO::loadRobot(kinematicUnitFile);
123 // if (!robot)
124 // {
125 // ARMARX_ERROR << "Could not find Robot XML file with name '" << kinematicUnitFile << "'" << flush;
126 // }
127
128
129 // usingProxy(kinematicUnitName);
131 usingProxy("RobotStateComponent");
132}
133
134void
136{
137
140
141 robotPrx = robotStateComponentPrx->getSynchronizedRobot();
142 NameList nodeSets = robotPrx->getRobotNodeSets();
143 QStringList nodeSetsQStr;
144
145 for (unsigned int i = 0; i < nodeSets.size(); i++)
146 {
147 if (!robotPrx->getRobotNodeSet(nodeSets.at(i))->tcpName.empty())
148 {
149 tcpData[nodeSets.at(i)].resize(6, 0.f);
150 nodeSetsQStr << QString::fromStdString(nodeSets.at(i));
151 }
152 }
153
154 QString selected = ui->cbselectedTCP->currentText();
155 ui->cbselectedTCP->clear();
156 ui->cbselectedTCP->addItems(nodeSetsQStr);
157 int index = ui->cbselectedTCP->findText(selected);
158
159 if (index != -1)
160 {
161 ui->cbselectedTCP->setCurrentIndex(index);
162 }
163
164 refFrame = robotStateComponentPrx->getSynchronizedRobot()->getRootNode()->getName();
165
166 // kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinematicUnitName);
167
168 // tcpNodeSetName = "LARM";
169 // tcpNodeSet = robot->getRobotNodeSet(tcpNodeSetName);
170 // NameControlModeMap modeMap;
171 // for(unsigned int i = 0; i < tcpNodeSet->getSize(); i++)
172 // {
173 // modeMap[tcpNodeSet->getNode(i)->getName()] = eVelocityControl;
174 // }
175 // kinematicUnitPrx->switchControlMode(modeMap);
176 // ik = DifferentialIKPtr(new DifferentialIK(tcpNodeSet));
177 ui->gridLayout->setEnabled(false);
178}
179
180void
182{
183
184 // if(robotRequested)
185 // kinematicUnitPrx->release();
186}
187
188void
190{
191 // moveRelative(-1,0,0);
192 tcpData[selectedTCP][0]++;
193 execMove();
194}
195
196void
198{
199 // moveRelative(1,0,0);
200 tcpData[selectedTCP][0]--;
201 execMove();
202}
203
204void
206{
207 tcpData[selectedTCP][2]++;
208 execMove();
209}
210
211void
213{
214 tcpData[selectedTCP][2]--;
215 execMove();
216}
217
218void
220{
221 // moveRelative(0,1,0);
222 tcpData[selectedTCP][1]++;
223 execMove();
224}
225
226void
228{
229 tcpData[selectedTCP][1]--;
230 execMove();
231
232 // moveRelative(0,-1,0);
233}
234
235void
237{
238 tcpData[selectedTCP].at(3) += 2.f;
239 execMove();
240}
241
242void
244{
245 tcpData[selectedTCP].at(3) -= 2.f;
246 execMove();
247}
248
249void
251{
252 tcpData[selectedTCP].at(4) += 2.f;
253 execMove();
254}
255
256void
258{
259 tcpData[selectedTCP].at(4) -= 2.f;
260 execMove();
261}
262
263void
265{
266 tcpData[selectedTCP].at(5) += 2.f;
267 execMove();
268}
269
270void
272{
273 tcpData[selectedTCP].at(5) -= 2.f;
274 execMove();
275}
276
277void
279{
281
282 execMove();
283}
284
285void
287{
289 tcpData[selectedTCP].at(3) = tcpData[selectedTCP].at(4) = tcpData[selectedTCP].at(5) = 0.0f;
290 execMove();
291 tcpMoverUnitPrx->release();
292 // tcpMoverUnitPrx->resetArmToHomePosition(eLeftHand);
293}
294
295void
297{
298 tcpMoverUnitPrx->request();
299 // try{
300 // if(request)
301 // kinematicUnitPrx->request();
302 // else
303 // kinematicUnitPrx->release();
304 // }catch(ResourceUnavailableException &e){
305 // ui->BtnRequestControl->setChecked(false);
306
307 // }catch(ResourceNotOwnedException &e){
308 // ui->BtnRequestControl->setChecked(true);
309 // }
310 // robotRequested = ui->BtnRequestControl->isChecked();
311}
312
313void
315{
316 selectedTCP = ui->cbselectedTCP->itemText(index).toStdString();
317}
318
319void
321{
322 ARMARX_INFO << "Setting new velos and orientation";
323 ui->lblXValue->setText(QString::number(tcpData[selectedTCP][0]));
324 ui->lblYValue->setText(QString::number(tcpData[selectedTCP][1]));
325 ui->lblZValue->setText(QString::number(tcpData[selectedTCP][2]));
326 ui->lblAlphaValue->setText(QString::number(tcpData[selectedTCP].at(3)));
327 ui->lblBetaValue->setText(QString::number(tcpData[selectedTCP].at(4)));
328 ui->lblGammaValue->setText(QString::number(tcpData[selectedTCP].at(5)));
329
330 Eigen::Vector3f vec;
332 vec *= ui->sbFactor->value();
333 const auto agentName = robotPrx->getName();
334 FramedDirectionPtr tcpVel = new FramedDirection(vec, refFrame, agentName);
335 Eigen::Vector3f vecOri;
336 vecOri << tcpData[selectedTCP].at(3) / 180.f * 3.145f,
337 tcpData[selectedTCP].at(4) / 180.f * 3.145f, tcpData[selectedTCP].at(5) / 180.f * 3.145f;
338 vecOri *= ui->sbFactor->value();
339 FramedDirectionPtr tcpOri = new FramedDirection(vecOri, refFrame, agentName);
340
341 if (!ui->cbTranslation->isChecked())
342 {
343 tcpVel = NULL;
344 }
345
346 if (!ui->cbOrientation->isChecked())
347 {
348 tcpOri = NULL;
349 }
350
351 tcpMoverUnitPrx->begin_setTCPVelocity(
352 selectedTCP, ui->edtTCPName->text().toStdString(), tcpVel, tcpOri);
353
354 // tcpMoverUnitPrx->setCartesianTCPVelocity(selectedTCP, handData[selectedTCP][0], handData[selectedTCP][1], handData[selectedTCP][2], ui->sbFactor->value());
355 // tcpMoverUnitPrx->setTCPOrientation(selectedTCP, handData[selectedTCP].at(3)/180.f*3.145f, handData[selectedTCP].at(4)/180.f*3.145f, handData[selectedTCP].at(5)/180.f*3.145f);
356}
357
358void
359TCPMover::moveRelative(float x, float y, float z)
360{
361 // RobotNodePtr tcpNode = tcpNodeSet->getTCP();
362 // // calculate cartesian error
363 // Eigen::Matrix4f newPosRelative;
364 // newPosRelative
365 // << 1, 0, 0, 10*ui->sbFactor->value(),
366 // 0, 1, 0, 0,
367 // 0, 0, 1, 0,
368 // 0, 0, 0, 1;
369 // Eigen::VectorXf errorCartVec(3);
370 // errorCartVec << x*ui->sbFactor->value(),y*ui->sbFactor->value(),z*ui->sbFactor->value();
371 //// errorCartVec.segment(0,3) = newPosRelative.block(0,3,3,1);
372
373
374 // Eigen::MatrixXf Ji = ik->getPseudoInverseJacobianMatrix(tcpNode, IKSolver::Position);
375 // // calculat joint error
376 // Eigen::VectorXf errorJoint(tcpNodeSet->getSize());
377 // errorJoint = Ji * errorCartVec;
378 // std::vector<float> angles = tcpNodeSet->getJointValues();
379 // std::vector<float> targetAngles(tcpNodeSet->getSize());
380 // NameValueMap targetAnglesMap;
381
382 // for(unsigned int i = 0; i < tcpNodeSet->getSize(); i++)
383 // {
384 //// float newAngle = angles[i] + errorJoint(i);
385 // float newAngle = errorJoint(i);
386 // targetAngles[i] = newAngle;
387 // targetAnglesMap[tcpNodeSet->getNode(i)->getName()] = newAngle;
388 // //ARMARX_VERBOSE << tcpNodeSet->getNode(i)->getName() << ": " << newAngle;
389 // }
390 // tcpNodeSet->setJointValues(targetAngles);
391 // kinematicUnitPrx->setJointVelocities(targetAnglesMap);
392}
393
394/*void TCPMoverConfigDialog::setupUI(QWidget *parent)
395{
396 this->setWindowTitle("Enter name of TCPMoverUnit");
397
398 layout = new QGridLayout(parent);
399
400
401 proxyFinder->setSearchMask("*Unit");
402 layout->addWidget(proxyFinder, 0, 0, 1, 2);
403
404 //label = new QLabel("TCPControlUnit name:", parent);
405 //layout->addWidget(label, 0,0);
406
407 //editTCPMoverUnitName = new QLineEdit("TCPControlUnit", parent);
408 //layout->addWidget(editTCPMoverUnitName, 0, 1);
409
410 buttonBox = new QDialogButtonBox(parent);
411 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
412 buttonBox->setOrientation(Qt::Horizontal);
413 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
414
415 layout->addWidget(buttonBox, 1, 0, 1, 2);
416
417
418 QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
419 QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
420
421
422
423}
424
425
426TCPMoverConfigDialog::TCPMoverConfigDialog(QWidget *parent) :
427 QDialog(parent)
428{
429 proxyFinder = new IceProxyFinder<TCPControlUnitInterfacePrx>(this);
430 setupUI(this);
431}*/
uint8_t index
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onInitComponent() override
Pure virtual hook for the subclass.
Definition TCPMover.cpp:115
std::string refFrame
Definition TCPMover.h:150
void selectHand(int index)
Definition TCPMover.cpp:314
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition TCPMover.cpp:83
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition TCPMover.cpp:90
std::map< std::string, std::vector< float > > tcpData
Definition TCPMover.h:148
void moveRelative(float x, float y, float z)
Definition TCPMover.cpp:359
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition TCPMover.cpp:96
std::unique_ptr< Ui::TCPMover > ui
Definition TCPMover.h:158
std::string tcpMoverUnitName
Definition TCPMover.h:161
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition TCPMover.cpp:135
std::string selectedTCP
Definition TCPMover.h:149
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition TCPMover.cpp:107
SharedRobotInterfacePrx robotPrx
Definition TCPMover.h:165
RobotStateComponentInterfacePrx robotStateComponentPrx
Definition TCPMover.h:164
void onExitComponent() override
Hook for subclass.
Definition TCPMover.cpp:181
void robotControl(bool request)
Definition TCPMover.cpp:296
~TCPMover() override
Definition TCPMover.cpp:78
TCPControlUnitInterfacePrx tcpMoverUnitPrx
Definition TCPMover.h:163
QPointer< TCPMoverConfigDialog > configDialog
Definition TCPMover.h:166
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:179
ArmarX Headers.
This file is part of ArmarX.
Definition FramedPose.h:43
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84