26#include <RobotAPI/gui-plugins/PlatformUnitPlugin/ui_PlatformUnitGuiPlugin.h>
28#include <Eigen/Geometry>
32#include <RobotAPI/gui-plugins/PlatformUnitPlugin/ui_PlatformUnitConfigDialog.h>
48#include <SimoxUtility/math/convert/mat3f_to_rpy.h>
50#include <RobotAPI/interface/core/RobotLocalization.h>
62 platformUnitProxyName(
"PlatformUnit"),
63 platformName(
"Platform"),
66 ctrlEvaluationTimer{},
71 ui = std::make_unique<Ui::PlatformUnitGuiPlugin>();
75 speedCtrl = speed.get();
76 speedCtrl->setSteps(0);
79 rotaCtrl = rotat.get();
80 rotaCtrl->setSteps(0);
82 ui->gridLayout_2->addWidget(rotat.release(), 2, 0, 1, 2);
83 ui->gridLayout_3->addWidget(speed.release(), 2, 0, 1, 2);
85 ctrlEvaluationTimer.setSingleShot(
false);
86 keyboardVelocityTimer.setInterval(50);
87 stopPlatformTimer.setInterval(100);
88 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(
stopControlTimer()));
89 connect(&stopPlatformTimer, SIGNAL(timeout()),
this, SLOT(stopPlatform()));
93 SIGNAL(commandKeyPressed(
int)),
95 SLOT(controlPlatformWithKeyboard(
int)));
97 SIGNAL(commandKeyReleased(
int)),
99 SLOT(stopPlatformWithKeyboard(
int)));
136 dialog->ui->editPlatformName->setText(QString::fromStdString(platformName));
137 return qobject_cast<PlatformUnitConfigDialog*>(dialog);
143 platformUnitProxyName = dialog->finder->getSelectedProxyName().toStdString();
144 platformName = dialog->ui->editPlatformName->text().toStdString();
150 platformUnitProxyName =
151 settings->value(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName))
154 platformName = settings->value(
"platformName", QString::fromStdString(platformName))
162 settings->setValue(
"platformUnitProxyName", QString::fromStdString(platformUnitProxyName));
163 settings->setValue(
"platformName", QString::fromStdString(platformName));
169 connect(
ui->buttonMoveToPosition, SIGNAL(clicked()),
this, SLOT(
moveTo()), Qt::UniqueConnection);
170 connect(&ctrlEvaluationTimer,
173 SLOT(controlTimerTick()),
174 Qt::UniqueConnection);
175 connect(&keyboardVelocityTimer,
178 SLOT(keyboardVelocityControl()),
179 Qt::UniqueConnection);
180 connect(speedCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
182 speedCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
183 connect(rotaCtrl, SIGNAL(pressed()),
this, SLOT(
startControlTimer()), Qt::UniqueConnection);
185 rotaCtrl, SIGNAL(pressed()), &keyboardVelocityTimer, SLOT(stop()), Qt::UniqueConnection);
186 connect(speedCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
187 connect(speedCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
188 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
189 connect(rotaCtrl, SIGNAL(released()),
this, SLOT(
stopControlTimer()), Qt::UniqueConnection);
191 ui->buttonStopPlatform, SIGNAL(pressed()),
this, SLOT(stopPlatform()), Qt::UniqueConnection);
198 ::Ice::Float positionX =
ui->editTargetPositionX->text().toFloat();
199 ::Ice::Float positionY =
ui->editTargetPositionY->text().toFloat();
200 ::Ice::Float rotation =
ui->editTargetRotation->text().toFloat();
201 ::Ice::Float posAcc = 10.0f;
202 ::Ice::Float rotAcc = 0.1f;
203 platformUnitProxy->moveTo(positionX, positionY, rotation, posAcc, rotAcc);
209 ui->labelCurrentPositionX->setText(QString::number(
x));
210 ui->labelCurrentPositionY->setText(QString::number(y));
211 ui->labelCurrentRotation->setText(QString::number(alpha));
217 ui->editTargetPositionX->setText(QString::number(
x));
218 ui->editTargetPositionY->setText(QString::number(y));
219 ui->editTargetRotation->setText(QString::number(alpha));
225 ctrlEvaluationTimer.start(CONTROL_TICK_RATE);
231 ctrlEvaluationTimer.stop();
232 speedCtrl->setNibble({0, 0});
233 rotaCtrl->setNibble({0, 0});
238 const ::Ice::Current&)
240 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
241 const float x = global_T_robot.translation().x();
242 const float y = global_T_robot.translation().y();
243 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
246 QMetaObject::invokeMethod(
247 this,
"setNewPlatformPoseLabels", Q_ARG(
float,
x), Q_ARG(
float, y), Q_ARG(
float, yaw));
248 platformRotation = yaw;
252PlatformUnitWidget::stopPlatform()
254 platformUnitProxy->stopPlatform();
258PlatformUnitWidget::controlPlatformWithKeyboard(
int key)
260 pressedKeys.insert(key);
261 if (!ctrlEvaluationTimer.isActive())
263 ctrlEvaluationTimer.start();
265 if (!keyboardVelocityTimer.isActive())
267 keyboardVelocityControl();
268 keyboardVelocityTimer.start();
273PlatformUnitWidget::stopPlatformWithKeyboard(
int key)
275 pressedKeys.remove(key);
277 if (!keyboardVelocityTimer.isActive())
279 keyboardVelocityControl();
280 keyboardVelocityTimer.start();
285PlatformUnitWidget::keyboardVelocityControl()
287 if (!pressedKeys.contains(Qt::Key_A) && !pressedKeys.contains(Qt::Key_D))
289 currentKeyboardVelocityX *= deceleration;
290 if (fabs(currentKeyboardVelocityX) < 0.001)
292 currentKeyboardVelocityX = 0;
295 if (!pressedKeys.contains(Qt::Key_W) && !pressedKeys.contains(Qt::Key_S))
297 currentKeyboardVelocityY *= deceleration;
298 if (fabs(currentKeyboardVelocityY) < 0.001)
300 currentKeyboardVelocityY = 0;
303 if (!pressedKeys.contains(Qt::Key_Q) && !pressedKeys.contains(Qt::Key_E))
305 currentKeyboardVelocityAlpha *= deceleration;
306 if (fabs(currentKeyboardVelocityAlpha) < 0.001)
308 currentKeyboardVelocityAlpha = 0;
312 for (
auto key : pressedKeys)
317 currentKeyboardVelocityAlpha -= acceleration;
320 currentKeyboardVelocityAlpha += acceleration;
323 currentKeyboardVelocityY -= acceleration;
326 currentKeyboardVelocityY += acceleration;
329 currentKeyboardVelocityX -= acceleration;
332 currentKeyboardVelocityX += acceleration;
339 currentKeyboardVelocityAlpha = std::max(-1.f, currentKeyboardVelocityAlpha);
340 currentKeyboardVelocityAlpha = std::min(1.f, currentKeyboardVelocityAlpha);
341 currentKeyboardVelocityX = std::max(-1.f, currentKeyboardVelocityX);
342 currentKeyboardVelocityX = std::min(1.f, currentKeyboardVelocityX);
343 currentKeyboardVelocityY = std::max(-1.f, currentKeyboardVelocityY);
344 currentKeyboardVelocityY = std::min(1.f, currentKeyboardVelocityY);
346 float y = sin(acos(currentKeyboardVelocityAlpha));
347 speedCtrl->setNibble(QPointF(currentKeyboardVelocityX, currentKeyboardVelocityY));
348 rotaCtrl->setNibble(QPointF(currentKeyboardVelocityAlpha, -y));
363PlatformUnitWidget::controlTimerTick()
365 float translationFactor =
ui->maxTranslationSpeed->value();
366 float rotationFactor =
ui->maxRotationSpeed->value() * -1;
367 float rotationVel = rotaCtrl->getRotation() / M_PI_2 * rotationFactor;
369 << speedCtrl->getPosition().x() * translationFactor <<
", "
370 << speedCtrl->getPosition().y() * translationFactor <<
")"
371 <<
", \t rotation speed: " << (rotationVel);
373 platformUnitProxy->move(speedCtrl->getPosition().x() * translationFactor,
374 -1 * speedCtrl->getPosition().y() * translationFactor,
377 if (speedCtrl->getPosition().x() == 0 && speedCtrl->getPosition().y() == 0 &&
378 rotaCtrl->getRotation() == 0)
387 switch (event->key())
395 if (!event->isAutoRepeat())
400 QWidget::keyPressEvent(event);
406 switch (event->key())
414 if (!event->isAutoRepeat())
419 QWidget::keyReleaseEvent(event);
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
#define ARMARX_INFO
The normal logging level.
This file offers overloads of toIce() and fromIce() functions for STL container types.