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/gui-plugins/PlatformUnitPlugin/ui_PlatformUnitGuiPlugin.h>
34#include <RobotAPI/interface/core/RobotLocalization.h>
35#include <RobotAPI/interface/units/PlatformUnitInterface.h>
36
37/* Qt headers */
38#include <string>
39
40#include <QMainWindow>
41#include <QTimer>
42
43namespace armarx
44{
45
46 class KeyboardPlatformHookWidget : public QWidget
47 {
48 Q_OBJECT
49 public:
50 KeyboardPlatformHookWidget(QWidget* parent = NULL) : QWidget(parent)
51 {
52 setFocusPolicy(Qt::ClickFocus);
53 }
54
55 signals:
56 void commandKeyPressed(int key);
57 void commandKeyReleased(int key);
58 // QWidget interface
59 protected:
60 void keyPressEvent(QKeyEvent* event) override;
61
62 void keyReleaseEvent(QKeyEvent* event) override;
63 };
64
66
67 /**
68 \class PlatformUnitGuiPlugin
69 \brief This plugin provides a widget with which the PlatformUnit can be controlled.
70 \see PlatformUnitWidget
71 */
73 {
74 Q_OBJECT
75 Q_INTERFACES(ArmarXGuiInterface)
76 Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
77 public:
79
80 QString
81 getPluginName() override
82 {
83 return "PlatformUnitGuiPlugin";
84 }
85 };
86
87 /*!
88 \page RobotAPI-GuiPlugins-PlatformUnitPlugin PlatformUnitPlugin
89 \brief With this widget the PlatformUnit can be controlled.
90
91 \image html PlatformUnitGUI.png "The plugin's ui." width=300px
92 -# The current position and rotation, fields to enter a new target and a button to set the platform in motion.
93 -# A joystick like control widget to move the platform. The platform does not rotate to move in a direction. Up moves the platform forward.
94 -# A joystick like control widget to rotate the platform.
95 -# Be careful to set a maximum velocity before using the joysticks.
96
97 When you add the widget to the Gui, you need to specify the following parameters:
98
99 Parameter Name | Example Value | Required? | Description
100 :---------------- | :-------------: | :-------------- |:--------------------
101 PlatformUnit - Proxy | PlatformUnit | Yes | The name of the platform unit.
102 Platform | Platform | Yes | The name of the platform.
103 */
105 public ArmarXComponentWidgetControllerTemplate<PlatformUnitWidget>,
106 public GlobalRobotPoseLocalizationListener
107 {
108 Q_OBJECT
109 public:
111
113 {
114 }
115
116 // inherited from Component
117 void onInitComponent() override;
118 void onConnectComponent() override;
119 void onDisconnectComponent() override;
120 void onExitComponent() override;
121
122 // slice interface implementation
123 void reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped,
124 const ::Ice::Current& = ::Ice::emptyCurrent) override;
125
126 // inherited of ArmarXWidget
127 static QString
129 {
130 return "RobotControl.PlatformUnitGUI";
131 }
132
133 static QIcon
135 {
136 return QIcon("://icons/retro_joystick2.svg");
137 }
138
139 QPointer<QDialog> getConfigDialog(QWidget* parent = 0) override;
140 void loadSettings(QSettings* settings) override;
141 void saveSettings(QSettings* settings) override;
142 void configured() override;
143
144 public slots:
145
146 void moveTo();
147
148 void setNewPlatformPoseLabels(float x, float y, float alpha);
149 void setNewTargetPoseLabels(float x, float y, float alpha);
150
151 void startControlTimer();
152 void stopControlTimer();
153
154 protected:
155 void connectSlots();
156
157 Ui::PlatformUnitGuiPlugin ui;
158
159 private slots:
160 /**
161 \brief Checks the joystick contol widgets speedCtrl and rotaCtrl and performs a move if necessary.
162 Activated when ctrlEvaluationTimer times out.
163 */
164 void controlTimerTick();
165
166 /**
167 \brief Stops the platform
168 */
169 void stopPlatform();
170 void controlPlatformWithKeyboard(int key);
171 void stopPlatformWithKeyboard(int key);
172 void keyboardVelocityControl();
173
174 private:
175 std::string platformUnitProxyName;
176 std::string platformName;
177
178 PlatformUnitInterfacePrx platformUnitProxy;
179
180 QPointer<QWidget> __widget;
181 QPointer<PlatformUnitConfigDialog> dialog;
182
183 /**
184 * \brief A Joystick control for the platform speed.
185 * (currently the velocity control is nyi is the simulator so this is emulated by
186 * adding a delta to the target positions)
187 */
188 QPointer<JoystickControlWidget> speedCtrl;
189
190 /**
191 * \brief A Joystick control for the platform rotation.
192 */
193 QPointer<JoystickControlWidget> rotaCtrl;
194
195 /**
196 * \brief A timer to evaluate the speedCtrl and rotaCtrl
197 */
198 QTimer ctrlEvaluationTimer;
199 QTimer stopPlatformTimer;
200 QTimer keyboardVelocityTimer;
201 /**
202 * \brief Holds the last reported platform rotation. (required to emulate the speed control)
203 */
204 ::Ice::Float platformRotation;
205
206 /**
207 * \brief Whether the platform is moved with speedCtrl.
208 */
209 bool platformMoves;
210
211 /**
212 * \brief Whether the platform is moved with speedCtrl
213 */
214 ::Ice::Float platformRotationAtMoveStart;
215
216 /**
217 * \brief The tick rate (in ms) for the ctrlEvaluationTimer.
218 */
219 static const int CONTROL_TICK_RATE = 50;
220
221 QSet<int> pressedKeys;
222
223 float currentKeyboardVelocityX = 0;
224 float currentKeyboardVelocityY = 0;
225 float currentKeyboardVelocityAlpha = 0;
226 float acceleration = 0.2;
227 float deceleration = 0.8;
228
229 // ArmarXWidgetController interface
230 public:
231 QPointer<QWidget> getWidget() override;
232 };
233
234 using PlatformUnitGuiPluginPtr = std::shared_ptr<PlatformUnitWidget>;
235} // 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.
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.
Ui::PlatformUnitGuiPlugin ui
void onExitComponent() override
Hook for subclass.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< PlatformUnitWidget > PlatformUnitGuiPluginPtr