8#include "ui_mainwindow.h"
19#include <QFontMetrics>
35 QLocale::setDefault(QLocale::C);
37 m_sequenceActiveCount = 0;
39 setWindowTitle(
"Qt Robot Motor GUI V2.0");
42 m_sliderOpt =
nullptr;
45 m_globalToolBar =
new QToolBar(
"Global Joints Commands",
this);
51 m_globalToolBar->addWidget(
label1)->setCheckable(
false);
54 m_globalToolBar->addSeparator();
55 m_goAll = m_globalToolBar->addAction(
QIcon(
":/play-all.svg"),
"Go All");
56 m_globalToolBar->addSeparator();
57 m_runAllSeq = m_globalToolBar->addAction(
QIcon(
":/images/runSequence.png"),
"Run All Sequences (use joint speeds from Speed tab)");
58 m_runAllSeqTime = m_globalToolBar->addAction(
QIcon(
":/images/runSequenceTime.png"),
"Run All Sequences (ignore Speed tab, produce coordinated movement using Timing)");
59 m_saveAllSeq = m_globalToolBar->addAction(
QIcon(
":/file-save.svg"),
"Save All Sequences");
60 m_loadAllSeq = m_globalToolBar->addAction(
QIcon(
":/file-open.svg"),
"Load All Sequences");
61 m_cycleAllSeq = m_globalToolBar->addAction(
QIcon(
":/images/cycleAllSequence.png"),
"Cycle All Sequences (use joint speeds from Speed tab)");
62 m_cycleAllSeqTime = m_globalToolBar->addAction(
QIcon(
":/images/cycleAllSequenceTime.png"),
"Cycle All Sequences (ignore Speed tab, produce coordinated movement using Timing)");
63 m_stopAllSeq = m_globalToolBar->addAction(
QIcon(
":/stop.svg"),
"Stop All Sequences");
64 m_globalToolBar->addSeparator();
65 m_idleAllParts = m_globalToolBar->addAction(
QIcon(
":/idle.svg"),
"Idle All Parts");
66 m_runAllParts = m_globalToolBar->addAction(
QIcon(
":/play.svg"),
"Run All Parts");
67 m_homeAllParts = m_globalToolBar->addAction(
QIcon(
":/home.svg"),
"Home All Parts");
68 m_globalToolBar->addSeparator();
69 m_script1 = m_globalToolBar->addAction(
QIcon(
":/action1.svg"),
"Execute User Script1");
70 m_script2 = m_globalToolBar->addAction(
QIcon(
":/action2.svg"),
"Execute User Script2");
71 addToolBar(m_globalToolBar);
95 for (
size_t index = 0; index <
ini.size(); ++index) {
109 std::string key =
subElement->get(0).asString();
110 std::string
pattern =
"customPosition_";
129 m_customPositionsAllParts.push_back(
newAction);
137 newAction->setShortcutContext(Qt::ApplicationShortcut);
168 m_partToolBar =
new QToolBar(
"Current Part",
this);
169 m_partToolBar->setMovable(
true);
170 m_partToolBar->setFloatable(
true);
171 m_partToolBar->setAllowedAreas(Qt::AllToolBarAreas);
173 m_partName =
new QLabel(
"NONE");
174 f = m_partName->font();
176 m_partName->setFont(
f);
178 m_partToolBar->addWidget(m_partName)->setCheckable(
false);
180 m_partToolBar->addSeparator();
181 openSequenceAction = m_partToolBar->addAction(
QIcon(
":/file-new.svg"),
"Open Sequence Tab");
182 m_partToolBar->addSeparator();
183 m_runSinglePart = m_partToolBar->addAction(
QIcon(
":/play.svg"),
"Run all joints of this part");
184 m_idleSinglePart = m_partToolBar->addAction(
QIcon(
":/idle.svg"),
"Idle all joints of this part");
185 m_calibSinglePart = m_partToolBar->addAction(
QIcon(
":/images/calibrate.png"),
"Calibrate all joints of this part");
186 m_homeSinglePart = m_partToolBar->addAction(
QIcon(
":/home.svg"),
"Home all joints of this part");
192 m_customPositionsSinglePartToolbar.push_back(
newAction);
201 addToolBar(m_partToolBar);
203 m_currentPartMenu = m_ui->menuBar->addMenu(
"Current Part: ");
204 m_currentPartMenu->addAction(openSequenceAction);
205 m_currentPartMenu->addSeparator();
206 m_currentPartMenu->addAction(m_runSinglePart);
207 m_currentPartMenu->addAction(m_calibSinglePart);
208 m_currentPartMenu->addAction(m_homeSinglePart);
209 m_currentPartMenu->addAction(m_idleSinglePart);
220 m_customPositionsSinglePartToolbar.push_back(
newAction);
228 newAction->setShortcutContext(Qt::ApplicationShortcut);
250 QAction *viewPositionTargetBox =
windows->addAction(
"View Position Target Box");
251 QAction* viewPositionTargetValue =
windows->addAction(
"View Position Target Value");
252 QAction *enableControlVelocity =
windows->addAction(
"Enable Velocity Control");
253 QAction *enableControlMixed =
windows->addAction(
"Enable Mixed Control");
254 QAction *enableControlPositionDirect =
windows->addAction(
"Enable Position Direct Control");
255 QAction *enableControlPWM =
windows->addAction(
"Enable PWM Control");
256 QAction *enableControlCurrent =
windows->addAction(
"Enable Current Control");
257 QAction *enableControlTorque =
windows->addAction(
"Enable Torque Control");
266 enableControlVelocity->setCheckable(
true);
267 enableControlMixed->setCheckable(
true);
268 enableControlPositionDirect->setCheckable(
true);
269 enableControlPWM->setCheckable(
true);
270 enableControlCurrent->setCheckable(
true);
271 enableControlTorque->setCheckable(
true);
272 viewPositionTargetBox->setCheckable(
true);
273 viewPositionTargetValue->setCheckable(
true);
275 QSettings settings(
"YARP",
"yarpmotorgui");
278 bool bSpeedValues = settings.value(
"SpeedValuesVisible",
false).toBool();
282 bool bviewDutyCycles = settings.value(
"DutyCycleVisible",
false).toBool();
283 bool bCurrentValues = settings.value(
"CurrentsVisible",
false).toBool();
293 enableControlVelocity->setChecked(
false);
294 enableControlMixed->setChecked(
false);
295 enableControlPositionDirect->setChecked(
false);
296 enableControlPWM->setChecked(
false);
297 enableControlCurrent->setChecked(
false);
298 enableControlTorque->setChecked(
false);
309 connect(viewPositionTargetBox,
SIGNAL(
triggered(
bool)),
this,
SLOT(onViewPositionTargetBox(
bool)));
310 connect(viewPositionTargetValue,
SIGNAL(
triggered(
bool)),
this,
SLOT(onViewPositionTargetValue(
bool)));
311 connect(enableControlVelocity,
SIGNAL(
triggered(
bool)),
this,
SLOT(onEnableControlVelocity(
bool)));
312 connect(enableControlMixed,
SIGNAL(
triggered(
bool)),
this,
SLOT(onEnableControlMixed(
bool)));
313 connect(enableControlPositionDirect,
SIGNAL(
triggered(
bool)),
this,
SLOT(onEnableControlPositionDirect(
bool)));
315 connect(enableControlCurrent,
SIGNAL(
triggered(
bool)),
this,
SLOT(onEnableControlCurrent(
bool)));
316 connect(enableControlTorque,
SIGNAL(
triggered(
bool)),
this,
SLOT(onEnableControlTorque(
bool)));
319 connect(
this,
SIGNAL(sig_internalClose()),
this,
SLOT(close()),Qt::QueuedConnection);
324 lay->setSizeConstraint(QLayout::SetMaximumSize);
325 m_ui->treeWidgetContainer->setLayout(
lay);
327 connect(m_modesTreeManager,
SIGNAL(sig_jointClicked(
int,
int)),
this,
SLOT(onJointClicked(
int,
int)));
328 connect(m_modesTreeManager,
SIGNAL(sig_partDoubleClicked(
int)),
this,
SLOT(onPartDoubleClicked(
int)));
330 m_timer.setInterval(200);
331 m_timer.setSingleShot(
false);
332 connect(&m_timer,
SIGNAL(timeout()),
this,
SLOT(onUpdate()), Qt::QueuedConnection);
338 m_glowEffect->setOffset(.0);
340 m_glowEffect->setColor(Qt::yellow);
342 m_glowTimer.setSingleShot(
true);
343 connect(&m_glowTimer,
SIGNAL(timeout()),
this,
SLOT(onGlowTimerExpired()));
350 disconnect(&m_timer,
SIGNAL(timeout()),
this,
SLOT(onUpdate()));
357 for (
int i = 0; i<m_tabPanel->count(); i++)
359 if (m_tabPanel->widget(i))
361 delete m_tabPanel->widget(i);
365 m_tabPanel =
nullptr;
379void MainWindow::onSequenceActivated()
381 m_sequenceActiveCount++;
382 m_goAll->setEnabled(
false);
383 m_runAllSeq->setEnabled(
false);
384 m_runAllSeqTime->setEnabled(
false);
385 m_saveAllSeq->setEnabled(
false);
386 m_loadAllSeq->setEnabled(
false);
387 m_cycleAllSeq->setEnabled(
false);
388 m_cycleAllSeqTime->setEnabled(
false);
389 m_runAllParts->setEnabled(
false);
390 m_idleAllParts->setEnabled(
false);
391 m_homeAllParts->setEnabled(
false);
394void MainWindow::onSequenceStopped()
396 m_sequenceActiveCount--;
397 if (m_sequenceActiveCount <= 0)
399 m_sequenceActiveCount = 0;
400 m_goAll->setEnabled(
true);
401 m_runAllSeq->setEnabled(
true);
402 m_runAllSeqTime->setEnabled(
true);
403 m_saveAllSeq->setEnabled(
true);
404 m_loadAllSeq->setEnabled(
true);
405 m_cycleAllSeq->setEnabled(
true);
406 m_cycleAllSeqTime->setEnabled(
true);
407 m_runAllParts->setEnabled(
true);
408 m_idleAllParts->setEnabled(
true);
409 m_homeAllParts->setEnabled(
true);
414void MainWindow::onViewGlobalToolbar(
bool val)
416 QSettings settings(
"YARP",
"yarpmotorgui");
417 settings.setValue(
"GlobalToolVisible",val);
419 m_globalToolBar->hide();
421 m_globalToolBar->show();
426void MainWindow::onViewPartToolbar(
bool val)
428 QSettings settings(
"YARP",
"yarpmotorgui");
429 settings.setValue(
"PartToolVisible",val);
431 m_partToolBar->hide();
433 m_partToolBar->show();
437void MainWindow::onEnableControlVelocity(
bool val)
442void MainWindow::onEnableControlMixed(
bool val)
447void MainWindow::onEnableControlPositionDirect(
bool val)
452void MainWindow::onEnableControlPWM(
bool val)
457void MainWindow::onEnableControlCurrent(
bool val)
462void MainWindow::onEnableControlTorque(
bool val)
467void MainWindow::onSliderOptionsClicked()
474 m_sliderOpt =
nullptr;
477void MainWindow::onViewSpeeds(
bool val)
479 QSettings settings(
"YARP",
"yarpmotorgui");
480 settings.setValue(
"SpeedValuesVisible",val);
485void MainWindow::onViewCurrents(
bool val)
487 QSettings settings(
"YARP",
"yarpmotorgui");
488 settings.setValue(
"CurrentValuesVisible", val);
493void MainWindow::onViewMotorPositions(
bool val)
495 QSettings settings(
"YARP",
"yarpmotorgui");
496 settings.setValue(
"MotorPositionVisible", val);
501void MainWindow::onViewDutyCycles(
bool val)
503 QSettings settings(
"YARP",
"yarpmotorgui");
504 settings.setValue(
"DutyCyclesVisible", val);
509void MainWindow::onViewPositionTargetBox(
bool val)
511 QSettings settings(
"YARP",
"yarpmotorgui");
512 settings.setValue(
"ViewPositionTarget", val);
517void MainWindow::onViewPositionTargetValue(
bool val)
519 QSettings settings(
"YARP",
"yarpmotorgui");
520 settings.setValue(
"ViewPositionTarget", val);
525void MainWindow::onSetPosSliderOptionMW(
int choice,
double val,
int digits)
529void MainWindow::onSetVelSliderOptionMW(
int choice,
double val)
533void MainWindow::onSetTrqSliderOptionMW(
int choice,
double val)
538void MainWindow::onJointClicked(
int partIndex,
int jointIndex)
547 auto*
jointWidget = part->getJointWidget(jointIndex);
549 m_glowEffect->setEnabled(
false);
551 m_glowEffect->setEnabled(
true);
555void MainWindow::onGlowTimerExpired()
557 m_glowEffect->setEnabled(
false);
560void MainWindow::onPartDoubleClicked(
int partIndex)
576 disconnect(&m_timer,
SIGNAL(timeout()),
this,
SLOT(onUpdate()));
583 for (
int i = 0; i<m_tabPanel->count(); i++){
584 if (m_tabPanel->widget(i)){
585 delete m_tabPanel->widget(i);
589 m_tabPanel =
nullptr;
594 QMainWindow::closeEvent(event);
607 m_tabPanel =
new QTabWidget(m_ui->mainContainer);
611 m_calibSinglePart->setEnabled(
false);
635 std::map<std::string, robot_type>
robots;
636 std::map<std::string, part_type>
parts;
641 size_t b1 =
ss.find(
'/');
642 size_t b2 =
ss.find(
'/',
b1 + 1);
643 if (
b1 == std::string::npos ||
644 b2 == std::string::npos)
646 yError() <<
"Invalid parts name, missing / char?";
655 if (r.robot_name_without_slash[0] ==
'/') {
656 r.robot_name_without_slash.erase(0, 1);
663 p.part_name_without_slash =
ss.substr(
b2);
664 if (p.part_name_without_slash[0] ==
'/') {
665 p.part_name_without_slash.erase(0, 1);
672 for (
auto& robot :
robots)
674 m_modesTreeManager->
addRobot(robot.first.c_str());
682 scroll->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
683 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
684 scroll->setWidgetResizable(
true);
694 connect(part,
SIGNAL(sequenceActivated()),
this,
SLOT(onSequenceActivated()));
695 connect(part,
SIGNAL(sequenceStopped()),
this,
SLOT(onSequenceStopped()));
718 m_currentPartMenu->setTitle(
QString(
"%1 Commands ").arg(
auxName));
740 if((
unsigned int)errorCount ==
parts.size())
748 m_ui->mainContainer->setLayout(
lay);
749 m_ui->mainContainer->layout()->addWidget(m_tabPanel);
752 QSettings settings(
"YARP",
"yarpmotorgui");
753 bool speedVisible = settings.value(
"SpeedValuesVisible",
false).toBool();
754 bool motorPosVisible = settings.value(
"MotorPositionVisible",
false).toBool();
755 bool currentVisible = settings.value(
"CurrentsVisible",
false).toBool();
756 bool dutyVisible = settings.value(
"DutyCyclesVisible",
false).toBool();
766void MainWindow::onCurrentPartChanged(
int index)
771 QString partName = m_tabPanel->tabText(index);
774 auxName.replace(0,1,partName.at(0).toUpper());
784 part->resizeWidget(part->width());
788void MainWindow::onCalibSinglePart()
800 if (QMessageBox::question(
this,
"Question",
QString(
"Do you really want to recalibrate all joints of this part?")) == QMessageBox::Yes)
802 part->calibratePart();
806void MainWindow::onExecuteScript1()
808 if (m_user_script1 ==
"")
810 QMessageBox::information(
this,
"Info",
QString(
"user script1 not specified. use --script1 option"));
814 if (QMessageBox::question(
this,
"Question",
QString(
"Do you really want to execute user script1?")) == QMessageBox::Yes)
822 yDebug() <<
"yarpmotorgui_script1 returned value:" << r;
826 QMessageBox::information(
this,
"Info",
QString(
"Unable to find script1 file"));
831 QMessageBox::information(
this,
"Info",
QString(
"System is unable to run script1"));
836void MainWindow::onExecuteScript2()
838 if (m_user_script2 ==
"")
840 QMessageBox::information(
this,
"Info",
QString(
"user script2 not specified. use --script2 option"));
844 if (QMessageBox::question(
this,
"Question",
QString(
"Do you really want to execute user script2?")) == QMessageBox::Yes)
852 yDebug() <<
"yarpmotorgui_script2 returned value:" << r;
856 QMessageBox::information(
this,
"Info",
QString(
"Unable to find script2 file"));
861 QMessageBox::information(
this,
"Info",
QString(
"System is unable to run script2"));
866void MainWindow::onHomeSinglePart()
868 if (QMessageBox::question(
this,
"Question",
"Do you really want to home all joints of this part?") != QMessageBox::Yes){
885void MainWindow::onHomeAllParts()
887 if (QMessageBox::question(
this,
"Question",
"Do you really want to home all parts?") != QMessageBox::Yes){
895 for (
int i = 0; i<m_tabPanel->count(); i++)
910 if (QMessageBox::question(
this,
"Question",
"Do you really want to home all parts?") != QMessageBox::Yes){
918 for (
int i = 0; i<m_tabPanel->count(); i++)
934 if (QMessageBox::question(
this,
"Question",
"Do you really want to home all joints of this part?") != QMessageBox::Yes){
951void MainWindow::onIdleSinglePart()
966void MainWindow::onCycleTimeAllSeq()
974 for (
int i = 0; i<m_tabPanel->count(); i++){
981 bool done = part->checkAndCycleTimeAllSeq();
987 QMessageBox::critical(
this,
"Error",
QString(
"Load a valid sequence before performing this action for these parts:\n%1").arg(
notSelectedParts));
991void MainWindow::onCycleAllSeq()
999 for (
int i = 0; i<m_tabPanel->count(); i++){
1006 bool done = part->checkAndCycleAllSeq();
1012 QMessageBox::critical(
this,
"Error",
QString(
"Load a valid sequence before performing this action for these parts:\n%1").arg(
notSelectedParts));
1016void MainWindow::onRunAllSeq()
1024 for (
int i = 0; i<m_tabPanel->count(); i++){
1031 bool done = part->checkAndRunAllSeq();
1037 QMessageBox::critical(
this,
"Error",
QString(
"Load a valid sequence before performing this action for these parts:\n%1").arg(
notSelectedParts));
1042void MainWindow::onRunTimeAllSeq()
1050 for (
int i = 0; i<m_tabPanel->count(); i++){
1057 bool done = part->checkAndRunTimeAllSeq();
1063 QMessageBox::critical(
this,
"Error",
QString(
"Load a valid sequence before performing this action for these parts:\n%1").arg(
notSelectedParts));
1067void MainWindow::onLoadAllSeq()
1074 for (
int i = 0; i<m_tabPanel->count(); i++){
1081 part->loadSequence();
1086void MainWindow::onSaveAllSeq()
1092 QString fileName = QFileDialog::getSaveFileName(
this,
QString(
"Save Sequence for all parts as:"), QDir::homePath());
1094 for (
int i = 0; i<m_tabPanel->count(); i++)
1102 part->saveSequence(fileName);
1103 part->closeSequenceWindow();
1107void MainWindow::onStopAllSeq()
1114 for (
int i = 0; i<m_tabPanel->count(); i++){
1121 part->stopSequence();
1127void MainWindow::onGoAll()
1135 for (
int i = 0; i<m_tabPanel->count(); i++){
1142 bool done = part->checkAndGo();
1149 QMessageBox::critical(
this,
"Error",
QString(
"Select a valid entry in the table before performing a movement for these parts:\n%1").arg(
notSelectedParts));
1154void MainWindow::onIdleAllParts()
1156 if (QMessageBox::question(
this,
"Question",
"Do you really want to idle all parts?") != QMessageBox::Yes){
1164 for (
int i = 0; i<m_tabPanel->count(); i++)
1176void MainWindow::onRunAllParts()
1182 for (
int i = 0; i<m_tabPanel->count(); i++){
1193void MainWindow::onRunSinglePart()
1208void MainWindow::onOpenSequenceTab()
1219 part->openSequenceWindow();
1224void MainWindow::onUpdate()
1241 for (
int i = 0; i<m_tabPanel->count(); i++)
1245 item->updateControlMode();
1249 if (
item->updatePart() ==
false)
int SIGNAL(int pid, int signum)
void sig_enableControlMixed(bool)
void sig_enableControlPWM(bool)
void closeEvent(QCloseEvent *event) override
void sig_setPosSliderOptionMW(int, double, int)
void sig_enableControlTorque(bool)
void sig_setVelSliderOptionMW(int, double)
void sig_enableControlVelocity(bool)
void init(yarp::os::Property config)
Init the application with the current configuration.
MainWindow(const yarp::os::ResourceFinder &rf, yarp::dev::IBattery *ibat, QWidget *parent=0, double refresh_period=10.0)
void sig_viewPositionTargetValue(bool)
void sig_viewSpeedValues(bool)
void sig_enableControlPositionDirect(bool)
void sig_setTrqSliderOptionMW(int, double)
void sig_viewMotorPositions(bool)
void sig_viewDutyCycles(bool)
void sig_enableControlCurrent(bool)
void sig_viewCurrentValues(bool)
void sig_viewPositionTargetBox(bool)
void updateRobotPart(int index)
void addRobotPart(const std::string &robotName, const std::string &partName, int partIndex, PartItem *part)
void addRobot(const std::string &robotName)
A simple collection of objects that can be described and transmitted in a portable way.
A mini-server for performing network communication in the background.
Helper class for finding config files and other external resources.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
std::string findFileByName(const std::string &name)
Find the full path to a file.
A single value (typically within a Bottle).
virtual std::string asString() const
Get string value.
bool speedview_param_enabled