PlatformUnitGuiPlugin.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* \package ArmarX::Component::ObjectExaminerGuiPlugin
17* \author Nikolaus Vahrenkamp ( vahrenkamp at kit dot edu)
18* \copyright 2012
19* \license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21
22*/
23
24#pragma once
25
26/* ArmarX headers */
28
32
33#include <RobotAPI/interface/core/RobotLocalization.h>
34#include <RobotAPI/interface/units/PlatformUnitInterface.h>
35
36/* Qt headers */
37#include <string>
38
39#include <QMainWindow>
40#include <QTimer>
41
42// C++ includes
43#include <memory>
44
45// ui_PlatformUnitGuiPlugin.h is included by the .cpp, not here: moc textually inlines every
46// #include it can resolve, and parsing the uic-generated header alongside this one
47// makes moc mis-qualify this class as Ui::armarx::*.
48namespace Ui
49{
50 class PlatformUnitGuiPlugin;
51}
52
53namespace armarx
54{
55
56 class KeyboardPlatformHookWidget : public QWidget
57 {
58 Q_OBJECT
59 public:
60 KeyboardPlatformHookWidget(QWidget* parent = NULL) : QWidget(parent)
61 {
62 setFocusPolicy(Qt::ClickFocus);
63 }
64
65 signals:
66 void commandKeyPressed(int key);
67 void commandKeyReleased(int key);
68 // QWidget interface
69 protected:
70 void keyPressEvent(QKeyEvent* event) override;
71
72 void keyReleaseEvent(QKeyEvent* event) override;
73 };
74
76
77 /**
78 \class PlatformUnitGuiPlugin
79 \brief This plugin provides a widget with which the PlatformUnit can be controlled.
80 \see PlatformUnitWidget
81 */
83 {
84 Q_OBJECT
85 Q_INTERFACES(ArmarXGuiInterface)
86 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
87 public:
89
90 QString
91 getPluginName() override
92 {
93 return "PlatformUnitGuiPlugin";
94 }
95 };
96
97 /*!
98 \page RobotAPI-GuiPlugins-PlatformUnitPlugin PlatformUnitPlugin
99 \brief With this widget the PlatformUnit can be controlled.
100
101 \image html PlatformUnitGUI.png "The plugin's ui->" width=300px
102 -# The current position and rotation, fields to enter a new target and a button to set the platform in motion.
103 -# A joystick like control widget to move the platform. The platform does not rotate to move in a direction. Up moves the platform forward.
104 -# A joystick like control widget to rotate the platform.
105 -# Be careful to set a maximum velocity before using the joysticks.
106
107 When you add the widget to the Gui, you need to specify the following parameters:
108
109 Parameter Name | Example Value | Required? | Description
110 :---------------- | :-------------: | :-------------- |:--------------------
111 PlatformUnit - Proxy | PlatformUnit | Yes | The name of the platform unit.
112 Platform | Platform | Yes | The name of the platform.
113 */
115 public ArmarXComponentWidgetControllerTemplate<PlatformUnitWidget>,
116 public GlobalRobotPoseLocalizationListener
117 {
118 Q_OBJECT
119 public:
121
122 // Defined in the .cpp, where Ui::PlatformUnitGuiPlugin is complete.
124 // inherited from Component
125 void onInitComponent() override;
126 void onConnectComponent() override;
127 void onDisconnectComponent() override;
128 void onExitComponent() override;
129
130 // slice interface implementation
131 void reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped,
132 const ::Ice::Current& = ::Ice::emptyCurrent) override;
133
134 // inherited of ArmarXWidget
135 static QString
137 {
138 return "RobotControl.PlatformUnitGUI";
139 }
140
141 static QIcon
143 {
144 return QIcon("://icons/retro_joystick2.svg");
145 }
146
147 QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
148 void loadSettings(QSettings* settings) override;
149 void saveSettings(QSettings* settings) override;
150 void configured() override;
151
152 public slots:
153
154 void moveTo();
155
156 void setNewPlatformPoseLabels(float x, float y, float alpha);
157 void setNewTargetPoseLabels(float x, float y, float alpha);
158
159 void startControlTimer();
160 void stopControlTimer();
161
162 protected:
163 void connectSlots();
164
165 std::unique_ptr<Ui::PlatformUnitGuiPlugin> ui;
166
167 private slots:
168 /**
169 \brief Checks the joystick contol widgets speedCtrl and rotaCtrl and performs a move if necessary.
170 Activated when ctrlEvaluationTimer times out.
171 */
172 void controlTimerTick();
173
174 /**
175 \brief Stops the platform
176 */
177 void stopPlatform();
178 void controlPlatformWithKeyboard(int key);
179 void stopPlatformWithKeyboard(int key);
180 void keyboardVelocityControl();
181
182 private:
183 std::string platformUnitProxyName;
184 std::string platformName;
185
186 PlatformUnitInterfacePrx platformUnitProxy;
187
188 QPointer<QWidget> __widget;
189 QPointer<PlatformUnitConfigDialog> dialog;
190
191 /**
192 * \brief A Joystick control for the platform speed.
193 * (currently the velocity control is nyi is the simulator so this is emulated by
194 * adding a delta to the target positions)
195 */
196 QPointer<JoystickControlWidget> speedCtrl;
197
198 /**
199 * \brief A Joystick control for the platform rotation.
200 */
201 QPointer<JoystickControlWidget> rotaCtrl;
202
203 /**
204 * \brief A timer to evaluate the speedCtrl and rotaCtrl
205 */
206 QTimer ctrlEvaluationTimer;
207 QTimer stopPlatformTimer;
208 QTimer keyboardVelocityTimer;
209 /**
210 * \brief Holds the last reported platform rotation. (required to emulate the speed control)
211 */
212 ::Ice::Float platformRotation;
213
214 /**
215 * \brief Whether the platform is moved with speedCtrl.
216 */
217 bool platformMoves;
218
219 /**
220 * \brief Whether the platform is moved with speedCtrl
221 */
222 ::Ice::Float platformRotationAtMoveStart;
223
224 /**
225 * \brief The tick rate (in ms) for the ctrlEvaluationTimer.
226 */
227 static const int CONTROL_TICK_RATE = 50;
228
229 QSet<int> pressedKeys;
230
231 float currentKeyboardVelocityX = 0;
232 float currentKeyboardVelocityY = 0;
233 float currentKeyboardVelocityAlpha = 0;
234 float acceleration = 0.2;
235 float deceleration = 0.8;
236
237 // ArmarXWidgetController interface
238 public:
239 QPointer<QWidget> getWidget() override;
240 };
241
242 using PlatformUnitGuiPluginPtr = std::shared_ptr<PlatformUnitWidget>;
243} // namespace armarx
The main gui interface.
void keyReleaseEvent(QKeyEvent *event) override
void keyPressEvent(QKeyEvent *event) override
KeyboardPlatformHookWidget(QWidget *parent=NULL)
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void setNewPlatformPoseLabels(float x, float y, float alpha)
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
std::unique_ptr< Ui::PlatformUnitGuiPlugin > ui
void setNewTargetPoseLabels(float x, float y, float alpha)
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
QPointer< QWidget > getWidget() override
getWidget returns a pointer to the a widget of this controller.
void onConnectComponent() override
Pure virtual hook for the subclass.
void reportGlobalRobotPose(const ::armarx::TransformStamped &transformStamped, const ::Ice::Current &=::Ice::emptyCurrent) override
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void onExitComponent() override
Hook for subclass.
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< PlatformUnitWidget > PlatformUnitGuiPluginPtr