MainWindow.h 5.66 KB
Newer Older
roangel's avatar
roangel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//    Main window of the Student's GUI
//
//    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/>.

roangel's avatar
roangel committed
18
19
20
21
22
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

23
#include <std_msgs/Int32.h>
24
#include <std_msgs/Float32.h>
25
26
27

#include "rosNodeThread.h"

28
29
#include "d_fall_pps/CrazyflieContext.h"
#include "d_fall_pps/CrazyflieData.h"
30
#include "d_fall_pps/Setpoint.h"
31
32


33
34
35
36
// tipes of controllers being used:
#define SAFE_CONTROLLER   0
#define CUSTOM_CONTROLLER 1

37
// commands for CrazyRadio
38
#define CMD_RECONNECT  0
39
#define CMD_DISCONNECT 1
40

41
42
43
44
45
46
47

// CrazyRadio states:
#define CONNECTED        0
#define CONNECTING       1
#define DISCONNECTED     2

// Commands for PPSClient
48
#define CMD_USE_SAFE_CONTROLLER   1
49
#define CMD_USE_CUSTOM_CONTROLLER 2
50
51
52
53
54
55
56
57
58
#define CMD_CRAZYFLY_TAKE_OFF     3
#define CMD_CRAZYFLY_LAND         4
#define CMD_CRAZYFLY_MOTORS_OFF   5

// Flying States
#define STATE_MOTORS_OFF 1
#define STATE_TAKE_OFF   2
#define STATE_FLYING     3
#define STATE_LAND       4
59

60
61
62
63
64
// battery states

#define BATTERY_STATE_NORMAL 0
#define BATTERY_STATE_LOW    1

roangel's avatar
roangel committed
65
66
67
68
69
70

#define PI 3.141592653589

#define RAD2DEG 180.0/PI
#define DEG2RAD PI/180.0

roangel's avatar
roangel committed
71
72
73
74
75
76
77
78
79
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
80
    explicit MainWindow(int argc, char **argv, QWidget *parent = 0);
roangel's avatar
roangel committed
81
82
    ~MainWindow();

83
private slots:
84
    void updatePositionData(const CrazyflieData& data);
85
    void on_RF_Connect_button_clicked();
86
87
88
89
90
91

    void on_take_off_button_clicked();

    void on_land_button_clicked();

    void on_motors_OFF_button_clicked();
92

93
    void on_set_setpoint_button_clicked();
94
    void on_set_setpoint_button_2_clicked();
95

96
    void on_RF_disconnect_button_clicked();
97

98
99
    void on_load_custom_yaml_button_clicked();
    void on_load_safe_yaml_button_clicked();
100
101
102
103
104

    void on_en_custom_controller_clicked();

    void on_en_safe_controller_clicked();

105
106
    void on_checkBox_enable_UWB_toggled(int state);

roangel's avatar
roangel committed
107
108
private:
    Ui::MainWindow *ui;
109
110

    rosNodeThread* m_rosNodeThread;
111
    int m_radio_status;
112
113
    float m_battery_voltage;
    int m_battery_level;
114

115
116
    std::string m_ros_namespace;

117
    ros::Timer m_custom_timer_yaml_file;
roangel's avatar
roangel committed
118

119
120
121
    int m_student_id;
    CrazyflieContext m_context;

122
123
    Setpoint m_safe_setpoint;
    Setpoint m_custom_setpoint;
124

roangel's avatar
roangel committed
125
126
    int m_battery_state;

127
    ros::Publisher crazyRadioCommandPublisher;
128
    ros::Subscriber crazyRadioStatusSubscriber;
roangel's avatar
roangel committed
129
    ros::Publisher PPSClientCommandPublisher;
130
    ros::Subscriber CFBatterySubscriber;
131
    ros::Subscriber flyingStateSubscriber;
132
    ros::Subscriber batteryStateSubscriber;
133

134
    ros::Publisher controllerSetpointPublisher;
135
136
137
138
    ros::Subscriber safeSetpointSubscriber;

    ros::Publisher customSetpointPublisher;
    ros::Subscriber customSetpointSubscriber;
139

140
141
    ros::Subscriber DBChangedSubscriber;

142
143
144
    ros::Publisher customYAMLloadedPublisher;
    ros::Publisher safeYAMLloadedPublisher;

145
146
    ros::Subscriber controllerUsedSubscriber;

147
    ros::ServiceClient centralManager;
148
149
150
151
    ros::ServiceClient UWBServiceClient;

    ros::Subscriber UWBChangedSubscriber;
    ros::Publisher UWBActivatedPublisher;
152

153
    // callbacks
154
    void crazyRadioStatusCallback(const std_msgs::Int32& msg);
155
    void CFBatteryCallback(const std_msgs::Float32& msg);
156
    void flyingStateChangedCallback(const std_msgs::Int32& msg);
157
158
    void safeSetpointCallback(const Setpoint& newSetpoint);
    void customSetpointCallback(const Setpoint& newSetpoint);
159
    void DBChangedCallback(const std_msgs::Int32& msg);
160
161
    void customYamlFileTimerCallback(const ros::TimerEvent&);
    void safeYamlFileTimerCallback(const ros::TimerEvent&);
162
    void controllerUsedChangedCallback(const std_msgs::Int32& msg);
163
    void batteryStateChangedCallback(const std_msgs::Int32& msg);
164
    void uwbChangedCallback(const std_msgs::Int32& msg);
165
166
167

    float fromVoltageToPercent(float voltage);
    void updateBatteryVoltage(float battery_voltage);
168
    void setCrazyRadioStatus(int radio_status);
169
170
171
    void loadCrazyflieContext();
    void coordinatesToLocal(CrazyflieData& cf);

172
173
174

    void disableGUI();
    void enableGUI();
175
176
    void highlightSafeControllerTab();
    void highlightCustomControllerTab();
177

178
179
    void updateUWBState();

180
    const std::vector<float> m_cutoff_voltages {3.1966,        3.2711,        3.3061,        3.3229,        3.3423,        3.3592,        3.3694,        3.385,        3.4006,        3.4044,        3.4228,        3.4228,        3.4301,        3.4445,        3.4531,        3.4677,        3.4705,        3.4712,        3.4756,        3.483,        3.4944,        3.5008,        3.5008,        3.5084,        3.511,        3.5122,        3.5243,        3.5329,        3.5412,        3.5529,        3.5609,        3.5625,        3.5638,        3.5848,        3.6016,        3.6089,        3.6223,        3.628,        3.6299,        3.6436,        3.6649,        3.6878,        3.6983,        3.7171,        3.7231,        3.7464,        3.7664,        3.7938,        3.8008,        3.816,        3.8313,        3.8482,        3.866,        3.8857,        3.8984,        3.9159,        3.9302,        3.9691,        3.997,        4.14    };
roangel's avatar
roangel committed
181
182
183
};

#endif // MAINWINDOW_H