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){
733 if (m_currentPidDlg){
738void PartItem::onSendPositionPid(
int jointIndex,
Pid newPid)
745 if (m_currentPidDlg){
750void PartItem::onSendVelocityPid(
int jointIndex,
Pid newPid)
757 if (m_currentPidDlg){
762void PartItem::onRefreshPids(
int jointIndex)
825void PartItem::onSendCurrentPid(
int jointIndex,
Pid newPid)
827 if (m_iCur ==
nullptr)
829 yError() <<
"iCurrent interface not opened";
837 if (m_currentPidDlg){
842void PartItem::onSendSingleRemoteVariable(std::string key,
yarp::os::Bottle val)
848void PartItem::onUpdateAllRemoteVariables()
850 if (m_currentPidDlg){
859 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
863 if(QMessageBox::question(
this,
"Question",
"Do you really want to recalibrate the joint?") != QMessageBox::Yes){
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"));
874 QMessageBox::critical(
this,
"Calibration failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
882 const int jointIndex =
joint->getJointIndex();
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)));
889 connect(m_currentPidDlg,
SIGNAL(updateAllRemoteVariables()),
this,
SLOT(onUpdateAllRemoteVariables()));
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()));
896 this->onRefreshPids(jointIndex);
898 m_currentPidDlg->exec();
900 delete m_currentPidDlg;
901 m_currentPidDlg =
nullptr;
906 const int jointIndex =
joint->getJointIndex();
917 const int jointIndex =
joint->getJointIndex();
924 const int jointIndex =
joint->getJointIndex();
932 const int jointIndex =
joint->getJointIndex();
935 yInfo(
"joint: %d in IDLE mode", jointIndex);
939 yError(
"ERROR: cannot do!");
944 yInfo(
"joint: %d in POSITION mode", jointIndex);
947 joint->resetTarget();
949 yError(
"ERROR: cannot do!");
955 yInfo(
"joint: %d in POSITION DIRECT mode", jointIndex);
957 joint->resetTarget();
960 yError(
"ERROR: cannot do!");
975 yInfo(
"joint: %d in MIXED mode", jointIndex);
977 joint->resetTarget();
980 yError(
"ERROR: cannot do!");
996 yInfo(
"joint: %d in VELOCITY DIRECT mode", jointIndex);
999 joint->resetTarget();
1002 yError(
"ERROR: cannot do!");
1008 yInfo(
"joint: %d in VELOCITY mode", jointIndex);
1012 yInfo() <<
"Changing reference acceleration of joint " << jointIndex <<
" to 100000";
1015 yError(
"ERROR: cannot do!");
1031 yInfo(
"joint: %d in TORQUE mode", jointIndex);
1035 yError(
"ERROR: cannot do!");
1050 yInfo(
"joint: %d in PWM mode", jointIndex);
1054 yError(
"ERROR: cannot do!");
1059 yInfo(
"joint: %d in CURRENT mode", jointIndex);
1064 yError(
"ERROR: cannot do!");
1075 int count = m_layout->
count();
1090 for(
int i=0;i<count;i++){
1102 return m_layout->
count();
1133 if(event->type() == QEvent::WindowStateChange ){
1134 qDebug() <<
"State Changed " << width();
1135 int count = m_layout->
count();
1149 for(
int i=0;i<count;i++){
1164 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
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()));
1176 QMessageBox::critical(
this,
"Calibration failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1185 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
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()));
1201 QMessageBox::critical(
this,
"Operation failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1212 QMessageBox::critical(
this,
"Operation not supported",
QString(
"The IRemoteCalibrator interface was not found on this application"));
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()));
1228 QMessageBox::critical(
this,
"Operation failed",
QString(
"The remote calibrator reported that something went wrong during the calibration procedure"));
1242 QMessageBox::critical(
this,
"Operation failed",
QString(
"No custom position supplied in configuration file for part ") +
QString(m_partName.c_str()));
1258 double velocity =
ytmp.get(jointIndex + 1).asFloat64();
1265 QMessageBox::critical(
this,
"Error",
QString(
"Check the number of entries in the group %1").arg(m_robotPartPort.c_str()));
1284 if (!m_sequenceWindow){
1295 if (!m_sequenceWindow){
1306 if (!m_sequenceWindow){
1315 if (!m_sequenceWindow){
1347 if (m_sequenceWindow)
1349 m_sequenceWindow->close();
1355 if (!m_sequenceWindow){
1357 connect(m_sequenceWindow,
SIGNAL(itemDoubleClicked(
int)),
this,
SLOT(onSequenceWindowDoubleClicked(
int)), Qt::DirectConnection);
1363 connect(m_sequenceWindow,
SIGNAL(openSequence()),
this,
SLOT(onOpenSequence()));
1382 if (!m_sequenceWindow->isVisible()){
1383 m_sequenceWindow->show();
1385 m_sequenceWindow->setFocus();
1386 m_sequenceWindow->raise();
1387 m_sequenceWindow->setWindowState(Qt::WindowActive);
1394 if (!m_sequenceWindow){
1402 m_cycleTimer.stop();
1404 m_runTimeTimer.stop();
1405 m_cycleTimeTimer.stop();
1409void PartItem::onStopSequence()
1414void PartItem::onOpenSequence()
1416 QString fileName = QFileDialog::getOpenFileName(m_sequenceWindow,
QString(
"Load Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1419 if(!
fInfo.exists()){
1427 QMessageBox::critical(
this,
"Error Loading The Sequence",
1428 QString(
"Wrong format (check extensions) of the file associated with: ").arg(m_partName.c_str()));
1432 QFile file(fileName);
1433 if (!file.open(QFile::ReadOnly | QFile::Text)){
1436 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1447 while(!reader.atEnd()){
1450 if(reader.isStartElement()){
1451 if(reader.name().contains(
"Sequence_")){
1453 referencePart = attributes.value(
"ReferencePart").toString();
1456 if(reader.name() ==
"Position"){
1458 int index = attributes.value(
"Index").toInt();
1459 double timing = attributes.value(
"Timing").toDouble();
1460 item.setTiming(timing);
1461 item.setSequenceNumber(index);
1464 if(reader.name() ==
"JointPositions"){
1466 int count = attributes.value(
"Count").toInt();
1469 for(
int i=0; i<count;i++){
1471 if(reader.name() ==
"PosValue"){
1472 double pos = reader.readElementText().toDouble();
1473 item.addPositionValue(pos);
1480 if(reader.name() ==
"JointVelocities"){
1482 int count = attributes.value(
"Count").toInt();
1485 for(
int i=0; i<count;i++){
1487 if(reader.name() ==
"SpeedValue"){
1488 double speed = reader.readElementText().toDouble();
1489 item.addSpeedValue(speed);
1498 if(reader.isEndElement()){
1499 if(reader.name() ==
"Position"){
1508 if (reader.hasError())
1511 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1513 }
else if (file.error() != QFile::NoError) {
1515 QMessageBox::critical(
this,
"Error Loading The Sequence",
msg);
1519 if (m_sequenceWindow){
1529 fileName = QFileDialog::getSaveFileName(
this,
QString(
"Save Sequence for part %1 As").arg(m_partName.c_str()), QDir::homePath());
1532 if(fileName.isEmpty()){
1544 if(!file.open(QIODevice::WriteOnly)){
1549 writer.setAutoFormatting(
true);
1550 writer.writeStartDocument();
1552 writer.writeStartElement(
QString(
"Sequence_pos%1").arg(m_partName.c_str()));
1554 writer.writeAttribute(
"TotPositions",
QString(
"%1").arg(
values.count()));
1555 writer.writeAttribute(
"ReferencePart", m_partName.c_str());
1557 for(
int i=0;i<
values.count();i++){
1559 writer.writeStartElement(
"Position");
1563 writer.writeStartElement(
"JointPositions");
1565 for(
int j=0;j<
sequenceItem.getPositions().count(); j++){
1567 writer.writeTextElement(
"PosValue",s);
1569 writer.writeEndElement();
1571 writer.writeStartElement(
"JointVelocities");
1575 writer.writeTextElement(
"SpeedValue",s);
1577 writer.writeEndElement();
1578 writer.writeEndElement();
1580 writer.writeEndElement();
1581 writer.writeEndDocument();
1583 LOG_INFO(
"File saved and closed\n");
1623 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1627 m_cycleTimeValues.clear();
1628 for(
int i=0;i<
values.count();i++){
1630 if(
it.getTiming() > 0){
1631 m_cycleTimeValues.append(
it);
1636 if (m_cycleTimeValues.count() > 0)
1638 vals = m_cycleTimeValues.takeFirst();
1639 m_cycleTimeValues.append(
vals);
1641 fixedTimeMove(
vals);
1642 m_cycleTimeTimer.start(
vals.getTiming() * 1000);
1647void PartItem::onCycleTimeTimerTimeout()
1649 if (m_cycleTimeValues.count() > 0)
1652 m_cycleTimeValues.append(
vals);
1654 fixedTimeMove(
vals);
1655 m_cycleTimeTimer.start(
vals.getTiming() * 1000);
1662 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1666 m_cycleValues.clear();
1667 for(
int i=0;i<
values.count();i++){
1669 if(
it.getTiming() > 0){
1670 m_cycleValues.append(
it);
1675 if (m_cycleValues.count() > 0){
1676 vals = m_cycleValues.takeFirst();
1678 m_cycleValues.append(
vals);
1683 for(
int i=0;i<
vals.getPositions().count();i++){
1693 m_cycleTimer.start(
vals.getTiming() * 1000);
1699void PartItem::onCycleTimerTimeout()
1701 if (m_cycleValues.count() > 0){
1704 m_cycleValues.append(
vals);
1709 for(
int i=0;i<
vals.getPositions().count();i++){
1719 m_cycleTimer.start(
vals.getTiming() * 1000);
1726 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1730 m_runValues.clear();
1731 for(
int i=0;i<
values.count();i++){
1733 if(
it.getTiming() > 0){
1734 m_runValues.append(
it);
1739 if (m_runValues.count() > 0){
1740 vals = m_runValues.takeFirst();
1742 m_runValues.append(
vals);
1747 for(
int i=0;i<
vals.getPositions().count();i++){
1757 m_runTimer.start(
vals.getTiming() * 1000);
1762void PartItem::onRunTimeout()
1764 if (m_runValues.count() > 0){
1766 if(
vals.getTiming() < 0){
1773 for(
int i=0;i<
vals.getPositions().count();i++){
1785 m_runTimer.start(
vals.getTiming() * 1000);
1795 if (m_cycleTimeTimer.isActive() || m_cycleTimer.isActive() || m_runTimeTimer.isActive() || m_runTimer.isActive()){
1799 m_runTimeValues.clear();
1801 for(
int i=0;i<
values.count();i++){
1803 if(
it.getTiming() > 0){
1804 m_runTimeValues.append(
it);
1809 if (m_runTimeValues.count() > 0){
1810 vals = m_runTimeValues.takeFirst();
1813 fixedTimeMove(
vals);
1814 m_runTimeTimer.start(
vals.getTiming() * 1000);
1821void PartItem::onRunTimerTimeout()
1823 if (m_runTimeValues.count() > 0){
1825 if(
vals.getTiming() < 0){
1830 fixedTimeMove(
vals);
1831 m_runTimeTimer.start(
vals.getTiming() * 1000);
1865 m_sequence_port_stamp.
update();
1866 m_sequence_port.
setEnvelope(m_sequence_port_stamp);
1868 m_sequence_port.
write(v);
1879 QMessageBox::critical(
this,
"Error",
"Select an entry in the table before performing a movement");
1893void PartItem::onSequenceActivated()
1895 for (
int i = 0; i<m_layout->
count(); i++)
1899 joint->sequenceActivated();
1907void PartItem::onSequenceStopped()
1909 for (
int i = 0; i<m_layout->
count(); i++)
1913 joint->sequenceStopped();
1919void PartItem::onSequenceWindowDoubleClicked(
int sequenceNum)
1923 for (
int i = 0; i<m_layout->
count(); i++)
1926 values.append(this->m_positions[i]);
1927 speeds.append(
joint->getTrajectoryVelocityValue());
1935 for (
int i = 0; i<m_layout->
count(); i++)
1944 for (
int i = 0; i<m_layout->
count(); i++)
1953 for (
int i = 0; i<m_layout->
count(); i++)
1962 for (
int i = 0; i<m_layout->
count(); i++)
1971 for (
int i = 0; i<m_layout->
count(); i++)
1980 for (
int i = 0; i<m_layout->
count(); i++)
1989 for (
int i = 0; i<m_layout->
count(); i++)
1998 m_part_speedVisible = view;
1999 for (
int i = 0; i<m_layout->
count(); i++)
2002 joint->setSpeedVisible(view);
2008 m_part_motorPositionVisible = view;
2009 for (
int i = 0; i<m_layout->
count(); i++)
2012 joint->setMotorPositionVisible(view);
2018 m_part_dutyVisible = view;
2019 for (
int i = 0; i<m_layout->
count(); i++)
2022 joint->setDutyVisible(view);
2028 m_part_currentVisible = view;
2029 for (
int i = 0; i<m_layout->
count(); i++)
2032 joint->setCurrentsVisible(view);
2038 for (
int i = 0; i<m_layout->
count(); i++)
2047 for (
int i = 0; i < m_layout->
count(); i++)
2050 joint->viewPositionTargetValue(
ena);
2056 for (
int i = 0; i<m_layout->
count(); i++)
2061 joint->enablePositionSliderDoubleAuto();
2065 joint->enablePositionSliderDoubleValue(step);
2069 joint->enablePositionSliderDoubleValue(1.0);
2073 joint->disablePositionSliderDouble();
2080 for (
int i = 0; i<m_layout->
count(); i++)
2085 joint->enableVelocitySliderDoubleAuto();
2089 joint->enableVelocitySliderDoubleValue(step);
2093 joint->enableVelocitySliderDoubleValue(1.0);
2097 joint->disableVelocitySliderDouble();
2104 for (
int i = 0; i<m_layout->
count(); i++)
2109 joint->enableAccelerationSliderDoubleAuto();
2113 joint->enableAccelerationSliderDoubleValue(step);
2117 joint->enableAccelerationSliderDoubleValue(1.0);
2121 joint->disableAccelerationSliderDouble();
2128 for (
int i = 0; i<m_layout->
count(); i++)
2133 joint->enableCurrentSliderDoubleAuto();
2137 joint->enableCurrentSliderDoubleValue(step);
2141 joint->enableCurrentSliderDoubleValue(1.0);
2145 joint->disableCurrentSliderDouble();
2153 for (
int i = 0; i<m_layout->
count(); i++)
2158 joint->enableTorqueSliderDoubleAuto();
2162 joint->enableTorqueSliderDoubleValue(step);
2166 joint->enableTorqueSliderDoubleValue(1.0);
2170 joint->disableTorqueSliderDouble();
2190 m_modesList.resize(m_layout->
count());
2191 for (
int k = 0;
k < m_layout->
count();
k++){
2192 switch (m_controlModes[
k])
2257 LOG_ERROR(
"Lost connection with the robot. You should save and restart.\n" );
2260 for (
int i = 0; i<m_layout->
count(); i++){
2272 if (!b) {
yWarning(
"Unable to update encoders");
return false; }
2277 if (!b) {
yWarning(
"Unable to update torques"); }
2279 if (this->m_part_currentVisible)
2282 if (!b) {
yWarning(
"Unable to update currents"); }
2284 if (this->m_part_speedVisible)
2287 if (!b) {
yWarning(
"Unable to update speeds"); }
2289 if (this->m_part_motorPositionVisible)
2292 if (!b) {
yWarning(
"Unable to update motorPositions"); }
2294 if (this->m_part_dutyVisible)
2297 if (!b) {
yWarning(
"Unable to update dutyCycles"); }
2346 yError() <<
"Missing Implementation of getTargetPosition()";
2350 yError() <<
"Missing Implementation of getRefVelocity()";
2354 yError() <<
"Missing Implementation of getRefSpeed()";
2358 yError() <<
"Missing Implementation of getRefTorque()";
2362 yError() <<
"Missing Implementation of checkMotionDone()";
2366 yWarning() <<
"Missing Implementation of isJointBraked()";
2373 if (
true) {
joint->setPosition(m_positions[
jk]); }
2375 if (
true) {
joint->setTorque(m_torques[
jk]); }
2377 if (
true) {
joint->setSpeed(m_speeds[
jk]); }
2379 if (
true) {
joint->setCurrent(m_currents[
jk]); }
2381 if (
true) {
joint->setMotorPosition(m_motorPositions[
jk]); }
2383 if (
true) {
joint->setDutyCycles(m_dutyCycles[
jk]); }
2394 if (
ret_refPos) {
joint_slow_k->setPosTrajectory_ReferencePosition(m_refTrajectoryPositions[m_slow_k]); }
2398 if (
ret_refAcc) {
joint_slow_k->setVelTrajectory_ReferenceAcceleration(m_refVelocityAccelerations[m_slow_k]); }
2415 LOG_ERROR(
"iint->getInteractionlMode failed\n" );
2426 std::string message;
2434 LOG_ERROR(
"Unsuccessful call to getLastJointFault()\n");
2444 switch (m_controlModes[
k])
2503 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 initStiffness(double curStiffVal, double minStiff, double maxStiff, double curDampVal, double minDamp, double maxDamp, double curForceVal, double minForce, double maxForce)
void initTorque(Pid myPid, MotorTorqueParameters TorqueParam)
void initCurrent(Pid myPid)
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 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