-
Notifications
You must be signed in to change notification settings - Fork 15
/
Sender.h
117 lines (94 loc) · 2.8 KB
/
Sender.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
* *
* Copyright (C) 2017 by University of Illinois *
* *
* http://illinois.edu *
* *
***************************************************************************/
/**
* @file Sender.h
*
* A Sender object reads Vicon data from a Station object, processes the data
* with Kalman filtering and computes a GPS MAVLink data pack, sends MAVLink
* messages to a robot via UDP.
*
* This is the Model of the
* Model(Sender)-View(SenderWindow)-Controller(SenderController) pattern.
*
* @author Bo Liu <boliu1@illinois.edu>
*
*/
#ifndef SENDER_H
#define SENDER_H
#include <QObject>
#include <QUdpSocket>
#include <QDateTime>
#include <lib/MAVLink2/common/mavlink.h>
#include <Station.h>
#include "KalmanFilter.h"
#include <memory>
class Sender : public QObject
{
Q_OBJECT
public:
explicit Sender(const QString& name, std::unique_ptr<Station>& station, QObject *parent = 0);
~Sender();
void initialize();
void setupConnections();
void start();
void stop();
void updateMeas();
void updateLocPosFromMeas();
void updateGpsFromeLocPos();
void sendDatagram();
void startTimer(uint8_t rate);
void stopTimer();
void updateTimer(uint8_t rate);
QHostAddress getRemoteAddress() const;
quint16 getRemotePort() const;
uint8_t getSysID() const;
uint8_t getCompID() const;
bool getUseGps() const;
bool getUseLocPos() const;
bool getUseVicon() const;
uint8_t getRate() const;
void setRate(uint8_t rate);
void setUseGps(bool use);
void setUseVicon(bool use);
void setUseLocPos(bool use);
void setSysID(uint8_t id);
void setCompID(uint8_t id);
void setRemoteAddress(const QString& ip);
void setRemotePort(quint16 port);
signals:
void measUpdated();
public slots:
void timerHandler();
private:
KalmanFilter kf;
bool isInitialized;
bool isRunning;
std::unique_ptr<Station>& station;
double dt; // seconds/frame
long long frame;
uint8_t rate;
QTimer timer;
bool useGPS;
mavlink_hil_gps_t gpsMsg;
bool useLocPos;
mavlink_local_position_ned_t locPosMsg;
bool useViconEst;
mavlink_att_pos_mocap_t viconEstMsg;
QString name;
int sysid;
int compid;
QDateTime Qtime;
qint64 ustime;
QHostAddress remoteAddress;
quint16 remotePort;
QUdpSocket* udpSocket;
//helpers
mavlink_hil_gps_t locPos_to_gpsHIL(const mavlink_local_position_ned_t& locPos);
void init_KF();
};
#endif // SENDER_H