26 #include <Eigen/Geometry>
30 #include <RobotAPI/gui-plugins/PlatformUnitPlugin/ui_PlatformUnitConfigDialog.h>
35 #include <QHBoxLayout>
38 #include <QPushButton>
46 #include <SimoxUtility/math/convert/mat3f_to_rpy.h>
48 #include <RobotAPI/interface/core/RobotLocalization.h>
54 addWidget<PlatformUnitWidget>();
58 platformUnitProxyName(
"PlatformUnit"),
59 platformName(
"Platform"),
62 ctrlEvaluationTimer{},
67 ui.setupUi(getWidget());
70 speedCtrl = speed.get();
74 rotaCtrl = rotat.get();
77 ui.gridLayout_2->addWidget(rotat.release(), 2, 0, 1, 2);
78 ui.gridLayout_3->addWidget(speed.release(), 2, 0, 1, 2);
80 ctrlEvaluationTimer.setSingleShot(
false);
81 keyboardVelocityTimer.setInterval(50);
82 stopPlatformTimer.setInterval(100);
83 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(stopControlTimer()));
84 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(stopPlatform()));
87 connect(getWidget().
data(),
88 SIGNAL(commandKeyPressed(
int)),
90 SLOT(controlPlatformWithKeyboard(
int)));
91 connect(getWidget().
data(),
92 SIGNAL(commandKeyReleased(
int)),
94 SLOT(stopPlatformWithKeyboard(
int)));
108 platformUnitProxy = getProxy<PlatformUnitInterfacePrx>(platformUnitProxyName);
131 dialog->ui->editPlatformName->setText(QString::fromStdString(platformName));
132 return qobject_cast<PlatformUnitConfigDialog*>(dialog);
138 platformUnitProxyName = dialog->finder->getSelectedProxyName().toStdString();
139 platformName = dialog->ui->editPlatformName->text().toStdString();
145 platformUnitProxyName =
146 settings->value(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName))
149 platformName = settings->value(
"platformName", QString::fromStdString(platformName))
157 settings->setValue(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName));
158 settings->setValue(
"platformName", QString::fromStdString(platformName));
164 connect(
ui.buttonMoveToPosition, SIGNAL(clicked()),
this, SLOT(
moveTo()), Qt::UniqueConnection);
165 connect(&ctrlEvaluationTimer,
168 SLOT(controlTimerTick()),
169 Qt::UniqueConnection);
170 connect(&keyboardVelocityTimer,
173 SLOT(keyboardVelocityControl()),
174 Qt::UniqueConnection);
175 connect(speedCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
177 speedCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
178 connect(rotaCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
180 rotaCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
181 connect(speedCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
182 connect(speedCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
183 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
184 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
186 ui.buttonStopPlatform, SIGNAL(pressed()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
193 ::Ice::Float positionX =
ui.editTargetPositionX->text().toFloat();
194 ::Ice::Float positionY =
ui.editTargetPositionY->text().toFloat();
198 platformUnitProxy->moveTo(positionX, positionY, rotation, posAcc, rotAcc);
204 ui.labelCurrentPositionX->setText(QString::number(
x));
205 ui.labelCurrentPositionY->setText(QString::number(y));
206 ui.labelCurrentRotation->setText(QString::number(alpha));
212 ui.editTargetPositionX->setText(QString::number(
x));
213 ui.editTargetPositionY->setText(QString::number(y));
214 ui.editTargetRotation->setText(QString::number(alpha));
220 ctrlEvaluationTimer.start(CONTROL_TICK_RATE);
226 ctrlEvaluationTimer.stop();
227 speedCtrl->setNibble({0, 0});
228 rotaCtrl->setNibble({0, 0});
233 const ::Ice::Current&)
235 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
236 const float x = global_T_robot.translation().x();
237 const float y = global_T_robot.translation().y();
238 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
241 QMetaObject::invokeMethod(
242 this,
"setNewPlatformPoseLabels", Q_ARG(
float,
x), Q_ARG(
float, y), Q_ARG(
float, yaw));
243 platformRotation = yaw;
247 PlatformUnitWidget::stopPlatform()
249 platformUnitProxy->stopPlatform();
253 PlatformUnitWidget::controlPlatformWithKeyboard(
int key)
255 pressedKeys.insert(key);
256 if (!ctrlEvaluationTimer.isActive())
258 ctrlEvaluationTimer.start();
260 if (!keyboardVelocityTimer.isActive())
262 keyboardVelocityControl();
263 keyboardVelocityTimer.start();
268 PlatformUnitWidget::stopPlatformWithKeyboard(
int key)
270 pressedKeys.remove(key);
272 if (!keyboardVelocityTimer.isActive())
274 keyboardVelocityControl();
275 keyboardVelocityTimer.start();
280 PlatformUnitWidget::keyboardVelocityControl()
282 if (!pressedKeys.contains(Qt::Key_A) && !pressedKeys.contains(Qt::Key_D))
284 currentKeyboardVelocityX *= deceleration;
285 if (fabs(currentKeyboardVelocityX) < 0.001)
287 currentKeyboardVelocityX = 0;
290 if (!pressedKeys.contains(Qt::Key_W) && !pressedKeys.contains(Qt::Key_S))
292 currentKeyboardVelocityY *= deceleration;
293 if (fabs(currentKeyboardVelocityY) < 0.001)
295 currentKeyboardVelocityY = 0;
298 if (!pressedKeys.contains(Qt::Key_Q) && !pressedKeys.contains(Qt::Key_E))
300 currentKeyboardVelocityAlpha *= deceleration;
301 if (fabs(currentKeyboardVelocityAlpha) < 0.001)
303 currentKeyboardVelocityAlpha = 0;
307 for (
auto key : pressedKeys)
312 currentKeyboardVelocityAlpha -= acceleration;
315 currentKeyboardVelocityAlpha += acceleration;
318 currentKeyboardVelocityY -= acceleration;
321 currentKeyboardVelocityY += acceleration;
324 currentKeyboardVelocityX -= acceleration;
327 currentKeyboardVelocityX += acceleration;
334 currentKeyboardVelocityAlpha =
std::max(-1.f, currentKeyboardVelocityAlpha);
335 currentKeyboardVelocityAlpha =
std::min(1.f, currentKeyboardVelocityAlpha);
336 currentKeyboardVelocityX =
std::max(-1.f, currentKeyboardVelocityX);
337 currentKeyboardVelocityX =
std::min(1.f, currentKeyboardVelocityX);
338 currentKeyboardVelocityY =
std::max(-1.f, currentKeyboardVelocityY);
339 currentKeyboardVelocityY =
std::min(1.f, currentKeyboardVelocityY);
341 float y = sin(acos(currentKeyboardVelocityAlpha));
342 speedCtrl->setNibble(QPointF(currentKeyboardVelocityX, currentKeyboardVelocityY));
343 rotaCtrl->setNibble(QPointF(currentKeyboardVelocityAlpha, -y));
358 PlatformUnitWidget::controlTimerTick()
360 float translationFactor =
ui.maxTranslationSpeed->value();
361 float rotationFactor =
ui.maxRotationSpeed->value() * -1;
362 float rotationVel = rotaCtrl->getRotation() / M_PI_2 * rotationFactor;
364 << speedCtrl->getPosition().x() * translationFactor <<
", "
365 << speedCtrl->getPosition().y() * translationFactor <<
")"
366 <<
", \t rotation speed: " << (rotationVel);
368 platformUnitProxy->move(speedCtrl->getPosition().x() * translationFactor,
369 -1 * speedCtrl->getPosition().y() * translationFactor,
372 if (speedCtrl->getPosition().x() == 0 && speedCtrl->getPosition().y() == 0 &&
373 rotaCtrl->getRotation() == 0)
382 switch (event->key())
390 if (!event->isAutoRepeat())
395 QWidget::keyPressEvent(event);
401 switch (event->key())
409 if (!event->isAutoRepeat())
414 QWidget::keyReleaseEvent(event);