-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarvelmind.h
262 lines (204 loc) · 6.82 KB
/
marvelmind.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
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
// ----- Required for Visual Studio
#if defined(WIN32) || defined(_WIN64)
#ifdef _CRT_SECURE_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:4996)
#endif
// -----
#define DATA_INPUT_SEMAPHORE "/mm_data_input_semaphore"
#ifdef _WIN64
#define SERIAL_FILENAME const wchar_t*
#else
#define SERIAL_FILENAME const char*
#endif
typedef union {
uint32_t timestamp32;
int64_t timestamp64;
} TimestampOpt;
struct PositionValue
{
uint8_t address;
TimestampOpt timestamp;
bool realTime;
int32_t x, y, z;// coordinates in millimeters
uint8_t flags;
double angle;
bool highResolution;
bool ready;
bool processed;
};
struct RawIMUValue
{
int16_t acc_x;
int16_t acc_y;
int16_t acc_z;
int16_t gyro_x;
int16_t gyro_y;
int16_t gyro_z;
int16_t compass_x;
int16_t compass_y;
int16_t compass_z;
TimestampOpt timestamp;
bool realTime;
bool updated;
};
struct FusionIMUValue
{
int32_t x;
int32_t y;
int32_t z;// coordinates in mm
int16_t qw;
int16_t qx;
int16_t qy;
int16_t qz;// quaternion, normalized to 10000
int16_t vx;
int16_t vy;
int16_t vz;// velocity, mm/s
int16_t ax;
int16_t ay;
int16_t az;// acceleration, mm/s^2
TimestampOpt timestamp;
bool realTime;
bool updated;
};
struct RawDistanceItem
{
uint8_t address_beacon;
uint32_t distance;// distance, mm
};
struct RawDistances
{
uint8_t address_hedge;
struct RawDistanceItem distances[4];
TimestampOpt timestamp;
bool realTime;
uint16_t timeShift;
bool updated;
};
struct StationaryBeaconPosition
{
uint8_t address;
int32_t x, y, z;// coordinates in millimeters
bool highResolution;
};
#define MAX_STATIONARY_BEACONS 30
struct StationaryBeaconsPositions
{
uint8_t numBeacons;
struct StationaryBeaconPosition beacons[MAX_STATIONARY_BEACONS];
bool updated;
};
struct TelemetryData
{
uint16_t vbat_mv;
int8_t rssi_dbm;
bool updated;
};
struct QualityData
{
uint8_t address;
uint8_t quality_per;
bool updated;
};
#define MAX_BUFFERED_POSITIONS 1
struct MarvelmindHedge
{
// serial port device name (physical or USB/virtual). It should be provided as
// an argument:
// /dev/ttyACM0 - typical for Linux / Raspberry Pi
// /dev/tty.usbmodem1451 - typical for Mac OS X
SERIAL_FILENAME ttyFileName;
// Baud rate. Should be match to baudrate of hedgehog-beacon
// default: 9600
uint32_t baudRate;
// buffer of measurements
struct PositionValue * positionBuffer;
struct StationaryBeaconsPositions positionsBeacons;
struct RawIMUValue rawIMU;
struct FusionIMUValue fusionIMU;
struct RawDistances rawDistances;
struct TelemetryData telemetry;
struct QualityData quality;
int timeOffset;
// verbose flag which activate console output
// default: False
bool verbose;
// pause flag. If True, class would not read serial data
bool pause;
// If True, thread would exit from main loop and stop
bool terminationRequired;
// receiveDataCallback is callback function to recieve data
void (*receiveDataCallback)(struct PositionValue position);
void (*anyInputPacketCallback)();
// private variables
uint8_t lastValuesCount_;
uint8_t lastValues_next;
bool haveNewValues_;
#if defined(WIN32) || defined(_WIN64)
HANDLE thread_;
CRITICAL_SECTION lock_;
#else
pthread_t thread_;
pthread_mutex_t lock_;
#endif
};
#define POSITION_DATAGRAM_ID 0x0001
#define BEACONS_POSITIONS_DATAGRAM_ID 0x0002
#define POSITION_DATAGRAM_HIGHRES_ID 0x0011
#define BEACONS_POSITIONS_DATAGRAM_HIGHRES_ID 0x0012
#define IMU_RAW_DATAGRAM_ID 0x0003
#define BEACON_RAW_DISTANCE_DATAGRAM_ID 0x0004
#define IMU_FUSION_DATAGRAM_ID 0x0005
#define TELEMETRY_DATAGRAM_ID 0x0006
#define QUALITY_DATAGRAM_ID 0x0007
#define NT_POSITION_DATAGRAM_HIGHRES_ID 0x0081
#define NT_IMU_RAW_DATAGRAM_ID 0x0083
#define NT_BEACON_RAW_DISTANCE_DATAGRAM_ID 0x0084
#define NT_IMU_FUSION_DATAGRAM_ID 0x0085
#define WAYPOINT_DATAGRAM_ID 0x0201
struct MarvelmindHedge * createMarvelmindHedge ();
void destroyMarvelmindHedge (struct MarvelmindHedge * hedge);
void startMarvelmindHedge (struct MarvelmindHedge * hedge);
void printPositionFromMarvelmindHedge (struct MarvelmindHedge * hedge,
bool onlyNew);
bool getPositionFromMarvelmindHedge (struct MarvelmindHedge * hedge,
struct PositionValue * position);
bool getStationaryBeaconsPositionsFromMarvelmindHedge (struct MarvelmindHedge * hedge,
struct StationaryBeaconsPositions * positions);
void printStationaryBeaconsPositionsFromMarvelmindHedge (struct MarvelmindHedge * hedge,
bool onlyNew);
bool getRawDistancesFromMarvelmindHedge(struct MarvelmindHedge * hedge,
struct RawDistances* rawDistances);
void printRawDistancesFromMarvelmindHedge(struct MarvelmindHedge * hedge,
bool onlyNew);
bool getRawIMUFromMarvelmindHedge(struct MarvelmindHedge * hedge,
struct RawIMUValue* rawIMU);
void printRawIMUFromMarvelmindHedge(struct MarvelmindHedge * hedge,
bool onlyNew);
bool getFusionIMUFromMarvelmindHedge(struct MarvelmindHedge * hedge,
struct FusionIMUValue *fusionIMU);
void printFusionIMUFromMarvelmindHedge(struct MarvelmindHedge * hedge,
bool onlyNew);
bool getTelemetryFromMarvelmindHedge(struct MarvelmindHedge * hedge,
struct TelemetryData *telemetry);
void printTelemetryFromMarvelmindHedge(struct MarvelmindHedge * hedge,
bool onlyNew);
bool getQualityFromMarvelmindHedge(struct MarvelmindHedge * hedge,
struct QualityData *quality);
void printQualityFromMarvelmindHedge(struct MarvelmindHedge * hedge,
bool onlyNew);
void stopMarvelmindHedge (struct MarvelmindHedge * hedge);
struct PositionValue* getMobilePosition (struct MarvelmindHedge * hedge,
bool onlyNew,
int* resultSize);
#if defined(WIN32) || defined(_WIN64)
#define DEFAULT_TTY_FILENAME "\\\\.\\COM3"
#else
#define DEFAULT_TTY_FILENAME "/dev/ttyACM0"
#endif // WIN32