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