YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
partitem.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "partitem.h"
8#include "log.h"
9
10#include <yarp/os/LogStream.h>
11#include <yarp/dev/Drivers.h>
12#include <yarp/dev/PolyDriver.h>
13
14#include <QDebug>
15#include <QEvent>
16#include <QResizeEvent>
17#include <QFileDialog>
18#include <QXmlStreamWriter>
19#include <QXmlStreamAttribute>
20#include <QMessageBox>
21#include <QSettings>
22#include <cmath>
23#include <cstdio>
24
25PartItem::PartItem(std::string robotName, int id, std::string partName, ResourceFinder& _finder,
29 std::string rcb_protocol,
30 QWidget *parent) :
31 QWidget(parent),
32 m_sequenceWindow(nullptr),
33 m_partId(id),
34 m_mixedEnabled(false),
35 m_positionDirectEnabled(false),
36 m_pwmEnabled(false),
37 m_currentEnabled(false),
38 m_currentPidDlg(nullptr),
39 m_part_speedVisible(false),
40 m_part_motorPositionVisible(false),
41 m_part_dutyVisible(false),
42 m_part_currentVisible(false),
43 m_finder(&_finder),
44 m_iMot(nullptr),
45 m_iinfo(nullptr),
46 m_slow_k(0)
47{
48 m_layout = new FlowLayout();
49 setLayout(m_layout);
50
51 //PolyDriver *cartesiandd[MAX_NUMBER_ACTIVATED];
52
53 if (robotName.at(0) == '/') {
54 robotName.erase(0, 1);
55 }
56 if (partName.at(0) == '/') {
57 partName.erase(0, 1);
58 }
59 m_robotPartPort = std::string("/") + robotName +std::string("/") + partName;
60 m_partName = partName;
61 m_robotName = robotName;
62
63 //checking existence of the port
64 int ind = 0;
65 QString portLocalName = QString("/yarpmotorgui%1/%2").arg(ind).arg(m_robotPartPort.c_str());
66
67
69 nameToCheck += "/rpc:o";
70
71 // NameClient &nic=NameClient::getNameClient();
72 yDebug("Checking the existence of: %s \n", nameToCheck.toLatin1().data());
73 // Address adr=nic.queryName(nameToCheck.c_str());
74
75 Contact adr=Network::queryName(nameToCheck.toLatin1().data());
76
77 //Contact c = yarp::os::Network::queryName(portLocalName.c_str());
78 yDebug("ADDRESS is: %s \n", adr.toString().c_str());
79
80 while(adr.isValid()){
81 ind++;
82
83 portLocalName = QString("/yarpmotorgui%1/%2").arg(ind).arg(m_robotPartPort.c_str());
84
86 nameToCheck += "/rpc:o";
87 // adr=nic.queryName(nameToCheck.c_str());
88 adr=Network::queryName(nameToCheck.toLatin1().data());
89 }
90
91 m_interfaceError = false;
92
93 // Initializing the polydriver options and instantiating the polydrivers
94 m_partOptions.put("local", portLocalName.toLatin1().data());
95 m_partOptions.put("device", "remote_controlboard");
96 m_partOptions.put("remote", m_robotPartPort);
97 m_partOptions.put("carrier", rcb_protocol);
98
99 m_partsdd = new PolyDriver();
100
101 // Opening the drivers
102 m_interfaceError = !openPolyDrivers();
103 if (m_interfaceError == true)
104 {
105 yError("Opening PolyDriver for part %s failed...", m_robotPartPort.c_str());
106 QMessageBox::critical(nullptr, "Error opening a device", QString("Error while opening device for part ").append(m_robotPartPort.c_str()));
107 }
108
109 /*********************************************************************/
110 /**************** PartMover Content **********************************/
111
112 if (!m_finder->isNull()){
113 yDebug("Setting a valid finder \n");
114 }
115
116 QString sequence_portname = QString("/yarpmotorgui/%1/sequence:o").arg(partName.c_str());
117 m_sequence_port.open(sequence_portname.toLatin1().data());
118
121
122 if (m_interfaceError == false)
123 {
124 int i = 0;
125 std::string jointname;
127 m_iPos->getAxes(&number_of_joints);
128
129 m_controlModes.resize(number_of_joints); //for (i = 0; i < number_of_joints; i++) m_controlModes = 0;
130 m_refTrajectorySpeeds.resize(number_of_joints);
131 for (i = 0; i < number_of_joints; i++) {
132 m_refTrajectorySpeeds[i] = std::nan("");
133 }
134 m_refTrajectoryPositions.resize(number_of_joints);
135 for (i = 0; i < number_of_joints; i++) {
136 m_refTrajectoryPositions[i] = std::nan("");
137 }
138 m_refTorques.resize(number_of_joints);
139 for (i = 0; i < number_of_joints; i++) {
140 m_refTorques[i] = std::nan("");
141 }
142 m_refVelocitySpeeds.resize(number_of_joints);
143 for (i = 0; i < number_of_joints; i++) {
144 m_refVelocitySpeeds[i] = std::nan("");
145 }
146 m_refVelocityAccelerations.resize(number_of_joints);
147 for (i = 0; i < number_of_joints; i++) {
148 m_refVelocityAccelerations[i] = std::nan("");
149 }
150 m_torques.resize(number_of_joints);
151 for (i = 0; i < number_of_joints; i++) {
152 m_torques[i] = std::nan("");
153 }
154 m_positions.resize(number_of_joints);
155 for (i = 0; i < number_of_joints; i++) {
156 m_positions[i] = std::nan("");
157 }
158 m_speeds.resize(number_of_joints);
159 for (i = 0; i < number_of_joints; i++) {
160 m_speeds[i] = std::nan("");
161 }
162 m_currents.resize(number_of_joints);
163 for (i = 0; i < number_of_joints; i++) {
164 m_currents[i] = std::nan("");
165 }
166 m_motorPositions.resize(number_of_joints);
167 for (i = 0; i < number_of_joints; i++) {
168 m_motorPositions[i] = std::nan("");
169 }
170 m_dutyCycles.resize(number_of_joints);
171 for (i = 0; i < number_of_joints; i++) {
172 m_dutyCycles[i] = std::nan("");
173 }
174 m_done.resize(number_of_joints);
175 m_braked.resize(number_of_joints);
176 for (i = 0; i < number_of_joints; i++) {
177 m_braked[i] = false;
178 }
179 m_interactionModes.resize(number_of_joints);
180
181 bool ret = false;
183 do {
184 ret = m_iencs->getEncoders(m_positions.data());
185 if (!ret) {
186 yError("%s iencs->getEncoders() failed, retrying...\n", partName.c_str());
188 }
189 } while (!ret);
190
191 yInfo("%s iencs->getEncoders() ok!\n", partName.c_str());
192
193 double min_pos = 0;
194 double max_pos = 100;
195 double min_vel = 0;
196 double max_vel = 100;
197 double min_acc = 0;
198 double max_acc = 100;
199 double min_cur = -2.0;
200 double max_cur = +2.0;
201 for (int k = 0; k<number_of_joints; k++)
202 {
203 bool bpl = m_iLim->getLimits(k, &min_pos, &max_pos);
204 bool bvl = m_iLim->getVelLimits(k, &min_vel, &max_vel);
205 bool bcr = m_iCur->getCurrentRange(k, &min_cur, &max_cur);
206 if (bpl == false)
207 {
208 yError() << "Error while getting position limits, part " << partName << " joint " << k;
209 }
210 if (bvl == false || (min_vel == 0 && max_vel == 0))
211 {
212 yError() << "Error while getting velocity limits, part " << partName << " joint " << k;
213 }
214 if (bcr == false || (min_cur == 0 && max_cur == 0))
215 {
216 yError() << "Error while getting current range, part " << partName << " joint " << k;
217 }
218
219 QSettings settings("YARP", "yarpmotorgui");
220 double max_slider_vel = settings.value("velocity_slider_limit", 100.0).toDouble();
221 if (max_vel > max_slider_vel) {
223 }
224
225 m_iinfo->getAxisName(k, jointname);
227 m_iinfo->getJointType(k, jtype);
228
229 Pid myPid(0,0,0,0,0,0);
232
233 auto* joint = new JointItem(k);
234 joint->setJointName(jointname.c_str());
235 joint->setPWMRange(-100.0, 100.0);
236 joint->setCurrentRange(min_cur, max_cur);
237 m_layout->addWidget(joint);
238 joint->setPositionRange(min_pos, max_pos);
239 joint->setVelocityRange(min_vel, max_vel);
240 joint->setAccelerationRange(min_acc, max_acc);
241 joint->setTorqueRange(5.0);
242 joint->setUnits(jtype);
243 joint->enableControlPositionDirect(m_positionDirectEnabled);
244 joint->enableControlMixed(m_mixedEnabled);
245 joint->enableControlPWM(m_pwmEnabled);
246 joint->enableControlCurrent(m_currentEnabled);
247
248 int val_pos_choice = settings.value("val_pos_choice", 0).toInt();
249 int val_vel_choice = settings.value("val_vel_choice", 0).toInt();
250 int val_acc_choice = settings.value("val_acc_choice", 0).toInt();
251 int val_trq_choice = settings.value("val_trq_choice", 0).toInt();
252 int val_cur_choice = settings.value("val_cur_choice", 0).toInt();
253
254 int num_of_pos_decimals = settings.value("num_of_pos_decimals", 3).toInt();
255 int num_of_vel_decimals = settings.value("num_of_vel_decimals", 3).toInt();
256 int num_of_acc_decimals = settings.value("num_of_acc_decimals", 3).toInt();
257 int num_of_trq_decimals = settings.value("num_of_trq_decimals", 3).toInt();
258 int num_of_cur_decimals = settings.value("num_of_cur_decimals", 3).toInt();
259
260 double val_pos_custom_step = settings.value("val_pos_custom_step", 1.0).toDouble();
261 double val_vel_custom_step = settings.value("val_vel_custom_step", 1.0).toDouble();
262 double val_acc_custom_step = settings.value("val_acc_custom_step", 1.0).toDouble();
263 double val_trq_custom_step = settings.value("val_trq_custom_step", 1.0).toDouble();
264 double val_cur_custom_step = settings.value("val_cur_custom_step", 1.0).toDouble();
265
266 onSetPosSliderOptionPI(val_pos_choice, val_pos_custom_step, num_of_pos_decimals);
267 onSetVelSliderOptionPI(val_vel_choice, val_vel_custom_step, num_of_vel_decimals);
268 onSetAccSliderOptionPI(val_acc_choice, val_acc_custom_step, num_of_acc_decimals);
269 onSetTrqSliderOptionPI(val_trq_choice, val_trq_custom_step, num_of_trq_decimals);
270 onSetCurSliderOptionPI(val_cur_choice, val_cur_custom_step, num_of_cur_decimals);
271
272 joint->setEnabledOptions(debug_param_enabled,
275
276 connect(joint, SIGNAL(changeMode(int,JointItem*)), this, SLOT(onJointChangeMode(int,JointItem*)));
277 connect(joint, SIGNAL(changeInteraction(int,JointItem*)), this, SLOT(onJointInteraction(int,JointItem*)));
278 connect(joint, SIGNAL(sliderPosTrajectoryPositionCommand(double, int)), this, SLOT(onSliderPosTrajectoryPositionCommand(double, int)));
279 connect(joint, SIGNAL(sliderPosTrajectoryVelocityCommand(double, int)), this, SLOT(onSliderPosTrajectoryVelocityCommand(double, int)));
280 connect(joint, SIGNAL(sliderVelTrajectoryVelocityCommand(double, int)), this, SLOT(onSliderVelTrajectoryVelocityCommand(double, int)));
281 connect(joint, SIGNAL(sliderVelTrajectoryAccelerationCommand(double, int)), this, SLOT(onSliderVelTrajectoryAccelerationCommand(double, int)));
282 connect(joint, SIGNAL(sliderMixedPositionCommand(double, int)), this, SLOT(onSliderMixedPositionCommand(double, int)));
283 connect(joint, SIGNAL(sliderMixedVelocityCommand(double, int)), this, SLOT(onSliderMixedVelocityCommand(double, int)));
284 connect(joint, SIGNAL(sliderTorqueCommand(double, int)), this, SLOT(onSliderTorqueCommand(double, int)));
285 connect(joint, SIGNAL(sliderDirectPositionCommand(double, int)), this, SLOT(onSliderDirectPositionCommand(double, int)));
286 connect(joint, SIGNAL(sliderPWMCommand(double, int)), this, SLOT(onSliderPWMCommand(double, int)));
287 connect(joint, SIGNAL(sliderCurrentCommand(double, int)), this, SLOT(onSliderCurrentCommand(double, int)));
288 connect(joint, SIGNAL(sliderVelocityDirectCommand(double, int)), this, SLOT(onSliderVelocityDirectCommand(double, int)));
289 connect(joint, SIGNAL(homeClicked(JointItem*)),this,SLOT(onHomeClicked(JointItem*)));
290 connect(joint, SIGNAL(idleClicked(JointItem*)),this,SLOT(onIdleClicked(JointItem*)));
291 connect(joint, SIGNAL(runClicked(JointItem*)),this,SLOT(onRunClicked(JointItem*)));
292 connect(joint, SIGNAL(pidClicked(JointItem*)),this,SLOT(onPidClicked(JointItem*)));
293 connect(joint, SIGNAL(calibClicked(JointItem*)),this,SLOT(onCalibClicked(JointItem*)));
294 }
295 }
296
297 /*********************************************************************/
298 /*********************************************************************/
299
300 m_cycleTimer.setSingleShot(true);
301 m_cycleTimer.setTimerType(Qt::PreciseTimer);
302 connect(&m_cycleTimer, SIGNAL(timeout()), this, SLOT(onCycleTimerTimeout()), Qt::QueuedConnection);
303
304 m_cycleTimeTimer.setSingleShot(true);
305 m_cycleTimeTimer.setTimerType(Qt::PreciseTimer);
306 connect(&m_cycleTimeTimer, SIGNAL(timeout()), this, SLOT(onCycleTimeTimerTimeout()), Qt::QueuedConnection);
307
308
309 m_runTimeTimer.setSingleShot(true);
310 m_runTimeTimer.setTimerType(Qt::PreciseTimer);
311 connect(&m_runTimeTimer, SIGNAL(timeout()), this, SLOT(onRunTimerTimeout()), Qt::QueuedConnection);
312
313 m_runTimer.setSingleShot(true);
314 m_runTimer.setTimerType(Qt::PreciseTimer);
315 connect(&m_runTimer, SIGNAL(timeout()), this, SLOT(onRunTimeout()), Qt::QueuedConnection);
316}
317
319{
320 disconnect(&m_runTimer, SIGNAL(timeout()), this, SLOT(onRunTimeout()));
321 m_runTimer.stop();
322
323 disconnect(&m_runTimeTimer, SIGNAL(timeout()), this, SLOT(onRunTimerTimeout()));
324 m_runTimeTimer.stop();
325
326 disconnect(&m_cycleTimer, SIGNAL(timeout()), this, SLOT(onCycleTimerTimeout()));
327 m_cycleTimer.stop();
328
329 disconnect(&m_cycleTimeTimer, SIGNAL(timeout()), this, SLOT(onCycleTimeTimerTimeout()));
330 m_cycleTimeTimer.stop();
331
332 if (m_sequenceWindow){
333 m_sequenceWindow->hide();
334 delete m_sequenceWindow;
335 }
336
337 for (int i = 0; i<m_layout->count(); i++){
338 auto* joint = (JointItem *)m_layout->itemAt(i)->widget();
339 if(joint){
340 disconnect(joint,SIGNAL(changeMode(int,JointItem*)), this, SLOT(onJointChangeMode(int,JointItem*)));
341 disconnect(joint,SIGNAL(changeInteraction(int,JointItem*)), this, SLOT(onJointInteraction(int,JointItem*)));
342 disconnect(joint,SIGNAL(homeClicked(JointItem*)),this,SLOT(onHomeClicked(JointItem*)));
343 disconnect(joint,SIGNAL(idleClicked(JointItem*)),this,SLOT(onIdleClicked(JointItem*)));
344 disconnect(joint,SIGNAL(runClicked(JointItem*)),this,SLOT(onRunClicked(JointItem*)));
345 disconnect(joint,SIGNAL(pidClicked(JointItem*)),this,SLOT(onPidClicked(JointItem*)));
346 disconnect(joint,SIGNAL(calibClicked(JointItem*)),this,SLOT(onCalibClicked(JointItem*)));
347 delete joint;
348 }
349 }
350
351 if (m_partsdd){
352 m_partsdd->close();
353 delete m_partsdd;
354 m_partsdd = nullptr;
355 }
356}
357
359{
360 m_partsdd->open(m_partOptions);
361 if (!m_partsdd->isValid()) {
362 return false;
363 }
364
365 #ifdef DEBUG_INTERFACE
367 {
369 if(!debugdd->isValid()){
370 yError("Problems opening the debug client!");
371 }
372 } else {
373 debugdd = NULL;
374 }
375 #endif
376 return true;
377}
378
380{
381 yDebug("Initializing interfaces...");
382 //default value for unopened interfaces
383 m_iPos = nullptr;
384 m_iVel = nullptr;
385 m_iVar = nullptr;
386 m_iPosDir = nullptr;
387 m_iVelDir = nullptr;
388 m_iencs = nullptr;
389 m_iAmp = nullptr;
390 m_iPid = nullptr;
391 m_iCur = nullptr;
392 m_iPWM = nullptr;
393 m_iTrq = nullptr;
394 m_iImp = nullptr;
395 m_iLim = nullptr;
396 m_ical = nullptr;
397 m_ictrlmode = nullptr;
398 m_iinteract = nullptr;
399 m_iremCalib = nullptr;
400 m_ijointfault = nullptr;
401}
402
404{
405 yDebug("Opening interfaces...");
406 bool ok = false;
407
408 if (m_partsdd->isValid()) {
409 ok = m_partsdd->view(m_iPid);
410 if(!ok){
411 yError("...iPid was not ok...");
412 }
413 ok &= m_partsdd->view(m_iAmp);
414 if(!ok){
415 yError("...iAmp was not ok...");
416 }
417 ok &= m_partsdd->view(m_iPos);
418 if(!ok){
419 yError("...iPos was not ok...");
420 }
421 ok &= m_partsdd->view(m_iPosDir);
422 if(!ok){
423 yError("...posDirect was not ok...");
424 }
425 ok &= m_partsdd->view(m_iVelDir);
426 if(!ok){
427 yError("...velDirect was not ok...");
428 }
429 ok &= m_partsdd->view(m_iVel);
430 if(!ok){
431 yError("...iVel was not ok...");
432 }
433 ok &= m_partsdd->view(m_iLim);
434 if(!ok){
435 yError("...iLim was not ok...");
436 }
437 ok &= m_partsdd->view(m_iencs);
438 if(!ok){
439 yError("...enc was not ok...");
440 }
441 ok &= m_partsdd->view(m_ical);
442 if(!ok){
443 yError("...cal was not ok...");
444 }
445 ok &= m_partsdd->view(m_iTrq);
446 if(!ok){
447 yError("...trq was not ok...");
448 }
449 ok = m_partsdd->view(m_iPWM);
450 if(!ok){
451 yError("...opl was not ok...");
452 }
453 ok &= m_partsdd->view(m_iImp);
454 if(!ok){
455 yError("...imp was not ok...");
456 }
457 ok &= m_partsdd->view(m_ictrlmode);
458 if(!ok){
459 yError("...ctrlmode2 was not ok...");
460 }
461 ok &= m_partsdd->view(m_iinteract);
462 if(!ok){
463 yError("...iinteract was not ok...");
464 }
465
466 //optional interfaces
467 if (!m_partsdd->view(m_ijointfault))
468 {
469 yWarning("...m_iJointFault was not ok...");
470 }
471 if (!m_partsdd->view(m_ijointbrake))
472 {
473 yWarning("...m_iJointBrake was not ok...");
474 }
475 if (!m_partsdd->view(m_iVar))
476 {
477 yWarning("...iVar was not ok...");
478 }
479 if (!m_partsdd->view(m_iMot))
480 {
481 yWarning("...iMot was not ok...");
482 }
483 if (!m_partsdd->view(m_iremCalib))
484 {
485 yWarning("...remCalib was not ok...");
486 }
487 if (!m_partsdd->view(m_iinfo))
488 {
489 yWarning("...axisInfo was not ok...");
490 }
491 if (!m_partsdd->view(m_iCur))
492 {
493 yWarning("...iCur was not ok...");
494 }
495
496 if (!ok) {
497 yError("Error while acquiring interfaces!");
498 QMessageBox::critical(nullptr,"Problems acquiring interfaces.","Check if interface is running");
499 m_interfaceError = true;
500 }
501 }
502 else
503 {
504 yError("Device driver was not valid!");
505 m_interfaceError = true;
506 }
507
508 return !m_interfaceError;
509}
510
512{
513 return m_interfaceError;
514}
515
517{
518 return m_partName;
519}
520
521void PartItem::onSliderPWMCommand(double pwmVal, int index)
522{
523 m_iPWM->setRefDutyCycle(index, pwmVal);
524}
525
526void PartItem::onSliderCurrentCommand(double currentVal, int index)
527{
528 m_iCur->setRefCurrent(index, currentVal);
529}
530
531void PartItem::onSliderVelTrajectoryVelocityCommand(double speedVal, int index)
532{
533 m_iVel->velocityMove(index, speedVal);
534}
535
536void PartItem::onSliderVelTrajectoryAccelerationCommand(double accVal, int index)
537{
538 m_iVel->setRefAcceleration(index, accVal);
539}
540
541void PartItem::onSliderVelocityDirectCommand(double speedVal, int index)
542{
543 m_iVelDir->setDesiredVelocity(index, speedVal);
544}
545
546void PartItem::onSliderTorqueCommand(double torqueVal, int index)
547{
548 m_iTrq->setRefTorque(index, torqueVal);
549}
550
551void PartItem::onSliderPosTrajectoryVelocityCommand(double trajspeedVal, int index)
552{
553 m_iPos->setRefSpeed(index, trajspeedVal);
554}
555
556
557void PartItem::onSliderDirectPositionCommand(double dirpos, int index)
558{
559 int mode;
560 m_ictrlmode->getControlMode(index, &mode);
562 {
563 m_iPosDir->setPosition(index, dirpos);
564 }
565 else
566 {
567 yWarning("Joint not in position direct mode so cannot send references");
568 }
569}
570
571void PartItem::onDumpAllRemoteVariables()
572{
573 if (m_iVar == nullptr)
574 {
575 return;
576 }
577
578 QString fileName = QFileDialog::getSaveFileName(this, QString("Save Dump for Remote Variables as:"), QDir::homePath()+QString("/RemoteVariablesDump.txt"));
579
580 FILE* dumpfile = fopen(fileName.toStdString().c_str(), "w");
581 if (dumpfile != nullptr)
582 {
583 yarp::os::Bottle keys;
584 if (m_iVar->getRemoteVariablesList(&keys))
585 {
586 std::string s = keys.toString();
587 size_t keys_size = keys.size();
588 for (size_t i = 0; i < keys_size; i++)
589 {
590 std::string key_name;
591 if (keys.get(i).isString())
592 {
594 key_name = keys.get(i).asString();
595 if (m_iVar->getRemoteVariable(key_name, val))
596 {
597 std::string key_value = val.toString();
598 std::string p_value = std::string(key_name).append(" ").append(key_value).append("\n");
599 fputs(p_value.c_str(), dumpfile);
600 }
601 }
602 }
603 }
605 }
606}
607
608
609void PartItem::onSliderPosTrajectoryPositionCommand(double posVal, int index)
610{
611 int mode;
612 m_ictrlmode->getControlMode(index, &mode);
613
614 if ( mode == VOCAB_CM_POSITION)
615 {
616 m_iPos->positionMove(index, posVal);
617 }
618 else
619 {
620 yWarning("Joint not in position mode so cannot send references");
621 }
622}
623
624void PartItem::onSliderMixedPositionCommand(double posVal, int index)
625{
626 int mode;
627 m_ictrlmode->getControlMode(index, &mode);
628
629 if ( mode == VOCAB_CM_MIXED)
630 {
631 m_iPos->positionMove(index, posVal);
632 }
633 else
634 {
635 LOG_ERROR("Joint not in mixed mode so cannot send references");
636 }
637}
638
639void PartItem::onSliderMixedVelocityCommand( double vel, int index)
640{
641 int mode;
642 m_ictrlmode->getControlMode(index, &mode);
643
644 if (mode == VOCAB_CM_MIXED)
645 {
646 m_iVel->velocityMove(index, vel);
647 }
648 else
649 {
650 LOG_ERROR("Joint not in mixed mode so cannot send references");
651 }
652}
653
654void PartItem::onJointInteraction(int interaction,JointItem *joint)
655{
656 const int jointIndex = joint->getJointIndex();
657 switch (interaction) {
659 yInfo("interaction mode of joint %d set to COMPLIANT", jointIndex);
661 break;
662 case JointItem::Stiff:
663 yInfo("interaction mode of joint %d set to STIFF", jointIndex);
665 break;
666 default:
667 break;
668 }
669}
670
671
672void PartItem::onSendPWM(int jointIndex, double pwmVal)
673{
674 double pwm_reference = 0;
675 double current_pwm = 0;
676
677 m_iPWM->setRefDutyCycle(jointIndex, pwmVal);
678
680 m_iPWM->getRefDutyCycle(jointIndex, &pwm_reference); //This is the reference
682 m_iPWM->getDutyCycle(jointIndex, &current_pwm); //This is the real PWM output
683
684 if (m_currentPidDlg){
685 m_currentPidDlg->initPWM(pwm_reference, current_pwm);
686 }
687}
688
689void PartItem::onSendStiffness(int jointIdex,double stiff,double damp,double force)
690{
692 double stiff_val=0;
693 double damp_val=0;
694 double offset_val=0;
695
696 m_iImp->setImpedance(jointIdex, stiff, damp);
697 //imp->setImpedanceOffset(jointIdex, force);
701
702 //update the impedance limits
703 double stiff_max=0.0;
704 double stiff_min=0.0;
705 double damp_max=0.0;
706 double damp_min=0.0;
707 double off_max=0.0;
708 double off_min=0.0;
711
712 if (m_currentPidDlg)
713 {
714 m_currentPidDlg->initStiffness(stiff_val, stiff_min, stiff_max,
717 }
718
719
720}
721
722void PartItem::onSendTorquePid(int jointIndex,Pid newPid,MotorTorqueParameters newTrqParam)
723{
724 Pid myTrqPid(0,0,0,0,0,0);
726 m_iPid->setPid(VOCAB_PIDTYPE_TORQUE, jointIndex, newPid);
727
728 m_iTrq->setMotorTorqueParams(jointIndex, newTrqParam);
730 m_iPid->getPid(VOCAB_PIDTYPE_TORQUE,jointIndex, &myTrqPid);
731 m_iTrq->getMotorTorqueParams(jointIndex, &TrqParam);
732
733 if (m_currentPidDlg){
734 m_currentPidDlg->initTorque(myTrqPid, TrqParam);
735 }
736}
737
738void PartItem::onSendPositionPid(int jointIndex,Pid newPid)
739{
740 Pid myPosPid(0,0,0,0,0,0);
741 m_iPid->setPid(VOCAB_PIDTYPE_POSITION, jointIndex, newPid);
743 m_iPid->getPid(VOCAB_PIDTYPE_POSITION, jointIndex, &myPosPid);
744
745 if (m_currentPidDlg){
746 m_currentPidDlg->initPosition(myPosPid);
747 }
748}
749
750void PartItem::onSendVelocityPid(int jointIndex, Pid newPid)
751{
752 Pid myVelPid(0, 0, 0, 0, 0, 0);
753 m_iPid->setPid(VOCAB_PIDTYPE_VELOCITY, jointIndex, newPid);
755 m_iPid->getPid(VOCAB_PIDTYPE_VELOCITY, jointIndex, &myVelPid);
756
757 if (m_currentPidDlg){
758 m_currentPidDlg->initVelocity(myVelPid);
759 }
760}
761
762void PartItem::onRefreshPids(int jointIndex)
763{
764 Pid myPosPid(0, 0, 0, 0, 0, 0);
765 Pid myTrqPid(0, 0, 0, 0, 0, 0);
766 Pid myVelPid(0, 0, 0, 0, 0, 0);
767 Pid myCurPid(0, 0, 0, 0, 0, 0);
769 double stiff_val = 0;
770 double damp_val = 0;
771 double stiff_max = 0;
772 double damp_max = 0;
773 double off_max = 0;
774 double stiff_min = 0;
775 double damp_min = 0;
776 double off_min = 0;
777 double impedance_offset_val = 0;
778 double pwm_reference = 0;
779 double current_pwm = 0;
780
782 m_iTrq->getTorqueRange(jointIndex, &off_min, &off_max);
783
784 // Position
785 m_iPid->getPid(VOCAB_PIDTYPE_POSITION, jointIndex, &myPosPid);
787
788 // Velocity
789 m_iPid->getPid(VOCAB_PIDTYPE_VELOCITY, jointIndex, &myVelPid);
791
792 // Current
793 if (m_iCur)
794 {
795 m_iPid->getPid(VOCAB_PIDTYPE_CURRENT, jointIndex, &myCurPid);
797 }
798
799 // Torque
800 m_iPid->getPid(VOCAB_PIDTYPE_TORQUE, jointIndex, &myTrqPid);
801 m_iTrq->getMotorTorqueParams(jointIndex, &motorTorqueParams);
803
804 //Stiff
805 m_iImp->getImpedance(jointIndex, &stiff_val, &damp_val);
806 m_iImp->getImpedanceOffset(jointIndex, &impedance_offset_val);
808
809 // PWM
810 m_iPWM->getRefDutyCycle(jointIndex, &pwm_reference);
811 m_iPWM->getDutyCycle(jointIndex, &current_pwm);
812
813 if (m_currentPidDlg)
814 {
815 m_currentPidDlg->initPosition(myPosPid);
816 m_currentPidDlg->initTorque(myTrqPid, motorTorqueParams);
817 m_currentPidDlg->initVelocity(myVelPid);
818 m_currentPidDlg->initCurrent(myCurPid);
820 m_currentPidDlg->initPWM(pwm_reference, current_pwm);
821 m_currentPidDlg->initRemoteVariables(m_iVar);
822 }
823}
824
825void PartItem::onSendCurrentPid(int jointIndex, Pid newPid)
826{
827 if (m_iCur == nullptr)
828 {
829 yError() << "iCurrent interface not opened";
830 return;
831 }
832 Pid myCurPid(0, 0, 0, 0, 0, 0);
833 m_iPid->setPid(VOCAB_PIDTYPE_CURRENT, jointIndex, newPid);
835 m_iPid->getPid(VOCAB_PIDTYPE_CURRENT, jointIndex, &myCurPid);
836
837 if (m_currentPidDlg){
838 m_currentPidDlg->initCurrent(myCurPid);
839 }
840}
841
842void PartItem::onSendSingleRemoteVariable(std::string key, yarp::os::Bottle val)
843{
844 m_iVar->setRemoteVariable(key, val);
846}
847
848void PartItem::onUpdateAllRemoteVariables()
849{
850 if (m_currentPidDlg){
851 m_currentPidDlg->initRemoteVariables(m_iVar);
852 }
853}
854
855void PartItem::onCalibClicked(JointItem *joint)
856{
857 if (!m_iremCalib)
858 {
859 QMessageBox::critical(this,"Operation not supported", QString("The IRemoteCalibrator interface was not found on this application"));
860 return;
861 }
862
863 if(QMessageBox::question(this,"Question","Do you really want to recalibrate the joint?") != QMessageBox::Yes){
864 return;
865 }
866 if (!m_iremCalib->calibrateSingleJoint(joint->getJointIndex()))
867 {
868 // provide better feedback to user by verifying if the calibrator device was set or not
869 bool isCalib = false;
870 m_iremCalib->isCalibratorDevicePresent(&isCalib);
871 if (!isCalib) {
872 QMessageBox::critical(this,"Calibration failed", QString("No calibrator device was configured to perform this action, please verify that the wrapper config file has the 'Calibrator' keyword in the attach phase"));
873 } else {
874 QMessageBox::critical(this, "Calibration failed", QString("The remote calibrator reported that something went wrong during the calibration procedure"));
875 }
876 }
877
878}
879
880void PartItem::onPidClicked(JointItem *joint)
881{
882 const int jointIndex = joint->getJointIndex();
883 QString jointName = joint->getJointName();
884 m_currentPidDlg = new PidDlg(m_partName.c_str(), jointIndex, jointName);
885 connect(m_currentPidDlg, SIGNAL(sendPositionPid(int, Pid)), this, SLOT(onSendPositionPid(int, Pid)));
886 connect(m_currentPidDlg, SIGNAL(sendVelocityPid(int, Pid)), this, SLOT(onSendVelocityPid(int, Pid)));
887 connect(m_currentPidDlg, SIGNAL(sendCurrentPid(int, Pid)), this, SLOT(onSendCurrentPid(int, Pid)));
888 connect(m_currentPidDlg, SIGNAL(sendSingleRemoteVariable(std::string, yarp::os::Bottle)), this, SLOT(onSendSingleRemoteVariable(std::string, yarp::os::Bottle)));
889 connect(m_currentPidDlg, SIGNAL(updateAllRemoteVariables()), this, SLOT(onUpdateAllRemoteVariables()));
890 connect(m_currentPidDlg, SIGNAL(sendTorquePid(int, Pid, MotorTorqueParameters)), this, SLOT(onSendTorquePid(int, Pid, MotorTorqueParameters)));
891 connect(m_currentPidDlg, SIGNAL(sendStiffness(int, double, double, double)), this, SLOT(onSendStiffness(int, double, double, double)));
892 connect(m_currentPidDlg, SIGNAL(sendPWM(int, double)), this, SLOT(onSendPWM(int, double)));
893 connect(m_currentPidDlg, SIGNAL(refreshPids(int)), this, SLOT(onRefreshPids(int)));
894 connect(m_currentPidDlg, SIGNAL(dumpRemoteVariables()), this, SLOT(onDumpAllRemoteVariables()));
895
896 this->onRefreshPids(jointIndex);
897
898 m_currentPidDlg->exec();
899
900 delete m_currentPidDlg;
901 m_currentPidDlg = nullptr;
902}
903
904void PartItem::onRunClicked(JointItem *joint)
905{
906 const int jointIndex = joint->getJointIndex();
907 double posJoint;
908 while (!m_iencs->getEncoder(jointIndex, &posJoint)){
910 }
911
912 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_POSITION);
913}
914
915void PartItem::onIdleClicked(JointItem *joint)
916{
917 const int jointIndex = joint->getJointIndex();
918 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_FORCE_IDLE);
919}
920
921void PartItem::onHomeClicked(JointItem *joint)
922{
924 const int jointIndex = joint->getJointIndex();
925 m_iPos->getAxes(&NUMBER_OF_JOINTS);
926
927 this->homeJoint(jointIndex);
928}
929
930void PartItem::onJointChangeMode(int mode,JointItem *joint)
931{
932 const int jointIndex = joint->getJointIndex();
933 switch (mode) {
934 case JointItem::Idle:{
935 yInfo("joint: %d in IDLE mode", jointIndex);
936 if (m_ictrlmode){
937 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_IDLE);
938 } else {
939 yError("ERROR: cannot do!");
940 }
941 break;
942 }
944 yInfo("joint: %d in POSITION mode", jointIndex);
945 if (m_ictrlmode){
946 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_POSITION);
947 joint->resetTarget();
948 } else {
949 yError("ERROR: cannot do!");
950 }
951 break;
952 }
954 //if(positionDirectEnabled){
955 yInfo("joint: %d in POSITION DIRECT mode", jointIndex);
956 if (m_ictrlmode){
957 joint->resetTarget();
958 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_POSITION_DIRECT);
959 } else {
960 yError("ERROR: cannot do!");
961 }
962 break;
963 /*}else{
964 LOG_ERROR("joint: %d in MIXED mode", jointIndex);
965 if(ctrlmode2){
966 ctrlmode2->setControlMode(jointIndex, VOCAB_CM_MIXED);
967 } else {
968 yError("ERROR: cannot do!");
969 }
970 break;
971 }*/
972 }
973 case JointItem::Mixed:{
974 //if(positionDirectEnabled){
975 yInfo("joint: %d in MIXED mode", jointIndex);
976 if (m_ictrlmode){
977 joint->resetTarget();
978 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_MIXED);
979 } else {
980 yError("ERROR: cannot do!");
981 }
982 break;
983 /*}else{
984 LOG_ERROR("joint: %d in VELOCITY mode", jointIndex);
985 if(ctrlmode2){
986 ctrlmode2->setVelocityMode(jointIndex);
987 } else {
988 LOG_ERROR("ERROR: cannot do!");
989 }
990 break;
991 }*/
992
993 }
995 //if(positionDirectEnabled){
996 yInfo("joint: %d in VELOCITY DIRECT mode", jointIndex);
997 if (m_ictrlmode)
998 {
999 joint->resetTarget();
1000 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_VELOCITY_DIRECT);
1001 } else {
1002 yError("ERROR: cannot do!");
1003 }
1004 break;
1005 }
1006 case JointItem::Velocity:{
1007 //if(positionDirectEnabled){
1008 yInfo("joint: %d in VELOCITY mode", jointIndex);
1009 if (m_ictrlmode)
1010 {
1011 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_VELOCITY);
1012 yInfo() << "Changing reference acceleration of joint " << jointIndex << " to 100000";
1013 m_iVel->setRefAcceleration(jointIndex, 100000);
1014 } else {
1015 yError("ERROR: cannot do!");
1016 }
1017 break;
1018// } else {
1019// LOG_ERROR("joint: %d in TORQUE mode", jointIndex);
1020// if(ctrlmode2){
1021// ctrlmode2->setTorqueMode(jointIndex);
1022// } else {
1023// LOG_ERROR("ERROR: cannot do!");
1024// }
1025// break;
1026// }
1027 }
1028
1029 case JointItem::Torque:{
1030 //if(positionDirectEnabled){
1031 yInfo("joint: %d in TORQUE mode", jointIndex);
1032 if (m_ictrlmode){
1033 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_TORQUE);
1034 } else {
1035 yError("ERROR: cannot do!");
1036 }
1037 break;
1038// } else {
1039// LOG_ERROR("joint: %d in TORQUE mode", jointIndex);
1040// if(ctrlmode2){
1041// ctrlmode2->setTorqueMode(jointIndex);
1042// } else {
1043// LOG_ERROR("ERROR: cannot do!");
1044// }
1045// break;
1046// }
1047
1048 }
1049 case JointItem::Pwm:{
1050 yInfo("joint: %d in PWM mode", jointIndex);
1051 if (m_ictrlmode){
1052 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_PWM);
1053 } else {
1054 yError("ERROR: cannot do!");
1055 }
1056 break;
1057 }
1058 case JointItem::Current:{
1059 yInfo("joint: %d in CURRENT mode", jointIndex);
1060 if (m_ictrlmode){
1061 m_ictrlmode->setControlMode(jointIndex, VOCAB_CM_CURRENT);
1062 }
1063 else {
1064 yError("ERROR: cannot do!");
1065 }
1066 break;
1067 }
1068 default:
1069 break;
1070 }
1071}
1072
1074{
1075 int count = m_layout->count();
1076
1077
1078 int jointPerLineCount = (w - 20) / (MAX_WIDTH_JOINT + 10);
1079 if(jointPerLineCount > count){
1080 jointPerLineCount = count;
1081 }
1082 if(jointPerLineCount <= 0){
1083 return;
1084 }
1085
1086 int extraSpace = (w - 20) - jointPerLineCount * (MAX_WIDTH_JOINT + 10);
1087
1088
1089
1090 for(int i=0;i<count;i++){
1091 QWidget *widget = m_layout->itemAt(i)->widget();
1092 if(widget){
1093 widget->setMaximumWidth(MAX_WIDTH_JOINT + (extraSpace/jointPerLineCount));
1094 widget->setMinimumWidth(MAX_WIDTH_JOINT + (extraSpace/jointPerLineCount));
1095 }
1096
1097 }
1098}
1099
1101{
1102 return m_layout->count();
1103}
1104
1106{
1108 {
1109 return "";
1110 }
1111
1112 auto* jointWidget = (JointItem*)m_layout->itemAt(joint)->widget();
1113
1114 return jointWidget->getJointName();
1115}
1116
1118{
1119 return (JointItem*)m_layout->itemAt(jointIndex)->widget();
1120}
1121
1123{
1124 if(!isVisible()){
1125 return;
1126 }
1127
1128 resizeWidget(event->size().width());
1129}
1130
1132{
1133 if(event->type() == QEvent::WindowStateChange ){
1134 qDebug() << "State Changed " << width();
1135 int count = m_layout->count();
1136 int jointPerLineCount = (width() - 20) / (MAX_WIDTH_JOINT + 10);
1137
1138 if(jointPerLineCount > count){
1139 jointPerLineCount = count;
1140 }
1141 if(jointPerLineCount <= 0){
1142 return;
1143 }
1144 int extraSpace = (width() - 20) - jointPerLineCount * (MAX_WIDTH_JOINT + 10);
1145
1146
1148
1149 for(int i=0;i<count;i++){
1150 QWidget *widget = m_layout->itemAt(i)->widget();
1151 if(widget){
1152 widget->setMaximumWidth(MAX_WIDTH_JOINT + (extraSpace/jointPerLineCount));
1153 widget->setMinimumWidth(MAX_WIDTH_JOINT + (extraSpace/jointPerLineCount));
1154 }
1155 }
1156 }
1157
1158}
1159
1161{
1162 if (!m_iremCalib)
1163 {
1164 QMessageBox::critical(this,"Operation not supported", QString("The IRemoteCalibrator interface was not found on this application"));
1165 return;
1166 }
1167
1168 if (!m_iremCalib->calibrateWholePart())
1169 {
1170 // provide better feedback to user by verifying if the calibrator device was set or not
1171 bool isCalib = false;
1172 m_iremCalib->isCalibratorDevicePresent(&isCalib);
1173 if (!isCalib) {
1174 QMessageBox::critical(this, "Calibration failed", QString("No calibrator device was configured to perform this action, please verify that the wrapper config file for part %1 has the 'Calibrator' keyword in the attach phase").arg(m_partName.c_str()));
1175 } else {
1176 QMessageBox::critical(this, "Calibration failed", QString("The remote calibrator reported that something went wrong during the calibration procedure"));
1177 }
1178 }
1179}
1180
1181bool PartItem::homeJoint(int jointIndex)
1182{
1183 if (!m_iremCalib)
1184 {
1185 QMessageBox::critical(this, "Operation not supported", QString("The IRemoteCalibrator interface was not found on this application"));
1186 return false;
1187 }
1188
1189 if (!m_iremCalib->homingSingleJoint(jointIndex))
1190 {
1191 // provide better feedback to user by verifying if the calibrator device was set or not
1192 bool isCalib = false;
1193 m_iremCalib->isCalibratorDevicePresent(&isCalib);
1194 if (!isCalib)
1195 {
1196 QMessageBox::critical(this, "Operation failed", QString("No calibrator device was configured to perform this action, please verify that the wrapper config file for part %1 has the 'Calibrator' keyword in the attach phase").arg(m_partName.c_str()));
1197 return false;
1198 }
1199 else
1200 {
1201 QMessageBox::critical(this, "Operation failed", QString("The remote calibrator reported that something went wrong during the calibration procedure"));
1202 return false;
1203 }
1204 }
1205 return true;
1206}
1207
1209{
1210 if (!m_iremCalib)
1211 {
1212 QMessageBox::critical(this, "Operation not supported", QString("The IRemoteCalibrator interface was not found on this application"));
1213 return false;
1214 }
1215
1216 if (!m_iremCalib->homingWholePart())
1217 {
1218 // provide better feedback to user by verifying if the calibrator device was set or not
1219 bool isCalib = false;
1220 m_iremCalib->isCalibratorDevicePresent(&isCalib);
1221 if (!isCalib)
1222 {
1223 QMessageBox::critical(this, "Operation failed", QString("No calibrator device was configured to perform this action, please verify that the wrapper config file for part %1 has the 'Calibrator' keyword in the attach phase").arg(m_partName.c_str()));
1224 return false;
1225 }
1226 else
1227 {
1228 QMessageBox::critical(this, "Operation failed", QString("The remote calibrator reported that something went wrong during the calibration procedure"));
1229 return false;
1230 }
1231 }
1232 return true;
1233}
1234
1236{
1237 bool ok = true;
1238 int NUMBER_OF_JOINTS;
1239 m_iPos->getAxes(&NUMBER_OF_JOINTS);
1240
1241 if (positionElement.isNull()) {
1242 QMessageBox::critical(this, "Operation failed", QString("No custom position supplied in configuration file for part ") + QString(m_partName.c_str()));
1243 return false;
1244 }
1245
1246 //Look for group called m_robotPartPort_Position and m_robotPartPort_Velocity
1247 Bottle xtmp, ytmp;
1248 xtmp = positionElement.findGroup(m_robotPartPort + "_Position");
1249 ok = ok && (xtmp.size() == (size_t) NUMBER_OF_JOINTS + 1);
1250 ytmp = positionElement.findGroup(m_robotPartPort + "_Velocity");
1251 ok = ok && (ytmp.size() == (size_t) NUMBER_OF_JOINTS + 1);
1252
1253 if(ok)
1254 {
1255 for (int jointIndex = 0; jointIndex < NUMBER_OF_JOINTS; jointIndex++)
1256 {
1257 double position = xtmp.get(jointIndex+1).asFloat64();
1258 double velocity = ytmp.get(jointIndex + 1).asFloat64();
1259 m_iPos->setRefSpeed(jointIndex, velocity);
1260 m_iPos->positionMove(jointIndex, position);
1261 }
1262 }
1263 else
1264 {
1265 QMessageBox::critical(this, "Error", QString("Check the number of entries in the group %1").arg(m_robotPartPort.c_str()));
1266 ok = false;
1267 }
1268
1269 return ok;
1270}
1271
1273{
1274 int NUMBER_OF_JOINTS;
1275 m_iPos->getAxes(&NUMBER_OF_JOINTS);
1276
1277 for (int joint=0; joint < NUMBER_OF_JOINTS; joint++){
1278 m_ictrlmode->setControlMode(joint, VOCAB_CM_IDLE);
1279 }
1280}
1281
1283{
1284 if (!m_sequenceWindow){
1285 return false;
1286 }
1287
1288 return m_sequenceWindow->checkAndRun();
1289
1290
1291}
1292
1294{
1295 if (!m_sequenceWindow){
1296 return false;
1297 }
1298
1299 return m_sequenceWindow->checkAndRunTime();
1300
1301
1302}
1303
1305{
1306 if (!m_sequenceWindow){
1307 return false;
1308 }
1309
1310 return m_sequenceWindow->checkAndCycleTimeSeq();
1311}
1312
1314{
1315 if (!m_sequenceWindow){
1316 return false;
1317 }
1318
1319 return m_sequenceWindow->checkAndCycleSeq();
1320}
1321
1323{
1324 int NUMBER_OF_JOINTS;
1325 m_iPos->getAxes(&NUMBER_OF_JOINTS);
1326
1327 for (int joint=0; joint < NUMBER_OF_JOINTS; joint++){
1328 //iencs->getEncoder(joint, &posJoint);
1329 m_ictrlmode->setControlMode(joint, VOCAB_CM_POSITION);
1330 }
1331}
1332
1334{
1336 onOpenSequence();
1337}
1338
1344
1346{
1347 if (m_sequenceWindow)
1348 {
1349 m_sequenceWindow->close();
1350 }
1351}
1352
1354{
1355 if (!m_sequenceWindow){
1356 m_sequenceWindow = new SequenceWindow(m_partName.c_str(), m_layout->count());
1357 connect(m_sequenceWindow, SIGNAL(itemDoubleClicked(int)), this, SLOT(onSequenceWindowDoubleClicked(int)), Qt::DirectConnection);
1358 connect(this, SIGNAL(sendPartJointsValues(int, QList<double>, QList<double>)), m_sequenceWindow, SLOT(onReceiveValues(int, QList<double>, QList<double>)), Qt::DirectConnection);
1359 connect(m_sequenceWindow, SIGNAL(goToPosition(SequenceItem)), this, SLOT(onGo(SequenceItem)));
1360 connect(m_sequenceWindow, SIGNAL(runTime(QList<SequenceItem>)), this, SLOT(onSequenceRunTime(QList<SequenceItem>)), Qt::QueuedConnection);
1361 connect(m_sequenceWindow, SIGNAL(run(QList<SequenceItem>)), this, SLOT(onSequenceRun(QList<SequenceItem>)), Qt::QueuedConnection);
1362 connect(m_sequenceWindow, SIGNAL(saveSequence(QList<SequenceItem>, QString)), this, SLOT(onSaveSequence(QList<SequenceItem>, QString)), Qt::QueuedConnection);
1363 connect(m_sequenceWindow, SIGNAL(openSequence()), this, SLOT(onOpenSequence()));
1364 connect(m_sequenceWindow, SIGNAL(cycle(QList<SequenceItem>)), this, SLOT(onSequenceCycle(QList<SequenceItem>)), Qt::QueuedConnection);
1365 connect(m_sequenceWindow, SIGNAL(cycleTime(QList<SequenceItem>)), this, SLOT(onSequenceCycleTime(QList<SequenceItem>)), Qt::QueuedConnection);
1366 connect(m_sequenceWindow, SIGNAL(stopSequence()), this, SLOT(onStopSequence()), Qt::QueuedConnection);
1367
1368 connect(this, SIGNAL(runTimeSequence()), m_sequenceWindow, SLOT(onRunTimeSequence()));
1369 connect(this, SIGNAL(cycleTimeSequence()), m_sequenceWindow, SLOT(onCycleTimeSequence()));
1370 connect(this, SIGNAL(cycleSequence()), m_sequenceWindow, SLOT(onCycleSequence()));
1371 connect(this, SIGNAL(stoppedSequence()), m_sequenceWindow, SLOT(onStoppedSequence()));
1372 connect(this, SIGNAL(setCurrentIndex(int)), m_sequenceWindow, SLOT(onSetCurrentSequenceIndex(int)));
1373
1374 connect(this,SIGNAL(runTimeSequence()),this,SLOT(onSequenceActivated()));
1375 connect(this,SIGNAL(cycleTimeSequence()),this,SLOT(onSequenceActivated()));
1376 connect(this,SIGNAL(cycleSequence()),this,SLOT(onSequenceActivated()));
1377 connect(this,SIGNAL(stoppedSequence()),this,SLOT(onSequenceStopped()));
1378
1379
1380 }
1381
1382 if (!m_sequenceWindow->isVisible()){
1383 m_sequenceWindow->show();
1384 }else{
1385 m_sequenceWindow->setFocus();
1386 m_sequenceWindow->raise();
1387 m_sequenceWindow->setWindowState(Qt::WindowActive);
1388 }
1389
1390}
1391
1393{
1394 if (!m_sequenceWindow){
1395 return false;
1396 }
1397
1398 return m_sequenceWindow->checkAndGo();
1399}
1401{
1402 m_cycleTimer.stop();
1403 m_runTimer.stop();
1404 m_runTimeTimer.stop();
1405 m_cycleTimeTimer.stop();
1407}
1408
1409void PartItem::onStopSequence()
1410{
1411 stopSequence();
1412}
1413
1414void PartItem::onOpenSequence()
1415{
1416 QString fileName = QFileDialog::getOpenFileName(m_sequenceWindow, QString("Load Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1417
1418 QFileInfo fInfo(fileName);
1419 if(!fInfo.exists()){
1420 return;
1421 }
1422
1423 QString desiredExtension = QString("pos%1").arg(m_partName.c_str());
1424 QString extension = fInfo.suffix();
1425
1427 QMessageBox::critical(this,"Error Loading The Sequence",
1428 QString("Wrong format (check extensions) of the file associated with: ").arg(m_partName.c_str()));
1429 return;
1430 }
1431
1432 QFile file(fileName);
1433 if (!file.open(QFile::ReadOnly | QFile::Text)){
1434 QString msg = QString("Error: Cannot read file %1: %2").arg(qPrintable(fileName))
1435 .arg(qPrintable(file.errorString()));
1436 QMessageBox::critical(this,"Error Loading The Sequence",msg);
1437 return;
1438 }
1439
1440 QXmlStreamReader reader(&file);
1441 reader.readNext();
1442
1444
1447 while(!reader.atEnd()){
1448 reader.readNext();
1449
1450 if(reader.isStartElement()){
1451 if(reader.name().contains("Sequence_")){ //Sequence_
1452 QXmlStreamAttributes attributes = reader.attributes();
1453 referencePart = attributes.value("ReferencePart").toString();
1454 }
1455
1456 if(reader.name() == "Position"){ //Position
1457 QXmlStreamAttributes attributes = reader.attributes();
1458 int index = attributes.value("Index").toInt();
1459 double timing = attributes.value("Timing").toDouble();
1460 item.setTiming(timing);
1461 item.setSequenceNumber(index);
1462 }
1463
1464 if(reader.name() == "JointPositions"){
1465 QXmlStreamAttributes attributes = reader.attributes();
1466 int count = attributes.value("Count").toInt();
1467
1468 reader.readNext();
1469 for(int i=0; i<count;i++){
1470 reader.readNext();
1471 if(reader.name() == "PosValue"){ //PosValue
1472 double pos = reader.readElementText().toDouble();
1473 item.addPositionValue(pos);
1474 }
1475 reader.readNext();
1476 }
1477
1478 }
1479
1480 if(reader.name() == "JointVelocities"){
1481 QXmlStreamAttributes attributes = reader.attributes();
1482 int count = attributes.value("Count").toInt();
1483
1484 reader.readNext();
1485 for(int i=0; i<count;i++){
1486 reader.readNext();
1487 if(reader.name() == "SpeedValue"){ //SpeedValue
1488 double speed = reader.readElementText().toDouble();
1489 item.addSpeedValue(speed);
1490 }
1491 reader.readNext();
1492 }
1493
1494 }
1495
1496 }
1497
1498 if(reader.isEndElement()){
1499 if(reader.name() == "Position"){
1500 sequenceItems.append(item);
1501 item = SequenceItem();
1502 }
1503 }
1504 }
1505
1506 file.close();
1507
1508 if (reader.hasError())
1509 {
1510 QString msg = QString("Error: Failed to parse file %1: %2").arg(qPrintable(fileName)).arg(qPrintable(reader.errorString()));
1511 QMessageBox::critical(this,"Error Loading The Sequence",msg);
1512 return;
1513 } else if (file.error() != QFile::NoError) {
1514 QString msg = QString("Error: Cannot read file %1: %2").arg(qPrintable(fileName)).arg(qPrintable(file.errorString()));
1515 QMessageBox::critical(this,"Error Loading The Sequence",msg);
1516 return;
1517 }
1518
1519 if (m_sequenceWindow){
1520 m_sequenceWindow->loadSequence(sequenceItems);
1521 }
1522
1523}
1524
1525void PartItem::onSaveSequence(QList<SequenceItem> values, QString fileName)
1526{
1527 if (fileName=="")
1528 {
1529 fileName = QFileDialog::getSaveFileName(this, QString("Save Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1530 }
1531
1532 if(fileName.isEmpty()){
1533 return;
1534 }
1535
1536 QFileInfo fInfo(fileName);
1537 QString completeFileName = QString("%1/%2.pos%3").arg(fInfo.absolutePath()).arg(fInfo.baseName()).arg(m_partName.c_str());
1538 std::string completeFileName_s = completeFileName.toStdString();
1539
1540 //QFile file(completeFileName);
1541 yInfo("Saving file %s\n", completeFileName_s.c_str());
1542
1543 QFile file(completeFileName);
1544 if(!file.open(QIODevice::WriteOnly)){
1545 return;
1546 }
1547
1548 QXmlStreamWriter writer(&file);
1549 writer.setAutoFormatting(true);
1550 writer.writeStartDocument();
1551
1552 writer.writeStartElement(QString("Sequence_pos%1").arg(m_partName.c_str()));
1553
1554 writer.writeAttribute("TotPositions", QString("%1").arg(values.count()));
1555 writer.writeAttribute("ReferencePart", m_partName.c_str());
1556
1557 for(int i=0;i<values.count();i++){
1559 writer.writeStartElement("Position");
1560 writer.writeAttribute("Index",QString("%1").arg(sequenceItem.getSequenceNumber()));
1561 writer.writeAttribute("Timing",QString("%L1").arg(sequenceItem.getTiming(),0,'f',2));
1562
1563 writer.writeStartElement("JointPositions");
1564 writer.writeAttribute("Count",QString("%1").arg(sequenceItem.getPositions().count()));
1565 for(int j=0;j<sequenceItem.getPositions().count(); j++){
1566 QString s = QString("%L1").arg(sequenceItem.getPositions().at(j),0,'f',2);
1567 writer.writeTextElement("PosValue",s);
1568 }
1569 writer.writeEndElement();
1570
1571 writer.writeStartElement("JointVelocities");
1572 writer.writeAttribute("Count",QString("%1").arg(sequenceItem.getSpeeds().count()));
1573 for(int j=0;j<sequenceItem.getSpeeds().count(); j++){
1574 QString s = QString("%L1").arg(sequenceItem.getSpeeds().at(j),0,'f',2);
1575 writer.writeTextElement("SpeedValue",s);
1576 }
1577 writer.writeEndElement();
1578 writer.writeEndElement();
1579 }
1580 writer.writeEndElement();
1581 writer.writeEndDocument();
1582 file.close();
1583 LOG_INFO("File saved and closed\n");
1584
1585
1586// if(file.open(QIODevice::WriteOnly)){
1587// for(int i=0;i<values.count();i++){
1588// SequenceItem sequenceItem = values.at(i);
1589// QString s = QString("[POSITION%1] \n").arg(sequenceItem.getSequenceNumber());
1590// file.write(s.toLatin1().data(),s.length());
1591
1592// s = QString("jointPositions ");
1593// file.write(s.toLatin1().data(),s.length());
1594
1595// for(int j=0;j<sequenceItem.getPositions().count(); j++){
1596// s = QString("%L1 ").arg(sequenceItem.getPositions().at(j),0,'f',2);
1597// file.write(s.toLatin1().data(),s.length());
1598// }
1599
1600// s = QString("\njointVelocities ");
1601// file.write(s.toLatin1().data(),s.length());
1602// for(int j=0;j<sequenceItem.getSpeeds().count(); j++){
1603// s = QString("%L1 ").arg(sequenceItem.getSpeeds().at(j),0,'f',2);
1604// file.write(s.toLatin1().data(),s.length());
1605// }
1606
1607// s = QString("\ntiming ");
1608// file.write(s.toLatin1().data(),s.length());
1609// s = QString("%L1 \n").arg(sequenceItem.getTiming(),0,'f',2);
1610// file.write(s.toLatin1().data(),s.length());
1611// }
1612// file.flush();
1613// file.close();
1614
1615// LOG_ERROR("File saved and closed\n");
1616// }
1617
1618}
1619
1620void PartItem::onSequenceCycleTime(QList<SequenceItem> values)
1621{
1622 // Remove items after the first timing with value < 0
1623 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1624 return;
1625 }
1626
1627 m_cycleTimeValues.clear();
1628 for(int i=0;i<values.count();i++){
1629 SequenceItem it = values.at(i);
1630 if(it.getTiming() > 0){
1631 m_cycleTimeValues.append(it);
1632 }
1633 }
1634
1636 if (m_cycleTimeValues.count() > 0)
1637 {
1638 vals = m_cycleTimeValues.takeFirst();
1639 m_cycleTimeValues.append(vals);
1640 emit setCurrentIndex(vals.getSequenceNumber());
1641 fixedTimeMove(vals);
1642 m_cycleTimeTimer.start(vals.getTiming() * 1000);
1644 }
1645}
1646
1647void PartItem::onCycleTimeTimerTimeout()
1648{
1649 if (m_cycleTimeValues.count() > 0)
1650 {
1651 SequenceItem vals = m_cycleTimeValues.takeFirst();
1652 m_cycleTimeValues.append(vals);
1653 emit setCurrentIndex(vals.getSequenceNumber());
1654 fixedTimeMove(vals);
1655 m_cycleTimeTimer.start(vals.getTiming() * 1000);
1656 }
1657}
1658
1659void PartItem::onSequenceCycle(QList<SequenceItem> values)
1660{
1661 // Remove items after the first timing with value < 0
1662 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1663 return;
1664 }
1665
1666 m_cycleValues.clear();
1667 for(int i=0;i<values.count();i++){
1668 SequenceItem it = values.at(i);
1669 if(it.getTiming() > 0){
1670 m_cycleValues.append(it);
1671 }
1672 }
1673
1675 if (m_cycleValues.count() > 0){
1676 vals = m_cycleValues.takeFirst();
1677
1678 m_cycleValues.append(vals);
1679
1680 double *cmdPositions = new double[vals.getPositions().count()];
1681 double *cmdVelocities = new double[vals.getSpeeds().count()];
1682
1683 for(int i=0;i<vals.getPositions().count();i++){
1684 cmdPositions[i] = vals.getPositions().at(i);
1685 cmdVelocities[i] = vals.getSpeeds().at(i);
1686 //qDebug() << "vals.getSpeeds().at(i)" << vals.getSpeeds().at(i);
1687 }
1688
1689 emit setCurrentIndex(vals.getSequenceNumber());
1690 //fixedTimeMove(vals.getPositions());
1691 m_iPos->setRefSpeeds(cmdVelocities);
1692 m_iPos->positionMove(cmdPositions);
1693 m_cycleTimer.start(vals.getTiming() * 1000);
1694
1696 }
1697}
1698
1699void PartItem::onCycleTimerTimeout()
1700{
1701 if (m_cycleValues.count() > 0){
1702 SequenceItem vals = m_cycleValues.takeFirst();
1703
1704 m_cycleValues.append(vals);
1705
1706 double *cmdPositions = new double[vals.getPositions().count()];
1707 double *cmdVelocities = new double[vals.getSpeeds().count()];
1708
1709 for(int i=0;i<vals.getPositions().count();i++){
1710 cmdPositions[i] = vals.getPositions().at(i);
1711 cmdVelocities[i] = vals.getSpeeds().at(i);
1712 }
1713
1714 emit setCurrentIndex(vals.getSequenceNumber());
1715 //fixedTimeMove(vals.getPositions());
1716 m_iPos->setRefSpeeds(cmdVelocities);
1717 m_iPos->positionMove(cmdPositions);
1718
1719 m_cycleTimer.start(vals.getTiming() * 1000);
1720 }
1721}
1722
1723void PartItem::onSequenceRun(QList<SequenceItem> values)
1724{
1725 // Remove items after the first timing with value < 0
1726 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1727 return;
1728 }
1729
1730 m_runValues.clear();
1731 for(int i=0;i<values.count();i++){
1732 SequenceItem it = values.at(i);
1733 if(it.getTiming() > 0){
1734 m_runValues.append(it);
1735 }
1736 }
1737
1739 if (m_runValues.count() > 0){
1740 vals = m_runValues.takeFirst();
1741
1742 m_runValues.append(vals);
1743
1744 double *cmdPositions = new double[vals.getPositions().count()];
1745 double *cmdVelocities = new double[vals.getSpeeds().count()];
1746
1747 for(int i=0;i<vals.getPositions().count();i++){
1748 cmdPositions[i] = vals.getPositions().at(i);
1749 cmdVelocities[i] = vals.getSpeeds().at(i);
1750 //qDebug() << "vals.getSpeeds().at(i)" << vals.getSpeeds().at(i);
1751 }
1752
1753 emit setCurrentIndex(vals.getSequenceNumber());
1754 //fixedTimeMove(vals.getPositions());
1755 m_iPos->setRefSpeeds(cmdVelocities);
1756 m_iPos->positionMove(cmdPositions);
1757 m_runTimer.start(vals.getTiming() * 1000);
1758
1759 emit runSequence();
1760 }
1761}
1762void PartItem::onRunTimeout()
1763{
1764 if (m_runValues.count() > 0){
1765 SequenceItem vals = m_runValues.takeFirst();
1766 if(vals.getTiming() < 0){
1768 return;
1769 }
1770 double *cmdPositions = new double[vals.getPositions().count()];
1771 double *cmdVelocities = new double[vals.getSpeeds().count()];
1772
1773 for(int i=0;i<vals.getPositions().count();i++){
1774 cmdPositions[i] = vals.getPositions().at(i);
1775 cmdVelocities[i] = vals.getSpeeds().at(i);
1776 //qDebug() << "vals.getSpeeds().at(i)" << vals.getSpeeds().at(i);
1777 }
1778
1779 emit setCurrentIndex(vals.getSequenceNumber());
1780 //fixedTimeMove(vals.getPositions());
1781 m_iPos->setRefSpeeds(cmdVelocities);
1782 m_iPos->positionMove(cmdPositions);
1783
1784
1785 m_runTimer.start(vals.getTiming() * 1000);
1786 }else{
1788 }
1789}
1790
1791
1792
1793void PartItem::onSequenceRunTime(QList<SequenceItem> values)
1794{
1795 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1796 return;
1797 }
1798
1799 m_runTimeValues.clear();
1800
1801 for(int i=0;i<values.count();i++){
1802 SequenceItem it = values.at(i);
1803 if(it.getTiming() > 0){
1804 m_runTimeValues.append(it);
1805 }
1806 }
1807
1809 if (m_runTimeValues.count() > 0){
1810 vals = m_runTimeValues.takeFirst();
1811
1812 emit setCurrentIndex(vals.getSequenceNumber());
1813 fixedTimeMove(vals);
1814 m_runTimeTimer.start(vals.getTiming() * 1000);
1815
1817 }
1818
1819}
1820
1821void PartItem::onRunTimerTimeout()
1822{
1823 if (m_runTimeValues.count() > 0){
1824 SequenceItem vals = m_runTimeValues.takeFirst();
1825 if(vals.getTiming() < 0){
1827 return;
1828 }
1829 emit setCurrentIndex(vals.getSequenceNumber());
1830 fixedTimeMove(vals);
1831 m_runTimeTimer.start(vals.getTiming() * 1000);
1832 }else{
1834 }
1835}
1836
1837void PartItem::fixedTimeMove(SequenceItem sequence)
1838{
1839 int NUM_JOINTS;
1840 m_iPos->getAxes(&NUM_JOINTS);
1841 auto* cmdPositions = new double[NUM_JOINTS];
1842 auto* cmdVelocities = new double[NUM_JOINTS];
1843 auto* startPositions = new double[NUM_JOINTS];
1844 double cmdTime = sequence.getTiming();
1845
1846 while (!m_iencs->getEncoders(startPositions)){
1848 }
1849
1850
1851 for(int k=0; k<NUM_JOINTS; k++){
1852 cmdVelocities[k] = 0;
1853 cmdPositions[k] = sequence.getPositions().at(k);
1854
1855 if (fabs(startPositions[k] - cmdPositions[k]) > 0.01){
1857 } else {
1858 cmdVelocities[k] = 1.0;
1859 }
1860 }
1861
1862 m_iPos->setRefSpeeds(cmdVelocities);
1863 m_iPos->positionMove(cmdPositions);
1864
1865 m_sequence_port_stamp.update();
1866 m_sequence_port.setEnvelope(m_sequence_port_stamp);
1868 m_sequence_port.write(v);
1869 delete[] cmdVelocities;
1870 delete[] startPositions;
1871 delete[] cmdPositions;
1872 return;
1873}
1874
1875void PartItem::onGo(SequenceItem sequenceItem)
1876{
1877 if(sequenceItem.getPositions().isEmpty() || sequenceItem.getSpeeds().isEmpty())
1878 {
1879 QMessageBox::critical(this,"Error", "Select an entry in the table before performing a movement");
1880 return;
1881 }
1882
1883 int NUMBER_OF_JOINTS;
1884 m_iPos->getAxes(&NUMBER_OF_JOINTS);
1885
1886 for(int i=0;i<NUMBER_OF_JOINTS;i++)
1887 {
1888 m_iPos->setRefSpeed(i, sequenceItem.getSpeeds().at(i));
1889 m_iPos->positionMove(i, sequenceItem.getPositions().at(i));
1890 }
1891}
1892
1893void PartItem::onSequenceActivated()
1894{
1895 for (int i = 0; i<m_layout->count(); i++)
1896 {
1897 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1898 if(joint){
1899 joint->sequenceActivated();
1900 }
1901 }
1902
1904
1905}
1906
1907void PartItem::onSequenceStopped()
1908{
1909 for (int i = 0; i<m_layout->count(); i++)
1910 {
1911 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1912 if(joint){
1913 joint->sequenceStopped();
1914 }
1915 }
1917}
1918
1919void PartItem::onSequenceWindowDoubleClicked(int sequenceNum)
1920{
1922 QList<double>speeds;
1923 for (int i = 0; i<m_layout->count(); i++)
1924 {
1925 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1926 values.append(this->m_positions[i]);
1927 speeds.append(joint->getTrajectoryVelocityValue());
1928 }
1929
1931}
1932
1934{
1935 for (int i = 0; i<m_layout->count(); i++)
1936 {
1937 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1938 joint->enableControlVelocity(control);
1939 }
1940}
1941
1943{
1944 for (int i = 0; i<m_layout->count(); i++)
1945 {
1946 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1947 joint->enableControlMixed(control);
1948 }
1949}
1950
1952{
1953 for (int i = 0; i<m_layout->count(); i++)
1954 {
1955 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1956 joint->enableControlPositionDirect(control);
1957 }
1958}
1959
1961{
1962 for (int i = 0; i<m_layout->count(); i++)
1963 {
1964 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1965 joint->enableControlPWM(control);
1966 }
1967}
1968
1970{
1971 for (int i = 0; i<m_layout->count(); i++)
1972 {
1973 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1974 joint->enableControlCurrent(control);
1975 }
1976}
1977
1979{
1980 for (int i = 0; i<m_layout->count(); i++)
1981 {
1982 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1983 joint->enableControlTorque(control);
1984 }
1985}
1986
1988{
1989 for (int i = 0; i<m_layout->count(); i++)
1990 {
1991 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
1992 joint->enableControlVelocityDirect(control);
1993 }
1994}
1995
1997{
1998 m_part_speedVisible = view;
1999 for (int i = 0; i<m_layout->count(); i++)
2000 {
2001 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2002 joint->setSpeedVisible(view);
2003 }
2004}
2005
2007{
2008 m_part_motorPositionVisible = view;
2009 for (int i = 0; i<m_layout->count(); i++)
2010 {
2011 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2012 joint->setMotorPositionVisible(view);
2013 }
2014}
2015
2017{
2018 m_part_dutyVisible = view;
2019 for (int i = 0; i<m_layout->count(); i++)
2020 {
2021 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2022 joint->setDutyVisible(view);
2023 }
2024}
2025
2027{
2028 m_part_currentVisible = view;
2029 for (int i = 0; i<m_layout->count(); i++)
2030 {
2031 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2032 joint->setCurrentsVisible(view);
2033 }
2034}
2035
2037{
2038 for (int i = 0; i<m_layout->count(); i++)
2039 {
2040 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2041 joint->viewPositionTargetBox(ena);
2042 }
2043}
2044
2046{
2047 for (int i = 0; i < m_layout->count(); i++)
2048 {
2049 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2050 joint->viewPositionTargetValue(ena);
2051 }
2052}
2053
2055{
2056 for (int i = 0; i<m_layout->count(); i++)
2057 {
2058 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2059 if (mode==0)
2060 {
2061 joint->enablePositionSliderDoubleAuto();
2062 }
2063 else if(mode ==1)
2064 {
2065 joint->enablePositionSliderDoubleValue(step);
2066 }
2067 else if (mode == 2)
2068 {
2069 joint->enablePositionSliderDoubleValue(1.0);
2070 }
2071 else
2072 {
2073 joint->disablePositionSliderDouble();
2074 }
2075 joint->setNumberOfPositionSliderDecimals(numOfDec);
2076 }
2077}
2079{
2080 for (int i = 0; i<m_layout->count(); i++)
2081 {
2082 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2083 if (mode == 0)
2084 {
2085 joint->enableVelocitySliderDoubleAuto();
2086 }
2087 else if (mode == 1)
2088 {
2089 joint->enableVelocitySliderDoubleValue(step);
2090 }
2091 else if (mode == 2)
2092 {
2093 joint->enableVelocitySliderDoubleValue(1.0);
2094 }
2095 else
2096 {
2097 joint->disableVelocitySliderDouble();
2098 }
2099 joint->setNumberOfVelocitySliderDecimals(numOfDec);
2100 }
2101}
2103{
2104 for (int i = 0; i<m_layout->count(); i++)
2105 {
2106 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2107 if (mode == 0)
2108 {
2109 joint->enableAccelerationSliderDoubleAuto();
2110 }
2111 else if (mode == 1)
2112 {
2113 joint->enableAccelerationSliderDoubleValue(step);
2114 }
2115 else if (mode == 2)
2116 {
2117 joint->enableAccelerationSliderDoubleValue(1.0);
2118 }
2119 else
2120 {
2121 joint->disableAccelerationSliderDouble();
2122 }
2123 joint->setNumberOfAccelerationSliderDecimals(numOfDec);
2124 }
2125}
2127{
2128 for (int i = 0; i<m_layout->count(); i++)
2129 {
2130 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2131 if (mode == 0)
2132 {
2133 joint->enableCurrentSliderDoubleAuto();
2134 }
2135 else if (mode == 1)
2136 {
2137 joint->enableCurrentSliderDoubleValue(step);
2138 }
2139 else if (mode == 2)
2140 {
2141 joint->enableCurrentSliderDoubleValue(1.0);
2142 }
2143 else
2144 {
2145 joint->disableCurrentSliderDouble();
2146 }
2147 joint->setNumberOfCurrentSliderDecimals(numOfDec);
2148 }
2149}
2150
2152{
2153 for (int i = 0; i<m_layout->count(); i++)
2154 {
2155 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2156 if (mode == 0)
2157 {
2158 joint->enableTorqueSliderDoubleAuto();
2159 }
2160 else if(mode == 1)
2161 {
2162 joint->enableTorqueSliderDoubleValue(step);
2163 }
2164 else if(mode == 2)
2165 {
2166 joint->enableTorqueSliderDoubleValue(1.0);
2167 }
2168 else
2169 {
2170 joint->disableTorqueSliderDouble();
2171 }
2172 joint->setNumberOfTorqueSliderDecimals(numOfDec);
2173 }
2174}
2175
2177{
2178 return m_modesList;
2179}
2180
2182{
2183 bool ret = m_ictrlmode->getControlModes(m_controlModes.data());
2184
2185
2186 if(ret==false){
2187 LOG_ERROR("ictrl->getControlMode failed on %s\n", getPartName().c_str());
2188 }
2189
2190 m_modesList.resize(m_layout->count());
2191 for (int k = 0; k < m_layout->count(); k++){
2192 switch (m_controlModes[k])
2193 {
2194 case VOCAB_CM_IDLE:
2195 m_modesList[k] = JointItem::Idle;
2196 break;
2197 case VOCAB_CM_POSITION:
2198 m_modesList[k] = JointItem::Position;
2199 break;
2201 m_modesList[k] = JointItem::PositionDirect;
2202 break;
2203 case VOCAB_CM_MIXED:
2204 m_modesList[k] = JointItem::Mixed;
2205 break;
2206 case VOCAB_CM_VELOCITY:
2207 m_modesList[k] = JointItem::Velocity;
2208 break;
2210 m_modesList[k] = JointItem::VelocityDirect;
2211 break;
2212 case VOCAB_CM_TORQUE:
2213 m_modesList[k] = JointItem::Torque;
2214 break;
2215 case VOCAB_CM_PWM:
2216 m_modesList[k] = JointItem::Pwm;
2217 break;
2218 case VOCAB_CM_CURRENT:
2219 m_modesList[k] = JointItem::Current;
2220 break;
2221 case VOCAB_CM_HW_FAULT:
2222 m_modesList[k] = JointItem::HwFault;
2223 break;
2225 m_modesList[k] = JointItem::Calibrating;
2226 break;
2228 m_modesList[k] = JointItem::CalibDone;
2229 break;
2231 m_modesList[k] = JointItem::NotConfigured;
2232 break;
2234 m_modesList[k] = JointItem::Configured;
2235 break;
2236 default:
2237 case VOCAB_CM_UNKNOWN:
2238 m_modesList[k] = JointItem::Unknown;
2239 break;
2240 }
2241 }
2242}
2243
2245{
2246 bool ret = false;
2247 int number_of_joints=0;
2248 m_iPos->getAxes(&number_of_joints);
2249 if (m_slow_k >= number_of_joints - 1) {
2250 m_slow_k = 0;
2251 } else {
2252 m_slow_k++;
2253 }
2254
2255 if (number_of_joints == 0)
2256 {
2257 LOG_ERROR("Lost connection with the robot. You should save and restart.\n" );
2259
2260 for (int i = 0; i<m_layout->count(); i++){
2261 auto* joint = (JointItem*)m_layout->itemAt(i)->widget();
2262 joint->setJointState(JointItem::Disconnected);
2263 }
2264 return false;
2265 }
2266
2267 // *** update measured encoders, velocity, torques ***
2268 bool b = true;
2269 if (true)
2270 {
2271 b = m_iencs->getEncoders(m_positions.data());
2272 if (!b) { yWarning("Unable to update encoders"); return false; }
2273 }
2274 if (true)
2275 {
2276 b = m_iTrq->getTorques(m_torques.data());
2277 if (!b) { yWarning("Unable to update torques"); }
2278 }
2279 if (this->m_part_currentVisible)
2280 {
2281 b = m_iCur->getCurrents(m_currents.data());
2282 if (!b) { yWarning("Unable to update currents"); }
2283 }
2284 if (this->m_part_speedVisible)
2285 {
2286 b = m_iencs->getEncoderSpeeds(m_speeds.data());
2287 if (!b) { yWarning("Unable to update speeds"); }
2288 }
2289 if (this->m_part_motorPositionVisible)
2290 {
2291 b = m_iMot->getMotorEncoders(m_motorPositions.data());
2292 if (!b) { yWarning("Unable to update motorPositions"); }
2293 }
2294 if (this->m_part_dutyVisible)
2295 {
2296 b = m_iPWM->getDutyCycles(m_dutyCycles.data());
2297 if (!b) { yWarning("Unable to update dutyCycles"); }
2298 }
2299
2300 // *** update checkMotionDone, refTorque, refTrajectorySpeed, refSpeed ***
2301 // (only one at a time in order to save bandwidth)
2302 bool ret_motdone = false;
2303 bool ret_refTrq = false;
2304 bool ret_refPosSpeed = false;
2305 bool ret_refVel = false;
2306 bool ret_refAcc = false;
2307 bool ret_refPos = false;
2308 bool ret_jntbrk = false;
2309
2310 if (m_iPos)
2311 {
2312 bool boolval = true;
2313 m_iPos->checkMotionDone(m_slow_k, &boolval); // using k to save bandwidth
2314 m_done[m_slow_k] = boolval;
2315 }
2316 if (m_ijointbrake)
2317 {
2318 bool boolval = true;
2319 ret_jntbrk = m_ijointbrake->isJointBraked(m_slow_k, boolval);
2320 m_braked[m_slow_k] = boolval;
2321 }
2322 if (m_iTrq)
2323 {
2324 ret_refTrq = m_iTrq->getRefTorque(m_slow_k, &m_refTorques[m_slow_k]); // using k to save bandwidth
2325 }
2326 if (m_iPos)
2327 {
2328 ret_refPosSpeed = m_iPos->getRefSpeed(m_slow_k, &m_refTrajectorySpeeds[m_slow_k]); // using k to save bandwidth
2329 }
2330 if (m_iVel)
2331 {
2332 ret_refVel = m_iVel->getRefVelocity(m_slow_k, &m_refVelocitySpeeds[m_slow_k]); // this interface is missing!
2333 }
2334 if (m_iVel)
2335 {
2336 ret_refAcc = m_iVel->getRefAcceleration(m_slow_k, &m_refVelocityAccelerations[m_slow_k]); // this interface is missing!
2337 }
2338 if (m_iPos)
2339 {
2340 ret_refPos = m_iPos->getTargetPosition(m_slow_k, &m_refTrajectoryPositions[m_slow_k]);
2341 }
2342
2343 //Check return values of methods
2344 if (!ret_refPos)
2345 {
2346 yError() << "Missing Implementation of getTargetPosition()";
2347 }
2348 if (!ret_refVel)
2349 {
2350 yError() << "Missing Implementation of getRefVelocity()";
2351 }
2352 if (!ret_refPosSpeed)
2353 {
2354 yError() << "Missing Implementation of getRefSpeed()";
2355 }
2356 if (!ret_refTrq)
2357 {
2358 yError() << "Missing Implementation of getRefTorque()";
2359 }
2360 if (!ret_motdone)
2361 {
2362 yError() << "Missing Implementation of checkMotionDone()";
2363 }
2364 if (!ret_jntbrk)
2365 {
2366 yWarning() << "Missing Implementation of isJointBraked()";
2367 }
2368
2369 // *** update the widget every cycle ***
2370 for (int jk = 0; jk < number_of_joints; jk++)
2371 {
2372 auto* joint = (JointItem*)m_layout->itemAt(jk)->widget();
2373 if (true) { joint->setPosition(m_positions[jk]); }
2374 else {}
2375 if (true) { joint->setTorque(m_torques[jk]); }
2376 else {}
2377 if (true) { joint->setSpeed(m_speeds[jk]); }
2378 else {}
2379 if (true) { joint->setCurrent(m_currents[jk]); }
2380 else {}
2381 if (true) { joint->setMotorPosition(m_motorPositions[jk]); }
2382 else {}
2383 if (true) { joint->setDutyCycles(m_dutyCycles[jk]); }
2384 else {}
2385 }
2386
2387 // *** update the widget NOT every cycle ***
2388 {
2389 auto* joint_slow_k = (JointItem*)m_layout->itemAt(m_slow_k)->widget();
2390 if (ret_refTrq) { joint_slow_k->setRefTorque(m_refTorques[m_slow_k]); }
2391 else {}
2392 if (ret_refPosSpeed) { joint_slow_k->setPosTrajectory_ReferenceSpeed(m_refTrajectorySpeeds[m_slow_k]); }
2393 else {}
2394 if (ret_refPos) { joint_slow_k->setPosTrajectory_ReferencePosition(m_refTrajectoryPositions[m_slow_k]); }
2395 else {}
2396 if (ret_refVel) { joint_slow_k->setVelTrajectory_ReferenceSpeed(m_refVelocitySpeeds[m_slow_k]); }
2397 else {}
2398 if (ret_refAcc) { joint_slow_k->setVelTrajectory_ReferenceAcceleration(m_refVelocityAccelerations[m_slow_k]); }
2399 else {}
2400 if (ret_motdone) { joint_slow_k->updateMotionDone(m_done[m_slow_k]); }
2401 else {}
2402 if (ret_jntbrk) { joint_slow_k->updateBraked(m_braked[m_slow_k]); }
2403 else {}
2404 }
2405
2406
2407 // *** update the controlMode, interactionMode ***
2408 // this is already done by updateControlMode() (because it also needs to update the tree, not only the single joint widget)
2409 // ret=ctrlmode2->getControlModes(controlModes);
2410 // if(ret==false){
2411 // LOG_ERROR("ictrl->getControlMode failed\n" );
2412 // }
2413 ret = m_iinteract->getInteractionModes(m_interactionModes.data());
2414 if(ret==false){
2415 LOG_ERROR("iint->getInteractionlMode failed\n" );
2416 }
2417
2418 //optional
2419 if (m_ijointfault)
2420 {
2421 for (int k = 0; k < number_of_joints; k++)
2422 {
2423 if (m_controlModes[k]==VOCAB_CM_HW_FAULT)
2424 {
2425 int fault;
2426 std::string message;
2427 if (m_ijointfault->getLastJointFault(k,fault,message))
2428 {
2429 auto* joint_slow_k = (JointItem*)m_layout->itemAt(m_slow_k)->widget();
2430 joint_slow_k->updateJointFault(fault, message);
2431 }
2432 else
2433 {
2434 LOG_ERROR("Unsuccessful call to getLastJointFault()\n");
2435 }
2436 }
2437 }
2438 }
2439
2440
2441 for (int k = 0; k < number_of_joints; k++)
2442 {
2443 auto* joint = (JointItem*)m_layout->itemAt(k)->widget();
2444 switch (m_controlModes[k])
2445 {
2446 case VOCAB_CM_IDLE:
2447 joint->setJointState(JointItem::Idle);
2448 break;
2449 case VOCAB_CM_POSITION:
2450 joint->setJointState(JointItem::Position);
2451 break;
2453 joint->setJointState(JointItem::PositionDirect);
2454 break;
2455 case VOCAB_CM_MIXED:
2456 joint->setJointState(JointItem::Mixed);
2457 break;
2458 case VOCAB_CM_VELOCITY:
2459 joint->setJointState(JointItem::Velocity);
2460 break;
2462 joint->setJointState(JointItem::VelocityDirect);
2463 break;
2464 case VOCAB_CM_TORQUE:
2465 joint->setJointState(JointItem::Torque);
2466 break;
2467 case VOCAB_CM_CURRENT:
2468 {
2469 joint->setJointState(JointItem::Current);
2470 double ref_current = 0;
2471 m_iCur->getRefCurrent(k, &ref_current);
2472 joint->setRefCurrent(ref_current);
2473 break;
2474 }
2475 case VOCAB_CM_PWM:
2476 {
2477 joint->setJointState(JointItem::Pwm);
2478 double ref_duty = 0;
2479 m_iPWM->getRefDutyCycle(k, &ref_duty);
2480 joint->setRefPWM(ref_duty);
2481 break;
2482 }
2483 case VOCAB_CM_HW_FAULT:
2484 joint->setJointState(JointItem::HwFault);
2485 break;
2487 joint->setJointState(JointItem::Calibrating);
2488 break;
2490 joint->setJointState(JointItem::CalibDone);
2491 break;
2493 joint->setJointState(JointItem::NotConfigured);
2494 break;
2496 joint->setJointState(JointItem::Configured);
2497 break;
2498 default:
2499 case VOCAB_CM_UNKNOWN:
2500 joint->setJointState(JointItem::Unknown);
2501 break;
2502 }
2503 switch (m_interactionModes[k])
2504 {
2505 case VOCAB_IM_STIFF:
2506 joint->setJointInteraction(JointItem::Stiff);
2507 break;
2508 case VOCAB_IM_COMPLIANT:
2509 joint->setJointInteraction(JointItem::Compliant);
2510 break;
2511 default:
2512 case VOCAB_IM_UNKNOWN:
2513 //joint->setJointInteraction(JointItem::Stiff); TODO
2514 break;
2515 }
2516 }
2517 return true;
2518}
FeatureMode mode
constexpr yarp::conf::vocab32_t VOCAB_CM_UNKNOWN
constexpr yarp::conf::vocab32_t VOCAB_CM_MIXED
constexpr yarp::conf::vocab32_t VOCAB_CM_TORQUE
constexpr yarp::conf::vocab32_t VOCAB_CM_PWM
constexpr yarp::conf::vocab32_t VOCAB_CM_HW_FAULT
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_CM_IDLE
constexpr yarp::conf::vocab32_t VOCAB_CM_CALIB_DONE
constexpr yarp::conf::vocab32_t VOCAB_CM_NOT_CONFIGURED
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
constexpr yarp::conf::vocab32_t VOCAB_CM_CONFIGURED
constexpr yarp::conf::vocab32_t VOCAB_CM_CURRENT
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION_DIRECT
constexpr yarp::conf::vocab32_t VOCAB_CM_VELOCITY
constexpr yarp::conf::vocab32_t VOCAB_CM_FORCE_IDLE
constexpr yarp::conf::vocab32_t VOCAB_CM_CALIBRATING
bool ret
#define yInfo(...)
Definition Log.h:319
#define yError(...)
Definition Log.h:361
#define yDebug(...)
Definition Log.h:275
#define yWarning(...)
Definition Log.h:340
int SIGNAL(int pid, int signum)
Original license follows:
Definition flowlayout.h:59
QLayoutItem * itemAt(int index) const override
int count() const override
@ PositionDirect
Definition jointitem.h:33
@ Disconnected
Definition jointitem.h:34
@ VelocityDirect
Definition jointitem.h:33
@ Calibrating
Definition jointitem.h:34
@ NotConfigured
Definition jointitem.h:34
void initInterfaces()
Definition partitem.cpp:379
bool openPolyDrivers()
Definition partitem.cpp:358
bool checkAndGo()
void cycleTimeSequence()
bool homePart()
void onEnableControlVelocityDirect(bool control)
bool checkAndRunAllSeq()
void onViewDutyCycles(bool)
void resizeWidget(int w)
bool homeToCustomPosition(const yarp::os::Bottle &positionElement)
void setCurrentIndex(int)
void runTimeSequence()
void idlePart()
JointItem * getJointWidget(int jointIndex)
int getNumberOfJoints()
void onEnableControlCurrent(bool control)
bool getInterfaceError()
Definition partitem.cpp:511
void onSetVelSliderOptionPI(int mode, double step, int numOfDec)
void onViewMotorPositions(bool)
void onEnableControlPWM(bool control)
void runPart()
void onEnableControlVelocity(bool control)
PartItem(std::string robotName, int partId, std::string partName, ResourceFinder &_finder, bool debug_param_enabled, bool speedview_param_enabled, bool enable_calib_all, std::string rcb_protocol, QWidget *parent=0)
Definition partitem.cpp:25
QString getJointName(int joint)
std::string getPartName()
Definition partitem.cpp:516
void onSetCurSliderOptionPI(int mode, double step, int numOfDec)
void onViewPositionTargetValue(bool)
void onViewPositionTargetBox(bool)
bool homeJoint(int joint)
void onViewCurrentValues(bool)
void runSequence()
void onSetTrqSliderOptionPI(int mode, double step, int numOfDec)
void sendPartJointsValues(int, QList< double >, QList< double >)
bool checkAndCycleAllSeq()
void closeSequenceWindow()
bool updatePart()
void onViewSpeedValues(bool)
void openSequenceWindow()
void updateControlMode()
void stopSequence()
void stoppedSequence()
void onEnableControlPositionDirect(bool control)
void saveSequence(QString global_filename)
void resizeEvent(QResizeEvent *event) override
void changeEvent(QEvent *event) override
void onEnableControlTorque(bool control)
void loadSequence()
void sequenceStopped()
const QVector< JointItem::JointState > & getPartModes()
void cycleSequence()
void onEnableControlMixed(bool control)
void onSetPosSliderOptionPI(int mode, double step, int numOfDec)
void sequenceActivated()
bool checkAndRunTimeAllSeq()
bool checkAndCycleTimeAllSeq()
void onSetAccSliderOptionPI(int mode, double step, int numOfDec)
void calibratePart()
bool openInterfaces()
Definition partitem.cpp:403
void initVelocity(Pid myPid)
Definition piddlg.cpp:141
void initPosition(Pid myPid)
Definition piddlg.cpp:111
void initStiffness(double curStiffVal, double minStiff, double maxStiff, double curDampVal, double minDamp, double maxDamp, double curForceVal, double minForce, double maxForce)
Definition piddlg.cpp:317
void initTorque(Pid myPid, MotorTorqueParameters TorqueParam)
Definition piddlg.cpp:171
void initCurrent(Pid myPid)
Definition piddlg.cpp:346
void initRemoteVariables(IRemoteVariables *iVar)
Definition piddlg.cpp:251
void initPWM(double pwmVal, double pwm)
Definition piddlg.cpp:338
void save(QString global_filename)
void loadSequence(QList< SequenceItem >)
bool view(T *&x)
Get an interface to the device driver.
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
Definition IAxisInfo.h:63
virtual bool getVelLimits(int axis, double *min, double *max)=0
Get the software speed limits for a particular axis.
virtual bool getLimits(int axis, double *min, double *max)=0
Get the software limits for a particular axis.
virtual bool setControlMode(const int j, const int mode)=0
Set the current control mode.
virtual bool getControlModes(int *modes)=0
Get the current control mode (multiple joints).
virtual bool getControlMode(int j, int *mode)=0
Get the current control mode.
virtual bool getCurrents(double *currs)=0
Get the instantaneous current measurement for all motors.
virtual bool setRefCurrent(int m, double curr)=0
Set the reference value of the current for a single motor.
virtual bool getCurrentRange(int m, double *min, double *max)=0
Get the full scale of the current measurement for a given motor (e.g.
virtual bool getRefCurrent(int m, double *curr)=0
Get the reference value of the current for a single motor.
virtual bool getEncoder(int j, double *v)=0
Read the value of an encoder.
virtual bool getEncoders(double *encs)=0
Read the position of all axes.
virtual bool getEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all axes.
virtual bool setImpedance(int j, double stiffness, double damping)=0
Set current impedance gains (stiffness,damping) for a specific joint.
virtual bool getImpedanceOffset(int j, double *offset)=0
Get current force Offset for a specific joint.
virtual bool getImpedance(int j, double *stiffness, double *damping)=0
Get current impedance gains (stiffness,damping,offset) for a specific joint.
virtual bool getCurrentImpedanceLimit(int j, double *min_stiff, double *max_stiff, double *min_damp, double *max_damp)=0
Get the current impedandance limits for a specific joint.
virtual bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool setInteractionMode(int axis, yarp::dev::InteractionModeEnum mode)=0
Set the interaction mode of the robot, values can be stiff or compliant.
virtual yarp::dev::ReturnValue isJointBraked(int j, bool &braked) const =0
Check is the joint brake is currently active.
virtual bool getLastJointFault(int j, int &fault, std::string &message)=0
virtual bool getMotorEncoders(double *encs)=0
Read the position of all motor encoders.
virtual bool getDutyCycle(int m, double *val)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual bool setRefDutyCycle(int m, double ref)=0
Sets the reference dutycycle to a single motor.
virtual bool getRefDutyCycle(int m, double *ref)=0
Gets the last reference sent using the setRefDutyCycle function.
virtual bool getDutyCycles(double *vals)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual bool setPid(const PidControlTypeEnum &pidtype, int j, const Pid &pid)=0
Set new pid value for a joint axis.
virtual bool getPid(const PidControlTypeEnum &pidtype, int j, Pid *pid)=0
Get current pid value for a specific joint.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool setRefSpeed(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual bool getTargetPosition(const int joint, double *ref)
Get the last position reference for the specified axis.
virtual bool setRefSpeeds(const double *spds)=0
Set reference speed on all joints.
virtual bool checkMotionDone(int j, bool *flag)=0
Check if the current trajectory is terminated.
virtual bool getRefSpeed(int j, double *ref)=0
Get reference speed for a joint.
virtual bool positionMove(int j, double ref)=0
Set new reference point for a single axis.
virtual bool setPosition(int j, double ref)=0
Set new position for a single axis.
virtual bool homingSingleJoint(int j)=0
homingSingleJoint: call the homing procedure for a single joint
virtual bool isCalibratorDevicePresent(bool *isCalib)
isCalibratorDevicePresent: check if a calibrator device has been set
virtual bool homingWholePart()=0
homingWholePart: call the homing procedure for a the whole part/device
virtual bool calibrateSingleJoint(int j)=0
calibrateSingleJoint: call the calibration procedure for the single joint
virtual bool calibrateWholePart()=0
calibrateWholePart: call the procedure for calibrating the whole device
virtual bool setRemoteVariable(std::string key, const yarp::os::Bottle &val)=0
virtual bool getRemoteVariable(std::string key, yarp::os::Bottle &val)=0
virtual bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys)=0
virtual bool setRefTorque(int j, double t)=0
Set the reference value of the torque for a given joint.
virtual bool setMotorTorqueParams(int j, const yarp::dev::MotorTorqueParameters params)
Set a subset of motor parameters (bemf, ktau etc) useful for torque control.
virtual bool getMotorTorqueParams(int j, yarp::dev::MotorTorqueParameters *params)
Get a subset of motor parameters (bemf, ktau etc) useful for torque control.
virtual bool getTorques(double *t)=0
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
virtual bool getTorqueRange(int j, double *min, double *max)=0
Get the full scale of the torque sensor of a given joint.
virtual bool getRefTorque(int j, double *t)=0
Get the reference value of the torque for a given joint.
virtual bool setRefAcceleration(int j, double acc)=0
Set reference acceleration for a joint.
virtual bool getRefVelocity(const int joint, double *vel)
Get the last reference speed set by velocityMove for single joint.
virtual bool getRefAcceleration(int j, double *acc)=0
Get reference acceleration for a joint.
virtual bool velocityMove(int j, double sp)=0
Start motion at a given speed, single joint.
virtual yarp::dev::ReturnValue setDesiredVelocity(int jnt, double vel)=0
Set the velocity of single joint.
Contains the parameters for a PID.
A container for a device driver.
Definition PolyDriver.h:23
bool close() override
Close the DeviceDriver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:217
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:395
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
Definition Port.cpp:506
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
Helper class for finding config files and other external resources.
bool isNull() const override
Checks if the object is invalid.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
Definition Stamp.cpp:124
static void delaySystem(double seconds)
virtual bool isString() const
Checks if value is a string.
Definition Value.cpp:156
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
bool speedview_param_enabled
Definition main.cpp:35
bool debug_param_enabled
Definition main.cpp:34
bool enable_calib_all
Definition main.cpp:36
#define LOG_INFO(...)
Definition log.h:25
#define LOG_ERROR(...)
Definition log.h:19
@ VOCAB_PIDTYPE_TORQUE
Definition PidEnums.h:18
@ VOCAB_PIDTYPE_VELOCITY
Definition PidEnums.h:17
@ VOCAB_PIDTYPE_POSITION
Definition PidEnums.h:16
@ VOCAB_PIDTYPE_CURRENT
Definition PidEnums.h:19
@ VOCAB_JOINTTYPE_REVOLUTE
Definition IAxisInfo.h:24
#define MAX_WIDTH_JOINT
Definition partitem.h:37