MMMPlayerGuiPlugin.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "MMMPlayerGuiPlugin.h"
25
26#include <IceUtil/Time.h>
27
32
33#include <RobotComponents/gui-plugins/MMMPlayerPlugin/ui_MMMPlayerConfigDialog.h>
34
36
37
38// Qt headers
39#include <filesystem>
40
41#include <QComboBox>
42#include <QInputDialog>
43#include <QMenu>
44#include <QMessageBox>
45#include <QPushButton>
46#include <Qt>
47#include <QtGlobal>
48
51using namespace armarx;
52
53#define PROJECT_DEFAULT "Armar4"
54#define CONFIG_FILE_DEFAULT "data/MMM/punching.xml"
55
56#define POSITION_CONTROL 0
57#define VELOCITY_CONTROL 1
58
63
65{
66 // init gui
67 ui.setupUi(getWidget());
68 fileDialog2 = new QFileDialog();
69 fileDialog2->setModal(true);
70 fileDialog2->setFileMode(QFileDialog::ExistingFiles);
71 QStringList fileTypes;
72 fileTypes << tr("XML (*.xml)") << tr("All Files (*.*)");
73 fileDialog2->setNameFilters(fileTypes);
74
75 jointList = new QListWidget();
76 updateTimer = new QTimer(this);
77}
78
79/*
80QPointer<QDialog> MMMPlayerWidget::getConfigDialog(QWidget* parent)
81{
82 if(!dialog)
83 {
84 dialog = new MMMLoaderConfigDialog(parent);
85 std::filesystem::path dir(CONFIG_FILE_DEFAULT);
86
87 dialog->fileDialog->setDirectory(QString::fromStdString(dir.remove_filename().string()));
88 dialog->ui->editConfigFile->setText(QString::fromStdString(CONFIG_FILE_DEFAULT));
89 }
90 return qobject_cast<MMMLoaderConfigDialog*>(dialog);
91}
92
93void MMMPlayerWidget::configured()
94{
95 ARMARX_VERBOSE << "MMMPlayerWidget::configured()";
96 configFile = dialog->ui->editConfigFile->text().toStdString();
97 ARMARX_VERBOSE << "config file " + configFile;
98}
99*/
100
101
102void
104{
105 isComponentCreated = false;
106 if (dialog->needtoCreate)
107 {
108
109 std::string kinematicUnitName =
110 dialog->kinematicUnitComponentProxyFinder->getSelectedProxyName()
111 .trimmed()
112 .toStdString();
113 std::string kinematicTopic = dialog->kinematicTopicName;
114
115 Ice::StringSeq pros;
116 std::string packageName("RobotComponents");
117 armarx::CMakePackageFinder finder(packageName);
118
119 std::string appPath = finder.getBinaryDir() + "/TrajectoryPlayerAppRun";
120
121 pros.push_back(appPath);
122 Ice::PropertiesPtr properties = Ice::createProperties(pros);
123
124 properties->setProperty("ArmarX.TrajectoryPlayer.KinematicUnitName", kinematicUnitName);
125 properties->setProperty("ArmarX.TrajectoryPlayer.KinematicTopicName", kinematicTopic);
126
127 // TrajectoryPlayerPtr mplptr = Component::create<TrajectoryPlayer>(properties, "TrajectoryPlayer");
128 // getArmarXManager()->addObject(mplptr);
129
130
131 appPath = finder.getBinaryDir() + "/MMMPlayerAppRun";
133 getArmarXManager()->addObject(mptr);
134
135 isComponentCreated = true;
136 }
137
139 dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
141 dialog->trajPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
142 // ui.frameSlider->setEnabled(false);
143
144
145 connectSlots();
146}
147
148void
150{
152 dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
154 dialog->trajPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
155
156 configFile = MMMLoader->getMotionPath();
157 ui.editConfigFile->setText(QString::fromStdString(configFile));
158 std::filesystem::path dir(configFile);
159 fileDialog2->setDirectory(QString::fromStdString(dir.remove_filename().string()));
160 setupMotionList();
161
162 if (MMMLoader->isMotionLoaded())
163 {
164 setupJointList();
166 }
167
168 ui.frameSlider->blockSignals(true);
169 ui.frameSlider->setMaximum(100);
170 on_loopPlayback_toggled(false);
171 //on_enableRobotPoseUnit_toggled(false);
172}
173
174void
178
179void
183
184bool
186{
187
188 if (getIceManager())
189 {
190 getIceManager()->removeObject("MMMPlayerConfigDialog");
191
192 if (isComponentCreated)
193 {
194 getIceManager()->removeObject(
195 dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName()
196 .trimmed()
197 .toStdString());
198 }
199 }
200
201
203}
204
205void
207{
208}
209
210void
212{
213}
214
215void
217{
218 TrajectoryBasePtr t = MMMLoader->getJointTraj();
220 trajPlayer->loadJointTraj(t);
221 trajPlayer->loadBasePoseTraj(MMMLoader->getBasePoseTraj());
222 //ARMARX_INFO << "spinbox info: " << ui.speedSpinBox->value();
223 //ARMARX_INFO << "end traj time: " << trajPlayer->getTrajEndTime();
224 // trajPlayer->setEndTime(trajPlayer->getTrajEndTime() / ui.speedSpinBox->value());
225}
226
227void
229{
230 connect(ui.initializeButton, SIGNAL(clicked()), this, SLOT(on_initializeButton_clicked()));
231 connect(ui.startButton, SIGNAL(clicked()), this, SLOT(on_startButton_clicked()));
232 connect(ui.pauseButton, SIGNAL(clicked()), this, SLOT(on_pauseButton_clicked()));
233 connect(ui.stopButton, SIGNAL(clicked()), this, SLOT(on_stopButton_clicked()));
234 connect(ui.previewButton, SIGNAL(clicked()), this, SLOT(on_previewButton_clicked()));
235
236 connect(ui.btnSelectConfig, SIGNAL(clicked()), fileDialog2, SLOT(show()));
237 connect(ui.selectJoints, SIGNAL(clicked()), jointList, SLOT(show()));
238 connect(fileDialog2, SIGNAL(accepted()), this, SLOT(configFileSelected()));
239 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateSlider()));
240 // connect(ui.frameSlider, SIGNAL(valueChanged(int)), this, SLOT(setFrameNumber(int)));
241 // connect(ui.loopPlayback, SIGNAL(toggled(bool)), this, SLOT(on_loopPlayback_toggled(bool)));
242 connect(ui.loopPlayback, SIGNAL(toggled(bool)), this, SLOT(on_loopPlayback_toggled(bool)));
243 connect(ui.enableRobotPoseUnit,
244 SIGNAL(toggled(bool)),
245 this,
246 SLOT(on_enableRobotPoseUnit_toggled(bool)));
247 connect(ui.speedSpinBox,
248 SIGNAL(valueChanged(double)),
249 this,
250 SLOT(on_spinBoxFPS_valueChanged(double)));
251 connect(
252 ui.controlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(on_controlMode_changed(int)));
253 connect(jointList,
254 SIGNAL(itemChanged(QListWidgetItem*)),
255 this,
256 SLOT(jointListChanged(QListWidgetItem*)));
257}
258
259void
260armarx::MMMPlayerWidget::on_initializeButton_clicked()
261{
262 // set position control mode and move to first frame as initial pose
263
264 trajPlayer->resetTrajectoryPlayer(true);
265 ui.startButton->setEnabled(true);
266 ui.previewButton->setEnabled(true);
267
268 updateSlider();
269}
270
271void
273{
274 trajPlayer->setEndTime(trajPlayer->getTrajEndTime() / value);
275}
276
277void
278armarx::MMMPlayerWidget::on_startButton_clicked()
279{
280 trajPlayer->setIsPreview(false);
281 setSpeed(ui.speedSpinBox->value());
282 on_controlMode_changed(ui.controlMode->currentIndex());
283 bool started = trajPlayer->startTrajectoryPlayer();
284
285
286 if (started)
287 {
288 updateTimer->start(100);
289 ui.initializeButton->setDisabled(started);
290 ui.startButton->setDisabled(started);
291 ui.previewButton->setDisabled(started);
292 ui.motionName->setDisabled(started);
293 ui.controlMode->setDisabled(started);
294 ui.pauseButton->setEnabled(started);
295 ui.pauseButton->setText("Pause");
296 ui.btnSelectConfig->setEnabled(false);
297 ui.speedSpinBox->setDisabled(started);
298 ui.stopButton->setEnabled(started);
299 ui.frameSlider->setDisabled(started);
300 ui.frameSlider->blockSignals(true);
301
302 ui.status->setText("Real");
303 }
304}
305
306void
307armarx::MMMPlayerWidget::on_previewButton_clicked()
308{
309 trajPlayer->setIsPreview(true);
310 ARMARX_INFO << "speed spin box val: " << ui.speedSpinBox->value();
311 setSpeed(ui.speedSpinBox->value());
312 trajPlayer->resetTrajectoryPlayer(false);
313 bool previewed = trajPlayer->startTrajectoryPlayer();
314
315 if (previewed)
316 {
317 updateTimer->start(100);
318 ui.initializeButton->setDisabled(previewed);
319 ui.startButton->setDisabled(previewed);
320 ui.previewButton->setDisabled(previewed);
321 ui.motionName->setDisabled(previewed);
322 ui.controlMode->setDisabled(previewed);
323 ui.pauseButton->setEnabled(previewed);
324 ui.pauseButton->setText("Pause");
325 ui.btnSelectConfig->setEnabled(false);
326 ui.speedSpinBox->setDisabled(previewed);
327 ui.stopButton->setEnabled(previewed);
328 ui.frameSlider->setDisabled(previewed);
329 ui.frameSlider->blockSignals(true);
330
331 ui.status->setText("Preview");
332 }
333}
334
335void
336MMMPlayerWidget::on_pauseButton_clicked()
337{
338 bool paused = trajPlayer->pauseTrajectoryPlayer();
339
340 if (paused)
341 {
342 ui.pauseButton->setText("Resume");
343 }
344 else
345 {
346 ui.pauseButton->setText("Pause");
347 }
348
349 ui.controlMode->setEnabled(paused);
350 ui.frameSlider->setEnabled(paused);
351 ui.speedSpinBox->setEnabled(paused);
352 ui.frameSlider->blockSignals(!paused);
353}
354
355void
356armarx::MMMPlayerWidget::on_stopButton_clicked()
357{
358 bool stopped = trajPlayer->stopTrajectoryPlayer();
359
360 if (stopped)
361 {
362 updateTimer->stop();
363 ui.initializeButton->setEnabled(stopped);
364 ui.startButton->setDisabled(stopped);
365 ui.previewButton->setEnabled(stopped);
366 ui.pauseButton->setText("Pause");
367 ui.btnSelectConfig->setEnabled(true);
368 ui.motionName->setEnabled(stopped);
369 ui.controlMode->setEnabled(stopped);
370 ui.speedSpinBox->setEnabled(stopped);
371 ui.frameSlider->blockSignals(false);
372 ui.pauseButton->setDisabled(stopped);
373 ui.stopButton->setDisabled(stopped);
374
375 ui.status->setText("");
376 }
377}
378
379void
380MMMPlayerWidget::configFileSelected()
381{
382 configFile = (this->fileDialog2->selectedFiles()[0]).toStdString();
383 ui.editConfigFile->setText(this->fileDialog2->selectedFiles()[0]);
384
385 // load mmm motion
386 MMMLoader->loadMMMFile(configFile, "");
387 ui.frameSlider->setMaximum(100);
388 setupJointList();
389 setupMotionList();
390
391 if (MMMLoader->isMotionLoaded())
392 {
394 }
395}
396
397void
398MMMPlayerWidget::setupMotionList()
399{
400 Ice::StringSeq motionNames = MMMLoader->getMotionNames();
401 QObject::disconnect(
402 ui.motionName, SIGNAL(currentIndexChanged(int)), this, SLOT(motionChanged(int)));
403 ui.motionName->clear();
404
405 for (size_t i = 0; i < motionNames.size(); ++i)
406 {
407 ui.motionName->addItem(QString::fromStdString(motionNames.at(i)));
408 }
409
410 if (motionNames.size() > 0)
411 {
412 ui.motionName->setCurrentIndex(0);
413 connect(ui.motionName, SIGNAL(currentIndexChanged(int)), this, SLOT(motionChanged(int)));
414 }
415}
416
417void
418MMMPlayerWidget::setupJointList()
419{
420 Ice::StringSeq jointNames = MMMLoader->getJointNames();
421 jointList->blockSignals(true);
422 jointList->clear();
423
424 for (size_t i = 0; i < jointNames.size(); ++i)
425 {
426 std::string jointName = jointNames.at(i);
427 QListWidgetItem* joint = new QListWidgetItem(QString::fromStdString(jointName), jointList);
428 joint->setCheckState(Qt::Checked);
429 }
430
431 jointList->blockSignals(false);
432}
433
434void
435MMMPlayerWidget::updateSlider()
436{
437 double currentTime = trajPlayer->getCurrentTime();
438 double endTime = trajPlayer->getEndTime();
439 double posPer = currentTime / endTime;
440
441 int sliderPos = posPer * 100;
442
443 ui.frameSlider->blockSignals(true);
444 ui.frameSlider->setSliderPosition(sliderPos);
445 ui.frameSlider->blockSignals(false);
446 ui.currentFrame->display(currentTime);
447}
448
449void
450MMMPlayerWidget::jointListChanged(QListWidgetItem* joint)
451{
452 bool jointState;
453
454 if (joint->checkState() == Qt::Checked)
455 {
456 jointState = trajPlayer->setJointsInUse(joint->text().toStdString(), true);
457 }
458 else
459 {
460 jointState = trajPlayer->setJointsInUse(joint->text().toStdString(), false);
461 }
462
463 if (jointState)
464 {
465 joint->setCheckState(Qt::Checked);
466 }
467 else
468 {
469 joint->setCheckState(Qt::Unchecked);
470 }
471}
472
473void
474MMMPlayerWidget::motionChanged(int)
475{
476 std::string motionName = ui.motionName->currentText().toStdString();
477 ARMARX_INFO << "Choosing motion with name '" << motionName << "'";
478 MMMLoader->setMotionData(motionName);
479
480 if (MMMLoader->isMotionLoaded())
481 {
482 setupJointList();
484 }
485}
486
487void
488MMMPlayerWidget::on_spinBoxFPS_valueChanged(double value)
489{
490 if (value <= 0)
491 {
492 return;
493 }
494}
495
496void
497MMMPlayerWidget::on_loopPlayback_toggled(bool state)
498{
499 trajPlayer->setLoopPlayback(state);
500 ui.loopPlayback->setChecked(state);
501}
502
503void
504MMMPlayerWidget::on_controlMode_changed(int controlMode)
505{
506 ui.controlMode->setCurrentIndex(controlMode);
507
508 if (controlMode == POSITION_CONTROL)
509 {
510 trajPlayer->setIsVelocityControl(false);
511 }
512 else
513 {
514 trajPlayer->setIsVelocityControl(true);
515 }
516}
517
518void
519armarx::MMMPlayerWidget::on_enableRobotPoseUnit_toggled(bool state)
520{
521 trajPlayer->enableRobotPoseUnit(state);
522 ui.enableRobotPoseUnit->setChecked(state);
523}
#define POSITION_CONTROL
bool onClose() override
If you overwrite this method, make sure to call this implementation at the end of your implementation...
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getBinaryDir() const
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
Definition Component.h:116
void onInitComponent() override
Pure virtual hook for the subclass.
bool onClose() override
If you overwrite this method, make sure to call this implementation at the end of your implementation...
MMMPlayerInterfacePrx MMMLoader
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
void onConnectComponent() override
Pure virtual hook for the subclass.
TrajectoryPlayerInterfacePrx trajPlayer
Ui::MMMPlayerGuiPlugin ui
void onExitComponent() override
Hook for subclass.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
Ice::PropertiesPtr createProperties()
::IceInternal::Handle<::Ice::Properties > PropertiesPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
::IceInternal::Handle<::armarx::MMMPlayer > MMMPlayerPtr
Definition MMMPlayer.h:144