26 #include <RobotAPI/gui-plugins/PlatformUnitPlugin/ui_PlatformUnitConfigDialog.h>
29 #include <Eigen/Geometry>
34 #include <QPushButton>
37 #include <QHBoxLayout>
40 #include <RobotAPI/interface/core/RobotLocalization.h>
41 #include <SimoxUtility/math/convert/mat3f_to_rpy.h>
51 addWidget<PlatformUnitWidget>();
56 platformUnitProxyName(
"PlatformUnit"),
57 platformName(
"Platform"),
60 ctrlEvaluationTimer {},
65 ui.setupUi(getWidget());
68 speedCtrl = speed.get();
72 rotaCtrl = rotat.get();
75 ui.gridLayout_2->addWidget(rotat.release(), 2, 0, 1, 2);
76 ui.gridLayout_3->addWidget(speed.release(), 2, 0, 1, 2);
78 ctrlEvaluationTimer.setSingleShot(
false);
79 keyboardVelocityTimer.setInterval(50);
80 stopPlatformTimer.setInterval(100);
81 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(stopControlTimer()));
82 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(stopPlatform()));
85 connect(getWidget().
data(), SIGNAL(commandKeyPressed(
int)),
this, SLOT(controlPlatformWithKeyboard(
int)));
86 connect(getWidget().
data(), SIGNAL(commandKeyReleased(
int)),
this, SLOT(stopPlatformWithKeyboard(
int)));
101 platformUnitProxy = getProxy<PlatformUnitInterfacePrx>(platformUnitProxyName);
124 dialog->ui->editPlatformName->setText(QString::fromStdString(platformName));
125 return qobject_cast<PlatformUnitConfigDialog*>(dialog);
131 platformUnitProxyName = dialog->finder->getSelectedProxyName().toStdString();
132 platformName = dialog->ui->editPlatformName->text().toStdString();
138 platformUnitProxyName = settings->value(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName)).toString().toStdString();
139 platformName = settings->value(
"platformName", QString::fromStdString(platformName)).toString().toStdString();
145 settings->setValue(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName));
146 settings->setValue(
"platformName", QString::fromStdString(platformName));
152 connect(
ui.buttonMoveToPosition, SIGNAL(clicked()),
this, SLOT(
moveTo()), Qt::UniqueConnection);
153 connect(&ctrlEvaluationTimer, SIGNAL(timeout()),
this, SLOT(controlTimerTick()), Qt::UniqueConnection);
154 connect(&keyboardVelocityTimer, SIGNAL(timeout()),
this, SLOT(keyboardVelocityControl()), Qt::UniqueConnection);
155 connect(speedCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
156 connect(speedCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
157 connect(rotaCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
158 connect(rotaCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
159 connect(speedCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
160 connect(speedCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
161 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
162 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
163 connect(
ui.buttonStopPlatform, SIGNAL(pressed()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
170 ::Ice::Float positionX =
ui.editTargetPositionX->text().toFloat();
171 ::Ice::Float positionY =
ui.editTargetPositionY->text().toFloat();
175 platformUnitProxy->moveTo(positionX, positionY, rotation, posAcc, rotAcc);
181 ui.labelCurrentPositionX->setText(QString::number(x));
182 ui.labelCurrentPositionY->setText(QString::number(y));
183 ui.labelCurrentRotation->setText(QString::number(alpha));
189 ui.editTargetPositionX->setText(QString::number(x));
190 ui.editTargetPositionY->setText(QString::number(y));
191 ui.editTargetRotation->setText(QString::number(alpha));
197 ctrlEvaluationTimer.start(CONTROL_TICK_RATE);
203 ctrlEvaluationTimer.stop();
204 speedCtrl->setNibble({0, 0});
205 rotaCtrl->setNibble({0, 0});
211 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
212 const float x = global_T_robot.translation().x();
213 const float y = global_T_robot.translation().y();
214 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
217 QMetaObject::invokeMethod(
this,
"setNewPlatformPoseLabels", Q_ARG(
float, x), Q_ARG(
float, y), Q_ARG(
float, yaw));
218 platformRotation = yaw;
222 void PlatformUnitWidget::stopPlatform()
224 platformUnitProxy->stopPlatform();
228 void PlatformUnitWidget::controlPlatformWithKeyboard(
int key)
230 pressedKeys.insert(key);
231 if (!ctrlEvaluationTimer.isActive())
233 ctrlEvaluationTimer.start();
235 if (!keyboardVelocityTimer.isActive())
237 keyboardVelocityControl();
238 keyboardVelocityTimer.start();
243 void PlatformUnitWidget::stopPlatformWithKeyboard(
int key)
245 pressedKeys.remove(key);
247 if (!keyboardVelocityTimer.isActive())
249 keyboardVelocityControl();
250 keyboardVelocityTimer.start();
255 void PlatformUnitWidget::keyboardVelocityControl()
257 if (!pressedKeys.contains(Qt::Key_A) && !pressedKeys.contains(Qt::Key_D))
259 currentKeyboardVelocityX *= deceleration;
260 if (fabs(currentKeyboardVelocityX) < 0.001)
262 currentKeyboardVelocityX = 0;
265 if (!pressedKeys.contains(Qt::Key_W) && !pressedKeys.contains(Qt::Key_S))
267 currentKeyboardVelocityY *= deceleration;
268 if (fabs(currentKeyboardVelocityY) < 0.001)
270 currentKeyboardVelocityY = 0;
273 if (!pressedKeys.contains(Qt::Key_Q) && !pressedKeys.contains(Qt::Key_E))
275 currentKeyboardVelocityAlpha *= deceleration;
276 if (fabs(currentKeyboardVelocityAlpha) < 0.001)
278 currentKeyboardVelocityAlpha = 0;
282 for (
auto key : pressedKeys)
287 currentKeyboardVelocityAlpha -= acceleration;
290 currentKeyboardVelocityAlpha += acceleration;
293 currentKeyboardVelocityY -= acceleration;
296 currentKeyboardVelocityY += acceleration;
299 currentKeyboardVelocityX -= acceleration;
302 currentKeyboardVelocityX += acceleration;
309 currentKeyboardVelocityAlpha =
std::max(-1.f, currentKeyboardVelocityAlpha);
310 currentKeyboardVelocityAlpha =
std::min(1.f, currentKeyboardVelocityAlpha);
311 currentKeyboardVelocityX =
std::max(-1.f, currentKeyboardVelocityX);
312 currentKeyboardVelocityX =
std::min(1.f, currentKeyboardVelocityX);
313 currentKeyboardVelocityY =
std::max(-1.f, currentKeyboardVelocityY);
314 currentKeyboardVelocityY =
std::min(1.f, currentKeyboardVelocityY);
316 float y = sin(acos(currentKeyboardVelocityAlpha));
317 speedCtrl->setNibble(QPointF(currentKeyboardVelocityX, currentKeyboardVelocityY));
318 rotaCtrl->setNibble(QPointF(currentKeyboardVelocityAlpha, -y));
333 void PlatformUnitWidget::controlTimerTick()
335 float translationFactor =
ui.maxTranslationSpeed->value();
336 float rotationFactor =
ui.maxRotationSpeed->value() * -1;
337 float rotationVel = rotaCtrl->getRotation() / M_PI_2 * rotationFactor;
339 <<
"Translation speed: (" << speedCtrl->getPosition().x() * translationFactor
340 <<
", " << speedCtrl->getPosition().y() * translationFactor <<
")"
341 <<
", \t rotation speed: " << (rotationVel);
343 platformUnitProxy->move(speedCtrl->getPosition().x() * translationFactor,
344 -1 * speedCtrl->getPosition().y() * translationFactor,
347 if (speedCtrl->getPosition().x() == 0
348 && speedCtrl->getPosition().y() == 0
349 && rotaCtrl->getRotation() == 0)
358 switch (event->key())
366 if (!event->isAutoRepeat())
371 QWidget::keyPressEvent(event);
377 switch (event->key())
385 if (!event->isAutoRepeat())
390 QWidget::keyReleaseEvent(event);