-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBebopDroneDecodeStream.h
306 lines (261 loc) · 9.17 KB
/
BebopDroneDecodeStream.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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
Copyright (C) 2014 Parrot SA
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Parrot nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef _SDK_EXAMPLE_BD_H_
#define _SDK_EXAMPLE_BD_H_
#include <ihm.h>
#include <DecoderManager.h>
#include <libARCommands/ARCommands.h>
typedef struct
{
int flag;
int roll;
int pitch;
int yaw;
int gaz;
}BD_PCMD_t;
typedef struct _ARDrone3CameraData_t_
{
int tilt;
int pan;
} BD_Cam_t;
// ++++++++++++++ M: More States ++++++++++++++++++
// Speed
typedef struct{
float speedX;
float speedY;
float speedZ;
} BD_Speed_t;
typedef struct{
float roll;
float pitch;
float yaw;
float altitude;
} BD_Pos_t;
typedef struct{
double kPxy;
double kIxy;
double kDxy;
double kPz;
double kIz;
double kDz;
} pid_C_t;
typedef struct
{
double x_posd;
double y_posd;
double z_posd;
double x_veld;
double y_veld;
double z_veld;
} desiredStates_t;
typedef struct{
double x_pos;
double y_pos;
double z_pos;
} odometry_t;
typedef struct{
double c3x;
double c3y;
double c3z;
double c4x;
double c4y;
double c4z;
double c5x;
double c5y;
double c5z;
double totalTime;
} lineTrajCoe_t;
typedef struct{
double x_veld;
double y_veld;
double pitch_error;
double roll_error;
} dataPrint_t;
typedef struct{
double r;
double totalTime;
int vertical;
} circleTrajCoe_t;
typedef struct{
lineTrajCoe_t line1Coe;
lineTrajCoe_t line2Coe;
lineTrajCoe_t line3Coe;
lineTrajCoe_t line4Coe;
double xd;
double yd;
double zd;
double totalTime;
} squareTrajCoe_t;
typedef struct{
double c3;
double c4;
double c5;
double r;
double totalTime;
} eightTrajCoe_t;
// +++++++++++++ M End +++++++++++++++++++++++++++
typedef struct READER_THREAD_DATA_t READER_THREAD_DATA_t;
typedef struct RawFrame_t RawFrame_t;
typedef struct
{
ARNETWORKAL_Manager_t *alManager;
ARNETWORK_Manager_t *netManager;
ARSTREAM_Reader_t *streamReader;
ARSAL_Thread_t looperThread;
ARSAL_Thread_t rxThread;
ARSAL_Thread_t txThread;
ARSAL_Thread_t videoTxThread;
ARSAL_Thread_t videoRxThread;
int d2cPort;
int c2dPort;
int arstreamFragSize;
int arstreamFragNb;
int arstreamAckDelay;
uint8_t *videoFrame;
uint32_t videoFrameSize;
BD_PCMD_t dataPCMD;
BD_Cam_t dataCam;
ARCODECS_Manager_t *decoder;
int decodingCanceled;
ARSAL_Thread_t decodingThread;
int hasReceivedFirstIFrame;
RawFrame_t **freeRawFramePool;
int rawFramePoolCapacity;
int lastRawFrameFreeIdx;
RawFrame_t **rawFrameFifo;
int fifoReadIdx;
int fifoWriteIdx;
eARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE flyingState;
FILE *video_out;
ARSAL_Mutex_t mutex;
ARSAL_Thread_t *readerThreads;
READER_THREAD_DATA_t *readerThreadsData;
int run;
IHM_t *ihm;
//States Added+++++++++++++++++
BD_Speed_t speed;
double timePassed;
BD_Pos_t pos;
double autoStartTime;
pid_C_t pid_Coe;
FILE *logFileCallback;
FILE *logFileControlA;
FILE *logFileControlB;
FILE *logFileControlC;
int logNum;
int autoFly;
int logingFlag;
desiredStates_t desiredStates;
odometry_t odometry;
double dtime;
double previousTime;
BD_Speed_t droneSpeed;
squareTrajCoe_t* squareTrajCoe;
lineTrajCoe_t *lineTrajCoe;
circleTrajCoe_t *circleTrajCoe;
eightTrajCoe_t *eightTrajCoe;
// uint8_t wobbleEnable;
BD_Speed_t worldSpeed;
double flyStartYaw;
dataPrint_t printData;
double flyStartAltitude;
//+++++++++++++++++++++++++++++
} BD_MANAGER_t;
struct READER_THREAD_DATA_t
{
BD_MANAGER_t *deviceManager;
int readerBufferId;
};
/** Connection part **/
int ardiscoveryConnect (BD_MANAGER_t *deviceManager);
eARDISCOVERY_ERROR ARDISCOVERY_Connection_SendJsonCallback (uint8_t *dataTx, uint32_t *dataTxSize, void *customData);
eARDISCOVERY_ERROR ARDISCOVERY_Connection_ReceiveJsonCallback (uint8_t *dataRx, uint32_t dataRxSize, char *ip, void *customData);
/** Network part **/
int startNetwork (BD_MANAGER_t *deviceManager);
void stopNetwork (BD_MANAGER_t *deviceManager);
void onDisconnectNetwork (ARNETWORK_Manager_t *manager, ARNETWORKAL_Manager_t *alManager, void *customData);
/** Video part **/
int startVideo (BD_MANAGER_t *deviceManager);
void stopVideo (BD_MANAGER_t *deviceManager);
uint8_t *frameCompleteCallback (eARSTREAM_READER_CAUSE cause, uint8_t *frame, uint32_t frameSize, int numberOfSkippedFrames, int isFlushFrame, uint32_t *newBufferCapacity, void *custom);
/** decoding part **/
int startDecoder (BD_MANAGER_t *deviceManager);
void stopDecoder (BD_MANAGER_t *deviceManager);
int getNextDataCallback(uint8_t **data, void *customData);
RawFrame_t *getFreeRawFrame(BD_MANAGER_t *deviceManager);
void addFreeRawFrameToFifo(BD_MANAGER_t *deviceManager, RawFrame_t *rawFrame);
void flushFifo(BD_MANAGER_t *deviceManager);
void putRawFrameBackToPool(BD_MANAGER_t *deviceManager, int fifoIdx);
RawFrame_t *getFrameFromData(BD_MANAGER_t *deviceManager, uint8_t *data);
/** Commands part **/
eARNETWORK_MANAGER_CALLBACK_RETURN arnetworkCmdCallback(int buffer_id, uint8_t *data, void *custom, eARNETWORK_MANAGER_CALLBACK_STATUS cause);
int sendPCMD(BD_MANAGER_t *deviceManager);
int sendCameraOrientation(BD_MANAGER_t *deviceManager);
int sendDate(BD_MANAGER_t *deviceManager);
int sendAllStates(BD_MANAGER_t *deviceManager);
int sendAllSettings(BD_MANAGER_t *deviceManager);
int sendTakeoff(BD_MANAGER_t *deviceManager);
int sendLanding(BD_MANAGER_t *deviceManager);
int sendEmergency(BD_MANAGER_t *deviceManager);
int sendBeginStream(BD_MANAGER_t *deviceManager);
//++++++++++++++++++++++++++ More Commends ++++
// int sendWobble(BD_MANAGER_t *deviceManager);
//++++++++++++++++++++++++++++++++++++++++++++
/** Commands callback part **/
void registerARCommandsCallbacks (BD_MANAGER_t *deviceManager);
void unregisterARCommandsCallbacks();
void batteryStateChangedCallback (uint8_t percent, void *custom);
void flyingStateChangedCallback (eARCOMMANDS_ARDRONE3_PILOTINGSTATE_FLYINGSTATECHANGED_STATE state, void *custom);
//+++++++ More Callback ++++++++++++++++
void speedChangedCallback (float speedX, float speedY, float speedZ, void *custom);
// void curTimeChangedCallback (char *curTime, void *custom);
void altitudeChangedCallback (double altitude, void *custom);
void attitudeChangedCallback (float roll, float pitch, float yaw, void *custom);
// void wobbleCancellationCallback (uint8_t enable, void *custom);
//++++++++++++++++++++++++++++++++++++++
/** IHM callbacks **/
void onInputEvent (eIHM_INPUT_EVENT event, void *customData);
int customPrintCallback (eARSAL_PRINT_LEVEL level, const char *tag, const char *format, va_list va);
//++++++++++++ Trajectory and control ++++++++++++++++
void pidControl(BD_MANAGER_t *deviceManager);
void lineTrajCoeGenrator(BD_MANAGER_t *deviceManager, double xf, double yf, double zf, double tf);
void getLineDesiredState(BD_MANAGER_t *deviceManager);
void squareTrajCoeGenrator(BD_MANAGER_t *deviceManager, double xd, double yd, double zd, double tf);
void getSquareDesiredState(BD_MANAGER_t *deviceManager);
void circleTrajCoeGenrator(BD_MANAGER_t *deviceManager, double r, double tf, int vertical);
void getCircleDesiredState(BD_MANAGER_t *deviceManager);
void eightTrajCoeGenrator(BD_MANAGER_t *deviceManager, double r, double tf);
void getEightDesiredState(BD_MANAGER_t *deviceManager);
void speedWorldFrameConversion(BD_MANAGER_t *deviceManager);
void odometryUpdate(BD_MANAGER_t *deviceManager);
void W2C(BD_MANAGER_t *deviceManager);
//+++++++++++++++++ util ++++++++++++++++++++++++
void startAutoFly(BD_MANAGER_t *deviceManager, int typeNum);
void endAutoFly(BD_MANAGER_t *deviceManager);
#endif /* _SDK_EXAMPLE_BD_H_ */