MainWindow.h 4.64 KB
Newer Older
roangel's avatar
roangel committed
1
2
3
4
5
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

6
#include <std_msgs/Int32.h>
7
#include <std_msgs/Float32.h>
8
9
10

#include "rosNodeThread.h"

11
12
#include "d_fall_pps/CrazyflieContext.h"
#include "d_fall_pps/CrazyflieData.h"
13
#include "d_fall_pps/Setpoint.h"
14
15


16
17
18
19
// tipes of controllers being used:
#define SAFE_CONTROLLER   0
#define CUSTOM_CONTROLLER 1

20
// commands for CrazyRadio
21
#define CMD_RECONNECT  0
22
#define CMD_DISCONNECT 1
23

24
25
26
27
28
29
30

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

// Commands for PPSClient
31
#define CMD_USE_SAFE_CONTROLLER   1
32
#define CMD_USE_CUSTOM_CONTROLLER 2
33
34
35
36
37
38
39
40
41
#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
42

43
44
45
46
47
// battery states

#define BATTERY_STATE_NORMAL 0
#define BATTERY_STATE_LOW    1

roangel's avatar
roangel committed
48
49
50
51
52
53

#define PI 3.141592653589

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

roangel's avatar
roangel committed
54
55
56
57
58
59
60
61
62
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
63
    explicit MainWindow(int argc, char **argv, QWidget *parent = 0);
roangel's avatar
roangel committed
64
65
    ~MainWindow();

66
67
private slots:
    void updateNewViconData(const ptrToMessage& p_msg);
68
    void on_RF_Connect_button_clicked();
69
70
71
72
73
74

    void on_take_off_button_clicked();

    void on_land_button_clicked();

    void on_motors_OFF_button_clicked();
75

76
    void on_set_setpoint_button_clicked();
77
    void on_set_setpoint_button_2_clicked();
78

79
    void on_RF_disconnect_button_clicked();
80

81
82
    void on_load_custom_yaml_button_clicked();
    void on_load_safe_yaml_button_clicked();
83
84
85
86
87

    void on_en_custom_controller_clicked();

    void on_en_safe_controller_clicked();

roangel's avatar
roangel committed
88
89
private:
    Ui::MainWindow *ui;
90
91

    rosNodeThread* m_rosNodeThread;
92
    int m_radio_status;
93
94
    float m_battery_voltage;
    int m_battery_level;
95

96
97
    std::string m_ros_namespace;

98
    ros::Timer m_custom_timer_yaml_file;
roangel's avatar
roangel committed
99

100
101
102
    int m_student_id;
    CrazyflieContext m_context;

103
104
    Setpoint m_safe_setpoint;
    Setpoint m_custom_setpoint;
105

106
    ros::Publisher crazyRadioCommandPublisher;
107
    ros::Subscriber crazyRadioStatusSubscriber;
roangel's avatar
roangel committed
108
    ros::Publisher PPSClientCommandPublisher;
109
    ros::Subscriber CFBatterySubscriber;
110
    ros::Subscriber flyingStateSubscriber;
111
    ros::Subscriber batteryStateSubscriber;
112

113
    ros::Publisher controllerSetpointPublisher;
114
115
116
117
    ros::Subscriber safeSetpointSubscriber;

    ros::Publisher customSetpointPublisher;
    ros::Subscriber customSetpointSubscriber;
118

119
120
    ros::Subscriber DBChangedSubscriber;

121
122
123
    ros::Publisher customYAMLloadedPublisher;
    ros::Publisher safeYAMLloadedPublisher;

124
125
    ros::Subscriber controllerUsedSubscriber;

126
127
    ros::ServiceClient centralManager;

128
    // callbacks
129
    void crazyRadioStatusCallback(const std_msgs::Int32& msg);
130
    void CFBatteryCallback(const std_msgs::Float32& msg);
131
    void flyingStateChangedCallback(const std_msgs::Int32& msg);
132
133
    void safeSetpointCallback(const Setpoint& newSetpoint);
    void customSetpointCallback(const Setpoint& newSetpoint);
134
    void DBChangedCallback(const std_msgs::Int32& msg);
135
136
    void customYamlFileTimerCallback(const ros::TimerEvent&);
    void safeYamlFileTimerCallback(const ros::TimerEvent&);
137
    void controllerUsedChangedCallback(const std_msgs::Int32& msg);
138
    void batteryStateChangedCallback(const std_msgs::Int32& msg);
139
140
141

    float fromVoltageToPercent(float voltage);
    void updateBatteryVoltage(float battery_voltage);
142
    void setCrazyRadioStatus(int radio_status);
143
144
145
    void loadCrazyflieContext();
    void coordinatesToLocal(CrazyflieData& cf);

146
147
148

    void disableGUI();
    void enableGUI();
149
150
    void highlightSafeControllerTab();
    void highlightCustomControllerTab();
151
152

    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
153
154
155
};

#endif // MAINWINDOW_H