]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/robomon/RobomonAtlantis.h
Merge branch 'maint-demo' into demo
[eurobot/public.git] / src / robomon / RobomonAtlantis.h
1 /*
2  * RobomonAtlantis.h                    07/10/31
3  *
4  * Robot's visualization and control GUI for robot of the
5  * Eurobot 2008 competition (Mission to Mars).
6  *
7  * Copyright: (c) 2008 CTU Dragons
8  *            CTU FEE - Department of Control Engineering
9  * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
10  * License: GNU GPL v.2
11  */
12
13 #ifndef ROBOMON_ATLANTIS_H
14 #define ROBOMON_ATLANTIS_H
15
16 #include <QDialog>
17 #include <QDateTime>
18 #include <QTimer>
19
20 #include <trgen.h>
21 #include "PlaygroundScene.h"
22 #include "playgroundview.h"
23 #include "Robot.h"
24 #include "Map.h"
25 #include <roboorte_robottype.h>
26 #include "trail.h"
27 #include "hokuyoscan.h"
28 #include <QMainWindow>
29
30 class QHBoxLayout;
31 class QVBoxLayout;
32 class QGridLayout;
33 class QGroupBox;
34 class QGraphicsView;
35 class QLabel;
36 class QPushButton;
37 class QCheckBox;
38 class QLineEdit;
39 class QTextEdit;
40 class QDial;
41 class QSlider;
42 class QProgressBar;
43 class QFont;
44 class QImage;
45
46 class MotorSimulation : QObject {
47     Q_OBJECT
48
49     QTimer timer;
50     qint64 last_time;
51     struct robottype_orte_data &orte;
52 public:
53     MotorSimulation(struct robottype_orte_data &orte) : QObject(), timer(this), orte(orte) {}
54     void start()
55     {
56         robottype_publisher_motion_irc_create(&orte, 0, 0);
57         connect(&timer, SIGNAL(timeout()), this, SLOT(updateIRC()));
58         timer.start(50);
59     }
60
61     void stop()
62     {
63         robottype_publisher_motion_irc_destroy(&orte);
64         timer.stop();
65         disconnect(&timer, SIGNAL(timeout()), this, SLOT(updateIRC()));
66     }
67 private slots:
68     void updateIRC()
69     {
70         qint64 now = QDateTime::currentMSecsSinceEpoch();
71         orte.motion_irc.left += orte.motion_speed.left * (now - last_time);   // TODO: Find constant for speed to irc conversion
72         orte.motion_irc.right+= orte.motion_speed.right * (now - last_time);
73         ORTEPublicationSend(orte.publication_motion_irc);
74         last_time = now;
75     }
76 };
77
78
79 class RobomonAtlantis : public QWidget
80 {
81         Q_OBJECT
82
83 public:
84         RobomonAtlantis(QStatusBar *_statusBar = 0);
85
86 protected:
87         bool event(QEvent *event);
88         void keyPressEvent(QKeyEvent *event);
89         void keyReleaseEvent(QKeyEvent *event);
90         void closeEvent(QCloseEvent *event);
91
92 signals:
93         void motionStatusReceivedSignal();
94         void actualPositionReceivedSignal();
95         void powerVoltageReceivedSignal();
96
97 public slots:
98         void showMap(bool show);
99         void useOpenGL(bool use);
100         void showTrails(bool show);
101         void showShapeDetect(bool show);
102         void resetTrails();
103 private slots:
104         /************************************************************
105          * GUI actions
106          ************************************************************/
107         void setVoltage33(int state);
108         void setVoltage50(int state);
109         void setVoltage80(int state);
110 /*      void setLeftMotor(int value); */
111 /*      void setRightMotor(int value); */
112 /*      void stopMotors(); */
113         void paintMap();
114         void setSimulation(int state);
115         void setObstacleSimulation(int state);
116         void simulateObstaclesHokuyo();
117         void changeObstacle(QPointF position);
118         void sendStart(int plug);
119         void setMotorSimulation(int state);
120
121         /************************************************************
122          * ORTE
123          ************************************************************/
124         void motionStatusReceived();
125         void actualPositionReceived();
126         void powerVoltageReceived();
127
128 private:
129         /************************************************************
130          * GUI
131          ************************************************************/
132         void createLeftLayout();
133         void createRightLayout();
134
135         void createPlaygroundGroupBox();
136         void createPositionGroupBox();
137         void createMiscGroupBox();
138         void createDebugGroupBox();
139         void createActuatorsGroupBox();
140         void createMotorsGroupBox();
141         void createDIOGroupBox();
142         void createSensorsGroupBox();
143         void createPowerGroupBox();
144         void createPickerGroupBox();
145         void createFSMGroupBox();
146
147         void createRobots();
148         void createActions();
149         void createMap();
150
151         QStatusBar *statusBar;
152
153         QVBoxLayout *leftLayout;
154         QVBoxLayout *rightLayout;
155
156         QGroupBox *playgroundGroupBox;
157         QGroupBox *positionGroupBox;
158         QGroupBox *miscGroupBox;
159         QGroupBox *debugGroupBox;
160         QGroupBox *actuatorsGroupBox;
161         QGroupBox *powerGroupBox;
162         QGroupBox *fsmGroupBox;
163
164 public:
165         PlaygroundScene *playgroundScene;
166 private:
167         PlaygroundView *playgroundSceneView;
168
169         /* position state */
170         QLineEdit *actPosX;
171         QLineEdit *actPosY;
172         QLineEdit *actPosPhi;
173
174         QLineEdit *estPosX;
175         QLineEdit *estPosY;
176         QLineEdit *estPosPhi;
177
178         /* debug window */
179         QTextEdit *debugWindow;
180         bool debugWindowEnabled;
181
182         /* actuators */
183 /*      QSlider *leftMotorSlider; */
184 /*      QSlider *rightMotorSlider; */
185 /*      QCheckBox *bothMotorsCheckBox; */
186 /*      QPushButton *stopMotorsPushButton; */
187         //QDial *vidle;
188
189         /* power management */
190         QCheckBox *voltage33CheckBox;
191         QCheckBox *voltage50CheckBox;
192         QCheckBox *voltage80CheckBox;
193         QLineEdit *voltage33LineEdit;
194         QLineEdit *voltage50LineEdit;
195         QLineEdit *voltage80LineEdit;
196         QLineEdit *voltageBATLineEdit;
197
198         /* misc */
199         QCheckBox *obstacleSimulationCheckBox;
200         QCheckBox *motorSimulationCheckBox;
201         QLabel *fsm_main_state;
202         QLabel *fsm_act_state;
203         QLabel *fsm_motion_state;
204         QLabel *system_status;
205         QCheckBox *startPlug;
206         QCheckBox *colorChoser;
207 public:
208         /* robot */
209         Robot *robotRefPos;
210         Robot *robotEstPosBest;
211         Robot *robotEstPosIndepOdo;
212         Robot *robotEstPosOdo;
213
214         Map *mapImage;
215 private:
216         Trail *trailRefPos;
217         Trail *trailEstPosBest;
218         Trail *trailPosIndepOdo;
219         Trail *trailOdoPos;
220
221         HokuyoScan *hokuyoScan;
222
223         /* keypad */
224         double leftMotorValue;
225         double rightMotorValue;
226
227         /* map */
228         void openSharedMemory();
229         bool sharedMemoryOpened;
230         QTimer *mapTimer;
231
232         /* obstacle simulation */
233         double distanceToWallHokuyo(int beamnum);
234         double distanceToObstacleHokuyo(int beamnum, Point obstacle, double obstacleSize);
235         int simulationEnabled;
236
237         QTimer *obstacleSimulationTimer;
238         Point simulatedObstacle;
239
240         class MotorSimulation motorSimulation;
241
242         /************************************************************
243          * ORTE
244          ************************************************************/
245         void createOrte();
246
247         struct robottype_orte_data orte;
248 };
249
250 #endif /* ROBOMON_ATLANTIS_H */