From 0dba00b25b06707020ed96a1387db4ab5a7865ea Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 9 Dec 2022 12:42:11 +0100 Subject: [PATCH 1/3] Adding a test port in yarpmotorgui to check conflicts only once This is to avoid expensive checks with the nameserver for every part we open --- src/yarpmotorgui/mainwindow.cpp | 22 ++++++++++++++++++- src/yarpmotorgui/mainwindow.h | 2 ++ src/yarpmotorgui/partitem.cpp | 39 ++++++--------------------------- src/yarpmotorgui/partitem.h | 1 + 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/yarpmotorgui/mainwindow.cpp b/src/yarpmotorgui/mainwindow.cpp index 926baa1751f..11faf3b27f2 100644 --- a/src/yarpmotorgui/mainwindow.cpp +++ b/src/yarpmotorgui/mainwindow.cpp @@ -623,6 +623,26 @@ bool MainWindow::init(QStringList enabledParts, int partindex; }; + //checking existence of the port + int ind = 0; + QString portPrefix = QString("/yarpmotorgui%1").arg(ind); + + // NameClient &nic=NameClient::getNameClient(); + yDebug("Checking the existence of: %s \n", portPrefix.toLatin1().data()); + Contact adr=Network::queryName(portPrefix.toLatin1().data()); + + while(adr.isValid()){ + ind++; + + portPrefix = QString("/yarpmotorgui%1").arg(ind); + yDebug("Checking the existence of: %s \n", portPrefix.toLatin1().data()); + adr=Network::queryName(portPrefix.toLatin1().data()); + } + + m_testNamePort.open(portPrefix.toLatin1().data()); //This port is needed only to register a name in the nameserver, + //so that other instances of yarpmotorgui will use a different port name + m_testNamePort.setWriteOnly(); + std::map robots; std::map parts; @@ -672,7 +692,7 @@ bool MainWindow::init(QStringList enabledParts, std::string robot_name_without_slash = i_parts.second.robot_name_without_slash; std::string part_name_without_slash = i_parts.second.part_name_without_slash; int part_id = i_parts.second.partindex; - part = new PartItem(robot_name_without_slash.c_str(), part_id, part_name_without_slash.c_str(), finder, debug_param_enabled, speedview_param_enabled, enable_calib_all, scroll); + part = new PartItem(robot_name_without_slash.c_str(), portPrefix, part_id, part_name_without_slash.c_str(), finder, debug_param_enabled, speedview_param_enabled, enable_calib_all, scroll); if(part && !part->getInterfaceError()) { diff --git a/src/yarpmotorgui/mainwindow.h b/src/yarpmotorgui/mainwindow.h index 046a69ddefa..3433253c392 100644 --- a/src/yarpmotorgui/mainwindow.h +++ b/src/yarpmotorgui/mainwindow.h @@ -8,6 +8,7 @@ #define MAINWINDOW_H #include +#include #include #include @@ -60,6 +61,7 @@ class MainWindow : public QMainWindow ResourceFinder m_finder; std::string m_user_script1; std::string m_user_script2; + Port m_testNamePort; QAction *m_goAll; QAction *m_runAllSeq; diff --git a/src/yarpmotorgui/partitem.cpp b/src/yarpmotorgui/partitem.cpp index 03bb57ba314..5c1aac79b5a 100644 --- a/src/yarpmotorgui/partitem.cpp +++ b/src/yarpmotorgui/partitem.cpp @@ -22,7 +22,10 @@ #include #include -PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder& _finder, +PartItem::PartItem(QString robotName, + QString portPrefix, + int id, QString partName, + ResourceFinder& _finder, bool debug_param_enabled, bool speedview_param_enabled, bool enable_calib_all, QWidget *parent) : @@ -67,37 +70,12 @@ PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder& if (partName.at(0) == '/') { partName.remove(0, 1); } - m_robotPartPort = QString("/%1/%2").arg(robotName).arg(partName); + m_robotPartPort = QString("/%1/%2").arg(robotName, partName); m_partName = partName; m_robotName = robotName; //checking existence of the port - int ind = 0; - QString portLocalName = QString("/yarpmotorgui%1/%2").arg(ind).arg(m_robotPartPort); - - - QString nameToCheck = portLocalName; - nameToCheck += "/rpc:o"; - - // NameClient &nic=NameClient::getNameClient(); - yDebug("Checking the existence of: %s \n", nameToCheck.toLatin1().data()); - // Address adr=nic.queryName(nameToCheck.c_str()); - - Contact adr=Network::queryName(nameToCheck.toLatin1().data()); - - //Contact c = yarp::os::Network::queryName(portLocalName.c_str()); - yDebug("ADDRESS is: %s \n", adr.toString().c_str()); - - while(adr.isValid()){ - ind++; - - portLocalName = QString("/yarpmotorgui%1/%2").arg(ind).arg(m_robotPartPort); - - nameToCheck = portLocalName; - nameToCheck += "/rpc:o"; - // adr=nic.queryName(nameToCheck.c_str()); - adr=Network::queryName(nameToCheck.toLatin1().data()); - } + QString portLocalName = QString("%1%2").arg(portPrefix, m_robotPartPort); m_interfaceError = false; @@ -124,7 +102,7 @@ PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder& yDebug("Setting a valid finder \n"); } - QString sequence_portname = QString("/yarpmotorgui/%1/sequence:o").arg(partName); + QString sequence_portname = QString("%1/sequence:o").arg(portLocalName); m_sequence_port.open(sequence_portname.toLatin1().data()); initInterfaces(); @@ -227,9 +205,6 @@ PartItem::PartItem(QString robotName, int id, QString partName, ResourceFinder& yarp::dev::JointTypeEnum jtype = yarp::dev::VOCAB_JOINTTYPE_REVOLUTE; m_iinfo->getJointType(k, jtype); - Pid myPid(0,0,0,0,0,0); - yarp::os::SystemClock::delaySystem(0.005); - m_iPid->getPid(VOCAB_PIDTYPE_POSITION, k, &myPid); auto* joint = new JointItem(k); joint->setJointName(jointname.c_str()); diff --git a/src/yarpmotorgui/partitem.h b/src/yarpmotorgui/partitem.h index 2fcbc7ba27d..1ded2c5c2d4 100644 --- a/src/yarpmotorgui/partitem.h +++ b/src/yarpmotorgui/partitem.h @@ -41,6 +41,7 @@ class PartItem : public QWidget Q_OBJECT public: explicit PartItem(QString robotName, + QString portPrefix, int partId, QString partName, ResourceFinder& _finder, From 54cf18d549aee3cad736000e7effccf91fac6034 Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 9 Dec 2022 16:22:24 +0100 Subject: [PATCH 2/3] Run the initialization of all the yarpmotorgui parts in parallel The parts are still parsed in order, but while waiting for one part, the others can configure --- src/yarpmotorgui/CMakeLists.txt | 1 + src/yarpmotorgui/mainwindow.cpp | 54 +++++--- src/yarpmotorgui/partitem.cpp | 222 +++++++++++++++++--------------- src/yarpmotorgui/partitem.h | 35 +++-- 4 files changed, 183 insertions(+), 129 deletions(-) diff --git a/src/yarpmotorgui/CMakeLists.txt b/src/yarpmotorgui/CMakeLists.txt index 17da0a5fc80..d3a46f7b5d5 100644 --- a/src/yarpmotorgui/CMakeLists.txt +++ b/src/yarpmotorgui/CMakeLists.txt @@ -109,6 +109,7 @@ if(YARP_COMPILE_yarpmotorgui) YARP::YARP_dev Qt5::Widgets Qt5::Gui + Threads::Threads ) install(TARGETS yarpmotorgui COMPONENT utilities DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/yarpmotorgui/mainwindow.cpp b/src/yarpmotorgui/mainwindow.cpp index 11faf3b27f2..e54d5b94a51 100644 --- a/src/yarpmotorgui/mainwindow.cpp +++ b/src/yarpmotorgui/mainwindow.cpp @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -603,8 +605,6 @@ bool MainWindow::init(QStringList enabledParts, } int errorCount = 0; - QScrollArea *scroll = nullptr; - PartItem *part = nullptr; m_finder = finder; m_user_script1 = m_finder.find("script1").asString(); m_user_script2 = m_finder.find("script2").asString(); @@ -679,23 +679,35 @@ bool MainWindow::init(QStringList enabledParts, m_modesTreeManager->addRobot(robot.first.c_str()); } + std::vector> initLambdas; + std::vector> partsFuture; + for (auto& i_parts : parts) { - //JointItem *item = new JointItem(); - //layout->addWidget(item); - scroll = new QScrollArea(m_tabPanel); - scroll->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); - scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - scroll->setWidgetResizable(true); std::string part_name = i_parts.first; std::string robot_name = i_parts.second.robot_name; std::string robot_name_without_slash = i_parts.second.robot_name_without_slash; std::string part_name_without_slash = i_parts.second.part_name_without_slash; int part_id = i_parts.second.partindex; - part = new PartItem(robot_name_without_slash.c_str(), portPrefix, part_id, part_name_without_slash.c_str(), finder, debug_param_enabled, speedview_param_enabled, enable_calib_all, scroll); + PartItem* newPart = new PartItem(robot_name_without_slash.c_str(), portPrefix, part_id, part_name_without_slash.c_str(), debug_param_enabled, speedview_param_enabled, enable_calib_all); + + initLambdas.push_back([newPart]() { + newPart->initializeYarpConnections(); + return newPart; + }); + + //Run the yarp initialization of all the parts in parallell + partsFuture.emplace_back(std::async(std::launch::async, initLambdas.back())); + } + + for (auto& partFuture : partsFuture) + { + + PartItem *part = partFuture.get(); //Wait until the initialization of the corresponding part is over if(part && !part->getInterfaceError()) { + part->initializeJointWidgets(); connect(part,SIGNAL(sequenceActivated()),this,SLOT(onSequenceActivated())); connect(part,SIGNAL(sequenceStopped()),this,SLOT(onSequenceStopped())); connect(this,SIGNAL(sig_viewSpeedValues(bool)),part,SLOT(onViewSpeedValues(bool))); @@ -713,30 +725,36 @@ bool MainWindow::init(QStringList enabledParts, connect(this, SIGNAL(sig_enableControlPWM(bool)), part, SLOT(onEnableControlPWM(bool))); connect(this, SIGNAL(sig_enableControlCurrent(bool)), part, SLOT(onEnableControlCurrent(bool))); + QString part_name = "/" + part->getPartName(); + QString robot_name = "/" + part->getRobotName(); + int part_id = part->getPartIndex(); + QScrollArea * scroll = new QScrollArea(m_tabPanel); + scroll->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); + scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + scroll->setWidgetResizable(true); + part->setParent(scroll); scroll->setWidget(part); - int tabIndex = m_tabPanel->addTab(scroll, part_name.c_str()); + int tabIndex = m_tabPanel->addTab(scroll, part_name); if (part_id == 0) { - QString auxName = part_name.c_str(); - auxName.replace(0, 1, QString(part_name.c_str()).at(0).toUpper()); + QString auxName = part_name; + auxName.replace(0, 1, QString(part_name).at(0).toUpper()); m_currentPartMenu->setTitle(QString("%1 Commands ").arg(auxName)); this->m_partName->setText(QString("%1 Commands ").arg(auxName)); } - m_modesTreeManager->addRobotPart(robot_name, part_name, tabIndex, part); + m_modesTreeManager->addRobotPart(robot_name.toStdString(), part_name.toStdString(), tabIndex, part); } else { if(part) { + yError("Opening PolyDriver for part /%s failed...", part->getPartName().toLatin1().data()); + QMessageBox::critical(nullptr, "Error opening a device", QString("Error while opening device for part /").append(part->getPartName())); + delete part; part = nullptr; } - if(scroll) - { - delete scroll; - scroll = nullptr; - } errorCount++; } } diff --git a/src/yarpmotorgui/partitem.cpp b/src/yarpmotorgui/partitem.cpp index 5c1aac79b5a..ccaeb0e2704 100644 --- a/src/yarpmotorgui/partitem.cpp +++ b/src/yarpmotorgui/partitem.cpp @@ -24,18 +24,23 @@ PartItem::PartItem(QString robotName, QString portPrefix, - int id, QString partName, - ResourceFinder& _finder, + int id, + QString partName, bool debug_param_enabled, bool speedview_param_enabled, - bool enable_calib_all, QWidget *parent) : + bool enable_calib_all, + QWidget *parent) : QWidget(parent), m_sequenceWindow(nullptr), + m_portPrefix(portPrefix), m_partId(id), m_mixedEnabled(false), m_positionDirectEnabled(false), m_pwmEnabled(false), m_currentEnabled(false), + m_debugParamEnabled(debug_param_enabled), + m_speedviewParamEnabled(speedview_param_enabled), + m_enableCalibAll(enable_calib_all), m_currentPidDlg(nullptr), m_controlModes(nullptr), m_refTrajectorySpeeds(nullptr), @@ -54,7 +59,6 @@ PartItem::PartItem(QString robotName, m_part_dutyVisible(false), m_part_currentVisible(false), m_interactionModes(nullptr), - m_finder(&_finder), m_iMot(nullptr), m_iinfo(nullptr), m_slow_k(0) @@ -73,9 +77,66 @@ PartItem::PartItem(QString robotName, m_robotPartPort = QString("/%1/%2").arg(robotName, partName); m_partName = partName; m_robotName = robotName; +} + +PartItem::~PartItem() +{ + disconnect(&m_runTimer, SIGNAL(timeout()), this, SLOT(onRunTimeout())); + m_runTimer.stop(); + + disconnect(&m_runTimeTimer, SIGNAL(timeout()), this, SLOT(onRunTimerTimeout())); + m_runTimeTimer.stop(); + disconnect(&m_cycleTimer, SIGNAL(timeout()), this, SLOT(onCycleTimerTimeout())); + m_cycleTimer.stop(); + + disconnect(&m_cycleTimeTimer, SIGNAL(timeout()), this, SLOT(onCycleTimeTimerTimeout())); + m_cycleTimeTimer.stop(); + + if (m_sequenceWindow){ + m_sequenceWindow->hide(); + delete m_sequenceWindow; + } + + for (int i = 0; icount(); i++){ + auto* joint = (JointItem *)m_layout->itemAt(i)->widget(); + if(joint){ + disconnect(joint,SIGNAL(changeMode(int,JointItem*)), this, SLOT(onJointChangeMode(int,JointItem*))); + disconnect(joint,SIGNAL(changeInteraction(int,JointItem*)), this, SLOT(onJointInteraction(int,JointItem*))); + disconnect(joint,SIGNAL(homeClicked(JointItem*)),this,SLOT(onHomeClicked(JointItem*))); + disconnect(joint,SIGNAL(idleClicked(JointItem*)),this,SLOT(onIdleClicked(JointItem*))); + disconnect(joint,SIGNAL(runClicked(JointItem*)),this,SLOT(onRunClicked(JointItem*))); + disconnect(joint,SIGNAL(pidClicked(JointItem*)),this,SLOT(onPidClicked(JointItem*))); + disconnect(joint,SIGNAL(calibClicked(JointItem*)),this,SLOT(onCalibClicked(JointItem*))); + delete joint; + } + } + + if (m_partsdd){ + m_partsdd->close(); + delete m_partsdd; + m_partsdd = nullptr; + } + + if (m_controlModes) { delete[] m_controlModes; m_controlModes = nullptr; } + if (m_refTrajectorySpeeds) { delete[] m_refTrajectorySpeeds; m_refTrajectorySpeeds = nullptr; } + if (m_refTrajectoryPositions) { delete[] m_refTrajectoryPositions; m_refTrajectoryPositions = nullptr; } + if (m_refTorques) { delete[] m_refTorques; m_refTorques = nullptr; } + if (m_refVelocitySpeeds) { delete[] m_refVelocitySpeeds; m_refVelocitySpeeds = nullptr; } + if (m_torques) { delete[] m_torques; m_torques = nullptr; } + if (m_positions) { delete[] m_positions; m_positions = nullptr; } + if (m_speeds) { delete[] m_speeds; m_speeds = nullptr; } + if (m_currents) { delete[] m_currents; m_currents = nullptr; } + if (m_motorPositions) { delete[] m_motorPositions; m_motorPositions = nullptr; } + if (m_dutyCycles) { delete[] m_dutyCycles; m_dutyCycles = nullptr; } + if (m_done) { delete[] m_done; m_done = nullptr; } + if (m_interactionModes) { delete [] m_interactionModes; m_interactionModes = nullptr; } +} + +void PartItem::initializeYarpConnections() +{ //checking existence of the port - QString portLocalName = QString("%1%2").arg(portPrefix, m_robotPartPort); + QString portLocalName = QString("%1%2").arg(m_portPrefix, m_robotPartPort); m_interfaceError = false; @@ -91,17 +152,12 @@ PartItem::PartItem(QString robotName, m_interfaceError = !openPolyDrivers(); if (m_interfaceError == true) { - yError("Opening PolyDriver for part %s failed...", m_robotPartPort.toLatin1().data()); - QMessageBox::critical(nullptr, "Error opening a device", QString("Error while opening device for part ").append(m_robotPartPort.toLatin1().data())); + return; } /*********************************************************************/ /**************** PartMover Content **********************************/ - if (!m_finder->isNull()){ - yDebug("Setting a valid finder \n"); - } - QString sequence_portname = QString("%1/sequence:o").arg(portLocalName); m_sequence_port.open(sequence_portname.toLatin1().data()); @@ -111,7 +167,6 @@ PartItem::PartItem(QString robotName, if (m_interfaceError == false) { int i = 0; - std::string jointname; int number_of_joints; m_iPos->getAxes(&number_of_joints); @@ -164,58 +219,65 @@ PartItem::PartItem(QString robotName, do { ret = m_iencs->getEncoders(m_positions); if (!ret) { - yError("%s iencs->getEncoders() failed, retrying...\n", partName.toLatin1().data()); + yError("%s iencs->getEncoders() failed, retrying...\n", m_partName.toLatin1().data()); SystemClock::delaySystem(0.050); } } while (!ret); - yInfo("%s iencs->getEncoders() ok!\n", partName.toLatin1().data()); + yInfo("%s iencs->getEncoders() ok!\n", m_partName.toLatin1().data()); - double min_pos = 0; - double max_pos = 100; - double min_vel = 0; - double max_vel = 100; - double min_cur = -2.0; - double max_cur = +2.0; - for (int k = 0; kgetLimits(k, &min_pos, &max_pos); - bool bvl = m_iLim->getVelLimits(k, &min_vel, &max_vel); - bool bcr = m_iCur->getCurrentRange(k, &min_cur, &max_cur); + JointInfo addedJoint; + m_iinfo->getAxisName(k, addedJoint.name); + bool bpl = m_iLim->getLimits(k, &addedJoint.minPosition, &addedJoint.maxPosition); + bool bvl = m_iLim->getVelLimits(k, &addedJoint.minVelocity, &addedJoint.maxVelocity); + bool bcr = m_iCur->getCurrentRange(k, &addedJoint.minCurrent, &addedJoint.maxCurrent); if (bpl == false) { - yError() << "Error while getting position limits, part " << partName.toStdString() << " joint " << k; + yError() << "Error while getting position limits, part " << m_partName.toStdString() << " joint " << k; } - if (bvl == false || (min_vel == 0 && max_vel == 0)) + if (bvl == false || (addedJoint.minVelocity == 0 && addedJoint.maxVelocity == 0)) { - yError() << "Error while getting velocity limits, part " << partName.toStdString() << " joint " << k; + yError() << "Error while getting velocity limits, part " << m_partName.toStdString() << " joint " << k; } - if (bcr == false || (min_cur == 0 && max_cur == 0)) + if (bcr == false || (addedJoint.minCurrent == 0 && addedJoint.maxCurrent == 0)) { - yError() << "Error while getting current range, part " << partName.toStdString() << " joint " << k; + yError() << "Error while getting current range, part " << m_partName.toStdString() << " joint " << k; } - QSettings settings("YARP", "yarpmotorgui"); - double max_slider_vel = settings.value("velocity_slider_limit", 100.0).toDouble(); - if (max_vel > max_slider_vel) { - max_vel = max_slider_vel; - } + m_iinfo->getJointType(k, addedJoint.jointType); + m_jointsInfo.push_back(addedJoint); + } + } +} + +void PartItem::initializeJointWidgets() +{ + if (m_interfaceError == false) + { + QSettings settings("YARP", "yarpmotorgui"); + double max_slider_vel = settings.value("velocity_slider_limit", 100.0).toDouble(); - m_iinfo->getAxisName(k, jointname); - yarp::dev::JointTypeEnum jtype = yarp::dev::VOCAB_JOINTTYPE_REVOLUTE; - m_iinfo->getJointType(k, jtype); + for (int k = 0; k < m_jointsInfo.size(); k++) + { + JointInfo& jointInfo = m_jointsInfo[k]; + + if (jointInfo.maxVelocity > max_slider_vel) { + jointInfo.maxVelocity = max_slider_vel; + } auto* joint = new JointItem(k); - joint->setJointName(jointname.c_str()); + joint->setJointName(jointInfo.name.c_str()); joint->setPWMRange(-100.0, 100.0); - joint->setCurrentRange(min_cur, max_cur); + joint->setCurrentRange(jointInfo.minCurrent, jointInfo.maxCurrent); m_layout->addWidget(joint); - joint->setPositionRange(min_pos, max_pos); - joint->setVelocityRange(min_vel, max_vel); - joint->setTrajectoryVelocityRange(max_vel); + joint->setPositionRange(jointInfo.minPosition, jointInfo.maxPosition); + joint->setVelocityRange(jointInfo.minVelocity, jointInfo.maxVelocity); + joint->setTrajectoryVelocityRange(jointInfo.maxVelocity); joint->setTorqueRange(5.0); - joint->setUnits(jtype); + joint->setUnits(jointInfo.jointType); joint->enableControlPositionDirect(m_positionDirectEnabled); joint->enableControlMixed(m_mixedEnabled); joint->enableControlPWM(m_pwmEnabled); @@ -232,9 +294,9 @@ PartItem::PartItem(QString robotName, onSetTrqSliderOptionPI(val_trq_choice, val_trq_custom_step); onSetCurSliderOptionPI(val_trq_choice, val_trq_custom_step); - joint->setEnabledOptions(debug_param_enabled, - speedview_param_enabled, - enable_calib_all); + joint->setEnabledOptions(m_debugParamEnabled, + m_speedviewParamEnabled, + m_enableCalibAll); connect(joint, SIGNAL(changeMode(int,JointItem*)), this, SLOT(onJointChangeMode(int,JointItem*))); connect(joint, SIGNAL(changeInteraction(int,JointItem*)), this, SLOT(onJointInteraction(int,JointItem*))); @@ -276,60 +338,6 @@ PartItem::PartItem(QString robotName, connect(&m_runTimer, SIGNAL(timeout()), this, SLOT(onRunTimeout()), Qt::QueuedConnection); } -PartItem::~PartItem() -{ - disconnect(&m_runTimer, SIGNAL(timeout()), this, SLOT(onRunTimeout())); - m_runTimer.stop(); - - disconnect(&m_runTimeTimer, SIGNAL(timeout()), this, SLOT(onRunTimerTimeout())); - m_runTimeTimer.stop(); - - disconnect(&m_cycleTimer, SIGNAL(timeout()), this, SLOT(onCycleTimerTimeout())); - m_cycleTimer.stop(); - - disconnect(&m_cycleTimeTimer, SIGNAL(timeout()), this, SLOT(onCycleTimeTimerTimeout())); - m_cycleTimeTimer.stop(); - - if (m_sequenceWindow){ - m_sequenceWindow->hide(); - delete m_sequenceWindow; - } - - for (int i = 0; icount(); i++){ - auto* joint = (JointItem *)m_layout->itemAt(i)->widget(); - if(joint){ - disconnect(joint,SIGNAL(changeMode(int,JointItem*)), this, SLOT(onJointChangeMode(int,JointItem*))); - disconnect(joint,SIGNAL(changeInteraction(int,JointItem*)), this, SLOT(onJointInteraction(int,JointItem*))); - disconnect(joint,SIGNAL(homeClicked(JointItem*)),this,SLOT(onHomeClicked(JointItem*))); - disconnect(joint,SIGNAL(idleClicked(JointItem*)),this,SLOT(onIdleClicked(JointItem*))); - disconnect(joint,SIGNAL(runClicked(JointItem*)),this,SLOT(onRunClicked(JointItem*))); - disconnect(joint,SIGNAL(pidClicked(JointItem*)),this,SLOT(onPidClicked(JointItem*))); - disconnect(joint,SIGNAL(calibClicked(JointItem*)),this,SLOT(onCalibClicked(JointItem*))); - delete joint; - } - } - - if (m_partsdd){ - m_partsdd->close(); - delete m_partsdd; - m_partsdd = nullptr; - } - - if (m_controlModes) { delete[] m_controlModes; m_controlModes = nullptr; } - if (m_refTrajectorySpeeds) { delete[] m_refTrajectorySpeeds; m_refTrajectorySpeeds = nullptr; } - if (m_refTrajectoryPositions) { delete[] m_refTrajectoryPositions; m_refTrajectoryPositions = nullptr; } - if (m_refTorques) { delete[] m_refTorques; m_refTorques = nullptr; } - if (m_refVelocitySpeeds) { delete[] m_refVelocitySpeeds; m_refVelocitySpeeds = nullptr; } - if (m_torques) { delete[] m_torques; m_torques = nullptr; } - if (m_positions) { delete[] m_positions; m_positions = nullptr; } - if (m_speeds) { delete[] m_speeds; m_speeds = nullptr; } - if (m_currents) { delete[] m_currents; m_currents = nullptr; } - if (m_motorPositions) { delete[] m_motorPositions; m_motorPositions = nullptr; } - if (m_dutyCycles) { delete[] m_dutyCycles; m_dutyCycles = nullptr; } - if (m_done) { delete[] m_done; m_done = nullptr; } - if (m_interactionModes) { delete [] m_interactionModes; m_interactionModes = nullptr; } -} - bool PartItem::openPolyDrivers() { m_partsdd->open(m_partOptions); @@ -353,7 +361,7 @@ bool PartItem::openPolyDrivers() void PartItem::initInterfaces() { - yDebug("Initializing interfaces..."); + yDebug("Initializing %s interfaces...", getPartName().toStdString().c_str()); //default value for unopened interfaces m_iPos = nullptr; m_iVel = nullptr; @@ -376,7 +384,7 @@ void PartItem::initInterfaces() bool PartItem::openInterfaces() { - yDebug("Opening interfaces..."); + yDebug("Opening %s interfaces...", getPartName().toStdString().c_str()); bool ok = false; if (m_partsdd->isValid()) { @@ -489,6 +497,16 @@ QString PartItem::getPartName() return m_partName; } +QString PartItem::getRobotName() +{ + return m_robotName; +} + +int PartItem::getPartIndex() +{ + return m_partId; +} + void PartItem::onSliderPWMCommand(double pwmVal, int index) { m_iPWM->setRefDutyCycle(index, pwmVal); diff --git a/src/yarpmotorgui/partitem.h b/src/yarpmotorgui/partitem.h index 1ded2c5c2d4..96d6b2590ec 100644 --- a/src/yarpmotorgui/partitem.h +++ b/src/yarpmotorgui/partitem.h @@ -44,7 +44,6 @@ class PartItem : public QWidget QString portPrefix, int partId, QString partName, - ResourceFinder& _finder, bool debug_param_enabled, bool speedview_param_enabled, bool enable_calib_all, @@ -52,30 +51,27 @@ class PartItem : public QWidget ~PartItem(); - bool openPolyDrivers(); - void initInterfaces(); - bool openInterfaces(); + void initializeYarpConnections(); + void initializeJointWidgets(); bool getInterfaceError(); void openSequenceWindow(); void closeSequenceWindow(); - bool cycleAllSeq(); bool checkAndRunAllSeq(); bool checkAndRunTimeAllSeq(); bool checkAndCycleAllSeq(); bool checkAndCycleTimeAllSeq(); void runPart(); void idlePart(); - bool homeJoint(int joint); bool homePart(); bool homeToCustomPosition(const yarp::os::Bottle& positionElement); void calibratePart(); bool checkAndGo(); void stopSequence(); - void setTreeWidgetModeNode(QTreeWidgetItem *node); void loadSequence(); void saveSequence(QString global_filename); - QTreeWidgetItem *getTreeWidgetModeNode(); QString getPartName(); + QString getRobotName(); + int getPartIndex(); const QVector& getPartModes(); void resizeWidget(int w); int getNumberOfJoints(); @@ -85,22 +81,43 @@ class PartItem : public QWidget private: void fixedTimeMove(SequenceItem sequence); + bool openPolyDrivers(); + void initInterfaces(); + bool openInterfaces(); + bool homeJoint(int joint); protected: void resizeEvent(QResizeEvent *event) override; void changeEvent(QEvent *event) override; private: + + struct JointInfo + { + std::string name; + double minPosition{0}; + double maxPosition{0}; + double minVelocity{0}; + double maxVelocity{0}; + double minCurrent{0}; + double maxCurrent{0}; + yarp::dev::JointTypeEnum jointType{yarp::dev::VOCAB_JOINTTYPE_REVOLUTE}; + }; + FlowLayout *m_layout; SequenceWindow *m_sequenceWindow; QString m_robotPartPort; QString m_robotName; QString m_partName; + QString m_portPrefix; int m_partId; bool m_mixedEnabled; bool m_positionDirectEnabled; bool m_pwmEnabled; bool m_currentEnabled; + bool m_debugParamEnabled; + bool m_speedviewParamEnabled; + bool m_enableCalibAll; PidDlg *m_currentPidDlg; Stamp m_sequence_port_stamp; QTimer m_runTimer; @@ -130,8 +147,8 @@ class PartItem : public QWidget bool m_part_currentVisible; yarp::dev::InteractionModeEnum* m_interactionModes; QVector m_modesList; + QVector m_jointsInfo; - ResourceFinder* m_finder; PolyDriver* m_partsdd; Property m_partOptions; Port m_sequence_port; From a9deeb7e3110b4e08330b7fe50cdedff8e6bc060 Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 9 Dec 2022 17:41:00 +0100 Subject: [PATCH 3/3] Added CHANGELOG file. --- doc/release/master/yarpmotorgui_open_speedup.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/release/master/yarpmotorgui_open_speedup.md diff --git a/doc/release/master/yarpmotorgui_open_speedup.md b/doc/release/master/yarpmotorgui_open_speedup.md new file mode 100644 index 00000000000..d7a97c5f5b2 --- /dev/null +++ b/doc/release/master/yarpmotorgui_open_speedup.md @@ -0,0 +1,14 @@ +yarpmotorgui_open_speedup {#master} +--------------------------------- + + + +Branch: [S-Dafarra:yarpmotorgui_speedup](https://github.com/S-Dafarra/yarp/tree/yarpmotorgui_speedup) + +#### `yarpmotorgui` + +* Improved the initialization time of ``yarpmotorgui`` by: + * removing useless code + * using a dummy port to check conflicts with other ``yarpmotorgui`` instances + * parallelize the opening of the different robot part via ``std::async`` +