mainguiwindow.h 6.27 KB
Newer Older
1
2
3
4
5
6
//    Copyright (C) 2018, ETH Zurich, D-ITET
//          Yvan Bosshard           byvan       @ee.ethz.ch
//          Michael Rogenmoser      michaero    @ee.ethz.ch
//          Tiago Salzmann          tiagos      @ee.ethz.ch
//    
//    Adapted from mainguiwindow of Angel Romero.
roangel's avatar
roangel committed
7
//
8
9
10
//    This file is part of D-FaLL-System.
//    
//    D-FaLL-System is free software: you can redistribute it and/or modify
roangel's avatar
roangel committed
11
12
13
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
14
15
//    
//    D-FaLL-System is distributed in the hope that it will be useful,
roangel's avatar
roangel committed
16
17
18
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
19
//    
roangel's avatar
roangel committed
20
//    You should have received a copy of the GNU General Public License
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//    along with D-FaLL-System.  If not, see <http://www.gnu.org/licenses/>.
//    
//
//    ----------------------------------------------------------------------------------
//    DDDD        FFFFF        L     L           SSSS  Y   Y   SSSS  TTTTT  EEEEE  M   M
//    D   D       F      aaa   L     L          S       Y Y   S        T    E      MM MM
//    D   D  ---  FFFF  a   a  L     L     ---   SSS     Y     SSS     T    EEE    M M M
//    D   D       F     a  aa  L     L              S    Y        S    T    E      M   M
//    DDDD        F      aa a  LLLL  LLLL       SSSS     Y    SSSS     T    EEEEE  M   M
//
//
//    DESCRIPTION:
//    Teacher's GUI main window.
//
//    ----------------------------------------------------------------------------------

roangel's avatar
roangel committed
37

38
39
40
#ifndef MAINGUIWINDOW_H
#define MAINGUIWINDOW_H

41
// The #define CATKIN_MAKE comes from cmake file
42
43
44
45
46
#include <QMainWindow>
#include <QTimer>
#include <QGridLayout>
#include <QGraphicsRectItem>

47
#ifdef CATKIN_MAKE
flashingx's avatar
flashingx committed
48
49
50
#include <std_msgs/Int32.h>
#include <std_msgs/Int32MultiArray.h>

51
#include "rosNodeThread.h"
52
53
#include "marker.h"
#include "crazyFly.h"
54
#include "UWBMarker.h"
55
#include "CFLinker.h"
56
57

#include "d_fall_pps/CrazyflieDB.h"
58
#include "d_fall_pps/CrazyflieEntry.h"
59
#include "d_fall_pps/CFIndex.h"
tiagos's avatar
tiagos committed
60
#include "d_fall_pps/Anchors.h"
61

62
#define CMD_CRAZYFLY_MOTORS_OFF   5
63
using namespace d_fall_pps;
64

65
#endif
66

67

68
69
#include "ui_mainguiwindow.h"
#include "myGraphicsScene.h"
70
71
#include "globalDefinitions.h"

72
73
74
75
76
77

namespace Ui {
class MainGUIWindow;
}


78
#ifdef CATKIN_MAKE
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
struct setpoint
{
    double x;
    double y;
    double z;
    double yaw;
};

class CSetpointQueue
{
public:
    CSetpointQueue();
    void insert(setpoint newElem);
    setpoint getNext();
    void print();

private:
    struct QueueElem
    {
        QueueElem(setpoint newElem) {elem.x=newElem.x; elem.y=newElem.y; elem.z=newElem.z; elem.yaw=newElem.yaw; next=NULL;}
        setpoint elem;
        QueueElem* next;
    };

    QueueElem* startElem;
    QueueElem* currElem;
    QueueElem* lastElem;
};
#endif

class MainGUIWindow : public QMainWindow
{
    Q_OBJECT

public:
114
115
    explicit MainGUIWindow(int argc, char **argv, QWidget *parent = 0);

116
117
118
    ~MainGUIWindow();

public slots:
119

120
private slots:
121
    #ifdef CATKIN_MAKE
122
    #endif
123

roangel's avatar
roangel committed
124
    void doNumCrazyFlyZonesChanged(int n);
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    void transitionToMode(int mode);
    void on_removeTable_clicked();

    void on_radioButton_table_mode_toggled(bool checked);

