-
Notifications
You must be signed in to change notification settings - Fork 11
/
xsens_constants.h
479 lines (417 loc) · 13.8 KB
/
xsens_constants.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#ifndef XSENS_CONSTANTS_H
#define XSENS_CONSTANTS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stdbool.h"
#include "stdint.h"
// Library Related Abstractions
#ifndef XSENS_PAYLOAD_BUFFER_SIZE
// Library users can define their own payload size
// Default to the largest possible packet size
#define XSENS_PAYLOAD_BUFFER_SIZE 2048
#endif
// The basic concept of a valid decoded packet
typedef struct
{
uint8_t message_id;
uint16_t length;
uint8_t payload[XSENS_PAYLOAD_BUFFER_SIZE]; // xsens 'extended packets' can be up to 2kB
} xsens_packet_buffer_t;
#define XSENS_PACKET_BUF_EMPTY { .message_id = 0, .length = 0, .payload = {0} }
// Event flags sent to application-level code
typedef enum
{
XSENS_EVT_TEMPERATURE = 0,
XSENS_EVT_UTC_TIME,
XSENS_EVT_PACKET_COUNT,
XSENS_EVT_TIME_FINE,
XSENS_EVT_TIME_COARSE,
XSENS_EVT_QUATERNION,
XSENS_EVT_EULER,
XSENS_EVT_ROT_MATRIX,
XSENS_EVT_PRESSURE,
XSENS_EVT_DELTA_V,
XSENS_EVT_DELTA_Q,
XSENS_EVT_ACCELERATION,
XSENS_EVT_FREE_ACCELERATION,
XSENS_EVT_ACCELERATION_HR,
XSENS_EVT_RATE_OF_TURN,
XSENS_EVT_RATE_OF_TURN_HR,
XSENS_EVT_GNSS_PVT_PULSE,
XSENS_EVT_RAW_ACC_GYRO_MAG_TEMP,
XSENS_EVT_RAW_GYRO_TEMP,
XSENS_EVT_MAGNETIC,
XSENS_EVT_STATUS_BYTE,
XSENS_EVT_STATUS_WORD,
XSENS_EVT_DEVICE_ID,
XSENS_EVT_LOCATION_ID,
XSENS_EVT_POSITION_ECEF,
XSENS_EVT_LAT_LON,
XSENS_EVT_ALTITUDE_ELLIPSOID,
XSENS_EVT_VELOCITY_XYZ,
} XsensEventFlag_t;
// Enum describes possible types sent to user in the event data union
typedef enum
{
XSENS_EVT_TYPE_NONE = 0,
XSENS_EVT_TYPE_U8,
XSENS_EVT_TYPE_U16,
XSENS_EVT_TYPE_U32,
XSENS_EVT_TYPE_FLOAT = 10,
XSENS_EVT_TYPE_FLOAT2,
XSENS_EVT_TYPE_FLOAT3,
XSENS_EVT_TYPE_FLOAT4,
XSENS_EVT_TYPE_FLOAT9,
XSENS_EVT_TYPE_1220FP = 20,
XSENS_EVT_TYPE_1220FP2,
XSENS_EVT_TYPE_1220FP3,
XSENS_EVT_TYPE_1220FP4,
XSENS_EVT_TYPE_1220FP9,
XSENS_EVT_TYPE_1632FP = 30,
XSENS_EVT_TYPE_1632FP2,
XSENS_EVT_TYPE_1632FP3,
XSENS_EVT_TYPE_1632FP4,
XSENS_EVT_TYPE_1632FP9,
XSENS_EVT_TYPE_DOUBLE = 40,
XSENS_EVT_TYPE_DOUBLE2,
XSENS_EVT_TYPE_DOUBLE3,
XSENS_EVT_TYPE_DOUBLE4,
XSENS_EVT_TYPE_DOUBLE9,
} XsensEventDataType_t;
// Enum describes possible types sent to user in the event data union
typedef enum
{
XSENS_EVT_ENU = 0x0,
XSENS_EVT_NED = 0x4,
XSENS_EVT_NWU = 0x8,
} XsensEventTangentPlaneFormat_t;
// Unionised data sent to user callback
typedef struct
{
XsensEventDataType_t type;
XsensEventTangentPlaneFormat_t coord_ref;
union
{
uint8_t u1;
uint16_t u2;
uint32_t u4;
// Single precision
float f4;
float f4x2[2];
float f4x3[3];
float f4x4[4];
float f4x9[9];
// Fixed-point 12.20
int32_t fp1220;
int32_t fp1220x2[2];
int32_t fp1220x3[3];
int32_t fp1220x4[4];
int32_t fp1220x9[9];
// Fixed-point 16.32
int64_t fp1632;
int64_t fp1632x2[2];
int64_t fp1632x3[3];
int64_t fp1632x4[4];
int64_t fp1632x9[9];
// Double precision
double f8;
double f8x2[2];
double f8x3[3];
double f8x4[4];
double f8x9[9];
} data;
} XsensEventData_t;
// Userspace callback to notify application layer code of a relevant event
// These events are accompanied by output-ready decoded data
typedef void ( *callback_event_t )( XsensEventFlag_t, XsensEventData_t * );
// Callback to userspace serial write function
// Uses args for a uint8_t buffer of bytes, with a uint16_t size value
typedef void ( *callback_data_out_t )( uint8_t *, uint16_t );
// Specific Values and Structures for xsens handling
#define PREAMBLE_BYTE 0xFA
#define ADDRESS_BYTE 0xFF
#define LENGTH_EXTENDED_MODE 0xFF
#define LENGTH_NONE 0x00
enum XSENS_ERRORCODE
{
ERROR_PERIOD_INVALID = 0x03,
ERROR_MESSAGE_INVALID = 0x04,
ERROR_TIMER_OVERFLOW = 0x30,
ERROR_BAUDRATE = 0x20,
ERROR_PARAMETER_INVALID = 0x21,
ERROR_DEVICE = 0x28,
};
// Message Identifiers for MTi->HOST
enum XSENS_MESSAGE_ID_INBOUND
{
// Wakeup and State
MT_WAKEUP = 0x3E,
MT_ACK_GOTOCONFIG = 0x31,
MT_ACK_GOTOMEASUREMENT = 0x11,
MT_ACK_RESET = 0x41,
// Informational Messages
MT_DEVICEID = 0x01,
MT_PRODUCTCODE = 0x1D,
MT_HARDWAREVERSION = 0x1F,
MT_FIRMWAREREV = 0x13,
MT_ERROR = 0x42,
// Device Specific Messages
MT_ACK_BAUDRATE = 0x19,
MT_ACK_SELFTEST = 0x25,
MT_ACK_GNSSPLATFORM = 0x77,
MT_ACK_ERRORMODE = 0xDB, // DEPRECATED by xsens 2020.A
MT_ACK_TRANSMITDELAY = 0xDD,
MT_ACK_OPTIONFLAGS = 0x49,
MT_ACK_LOCATIONID = 0x85,
// Synchronisation Messages
MT_ACK_SYNCSETTINGS = 0x2D,
// Configuration Messages
MT_CONFIGURATION = 0x0D,
MT_ACK_PERIOD = 0x05,
MT_ACK_EXTOUTPUTMODE = 0x87,
MT_ACK_OUTPUTCONFIGURATION = 0xC1,
MT_ACK_STRINGOUTPUTTYPES = 0x8F,
MT_ACK_OUTPUTMODE = 0xD1, // DEPRECATED by xsens rev w
MT_ACK_OUTPUTSETTINGS = 0xD3, // DEPRECATED by xsens rev w
// Data Messages
MT_MTDATA = 0x32,
MT_MTDATA2 = 0x36,
MT_ACK_RESETORIENTATION = 0xA5,
MT_UTCTIME = 0x61,
MT_ACK_AVAILABLEFILTERPROFILES = 0x63,
MT_ACK_FILTERPROFILE = 0x65,
MT_ACK_GNSSLEVERARM = 0x69,
MT_ACK_LATLONALT = 0x6F,
MT_ACK_NOROTATION = 0x23,
MT_ACK_ICCCOMMAND = 0x75,
// Not in xsens manual summary tables
MT_WARNING = 0x43,
MT_ACK_INITIALHEADING = 0xD7,
MT_ACK_FORWARDGNSSDATA = 0xE3,
};
// Message Identifiers for Host->MTi
enum XSENS_MESSAGE_ID_OUTBOUND
{
// Wakeup and State
MT_ACK_WAKEUP = 0x3F,
MT_GOTOCONFIG = 0x30,
MT_GOTOMEASUREMENT = 0x10,
MT_RESET = 0x40,
// Informational Messages
MT_REQDID = 0x00,
MT_REQPRODUCTCODE = 0x1C,
MT_REQHARDWAREVERSION = 0x1E,
MT_REQFWREV = 0x12,
// Device Specific Messages
MT_RESTOREFACTORYDEF = 0x0E,
MT_REQBAUDRATE = 0x18,
MT_SETBAUDRATE = 0x18,
MT_RUNSELFTEST = 0x24,
MT_REQGNSSPLATFORM = 0x76,
MT_SETGNSSPLATFORM = 0x76,
MT_REQERRORMODE = 0xDA,
MT_SETERRORMODE = 0xDA,
MT_REQTRANSMITDELAY = 0xDC,
MT_SETTRANSMITDELAY = 0xDC,
MT_REQOPTIONFLAGS = 0x48,
MT_SETOPTIONFLAGS = 0x48,
MT_REQLOCATIONID = 0x84,
MT_SETLOCATIONID = 0x84,
// Synchronisation Messages
MT_REQSYNCSETTINGS = 0x2C,
MT_SETSYNCSETTINGS = 0x2C,
// Configuration Messages
MT_REQCONFIGURATION = 0x0C,
MT_REQPERIOD = 0x04,
MT_SETPERIOD = 0x04,
MT_REQEXTOUTPUTMODE = 0x86,
MT_SETEXTOUTPUTMODE = 0x86,
MT_REQOUTPUTCONFIGURATION = 0xC0,
MT_SETOUTPUTCONFIGURATION = 0xC0,
MT_REQSTRINGOUTPUTTYPES = 0x8E,
MT_SETSTRINGOUTPUTTYPES = 0x8E,
MT_REQALIGNMENTROTATION = 0xEC,
MT_SETALIGNMENTROTATION = 0xEC,
MT_REQOUTPUTMODE = 0xD0, // DEPRECATED by xsens rev w
MT_SETOUTPUTMODE = 0xD0, // DEPRECATED by xsens rev w
MT_REQOUTPUTSETTINGS = 0xD2, // DEPRECATED by xsens rev w
MT_SETOUTPUTSETTINGS = 0xD2, // DEPRECATED by xsens rev w
// Data Messages
MT_REQDATA = 0x34,
MT_RESETORIENTATION = 0xA4,
MT_REQUTCTIME = 0x60,
MT_SETUTCTIME = 0x60,
MT_ADJUSTUTCTIME = 0xA8,
MT_REQAVAILABLEFILTERPROFILES = 0x62,
MT_REQFILTERPROFILE = 0x64,
MT_SETFILTERPROFILE = 0x64,
MT_REQGNSSLEVERARM = 0x68,
MT_SETGNSSLEVERARM = 0x68,
MT_REQLATLONALT = 0x6E,
MT_SETLATLONALT = 0x6E,
MT_SETNOROTATION = 0x22,
MT_ICCCOMMAND = 0x74,
// Not in xsens manual summary tables
MT_REQOUTPUTSKIPFACTOR = 0xD4,
MT_SETOUTPUTSKIPFACTOR = 0xD4,
MT_REQSETPORTCONFIG = 0x8C,
MT_REQSETCANOUTPUTCONFIG = 0xE8,
MT_REQSETCANCONFIG = 0xE6,
MT_SETINITIALHEADING = 0xD6,
MT_FORWARDGNSSDATA = 0xE2,
};
enum XSENS_DEVICE_MODE
{
MODE_WAKEUP = 0,
MODE_CONFIG,
MODE_MEASUREMENT,
};
typedef enum
{
XSENS_BAUD_4800 = 0x0B,
XSENS_BAUD_9600 = 0x09,
XSENS_BAUD_11400 = 0x08,
XSENS_BAUD_19200 = 0x07,
XSENS_BAUD_28800 = 0x06,
XSENS_BAUD_38400 = 0x05,
XSENS_BAUD_57600 = 0x04,
XSENS_BAUD_76600 = 0x03,
XSENS_BAUD_115200 = 0x02,
XSENS_BAUD_230400 = 0x01,
XSENS_BAUD_460800 = 0x00,
XSENS_BAUD_921600 = 0x80, // two valid bytes exist for this setting
// XSENS_BAUD_921600 = 0xA0,
XSENS_BAUD_2000000 = 0x0C,
XSENS_BAUD_3686400 = 0x0E,
XSENS_BAUD_4000000 = 0x0D,
} XsensBaudSetting_t;
typedef enum
{
XSENS_RESET_ORIENTATION_RESERVED = 0x02,
XSENS_ORIENTATION_STORE = 0x00,
XSENS_ORIENTATION_HEADING_RESET = 0x01,
XSENS_ORIENTATION_INCLINATION_RESET = 0x03,
XSENS_ORIENTATION_ALIGNMENT_RESET = 0x04,
XSENS_ORIENTATION_HEADING_DEFAULT = 0x05,
XSENS_ORIENTATION_INCLINATION_DEFAULT = 0x06,
XSENS_ORIENTATION_ALIGNMENT_DEFAULT = 0x07,
} XsensOrientationSetting_t;
enum XSENS_OPTION_FLAGS
{
XSENS_OPTFLAG_DISABLE_AUTOSTORE = 0x01,
XSENS_OPTFLAG_DISABLE_AUTOMEASUREMENT = 0x02,
XSENS_OPTFLAG_ENABLE_BEIDOU = 0x04,
XSENS_OPTFLAG_RESERVED = 0x08,
XSENS_OPTFLAG_ENABLE_AHS = 0x10,
XSENS_OPTFLAG_ENABLE_ORIENTATION_SMOOTHER = 0x20,
XSENS_OPTFLAG_ENABLE_CONFIG_BUS_ID = 0x40,
XSENS_OPTFLAG_ENABLE_IN_RUN_COMPASS_CAL = 0x80,
XSENS_OPTFLAG_ENABLE_STARTUP_CONFIG_MSG = 0x0200,
XSENS_OPTFLAG_ENABLE_COLD_FILTER_RESET = 0x0400,
XSENS_OPTFLAG_ENABLE_POSITION_VEL_SMOOTHER = 0x0800,
XSENS_OPTFLAG_ENABLE_CONTINUOUS_ZRU = 0x1000,
};
#define XSENS_OPTION_FLAG_IS_SET( OPTIONS, FLAG ) (((OPTIONS) & (FLAG)) == (FLAG))
#define XSENS_OPTION_FLAG_IS_ANY_SET(OPTIONS) ((OPTIONS) != 0)
#define XSENS_OPTION_FLAG_SET(OPTIONS, FLAG) ((OPTIONS) |= (FLAG))
enum XSENS_COORDINATE_SYSTEM
{
XSENS_COORD_ENU = 0x0,
XSENS_COORD_NED = 0x4,
XSENS_COORD_NWU = 0x8,
};
enum XSENS_FLOAT_TYPE
{
XSENS_FLOAT_SINGLE = 0x0,
XSENS_FLOAT_FIXED1220 = 0x1,
XSENS_FLOAT_FIXED1632 = 0x2,
XSENS_FLOAT_DOUBLE = 0x3,
};
// MData2 Field Identifiers
enum XDA_TYPE_IDENTIFIER
{
XDI_UTC_TIME = 0x1010,
XDI_PACKET_COUNTER = 0x1020,
XDI_SAMPLE_TIME_FINE = 0x1060,
XDI_SAMPLE_TIME_COARSE = 0x1070,
XDI_TEMPERATURE = 0x0810,
XDI_QUATERNION = 0x2010,
XDI_ROTATION_MATRIX = 0x2020,
XDI_EULER_ANGLES = 0x2030,
XDI_BARO_PRESSURE = 0x3010,
XDI_DELTA_V = 0x4010,
XDI_ACCELERATION = 0x4020,
XDI_FREE_ACCELERATION = 0x4030,
XDI_ACCELERATION_HIGH_RATE = 0x4040,
XDI_ALTITUDE_ELLIPSOID = 0x5020,
XDI_POSITION_ECEF = 0x5030,
XDI_LAT_LON = 0x5040,
XDI_GNSS_PVT_DATA = 0x7010,
XDI_GNSS_SAT_INFO = 0x7020,
XDI_GNSS_PVT_PULSE = 0x7030,
XDI_RATE_OF_TURN = 0x8020,
XDI_DELTA_Q = 0x8030,
XDI_RATE_OF_TURN_HIGH_RATE = 0x8040,
XDI_RAW_ACC_GYRO_MAG_TEMP = 0xA010,
XDI_RAW_GYRO_TEMP = 0xA020,
XDI_MAGNETIC_FIELD = 0xC020,
XDI_VELOCITY_XYZ = 0xD010,
XDI_STATUS_BYTE = 0xE010,
XDI_STATUS_WORD = 0xE020,
XDI_DEVICE_ID = 0xE080,
XDI_LOCATION_ID = 0xE090,
};
// Helper to modify identifier for precision and coordinate frame settings
#define XSENS_IDENTIFIER_FORMAT( ID, PRECISION, COORDINATE_SYSTEM ) ( (ID) | ( (PRECISION) | (COORDINATE_SYSTEM) ) )
#define XSENS_IDENTIFIER_FORMAT_SIMPLIFY( ID ) ( (ID) & 0xFFF0 )
#define XSENS_IDENTIFIER_FORMAT_GET_PRECISION( ID ) ( (ID) & 0x0003 )
#define XSENS_IDENTIFIER_FORMAT_GET_COORD_SYSTEM( ID ) ( (ID) & 0x000C )
typedef struct
{
uint16_t id;
uint16_t frequency;
} XsensFrequencyConfig_t;
// 32-bit status structure
// Casting to bitfield is end-users responsibility.
// union XDI_STATUS32_UNION status;
// status.word = xsens_coalesce_32BE_32LE(&output->payload[0]);
// printf("filterOK: %d\n", status.bitfield.filter_valid);
typedef struct
{
unsigned int self_test : 1;
unsigned int filter_valid : 1;
unsigned int gnss_fix : 1;
unsigned int no_rotation_status : 2;
unsigned int representative_motion : 1;
unsigned int clock_bias_estimation : 1;
unsigned int reserved_0 : 1;
unsigned int clip_acc_x : 1;
unsigned int clip_acc_y : 1;
unsigned int clip_acc_z : 1;
unsigned int clip_gyro_x : 1;
unsigned int clip_gyro_y : 1;
unsigned int clip_gyro_z : 1;
unsigned int clip_mag_x : 1;
unsigned int clip_mag_y : 1;
unsigned int clip_mag_z : 1;
unsigned int reserved_1 : 2;
unsigned int clipping : 1;
unsigned int reserved_2 : 1;
unsigned int sync_in_mark : 1;
unsigned int sync_out_mark : 1;
unsigned int filter_mode : 3;
unsigned int has_gnss_pulse : 1;
unsigned int rtk_status : 2;
unsigned int reserved_3 : 3;
} xdi_status32_t;
union XDI_STATUS32_UNION
{
uint32_t word;
xdi_status32_t bitfield;
};
#ifdef __cplusplus
}
#endif
#endif
// end XSENS_CONSTANTS_H