-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrovdataparser.h
More file actions
212 lines (181 loc) · 4.59 KB
/
Copy pathrovdataparser.h
File metadata and controls
212 lines (181 loc) · 4.59 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#ifndef ROVDATAPARSER_H
#define ROVDATAPARSER_H
#include "joystick.h"
#include "qdialog.h"
#include "qelapsedtimer.h"
#include "qwidget.h"
#include "rovdatatypes.h"
#include <QDataStream>
#include <QDebug>
#include <QMutex>
#include <QObject>
#include <algorithm>
#define DEFAULT_kP 3
#define DEFAULT_kI 0.01
#define DEFAULT_kD 5
/**
* @brief Floating point PD regulator implementation
*
*/
class FPPDRegulator {
public:
/**
* @brief Construct a new FPPDRegulator object
*
* @param coeffP Proportional coefficient
* @param coeffD Differential coefficient
*/
FPPDRegulator(float coeffP, float coeffI, float coeffD)
: kP(coeffP), kI(coeffI), kD(coeffD), lastError(0.0f), uI(0.0f), target(0.0f){};
/**
* @brief Evaluate the regulator expression
*
* @param data Data
* @param target Target
* @return float Control signal
*/
float eval(float data);
void setTarget(float target);
void enable();
void disable();
private:
bool enabled = false;
float kP;
float kI;
float kD;
float lastError;
float uI;
float target;
int lastData;
QElapsedTimer eTimer;
};
QT_BEGIN_NAMESPACE
namespace Ui {
class DataParser;
}
QT_END_NAMESPACE
/**
* \brief The RovDataParser class is responsible for packing control data in
* QByteArrays and unpacking telemetry data from them.
*/
class RovDataParser : public QDialog {
Q_OBJECT
public:
/**
* \brief Default constructor
* \param parent Parent
*/
explicit RovDataParser(QWidget *parent = nullptr);
signals:
/**
* \brief Emitted when the class is finished processing raw QByteArray
* \param tele Telemetry object
*/
void telemetryProcessed(RovTelemetry tele);
/**
* \brief Emitted when the class is finished packing RovControl struct into
* a QByteArray \param ba QByteArray with the control data
*/
void controlReady(QByteArray ba);
/**
* \brief Emitted when the class is finished packing RovAuxControl struct
* into a QByteArray \param ba QByteArray with the auxiliary data
*/
void auxControlReady(QByteArray ba);
public slots:
/**
* \brief Called to unpack telemetry data from the QByteArray into the
* RovTelemetry struct \param ba Datagrem with telemetry data
*/
void processTelemetry(QByteArray ba);
/**
* \brief Called to pack joystick data from Joystick struct and then into
* QByteArray \param joy Joystick struct with data
*/
void prepareControl(Joystick joy);
/**
* \brief Called to pack the auxiliary control data into QByteArray
*/
void prepareAuxControl();
/**
* \brief Sets RovAuxControl' auxiliary flags
* \param aFlags Flags
*/
void setAuxFlags(qint8 aFlags);
/**
* \brief Enables or disables depth regulator
* \param status
*/
void setDepthStatus(int status);
/**
* \brief Sets desired depth
* \param dVal Desired value
*/
void setDepth(double dVal);
/**
* \brief Enables or disables depth regulator
* \param status
*/
void setYawStatus(int status);
/**
* \brief Sets desired yaw
* \param dVal Desired value
*/
void setYaw(double dVal);
/**
* \brief Enables or disables depth regulator
* \param status
*/
void setRollStatus(int status);
/**
* \brief Sets desired roll
* \param dVal Desired value
*/
void setRoll(double dVal);
/**
* \brief Enables or disables depth regulator
* \param status
*/
void setPitchStatus(int status);
/**
* \brief Sets desired pitch
* \param dVal Desired value
*/
void setPitch(double dVal);
void toggleLight();
void togglePump();
void invalidateImuCalibration();
private:
/**
* \brief UI
*/
Ui::DataParser *ui;
/**
* \brief Internally-stored RovControl struct
*/
QScopedPointer<RovControl> m_control;
/**
* \brief Mutex for m_control
*/
QMutex m_controlMutex;
QTimer *overrideTelemetryUpdate;
/**
* \brief Previous CamSel state, used to switch cameras on the ROV
*/
bool m_prevCamSelState;
/**
* \brief Internally-stored RovAuxControl struct
*/
QScopedPointer<RovAuxControl> m_auxControl;
/**
* \brief Mutex for m_auxControl
*/
QMutex m_auxControlMutex;
RovTelemetry m_tele;
QMutex m_teleMutex;
FPPDRegulator depthReg;
FPPDRegulator yawReg;
FPPDRegulator rollReg;
FPPDRegulator pitchReg;
};
#endif // ROVDATAPARSER_H