    void on_radioButton_crazyfly_zones_mode_toggled(bool checked);
    void handleTablePiecesNumChanged(int newNum);

    void on_radioButton_lock_mode_toggled(bool checked);

    void on_checkBox_grid_toggled(bool checked);

    void on_checkBox_table_toggled(bool checked);

    void on_checkBox_crazyfly_zones_toggled(bool checked);

    void on_tabWidget_currentChanged(int index);

    void centerViewIndex(int index);

    void on_pushButton_fitAll_clicked();

147
148
149
150
    void on_checkBox_vicon_markers_toggled(bool checked);

    void on_checkBox_vicon_highlight_markers_toggled(bool checked);

151
152
153
154
    void on_save_in_DB_button_clicked();

    void on_load_from_DB_button_clicked();

155
156
    void on_checkBox_enable_UWB_toggled(bool checked);

tiagos's avatar
tiagos committed
157
158
    void on_calibrateAnchors_button_pressed();

tiagos's avatar
tiagos committed
159
    void on_reloadAnchors_button_pressed();
160
    void on_reloadAnchorsFromFile_button_pressed();
tiagos's avatar
tiagos committed
161

tiagos's avatar
tiagos committed
162
163
    void on_set_offset_button_pressed();

164
165
    void on_set_invert_button_pressed();

roangel's avatar
roangel committed
166
    #ifdef CATKIN_MAKE
167
    void updateNewViconData(const ptrToMessage& p_msg);
168
169
170
171

    void updateStudentIDs(const std_msgs::Int32MultiArray& ids);

    void updateCFPositions(const CrazyfliePositionData& data);
roangel's avatar
roangel committed
172
    #endif
173
174
175
    void on_checkBox_vicon_crazyflies_toggled(bool checked);

    void on_scaleSpinBox_valueChanged(double arg1);
176
177
178
    void on_refresh_cfs_button_clicked();

    void on_refresh_student_ids_button_clicked();
179

180
181
    void on_link_button_clicked();

182
183
    void on_unlink_button_clicked();

184
185
    void updateComboBoxes();

186
187
188
    void setTabIndex(int index);
    void doTabClosed(int tab_index);

189
190
    void on_comboBoxCFs_currentTextChanged(const QString &arg1);

191
192
    void on_all_motors_off_button_clicked();

193
194
195
196
197
198
private:

    Ui::MainGUIWindow *ui;
    myGraphicsScene* scene;
    void _init();

199

200
    #ifdef CATKIN_MAKE
201
    rosNodeThread* _rosNodeThread;
202
203
    std::vector<Marker*> markers_vector;
    std::vector<crazyFly*> crazyflies_vector;
204
    std::vector<crazyFly*> cf_positionsVector;
205
    CFLinker* cf_linker;
206
    std::vector<UWBMarker*> anchor_markers;
207

208
209
210
    std::map<std::string, std::string> channel_LUT;
    std::vector<crazyFly*> CF_vector;

211
    ros::ServiceClient UWBServiceClient;
212
    ros::ServiceClient TeacherServiceClient;
213

214
    ros::Publisher DBChangedPublisher;
215
    ros::Publisher emergencyStopPublisher;
216
217

    ros::Publisher refreshStudents_publisher;
tiagos's avatar
tiagos committed
218
    ros::Publisher UWBSettings_publisher;
219
    ros::Publisher UWBServiceClientUpdate_publisher;
220
    
221
    #endif
222
223
224
225
226

    void updateComboBoxesCFs();

    void updateComboBoxesCFZones();

227
228
    int getTabIndexFromName(QString name);

229
    CrazyflieDB m_data_base;
230
231
232
233
234
235
236
237
238
239
240

    void clear_database_file();

    void fill_database_file();

    int read_database_from_file(CrazyflieDB &read_db);

    void save_database_file();

    void insert_or_update_entry_database(CrazyflieEntry entry);

tiagos's avatar
tiagos committed
241
    bool updateUWBSettings(bool enableChecked);
tiagos's avatar
tiagos committed
242
243
    void updateAnchors(const Anchors* const a);

244
245
    void loadCFs(ros::NodeHandle& nh);

246
247
    //void createCFObject(const CrazyfliePositionData)

248
249
250
251
252
};



#endif // MAINGUIWINDOW_H