mainguiwindow.h 4.88 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 "CFLinker.h"
32
33

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

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

40

41
#define CMD_CRAZYFLY_MOTORS_OFF   5
42
using namespace d_fall_pps;
43

44
#endif
45

46

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

51
52
53
54
55
56

namespace Ui {
class MainGUIWindow;
}


57
#ifdef CATKIN_MAKE
58
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
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:
93
94
    explicit MainGUIWindow(int argc, char **argv, QWidget *parent = 0);

95
96
97
    ~MainGUIWindow();

public slots:
98

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

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

126
127
128
129
    void on_checkBox_vicon_markers_toggled(bool checked);

    void on_checkBox_vicon_highlight_markers_toggled(bool checked);

130
131
132
133
    void on_save_in_DB_button_clicked();

    void on_load_from_DB_button_clicked();

134
135
    void on_checkBox_enable_UWB_toggled(bool checked);

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

tiagos's avatar
tiagos committed
138
139
    void on_reloadAnchors_button_pressed();

roangel's avatar
roangel committed
140
    #ifdef CATKIN_MAKE
141
    void updateNewViconData(const ptrToMessage& p_msg);
142
143
144
145

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

    void updateCFPositions(const CrazyfliePositionData& data);
roangel's avatar
roangel committed
146
    #endif
147
148
149
    void on_checkBox_vicon_crazyflies_toggled(bool checked);

    void on_scaleSpinBox_valueChanged(double arg1);
150
151
152
    void on_refresh_cfs_button_clicked();

    void on_refresh_student_ids_button_clicked();
153

154
155
    void on_link_button_clicked();

156
157
    void on_unlink_button_clicked();

158
159
    void updateComboBoxes();

160
161
162
    void setTabIndex(int index);
    void doTabClosed(int tab_index);

163
164
    void on_comboBoxCFs_currentTextChanged(const QString &arg1);

165
166
    void on_all_motors_off_button_clicked();

167
168
169
170
171
172
private:

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

173

174
    #ifdef CATKIN_MAKE
175
    rosNodeThread* _rosNodeThread;
176
177
    std::vector<Marker*> markers_vector;
    std::vector<crazyFly*> crazyflies_vector;
178
    std::vector<crazyFly*> cf_positionsVector;
179
    CFLinker* cf_linker;
180

181
182
    ros::ServiceClient UWBServiceClient;

183
    ros::Publisher DBChangedPublisher;
184
    ros::Publisher emergencyStopPublisher;
185
186

    ros::Publisher refreshStudents_publisher;
tiagos's avatar
tiagos committed
187
    ros::Publisher UWBSettings_publisher;
188
    ros::Publisher UWBServiceClientUpdate_publisher;
189
    
190
    #endif
191
192
193
194
195

    void updateComboBoxesCFs();

    void updateComboBoxesCFZones();

196
197
    int getTabIndexFromName(QString name);

198
    CrazyflieDB m_data_base;
199
200
201
202
203
204
205
206
207
208
209

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

213
214
215
216
217
};



#endif // MAINGUIWINDOW_H