mainguiwindow.h 5.21 KB
Newer Older
roangel's avatar
roangel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//    Teacher's GUI main window header.
//    Copyright (C) 2017  Angel Romero
//
//    This program is free software: you can redistribute it and/or modify
//    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.
//
//    This program is distributed in the hope that it will be useful,
//    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.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

17
18
19
#ifndef MAINGUIWINDOW_H
#define MAINGUIWINDOW_H

20
// The #define CATKIN_MAKE comes from cmake file
21
22
23
24
25
#include <QMainWindow>
#include <QTimer>
#include <QGridLayout>
#include <QGraphicsRectItem>

26

27
#ifdef CATKIN_MAKE
28
#include "rosNodeThread.h"
29
30
#include "marker.h"
#include "crazyFly.h"
31
#include "UWBMarker.h"
32
#include "CFLinker.h"
33
34

#include "d_fall_pps/CrazyflieDB.h"
35
#include "d_fall_pps/CrazyflieEntry.h"
tiagos's avatar
tiagos committed
36
#include "d_fall_pps/Anchors.h"
37

38
#include <std_msgs/Int32.h>
39
#include <std_msgs/Int32MultiArray.h>
40

41

42
#define CMD_CRAZYFLY_MOTORS_OFF   5
43
using namespace d_fall_pps;
44

45
#endif
46

47

48
49
#include "ui_mainguiwindow.h"
#include "myGraphicsScene.h"
50
51
#include "globalDefinitions.h"

52
53
54
55
56
57

namespace Ui {
class MainGUIWindow;
}


58
#ifdef CATKIN_MAKE
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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:
94
95
    explicit MainGUIWindow(int argc, char **argv, QWidget *parent = 0);

96
97
98
    ~MainGUIWindow();

public slots:
99

100
private slots:
101
    #ifdef CATKIN_MAKE
102
    #endif
103

roangel's avatar
roangel committed
104
    void doNumCrazyFlyZonesChanged(int n);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    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();

127
128
129
130
    void on_checkBox_vicon_markers_toggled(bool checked);

    void on_checkBox_vicon_highlight_markers_toggled(bool checked);

131
132
133
134
    void on_save_in_DB_button_clicked();

    void on_load_from_DB_button_clicked();

135
136
    void on_checkBox_enable_UWB_toggled(bool checked);

tiagos's avatar
tiagos committed
137
138
    void on_calibrateAnchors_button_pressed();

tiagos's avatar
tiagos committed
139
    void on_reloadAnchors_button_pressed();
140
    void on_reloadAnchorsFromFile_button_pressed();
tiagos's avatar
tiagos committed
141

tiagos's avatar
tiagos committed
142
143
    void on_set_offset_button_pressed();

144
145
    void on_set_invert_button_pressed();

roangel's avatar
roangel committed
146
    #ifdef CATKIN_MAKE
147
    void updateNewViconData(const ptrToMessage& p_msg);
148
149
150
151

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

    void updateCFPositions(const CrazyfliePositionData& data);
roangel's avatar
roangel committed
152
    #endif
153
154
155
    void on_checkBox_vicon_crazyflies_toggled(bool checked);

    void on_scaleSpinBox_valueChanged(double arg1);
156
157
158
    void on_refresh_cfs_button_clicked();

    void on_refresh_student_ids_button_clicked();
159

160
161
    void on_link_button_clicked();

162
163
    void on_unlink_button_clicked();

164
165
    void updateComboBoxes();

166
167
168
    void setTabIndex(int index);
    void doTabClosed(int tab_index);

169
170
    void on_comboBoxCFs_currentTextChanged(const QString &arg1);

171
172
    void on_all_motors_off_button_clicked();

173
174
175
176
177
178
private:

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

179

180
    #ifdef CATKIN_MAKE
181
    rosNodeThread* _rosNodeThread;
182
183
    std::vector<Marker*> markers_vector;
    std::vector<crazyFly*> crazyflies_vector;
184
    std::vector<crazyFly*> cf_positionsVector;
185
    CFLinker* cf_linker;
186
    std::vector<UWBMarker*> anchor_markers;
187

188
189
190
    std::map<std::string, std::string> channel_LUT;
    std::vector<crazyFly*> CF_vector;

191
192
    ros::ServiceClient UWBServiceClient;

193
    ros::Publisher DBChangedPublisher;
194
    ros::Publisher emergencyStopPublisher;
195
196

    ros::Publisher refreshStudents_publisher;
tiagos's avatar
tiagos committed
197
    ros::Publisher UWBSettings_publisher;
198
    ros::Publisher UWBServiceClientUpdate_publisher;
199
    
200
    #endif
201
202
203
204
205

    void updateComboBoxesCFs();

    void updateComboBoxesCFZones();

206
207
    int getTabIndexFromName(QString name);

208
    CrazyflieDB m_data_base;
209
210
211
212
213
214
215
216
217
218
219

    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
220
    bool updateUWBSettings(bool enableChecked);
tiagos's avatar
tiagos committed
221
222
    void updateAnchors(const Anchors* const a);

223
224
    void loadCFs(ros::NodeHandle& nh);

225
226
227
228
229
};



#endif // MAINGUIWINDOW_H