26 #include <RobotComponents/gui-plugins/MMMPlayerPlugin/ui_MMMPlayerConfigDialog.h>
32 #include <IceUtil/Time.h>
36 #include <QInputDialog>
39 #include <QPushButton>
44 #include <QMessageBox>
50 #define PROJECT_DEFAULT "Armar4"
51 #define CONFIG_FILE_DEFAULT "data/MMM/punching.xml"
53 #define POSITION_CONTROL 0
54 #define VELOCITY_CONTROL 1
58 addWidget<MMMPlayerWidget>();
65 fileDialog2 =
new QFileDialog();
66 fileDialog2->setModal(
true);
67 fileDialog2->setFileMode(QFileDialog::ExistingFiles);
68 QStringList fileTypes;
69 fileTypes << tr(
"XML (*.xml)") << tr(
"All Files (*.*)");
70 fileDialog2->setNameFilters(fileTypes);
72 jointList =
new QListWidget();
73 updateTimer =
new QTimer(
this);
102 isComponentCreated =
false;
103 if (dialog->needtoCreate)
106 std::string kinematicUnitName = dialog->kinematicUnitComponentProxyFinder->getSelectedProxyName().trimmed().toStdString();
107 std::string kinematicTopic = dialog->kinematicTopicName;
110 std::string packageName(
"RobotComponents");
113 std::string appPath = finder.
getBinaryDir() +
"/TrajectoryPlayerAppRun";
115 pros.push_back(appPath);
118 properties->setProperty(
"ArmarX.TrajectoryPlayer.KinematicUnitName", kinematicUnitName);
119 properties->setProperty(
"ArmarX.TrajectoryPlayer.KinematicTopicName", kinematicTopic);
129 isComponentCreated =
true;
133 usingProxy(dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
134 usingProxy(dialog->trajPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
144 MMMLoader = getProxy<MMMPlayerInterfacePrx>(dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
145 trajPlayer = getProxy<TrajectoryPlayerInterfacePrx>(dialog->trajPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
148 ui.editConfigFile->setText(QString::fromStdString(
configFile));
150 fileDialog2->setDirectory(QString::fromStdString(dir.remove_filename().string()));
159 ui.frameSlider->blockSignals(
true);
160 ui.frameSlider->setMaximum(100);
161 on_loopPlayback_toggled(
false);
180 if (isComponentCreated)
182 getIceManager()->removeObject(dialog->mmmPlayerComponentProxyFinder->getSelectedProxyName().trimmed().toStdString());
204 TrajectoryBasePtr t =
MMMLoader->getJointTraj();
216 connect(
ui.initializeButton, SIGNAL(clicked()),
this, SLOT(on_initializeButton_clicked()));
217 connect(
ui.startButton, SIGNAL(clicked()),
this, SLOT(on_startButton_clicked()));
218 connect(
ui.pauseButton, SIGNAL(clicked()),
this, SLOT(on_pauseButton_clicked()));
219 connect(
ui.stopButton, SIGNAL(clicked()),
this, SLOT(on_stopButton_clicked()));
220 connect(
ui.previewButton, SIGNAL(clicked()),
this, SLOT(on_previewButton_clicked()));
222 connect(
ui.btnSelectConfig, SIGNAL(clicked()), fileDialog2, SLOT(show()));
223 connect(
ui.selectJoints, SIGNAL(clicked()), jointList, SLOT(show()));
224 connect(fileDialog2, SIGNAL(accepted()),
this, SLOT(configFileSelected()));
225 connect(updateTimer, SIGNAL(timeout()),
this, SLOT(updateSlider()));
228 connect(
ui.loopPlayback, SIGNAL(toggled(
bool)),
this, SLOT(on_loopPlayback_toggled(
bool)));
229 connect(
ui.enableRobotPoseUnit, SIGNAL(toggled(
bool)),
this, SLOT(on_enableRobotPoseUnit_toggled(
bool)));
230 connect(
ui.speedSpinBox, SIGNAL(valueChanged(
double)),
this, SLOT(on_spinBoxFPS_valueChanged(
double)));
231 connect(
ui.controlMode, SIGNAL(currentIndexChanged(
int)),
this, SLOT(on_controlMode_changed(
int)));
232 connect(jointList, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(jointListChanged(QListWidgetItem*)));
235 void armarx::MMMPlayerWidget::on_initializeButton_clicked()
239 trajPlayer->resetTrajectoryPlayer(
true);
240 ui.startButton->setEnabled(
true);
241 ui.previewButton->setEnabled(
true);
248 trajPlayer->setEndTime(trajPlayer->getTrajEndTime() /
value);
252 void armarx::MMMPlayerWidget::on_startButton_clicked()
254 trajPlayer->setIsPreview(
false);
255 setSpeed(ui.speedSpinBox->value());
256 on_controlMode_changed(ui.controlMode->currentIndex());
257 bool started = trajPlayer->startTrajectoryPlayer();
262 updateTimer->start(100);
263 ui.initializeButton->setDisabled(started);
264 ui.startButton->setDisabled(started);
265 ui.previewButton->setDisabled(started);
266 ui.motionName->setDisabled(started);
267 ui.controlMode->setDisabled(started);
268 ui.pauseButton->setEnabled(started);
269 ui.pauseButton->setText(
"Pause");
270 ui.btnSelectConfig->setEnabled(
false);
271 ui.speedSpinBox->setDisabled(started);
272 ui.stopButton->setEnabled(started);
273 ui.frameSlider->setDisabled(started);
274 ui.frameSlider->blockSignals(
true);
276 ui.status->setText(
"Real");
281 void armarx::MMMPlayerWidget::on_previewButton_clicked()
283 trajPlayer->setIsPreview(
true);
284 ARMARX_INFO <<
"speed spin box val: " << ui.speedSpinBox->value();
285 setSpeed(ui.speedSpinBox->value());
286 trajPlayer->resetTrajectoryPlayer(
false);
287 bool previewed = trajPlayer->startTrajectoryPlayer();
291 updateTimer->start(100);
292 ui.initializeButton->setDisabled(previewed);
293 ui.startButton->setDisabled(previewed);
294 ui.previewButton->setDisabled(previewed);
295 ui.motionName->setDisabled(previewed);
296 ui.controlMode->setDisabled(previewed);
297 ui.pauseButton->setEnabled(previewed);
298 ui.pauseButton->setText(
"Pause");
299 ui.btnSelectConfig->setEnabled(
false);
300 ui.speedSpinBox->setDisabled(previewed);
301 ui.stopButton->setEnabled(previewed);
302 ui.frameSlider->setDisabled(previewed);
303 ui.frameSlider->blockSignals(
true);
305 ui.status->setText(
"Preview");
309 void MMMPlayerWidget::on_pauseButton_clicked()
315 ui.pauseButton->setText(
"Resume");
319 ui.pauseButton->setText(
"Pause");
322 ui.controlMode->setEnabled(paused);
323 ui.frameSlider->setEnabled(paused);
324 ui.speedSpinBox->setEnabled(paused);
325 ui.frameSlider->blockSignals(!paused);
328 void armarx::MMMPlayerWidget::on_stopButton_clicked()
330 bool stopped = trajPlayer->stopTrajectoryPlayer();
335 ui.initializeButton->setEnabled(stopped);
336 ui.startButton->setDisabled(stopped);
337 ui.previewButton->setEnabled(stopped);
338 ui.pauseButton->setText(
"Pause");
339 ui.btnSelectConfig->setEnabled(
true);
340 ui.motionName->setEnabled(stopped);
341 ui.controlMode->setEnabled(stopped);
342 ui.speedSpinBox->setEnabled(stopped);
343 ui.frameSlider->blockSignals(
false);
344 ui.pauseButton->setDisabled(stopped);
345 ui.stopButton->setDisabled(stopped);
347 ui.status->setText(
"");
351 void MMMPlayerWidget::configFileSelected()
353 configFile = (this->fileDialog2->selectedFiles()[0]).toStdString();
354 ui.editConfigFile->setText(this->fileDialog2->selectedFiles()[0]);
358 ui.frameSlider->setMaximum(100);
368 void MMMPlayerWidget::setupMotionList()
370 Ice::StringSeq motionNames =
MMMLoader->getMotionNames();
371 QObject::disconnect(
ui.motionName, SIGNAL(currentIndexChanged(
int)),
this, SLOT(motionChanged(
int)));
372 ui.motionName->clear();
374 for (
size_t i = 0; i < motionNames.size(); ++i)
376 ui.motionName->addItem(QString::fromStdString(motionNames.at(i)));
379 if (motionNames.size() > 0)
381 ui.motionName->setCurrentIndex(0);
382 connect(
ui.motionName, SIGNAL(currentIndexChanged(
int)),
this, SLOT(motionChanged(
int)));
386 void MMMPlayerWidget::setupJointList()
388 Ice::StringSeq jointNames =
MMMLoader->getJointNames();
389 jointList->blockSignals(
true);
392 for (
size_t i = 0; i < jointNames.size(); ++i)
394 std::string jointName = jointNames.at(i);
395 QListWidgetItem* joint =
new QListWidgetItem(QString::fromStdString(jointName), jointList);
396 joint->setCheckState(Qt::Checked);
399 jointList->blockSignals(
false);
402 void MMMPlayerWidget::updateSlider()
404 double currentTime =
trajPlayer->getCurrentTime();
406 double posPer = currentTime / endTime ;
408 int sliderPos = posPer * 100;
410 ui.frameSlider->blockSignals(
true);
411 ui.frameSlider->setSliderPosition(sliderPos);
412 ui.frameSlider->blockSignals(
false);
413 ui.currentFrame->display(currentTime);
416 void MMMPlayerWidget::jointListChanged(QListWidgetItem* joint)
420 if (joint->checkState() == Qt::Checked)
422 jointState =
trajPlayer->setJointsInUse(joint->text().toStdString(),
true);
426 jointState =
trajPlayer->setJointsInUse(joint->text().toStdString(),
false);
431 joint->setCheckState(Qt::Checked);
435 joint->setCheckState(Qt::Unchecked);
439 void MMMPlayerWidget::motionChanged(
int)
441 std::string motionName =
ui.motionName->currentText().toStdString();
442 ARMARX_INFO <<
"Choosing motion with name '" << motionName <<
"'";
453 void MMMPlayerWidget::on_spinBoxFPS_valueChanged(
double value)
463 void MMMPlayerWidget::on_loopPlayback_toggled(
bool state)
466 ui.loopPlayback->setChecked(state);
469 void MMMPlayerWidget::on_controlMode_changed(
int controlMode)
471 ui.controlMode->setCurrentIndex(controlMode);
483 void armarx::MMMPlayerWidget::on_enableRobotPoseUnit_toggled(
bool state)
485 trajPlayer->enableRobotPoseUnit(state);
486 ui.enableRobotPoseUnit->setChecked(state);