16#include <QResizeEvent>
18#include <QXmlStreamWriter>
19#include <QXmlStreamAttribute>
32 m_sequenceWindow(nullptr),
34 m_mixedEnabled(
false),
35 m_positionDirectEnabled(
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),
56 if (partName.at(0) ==
'/') {
59 m_robotPartPort = std::string(
"/") +
robotName +std::string(
"/") + partName;
60 m_partName = partName;
78 yDebug(
"ADDRESS is: %s \n",
adr.toString().c_str());
91 m_interfaceError =
false;
95 m_partOptions.
put(
"device",
"remote_controlboard");
96 m_partOptions.
put(
"remote", m_robotPartPort);
103 if (m_interfaceError ==
true)
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()));
113 yDebug(
"Setting a valid finder \n");
122 if (m_interfaceError ==
false)
132 m_refTrajectorySpeeds[i] = std::nan(
"");
136 m_refTrajectoryPositions[i] = std::nan(
"");
140 m_refTorques[i] = std::nan(
"");
144 m_refVelocitySpeeds[i] = std::nan(
"");
148 m_refVelocityAccelerations[i] = std::nan(
"");
152 m_torques[i] = std::nan(
"");
156 m_positions[i] = std::nan(
"");
160 m_speeds[i] = std::nan(
"");
164 m_currents[i] = std::nan(
"");
168 m_motorPositions[i] = std::nan(
"");
172 m_dutyCycles[i] = std::nan(
"");
186 yError(
"%s iencs->getEncoders() failed, retrying...\n", partName.c_str());
191 yInfo(
"%s iencs->getEncoders() ok!\n", partName.c_str());
208 yError() <<
"Error while getting position limits, part " << partName <<
" joint " <<
k;
212 yError() <<
"Error while getting velocity limits, part " << partName <<
" joint " <<
k;
216 yError() <<
"Error while getting current range, part " << partName <<
" joint " <<
k;
219 QSettings settings(
"YARP",
"yarpmotorgui");
220 double max_slider_vel = settings.value(
"velocity_slider_limit", 100.0).toDouble();
235 joint->setPWMRange(-100.0, 100.0);
237 m_layout->addWidget(
joint);
241 joint->setTorqueRange(5.0);
243 joint->enableControlPositionDirect(m_positionDirectEnabled);
244 joint->enableControlMixed(m_mixedEnabled);
245 joint->enableControlPWM(m_pwmEnabled);
246 joint->enableControlCurrent(m_currentEnabled);
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();
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();
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)));
300 m_cycleTimer.setSingleShot(
true);
301 m_cycleTimer.setTimerType(Qt::PreciseTimer);
302 connect(&m_cycleTimer,
SIGNAL(timeout()),
this,
SLOT(onCycleTimerTimeout()), Qt::QueuedConnection);
304 m_cycleTimeTimer.setSingleShot(
true);
305 m_cycleTimeTimer.setTimerType(Qt::PreciseTimer);
306 connect(&m_cycleTimeTimer,
SIGNAL(timeout()),
this,
SLOT(onCycleTimeTimerTimeout()), Qt::QueuedConnection);
309 m_runTimeTimer.setSingleShot(
true);
310 m_runTimeTimer.setTimerType(Qt::PreciseTimer);
311 connect(&m_runTimeTimer,
SIGNAL(timeout()),
this,
SLOT(onRunTimerTimeout()), Qt::QueuedConnection);
313 m_runTimer.setSingleShot(
true);
314 m_runTimer.setTimerType(Qt::PreciseTimer);
315 connect(&m_runTimer,
SIGNAL(timeout()),
this,
SLOT(onRunTimeout()), Qt::QueuedConnection);
320 disconnect(&m_runTimer,
SIGNAL(timeout()),
this,
SLOT(onRunTimeout()));
323 disconnect(&m_runTimeTimer,
SIGNAL(timeout()),
this,
SLOT(onRunTimerTimeout()));
324 m_runTimeTimer.stop();
326 disconnect(&m_cycleTimer,
SIGNAL(timeout()),
this,
SLOT(onCycleTimerTimeout()));
329 disconnect(&m_cycleTimeTimer,
SIGNAL(timeout()),
this,
SLOT(onCycleTimeTimerTimeout()));
330 m_cycleTimeTimer.stop();
332 if (m_sequenceWindow){
333 m_sequenceWindow->hide();
334 delete m_sequenceWindow;
337 for (
int i = 0; i<m_layout->
count(); i++){
360 m_partsdd->
open(m_partOptions);
365 #ifdef DEBUG_INTERFACE
370 yError(
"Problems opening the debug client!");
381 yDebug(
"Initializing interfaces...");
397 m_ictrlmode =
nullptr;
398 m_iinteract =
nullptr;
399 m_iremCalib =
nullptr;
400 m_ijointfault =
nullptr;
405 yDebug(
"Opening interfaces...");
409 ok = m_partsdd->
view(m_iPid);
411 yError(
"...iPid was not ok...");
413 ok &= m_partsdd->
view(m_iAmp);
415 yError(
"...iAmp was not ok...");
417 ok &= m_partsdd->
view(m_iPos);
419 yError(
"...iPos was not ok...");
421 ok &= m_partsdd->
view(m_iPosDir);
423 yError(
"...posDirect was not ok...");
425 ok &= m_partsdd->
view(m_iVelDir);
427 yError(
"...velDirect was not ok...");
429 ok &= m_partsdd->
view(m_iVel);
431 yError(
"...iVel was not ok...");
433 ok &= m_partsdd->
view(m_iLim);
435 yError(
"...iLim was not ok...");
437 ok &= m_partsdd->
view(m_iencs);
439 yError(
"...enc was not ok...");
441 ok &= m_partsdd->
view(m_ical);
443 yError(
"...cal was not ok...");
445 ok &= m_partsdd->
view(m_iTrq);
447 yError(
"...trq was not ok...");
449 ok = m_partsdd->
view(m_iPWM);
451 yError(
"...opl was not ok...");
453 ok &= m_partsdd->
view(m_iImp);
455 yError(
"...imp was not ok...");
457 ok &= m_partsdd->
view(m_ictrlmode);
459 yError(
"...ctrlmode2 was not ok...");
461 ok &= m_partsdd->
view(m_iinteract);
463 yError(
"...iinteract was not ok...");
467 if (!m_partsdd->
view(m_ijointfault))
469 yWarning(
"...m_iJointFault was not ok...");
471 if (!m_partsdd->
view(m_ijointbrake))
473 yWarning(
"...m_iJointBrake was not ok...");
475 if (!m_partsdd->
view(m_iVar))
479 if (!m_partsdd->
view(m_iMot))
483 if (!m_partsdd->
view(m_iremCalib))
485 yWarning(
"...remCalib was not ok...");
487 if (!m_partsdd->
view(m_iinfo))
489 yWarning(
"...axisInfo was not ok...");
491 if (!m_partsdd->
view(m_iCur))
497 yError(
"Error while acquiring interfaces!");
498 QMessageBox::critical(
nullptr,
"Problems acquiring interfaces.",
"Check if interface is running");
499 m_interfaceError =
true;
504 yError(
"Device driver was not valid!");
505 m_interfaceError =
true;
508 return !m_interfaceError;
513 return m_interfaceError;
521void PartItem::onSliderPWMCommand(
double pwmVal,
int index)
526void PartItem::onSliderCurrentCommand(
double currentVal,
int index)
531void PartItem::onSliderVelTrajectoryVelocityCommand(
double speedVal,
int index)
536void PartItem::onSliderVelTrajectoryAccelerationCommand(
double accVal,
int index)
541void PartItem::onSliderVelocityDirectCommand(
double speedVal,
int index)
546void PartItem::onSliderTorqueCommand(
double torqueVal,
int index)
551void PartItem::onSliderPosTrajectoryVelocityCommand(
double trajspeedVal,
int index)
557void PartItem::onSliderDirectPositionCommand(
double dirpos,
int index)
567 yWarning(
"Joint not in position direct mode so cannot send references");
571void PartItem::onDumpAllRemoteVariables()
573 if (m_iVar ==
nullptr)
578 QString fileName = QFileDialog::getSaveFileName(
this,
QString(
"Save Dump for Remote Variables as:"), QDir::homePath()+
QString(
"/RemoteVariablesDump.txt"));
609void PartItem::onSliderPosTrajectoryPositionCommand(
double posVal,
int index)
620 yWarning(
"Joint not in position mode so cannot send references");
624void PartItem::onSliderMixedPositionCommand(
double posVal,
int index)
635 LOG_ERROR(
"Joint not in mixed mode so cannot send references");
639void PartItem::onSliderMixedVelocityCommand(
double vel,
int index)
650 LOG_ERROR(
"Joint not in mixed mode so cannot send references");
656 const int jointIndex =
joint->getJointIndex();
659 yInfo(
"interaction mode of joint %d set to COMPLIANT", jointIndex);
663 yInfo(
"interaction mode of joint %d set to STIFF", jointIndex);
672void PartItem::onSendPWM(
int jointIndex,
double pwmVal)
684 if (m_currentPidDlg){
744 if (m_currentPidDlg){
749void PartItem::onSendPositionPid(
int jointIndex,
Pid newPid)
756 if (m_currentPidDlg){
761void PartItem::onSendVelocityPid(
int jointIndex,
Pid newPid)
768 if (m_currentPidDlg){
773void PartItem::onRefreshPids(
int jointIndex)
837void PartItem::onSendCurrentPid(
int jointIndex,
Pid newPid)
839 if (m_iCur ==
nullptr)
841 yError() <<
"iCurrent interface not opened";
849 if (m_currentPidDlg){
854void PartItem::onSendSingleRemoteVariable(std::string key,
yarp::os::Bottle val)
860void PartItem::onUpdateAllRemoteVariables()
862 if (m_currentPidDlg){
871 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
875 if(QMessageBox::question(
this,
"Question",
"Do you really want to recalibrate the joint?") != QMessageBox::Yes){
884 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"));
886 QMessageBox::critical(
this,
"Calibration failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
894 const int jointIndex =
joint->getJointIndex();
896 m_currentPidDlg =
new PidDlg(m_partName.c_str(), jointIndex, jointName);
897 connect(m_currentPidDlg,
SIGNAL(sendPositionPid(
int,
Pid)),
this,
SLOT(onSendPositionPid(
int,
Pid)));
898 connect(m_currentPidDlg,
SIGNAL(sendVelocityPid(
int,
Pid)),
this,
SLOT(onSendVelocityPid(
int,
Pid)));
899 connect(m_currentPidDlg,
SIGNAL(sendCurrentPid(
int,
Pid)),
this,
SLOT(onSendCurrentPid(
int,
Pid)));
901 connect(m_currentPidDlg,
SIGNAL(updateAllRemoteVariables()),
this,
SLOT(onUpdateAllRemoteVariables()));
903 connect(m_currentPidDlg,
SIGNAL(sendStiffness(
int,
double,
double)),
this,
SLOT(onSendStiffness(
int,
double,
double)));
904 connect(m_currentPidDlg,
SIGNAL(sendForceOffset(
int,
double)),
this,
SLOT(onSendForceOffset(
int,
double)));
905 connect(m_currentPidDlg,
SIGNAL(sendPWM(
int,
double)),
this,
SLOT(onSendPWM(
int,
double)));
906 connect(m_currentPidDlg,
SIGNAL(refreshPids(
int)),
this,
SLOT(onRefreshPids(
int)));
907 connect(m_currentPidDlg,
SIGNAL(dumpRemoteVariables()),
this,
SLOT(onDumpAllRemoteVariables()));
909 this->onRefreshPids(jointIndex);
911 m_currentPidDlg->exec();
913 delete m_currentPidDlg;
914 m_currentPidDlg =
nullptr;
919 const int jointIndex =
joint->getJointIndex();
930 const int jointIndex =
joint->getJointIndex();
937 const int jointIndex =
joint->getJointIndex();
945 const int jointIndex =
joint->getJointIndex();
948 yInfo(
"joint: %d in IDLE mode", jointIndex);
952 yError(
"ERROR: cannot do!");
957 yInfo(
"joint: %d in POSITION mode", jointIndex);
960 joint->resetTarget();
962 yError(
"ERROR: cannot do!");
968 yInfo(
"joint: %d in POSITION DIRECT mode", jointIndex);
970 joint->resetTarget();
973 yError(
"ERROR: cannot do!");
988 yInfo(
"joint: %d in MIXED mode", jointIndex);
990 joint->resetTarget();
993 yError(
"ERROR: cannot do!");
1009 yInfo(
"joint: %d in VELOCITY DIRECT mode", jointIndex);
1012 joint->resetTarget();
1015 yError(
"ERROR: cannot do!");
1021 yInfo(
"joint: %d in VELOCITY mode", jointIndex);
1025 yInfo() <<
"Changing reference acceleration of joint " << jointIndex <<
" to 100000";
1028 yError(
"ERROR: cannot do!");
1044 yInfo(
"joint: %d in TORQUE mode", jointIndex);
1048 yError(
"ERROR: cannot do!");
1063 yInfo(
"joint: %d in PWM mode", jointIndex);
1067 yError(
"ERROR: cannot do!");
1072 yInfo(
"joint: %d in CURRENT mode", jointIndex);
1077 yError(
"ERROR: cannot do!");
1088 int count = m_layout->
count();
1103 for(
int i=0;i<count;i++){
1115 return m_layout->
count();
1146 if(event->type() == QEvent::WindowStateChange ){
1147 qDebug() <<
"State Changed " << width();
1148 int count = m_layout->
count();
1162 for(
int i=0;i<count;i++){
1177 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
1187 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()));
1189 QMessageBox::critical(
this,
"Calibration failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1198 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
1209 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()));
1214 QMessageBox::critical(
this,
"Operation failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1225 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
1236 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()));
1241 QMessageBox::critical(
this,
"Operation failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1255 QMessageBox::critical(
this,
"Operation failed",
QString(
"No custom position supplied in configuration file for part ") +
QString(m_partName.c_str()));
1271 double velocity =
ytmp.get(jointIndex + 1).asFloat64();
1278 QMessageBox::critical(
this,
"Error",
QString(
"Check the number of entries in the group %1").arg(m_robotPartPort.c_str()));
1297 if (!m_sequenceWindow){
1308 if (!m_sequenceWindow){
1319 if (!m_sequenceWindow){
1328 if (!m_sequenceWindow){
1360 if (m_sequenceWindow)
1362 m_sequenceWindow->close();
1368 if (!m_sequenceWindow){
1370 connect(m_sequenceWindow,
SIGNAL(itemDoubleClicked(
int)),
this,
SLOT(onSequenceWindowDoubleClicked(
int)), Qt::DirectConnection);
1376 connect(m_sequenceWindow,
SIGNAL(openSequence()),
this,
SLOT(onOpenSequence()));
1395 if (!m_sequenceWindow->isVisible()){
1396 m_sequenceWindow->show();
1398 m_sequenceWindow->setFocus();
1399 m_sequenceWindow->raise();
1400 m_sequenceWindow->setWindowState(Qt::WindowActive);
1407 if (!m_sequenceWindow){
1415 m_cycleTimer.stop();
1417 m_runTimeTimer.stop();
1418 m_cycleTimeTimer.stop();
1422void PartItem::onStopSequence()
1427void PartItem::onOpenSequence()
1429 QString fileName = QFileDialog::getOpenFileName(m_sequenceWindow,
QString(
"Load Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1432 if(!
fInfo.exists()){
1440 QMessageBox::critical(
this,
"Error Loading The Sequence",
1441 QString(
"Wrong format (check extensions) of the file associated with: ").arg(m_partName.c_str()));
1445 QFile file(fileName);
1446 if (!file.open(QFile::ReadOnly | QFile::Text)){
1449 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1460 while(!reader.atEnd()){
1463 if(reader.isStartElement()){
1464 if(reader.name().contains(
"Sequence_")){
1466 referencePart = attributes.value(
"ReferencePart").toString();
1469 if(reader.name() ==
"Position"){
1471 int index = attributes.value(
"Index").toInt();
1472 double timing = attributes.value(
"Timing").toDouble();
1473 item.setTiming(timing);
1474 item.setSequenceNumber(index);
1477 if(reader.name() ==
"JointPositions"){
1479 int count = attributes.value(
"Count").toInt();
1482 for(
int i=0; i<count;i++){
1484 if(reader.name() ==
"PosValue"){
1485 double pos = reader.readElementText().toDouble();
1486 item.addPositionValue(pos);
1493 if(reader.name() ==
"JointVelocities"){
1495 int count = attributes.value(
"Count").toInt();
1498 for(
int i=0; i<count;i++){
1500 if(reader.name() ==
"SpeedValue"){
1501 double speed = reader.readElementText().toDouble();
1502 item.addSpeedValue(speed);
1511 if(reader.isEndElement()){
1512 if(reader.name() ==
"Position"){
1521 if (reader.hasError())
1524 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1526 }
else if (file.error() != QFile::NoError) {
1528 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1532 if (m_sequenceWindow){
1542 fileName = QFileDialog::getSaveFileName(
this,
QString(
"Save Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1545 if(fileName.isEmpty()){
1557 if(!file.open(QIODevice::WriteOnly)){
1562 writer.setAutoFormatting(
true);
1563 writer.writeStartDocument();
1565 writer.writeStartElement(
QString(
"Sequence_pos%1").arg(m_partName.c_str()));
1567 writer.writeAttribute(
"TotPositions",
QString(
"%1").arg(
values.count()));
1568 writer.writeAttribute(
"ReferencePart", m_partName.c_str());
1570 for(
int i=0;i<
values.count();i++){
1572 writer.writeStartElement(
"Position");
1576 writer.writeStartElement(
"JointPositions");
1578 for(
int j=0;j<
sequenceItem.getPositions().count(); j++){
1580 writer.writeTextElement(
"PosValue",s);
1582 writer.writeEndElement();
1584 writer.writeStartElement(
"JointVelocities");
1588 writer.writeTextElement(
"SpeedValue",s);
1590 writer.writeEndElement();
1591 writer.writeEndElement();
1593 writer.writeEndElement();
1594 writer.writeEndDocument();
1596 LOG_INFO(
"File saved and closed\n");
1636 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1640 m_cycleTimeValues.clear();
1641 for(
int i=0;i<
values.count();i++){
1643 if(
it.getTiming() > 0){
1644 m_cycleTimeValues.append(
it);
1649 if (m_cycleTimeValues.count() > 0)
1651 vals = m_cycleTimeValues.takeFirst();
1652 m_cycleTimeValues.append(
vals);
1654 fixedTimeMove(
vals);
1655 m_cycleTimeTimer.start(
vals.getTiming() * 1000);
1660void PartItem::onCycleTimeTimerTimeout()
1662 if (m_cycleTimeValues.count() > 0)
1665 m_cycleTimeValues.append(
vals);
1667 fixedTimeMove(
vals);
1668 m_cycleTimeTimer.start(
vals.getTiming() * 1000);
1675 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1679 m_cycleValues.clear();
1680 for(
int i=0;i<
values.count();i++){
1682 if(
it.getTiming() > 0){
1683 m_cycleValues.append(
it);
1688 if (m_cycleValues.count() > 0){
1689 vals = m_cycleValues.takeFirst();
1691 m_cycleValues.append(
vals);
1696 for(
int i=0;i<
vals.getPositions().count();i++){
1706 m_cycleTimer.start(
vals.getTiming() * 1000);
1712void PartItem::onCycleTimerTimeout()
1714 if (m_cycleValues.count() > 0){
1717 m_cycleValues.append(
vals);
1722 for(
int i=0;i<
vals.getPositions().count();i++){
1732 m_cycleTimer.start(
vals.getTiming() * 1000);
1739 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1743 m_runValues.clear();
1744 for(
int i=0;i<
values.count();i++){
1746 if(
it.getTiming() > 0){
1747 m_runValues.append(
it);
1752 if (m_runValues.count() > 0){
1753 vals = m_runValues.takeFirst();
1755 m_runValues.append(
vals);
1760 for(
int i=0;i<
vals.getPositions().count();i++){
1770 m_runTimer.start(
vals.getTiming() * 1000);
1775void PartItem::onRunTimeout()
1777 if (m_runValues.count() > 0){
1779 if(
vals.getTiming() < 0){
1786 for(
int i=0;i<
vals.getPositions().count();i++){
1798 m_runTimer.start(
vals.getTiming() * 1000);
1808 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1812 m_runTimeValues.clear();
1814 for(
int i=0;i<
values.count();i++){
1816 if(
it.getTiming() > 0){
1817 m_runTimeValues.append(
it);
1822 if (m_runTimeValues.count() > 0){
1823 vals = m_runTimeValues.takeFirst();
1826 fixedTimeMove(
vals);
1827 m_runTimeTimer.start(
vals.getTiming() * 1000);
1834void PartItem::onRunTimerTimeout()
1836 if (m_runTimeValues.count() > 0){
1838 if(
vals.getTiming() < 0){
1843 fixedTimeMove(
vals);
1844 m_runTimeTimer.start(
vals.getTiming() * 1000);
1878 m_sequence_port_stamp.
update();
1879 m_sequence_port.
setEnvelope(m_sequence_port_stamp);
1881 m_sequence_port.
write(v);
1892 QMessageBox::critical(
this,
"Error",
"Select an entry in the table before performing a movement");
1906void PartItem::onSequenceActivated()
1908 for (
int i = 0; i<m_layout->
count(); i++)
1912 joint->sequenceActivated();
1920void PartItem::onSequenceStopped()
1922 for (
int i = 0; i<m_layout->
count(); i++)
1926 joint->sequenceStopped();
1932void PartItem::onSequenceWindowDoubleClicked(
int sequenceNum)
1936 for (
int i = 0; i<m_layout->
count(); i++)
1939 values.append(this->m_positions[i]);
1940 speeds.append(
joint->getTrajectoryVelocityValue());
1948 for (
int i = 0; i<m_layout->
count(); i++)
1957 for (
int i = 0; i<m_layout->
count(); i++)
1966 for (
int i = 0; i<m_layout->
count(); i++)
1975 for (
int i = 0; i<m_layout->
count(); i++)
1984 for (
int i = 0; i<m_layout->
count(); i++)
1993 for (
int i = 0; i<m_layout->
count(); i++)
2002 for (
int i = 0; i<m_layout->
count(); i++)
2011 m_part_speedVisible = view;
2012 for (
int i = 0; i<m_layout->
count(); i++)
2015 joint->setSpeedVisible(view);
2021 m_part_motorPositionVisible = view;
2022 for (
int i = 0; i<m_layout->
count(); i++)
2025 joint->setMotorPositionVisible(view);
2031 m_part_dutyVisible = view;
2032 for (
int i = 0; i<m_layout->
count(); i++)
2035 joint->setDutyVisible(view);
2041 m_part_currentVisible = view;
2042 for (
int i = 0; i<m_layout->
count(); i++)
2045 joint->setCurrentsVisible(view);
2051 for (
int i = 0; i<m_layout->
count(); i++)
2060 for (
int i = 0; i < m_layout->
count(); i++)
2063 joint->viewPositionTargetValue(
ena);
2069 for (
int i = 0; i<m_layout->
count(); i++)
2074 joint->enablePositionSliderDoubleAuto();
2078 joint->enablePositionSliderDoubleValue(step);
2082 joint->enablePositionSliderDoubleValue(1.0);
2086 joint->disablePositionSliderDouble();
2093 for (
int i = 0; i<m_layout->
count(); i++)
2098 joint->enableVelocitySliderDoubleAuto();
2102 joint->enableVelocitySliderDoubleValue(step);
2106 joint->enableVelocitySliderDoubleValue(1.0);
2110 joint->disableVelocitySliderDouble();
2117 for (
int i = 0; i<m_layout->
count(); i++)
2122 joint->enableAccelerationSliderDoubleAuto();
2126 joint->enableAccelerationSliderDoubleValue(step);
2130 joint->enableAccelerationSliderDoubleValue(1.0);
2134 joint->disableAccelerationSliderDouble();
2141 for (
int i = 0; i<m_layout->
count(); i++)
2146 joint->enableCurrentSliderDoubleAuto();
2150 joint->enableCurrentSliderDoubleValue(step);
2154 joint->enableCurrentSliderDoubleValue(1.0);
2158 joint->disableCurrentSliderDouble();
2166 for (
int i = 0; i<m_layout->
count(); i++)
2171 joint->enableTorqueSliderDoubleAuto();
2175 joint->enableTorqueSliderDoubleValue(step);
2179 joint->enableTorqueSliderDoubleValue(1.0);
2183 joint->disableTorqueSliderDouble();
2203 m_modesList.resize(m_layout->
count());
2204 for (
int k = 0;
k < m_layout->
count();
k++){
2205 switch (m_controlModes[
k])
2270 LOG_ERROR(
"Lost connection with the robot. You should save and restart.\n" );
2273 for (
int i = 0; i<m_layout->
count(); i++){
2285 if (!b) {
yWarning(
"Unable to update encoders");
return false; }
2290 if (!b) {
yWarning(
"Unable to update torques"); }
2292 if (this->m_part_currentVisible)
2295 if (!b) {
yWarning(
"Unable to update currents"); }
2297 if (this->m_part_speedVisible)
2300 if (!b) {
yWarning(
"Unable to update speeds"); }
2302 if (this->m_part_motorPositionVisible)
2305 if (!b) {
yWarning(
"Unable to update motorPositions"); }
2307 if (this->m_part_dutyVisible)
2310 if (!b) {
yWarning(
"Unable to update dutyCycles"); }
2359 yError() <<
"Missing Implementation of getTargetPosition()";
2363 yError() <<
"Missing Implementation of getRefVelocity()";
2367 yError() <<
"Missing Implementation of getRefSpeed()";
2371 yError() <<
"Missing Implementation of getRefTorque()";
2375 yError() <<
"Missing Implementation of checkMotionDone()";
2379 yWarning() <<
"Missing Implementation of isJointBraked()";
2386 if (
true) {
joint->setPosition(m_positions[
jk]); }
2388 if (
true) {
joint->setTorque(m_torques[
jk]); }
2390 if (
true) {
joint->setSpeed(m_speeds[
jk]); }
2392 if (
true) {
joint->setCurrent(m_currents[
jk]); }
2394 if (
true) {
joint->setMotorPosition(m_motorPositions[
jk]); }
2396 if (
true) {
joint->setDutyCycles(m_dutyCycles[
jk]); }
2407 if (
ret_refPos) {
joint_slow_k->setPosTrajectory_ReferencePosition(m_refTrajectoryPositions[m_slow_k]); }
2411 if (
ret_refAcc) {
joint_slow_k->setVelTrajectory_ReferenceAcceleration(m_refVelocityAccelerations[m_slow_k]); }
2428 LOG_ERROR(
"iint->getInteractionlMode failed\n" );
2439 std::string message;
2447 LOG_ERROR(
"Unsuccessful call to getLastJointFault()\n");
2457 switch (m_controlModes[
k])
2516 switch (m_interactionModes[
k])
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
int SIGNAL(int pid, int signum)
Original license follows:
QLayoutItem * itemAt(int index) const override
int count() const override
void onEnableControlVelocityDirect(bool control)
void onViewDutyCycles(bool)
bool homeToCustomPosition(const yarp::os::Bottle &positionElement)
void setCurrentIndex(int)
JointItem * getJointWidget(int jointIndex)
void onEnableControlCurrent(bool control)
void onSetVelSliderOptionPI(int mode, double step, int numOfDec)
void onViewMotorPositions(bool)
void onEnableControlPWM(bool control)
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)
QString getJointName(int joint)
std::string getPartName()
void onSetCurSliderOptionPI(int mode, double step, int numOfDec)
void onViewPositionTargetValue(bool)
void onViewPositionTargetBox(bool)
bool homeJoint(int joint)
void onViewCurrentValues(bool)
void onSetTrqSliderOptionPI(int mode, double step, int numOfDec)
void sendPartJointsValues(int, QList< double >, QList< double >)
bool checkAndCycleAllSeq()
void closeSequenceWindow()
void onViewSpeedValues(bool)
void openSequenceWindow()
void onEnableControlPositionDirect(bool control)
void saveSequence(QString global_filename)
void resizeEvent(QResizeEvent *event) override
void changeEvent(QEvent *event) override
void onEnableControlTorque(bool control)
const QVector< JointItem::JointState > & getPartModes()
void onEnableControlMixed(bool control)
void onSetPosSliderOptionPI(int mode, double step, int numOfDec)
bool checkAndRunTimeAllSeq()
bool checkAndCycleTimeAllSeq()
void onSetAccSliderOptionPI(int mode, double step, int numOfDec)
void initVelocity(Pid myPid)
void initPosition(Pid myPid)
void initTorque(Pid myPid, MotorTorqueParameters TorqueParam)
void initTorqueOffset(double curForceVal, double minForce, double maxForce)
void initCurrent(Pid myPid)
void initStiffness(double curStiffVal, double minStiff, double maxStiff, double curDampVal, double minDamp, double maxDamp)
void initRemoteVariables(IRemoteVariables *iVar)
void initPWM(double pwmVal, double pwm)
bool checkAndCycleTimeSeq()
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)
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 setImpedanceOffset(int j, double offset)=0
Set 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.
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.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
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.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
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...
static void delaySystem(double seconds)
virtual bool isString() const
Checks if value is a string.
virtual std::string asString() const
Get string value.
bool speedview_param_enabled
@ VOCAB_JOINTTYPE_REVOLUTE