MIRA
DriveView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_DRIVEVIEW_H_
48 #define _MIRA_DRIVEVIEW_H_
49 
50 #include <QPushButton>
51 #include <QTimer>
52 #include <QKeyEvent>
53 
55 #include <rcp/ViewPart.h>
56 #include <views/PropertyViewPage.h>
57 #include <fw/Framework.h>
58 #include <fw/ServiceProperty.h>
60 
61 #include <ui_DriveView.h>
62 
63 namespace mira { namespace robot {
64 
66 
97 class DriveView : public ViewPart
98 {
100  ("Category", "Robot")
101  ("Name", "DriveView")
102  ("Description", "View for driving a robot around"))
103 
104 public:
106  DriveView();
107 
109  virtual ~DriveView();
110 
112  template <typename Reflector>
113  void reflect(Reflector& r)
114  {
115  r.property("VelocityIncrement", velocityIncrement,
116  "Increment for velocity in [m/s]", 0.1f);
117  r.property("WatchdogTimeout", watchdogTimeout,
118  "Watchdog for stopping when no commands are signaled for "
119  "a given time", Duration::seconds(5));
120  r.property("DriveService", driveService,
122  "Service used for driving", ServiceProperty("IDrive"));
124  "The channel used to check motorstop status", ui);
125  }
126 
128  virtual Object* getAdapter(const Class& adapter);
129 
130 protected:
132  virtual QWidget* createPartControl();
133 
134  void driveServiceChanged();
135 
136 protected:
139 
142 
145 
148 
149 private:
150  PropertyViewPage* mControl;
151  class UI;
152  UI* ui;
153 };
154 
156 
158 
159 class DriveView::UI : public QWidget, public IAuthorityProvider, protected Ui::DriveViewWidget
160 {
161  Q_OBJECT
162 public:
163  UI(DriveView* parent);
164 
165 public slots:
166  void onForward();
167  void onBackward();
168  void onLeft();
169  void onRight();
170  void onStop();
171  void onResetMotorStop();
172  void onSuspendBumper();
173  void onResetOdometry();
174  void onEnableMotors();
175  void onDisableMotors();
176  void tick();
177  void updateService(bool serviceChanged = false);
178  void onGrabKeyboard(bool activate);
179  void onMute(bool mute);
180 
181 public:
182  virtual Authority& getAuthority() { return mAuthority; }
183  void onMotorstop(ChannelRead<bool> status);
184 
185 public:
186  float mTransSpeed;
187  float mRotSpeed;
188 
189  QTimer* mCommandTimer;
190  QTimer* mServiceTimer;
191  Authority mAuthority;
192  std::string mService;
193  Time mLastCommand;
194  bool mMute;
195 
196 protected:
197  bool mWaitingForSuspendBumperEnabled;
198  RPCFuture<bool> mSuspendBumperEnabledFuture;
199 
200  void waitForSuspendBumperEnabled();
201 
202 protected:
203  virtual void keyPressEvent(QKeyEvent *pEvent);
204 
205  void enableDriveButtons(bool enable);
206  void enableMotorButtons(bool enable);
207  void enableBumperButton(bool enable);
208 
209  void muteAllINavigation(bool mute);
210 
211 private:
212  QTabBar* getTabBar(QTabWidget* widget);
213 
214 private:
215  DriveView* mParent;
216 
217  bool mServiceQueried;
218 };
219 
221 
223 
224 }}
225 
226 #endif
static void channelProperty(Reflector &r, const std::string &name, ChannelProperty &channel, const std::string &comment, IAuthorityProvider *authorityProvider)
ServiceProperty driveService
The service name used for sending driving commands.
Definition: DriveView.h:144
virtual QWidget * createPartControl()
Implementation of mira::ViewPart.
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
sec_type seconds() const
Setter< T > setterNotify(T &member, boost::function< void()> notifyFn)
ChannelProperty< bool > motorstopChannel
The channel used for listening to the motorstop status.
Definition: DriveView.h:147
virtual void activate()
Duration watchdogTimeout
Watchdog interval for stopping when no commands are signaled. default: 5sec.
Definition: DriveView.h:141
float velocityIncrement
The velocity increment, default: 0.1f [m/s].
Definition: DriveView.h:138
A view plugin for steering a robot using arrow keys or button clicks.
Definition: DriveView.h:97