capacitor-motioncal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CapacitorMotionCal.podspec +23 -0
  2. package/README.md +126 -0
  3. package/android/build.gradle +67 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/com/denizak/motioncalibration/MotionCalibrationPlugin.java +248 -0
  6. package/android/src/main/jniLibs/arm64-v8a/libmotioncalibration.so +0 -0
  7. package/android/src/main/jniLibs/armeabi-v7a/libmotioncalibration.so +0 -0
  8. package/android/src/main/jniLibs/x86/libmotioncalibration.so +0 -0
  9. package/android/src/main/jniLibs/x86_64/libmotioncalibration.so +0 -0
  10. package/common/imuread.h +156 -0
  11. package/common/magcal.c +602 -0
  12. package/common/mahony.c +330 -0
  13. package/common/matrix.c +446 -0
  14. package/common/motioncalibration.c +7 -0
  15. package/common/motioncalibration.h +12 -0
  16. package/common/quality.c +257 -0
  17. package/common/rawdata.c +349 -0
  18. package/common/serialdata.c +501 -0
  19. package/common/visualize.c +131 -0
  20. package/dist/docs.json +292 -0
  21. package/dist/esm/definitions.d.ts +122 -0
  22. package/dist/esm/definitions.js +2 -0
  23. package/dist/esm/definitions.js.map +1 -0
  24. package/dist/esm/index.d.ts +4 -0
  25. package/dist/esm/index.js +7 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/web.d.ts +54 -0
  28. package/dist/esm/web.js +58 -0
  29. package/dist/esm/web.js.map +1 -0
  30. package/dist/plugin.cjs.js +72 -0
  31. package/dist/plugin.cjs.js.map +1 -0
  32. package/dist/plugin.js +75 -0
  33. package/dist/plugin.js.map +1 -0
  34. package/ios/Sources/MotionCalibrationPlugin/MotionCalibration-Bridging-Header.h +26 -0
  35. package/ios/Sources/MotionCalibrationPlugin/MotionCalibrationPlugin.swift +200 -0
  36. package/package.json +83 -0
@@ -0,0 +1,501 @@
1
+ #include "imuread.h"
2
+
3
+ void print_data(const char *name, const unsigned char *data, int len)
4
+ {
5
+ int i;
6
+
7
+ printf("%s (%2d bytes):", name, len);
8
+ for (i = 0; i < len; i++)
9
+ {
10
+ printf(" %02X", data[i]);
11
+ }
12
+ printf("\n");
13
+ }
14
+
15
+ static int packet_primary_data(const unsigned char *data)
16
+ {
17
+ current_orientation.q0 = (float)((int16_t)((data[25] << 8) | data[24])) / 30000.0f;
18
+ current_orientation.q1 = (float)((int16_t)((data[27] << 8) | data[26])) / 30000.0f;
19
+ current_orientation.q2 = (float)((int16_t)((data[29] << 8) | data[28])) / 30000.0f;
20
+ current_orientation.q3 = (float)((int16_t)((data[31] << 8) | data[30])) / 30000.0f;
21
+
22
+ return 1;
23
+ }
24
+
25
+ static int packet_magnetic_cal(const unsigned char *data)
26
+ {
27
+ int16_t id, x, y, z;
28
+ int n;
29
+
30
+ id = (data[7] << 8) | data[6];
31
+ x = (data[9] << 8) | data[8];
32
+ y = (data[11] << 8) | data[10];
33
+ z = (data[13] << 8) | data[12];
34
+
35
+ if (id == 1)
36
+ {
37
+ magcal.V[0] = (float)x * 0.1f;
38
+ magcal.V[1] = (float)y * 0.1f;
39
+ magcal.V[2] = (float)z * 0.1f;
40
+ return 1;
41
+ }
42
+ else if (id == 2)
43
+ {
44
+ magcal.invW[0][0] = (float)x * 0.001f;
45
+ magcal.invW[1][1] = (float)y * 0.001f;
46
+ magcal.invW[2][2] = (float)z * 0.001f;
47
+ return 1;
48
+ }
49
+ else if (id == 3)
50
+ {
51
+ magcal.invW[0][1] = (float)x / 1000.0f;
52
+ magcal.invW[1][0] = (float)x / 1000.0f; // TODO: check this assignment
53
+ magcal.invW[0][2] = (float)y / 1000.0f;
54
+ magcal.invW[1][2] = (float)y / 1000.0f; // TODO: check this assignment
55
+ magcal.invW[1][2] = (float)z / 1000.0f;
56
+ magcal.invW[2][1] = (float)z / 1000.0f; // TODO: check this assignment
57
+ return 1;
58
+ }
59
+ else if (id >= 10 && id < MAGBUFFSIZE + 10)
60
+ {
61
+ n = id - 10;
62
+ if (magcal.valid[n] == 0 || x != magcal.BpFast[0][n] || y != magcal.BpFast[1][n] || z != magcal.BpFast[2][n])
63
+ {
64
+ magcal.BpFast[0][n] = x;
65
+ magcal.BpFast[1][n] = y;
66
+ magcal.BpFast[2][n] = z;
67
+ magcal.valid[n] = 1;
68
+ }
69
+ return 1;
70
+ }
71
+ return 0;
72
+ }
73
+
74
+ static int packet(const unsigned char *data, int len)
75
+ {
76
+ if (len <= 0)
77
+ return 0;
78
+
79
+ if (data[0] == 1 && len == 34)
80
+ {
81
+ return packet_primary_data(data);
82
+ }
83
+ else if (data[0] == 6 && len == 14)
84
+ {
85
+ return packet_magnetic_cal(data);
86
+ }
87
+ return 0;
88
+ }
89
+
90
+ static int packet_encoded(const unsigned char *data, int len)
91
+ {
92
+ const unsigned char *p;
93
+ unsigned char buf[256];
94
+ int buflen = 0, copylen;
95
+
96
+ p = memchr(data, 0x7D, len);
97
+ if (p == NULL)
98
+ {
99
+ return packet(data, len);
100
+ }
101
+ else
102
+ {
103
+ while (1)
104
+ {
105
+ copylen = p - data;
106
+ if (copylen > 0)
107
+ {
108
+ if (buflen + copylen > sizeof(buf))
109
+ return 0;
110
+ memcpy(buf + buflen, data, copylen);
111
+ buflen += copylen;
112
+ data += copylen;
113
+ len -= copylen;
114
+ }
115
+ if (buflen + 1 > sizeof(buf))
116
+ return 0;
117
+ buf[buflen++] = (p[1] == 0x5E) ? 0x7E : 0x7D;
118
+ data += 2;
119
+ len -= 2;
120
+ if (len <= 0)
121
+ break;
122
+ p = memchr(data, 0x7D, len);
123
+ if (p == NULL)
124
+ {
125
+ if (buflen + len > sizeof(buf))
126
+ return 0;
127
+ memcpy(buf + buflen, data, len);
128
+ buflen += len;
129
+ break;
130
+ }
131
+ }
132
+ return packet(buf, buflen);
133
+ }
134
+ }
135
+
136
+ static int packet_parse(const unsigned char *data, int len)
137
+ {
138
+ static unsigned char packetbuf[256];
139
+ static unsigned int packetlen = 0;
140
+ const unsigned char *p;
141
+ int copylen;
142
+ int ret = 0;
143
+
144
+ // print_data("packet_parse", data, len);
145
+ while (len > 0)
146
+ {
147
+ p = memchr(data, 0x7E, len);
148
+ if (p == NULL)
149
+ {
150
+ if (packetlen + len > sizeof(packetbuf))
151
+ {
152
+ packetlen = 0;
153
+ return 0; // would overflow buffer
154
+ }
155
+ memcpy(packetbuf + packetlen, data, len);
156
+ packetlen += len;
157
+ len = 0;
158
+ }
159
+ else if (p > data)
160
+ {
161
+ copylen = p - data;
162
+ if (packetlen + copylen > sizeof(packetbuf))
163
+ {
164
+ packetlen = 0;
165
+ return 0; // would overflow buffer
166
+ }
167
+ memcpy(packetbuf + packetlen, data, copylen);
168
+ packet_encoded(packetbuf, packetlen + copylen);
169
+ packetlen = 0;
170
+ data += copylen + 1;
171
+ len -= copylen + 1;
172
+ }
173
+ else
174
+ {
175
+ if (packetlen > 0)
176
+ {
177
+ if (packet_encoded(packetbuf, packetlen))
178
+ ret = 1;
179
+ packetlen = 0;
180
+ }
181
+ data++;
182
+ len--;
183
+ }
184
+ }
185
+ return ret;
186
+ }
187
+
188
+ #define ASCII_STATE_WORD 0
189
+ #define ASCII_STATE_RAW 1
190
+ #define ASCII_STATE_CAL1 2
191
+ #define ASCII_STATE_CAL2 3
192
+
193
+ static int ascii_parse(const unsigned char *data, int len)
194
+ {
195
+ static int ascii_state = ASCII_STATE_WORD;
196
+ static int ascii_num = 0, ascii_neg = 0, ascii_count = 0;
197
+ static int16_t ascii_raw_data[9];
198
+ static float ascii_cal_data[10];
199
+ static unsigned int ascii_raw_data_count = 0;
200
+ const char *p, *end;
201
+ int ret = 0;
202
+
203
+ // print_data("ascii_parse", data, len);
204
+ end = (const char *)(data + len);
205
+ for (p = (const char *)data; p < end; p++)
206
+ {
207
+ if (ascii_state == ASCII_STATE_WORD)
208
+ {
209
+ if (ascii_count == 0)
210
+ {
211
+ if (*p == 'R')
212
+ {
213
+ ascii_num = ASCII_STATE_RAW;
214
+ ascii_count = 1;
215
+ }
216
+ else if (*p == 'C')
217
+ {
218
+ ascii_num = ASCII_STATE_CAL1;
219
+ ascii_count = 1;
220
+ }
221
+ }
222
+ else if (ascii_count == 1)
223
+ {
224
+ if (*p == 'a')
225
+ {
226
+ ascii_count = 2;
227
+ }
228
+ else
229
+ {
230
+ ascii_num = 0;
231
+ ascii_count = 0;
232
+ }
233
+ }
234
+ else if (ascii_count == 2)
235
+ {
236
+ if (*p == 'w' && ascii_num == ASCII_STATE_RAW)
237
+ {
238
+ ascii_count = 3;
239
+ }
240
+ else if (*p == 'l' && ascii_num == ASCII_STATE_CAL1)
241
+ {
242
+ ascii_count = 3;
243
+ }
244
+ else
245
+ {
246
+ ascii_num = 0;
247
+ ascii_count = 0;
248
+ }
249
+ }
250
+ else if (ascii_count == 3)
251
+ {
252
+ if (*p == ':' && ascii_num == ASCII_STATE_RAW)
253
+ {
254
+ ascii_state = ASCII_STATE_RAW;
255
+ ascii_raw_data_count = 0;
256
+ ascii_num = 0;
257
+ ascii_count = 0;
258
+ }
259
+ else if (*p == '1' && ascii_num == ASCII_STATE_CAL1)
260
+ {
261
+ ascii_count = 4;
262
+ }
263
+ else if (*p == '2' && ascii_num == ASCII_STATE_CAL1)
264
+ {
265
+ ascii_num = ASCII_STATE_CAL2;
266
+ ascii_count = 4;
267
+ }
268
+ else
269
+ {
270
+ ascii_num = 0;
271
+ ascii_count = 0;
272
+ }
273
+ }
274
+ else if (ascii_count == 4)
275
+ {
276
+ if (*p == ':' && ascii_num == ASCII_STATE_CAL1)
277
+ {
278
+ ascii_state = ASCII_STATE_CAL1;
279
+ ascii_raw_data_count = 0;
280
+ ascii_num = 0;
281
+ ascii_count = 0;
282
+ }
283
+ else if (*p == ':' && ascii_num == ASCII_STATE_CAL2)
284
+ {
285
+ ascii_state = ASCII_STATE_CAL2;
286
+ ascii_raw_data_count = 0;
287
+ ascii_num = 0;
288
+ ascii_count = 0;
289
+ }
290
+ else
291
+ {
292
+ ascii_num = 0;
293
+ ascii_count = 0;
294
+ }
295
+ }
296
+ else
297
+ {
298
+ goto fail;
299
+ }
300
+ }
301
+ else if (ascii_state == ASCII_STATE_RAW)
302
+ {
303
+ if (*p == '-')
304
+ {
305
+ // printf("ascii_parse negative\n");
306
+ if (ascii_count > 0)
307
+ goto fail;
308
+ ascii_neg = 1;
309
+ }
310
+ else if (isdigit(*p))
311
+ {
312
+ // printf("ascii_parse digit\n");
313
+ ascii_num = ascii_num * 10 + *p - '0';
314
+ ascii_count++;
315
+ }
316
+ else if (*p == ',')
317
+ {
318
+ // printf("ascii_parse comma, %d\n", ascii_num);
319
+ if (ascii_neg)
320
+ ascii_num = -ascii_num;
321
+ if (ascii_num < -32768 && ascii_num > 32767)
322
+ goto fail;
323
+ if (ascii_raw_data_count >= 8)
324
+ goto fail;
325
+ ascii_raw_data[ascii_raw_data_count++] = ascii_num;
326
+ ascii_num = 0;
327
+ ascii_neg = 0;
328
+ ascii_count = 0;
329
+ }
330
+ else if (*p == 13)
331
+ {
332
+ // printf("ascii_parse newline\n");
333
+ if (ascii_neg)
334
+ ascii_num = -ascii_num;
335
+ if (ascii_num < -32768 && ascii_num > 32767)
336
+ goto fail;
337
+ if (ascii_raw_data_count != 8)
338
+ goto fail;
339
+ ascii_raw_data[ascii_raw_data_count] = ascii_num;
340
+ raw_data(ascii_raw_data);
341
+ ret = 1;
342
+ ascii_raw_data_count = 0;
343
+ ascii_num = 0;
344
+ ascii_neg = 0;
345
+ ascii_count = 0;
346
+ ascii_state = ASCII_STATE_WORD;
347
+ }
348
+ else if (*p == 10)
349
+ {
350
+ }
351
+ else
352
+ {
353
+ goto fail;
354
+ }
355
+ }
356
+ else if (ascii_state == ASCII_STATE_CAL1 || ascii_state == ASCII_STATE_CAL2)
357
+ {
358
+ if (*p == '-')
359
+ {
360
+ // printf("ascii_parse negative\n");
361
+ if (ascii_count > 0)
362
+ goto fail;
363
+ ascii_neg = 1;
364
+ }
365
+ else if (isdigit(*p))
366
+ {
367
+ // printf("ascii_parse digit\n");
368
+ ascii_num = ascii_num * 10 + *p - '0';
369
+ ascii_count++;
370
+ }
371
+ else if (*p == '.')
372
+ {
373
+ // printf("ascii_parse decimal, %d\n", ascii_num);
374
+ if (ascii_raw_data_count > 9)
375
+ goto fail;
376
+ ascii_cal_data[ascii_raw_data_count] = (float)ascii_num;
377
+ ascii_num = 0;
378
+ ascii_count = 0;
379
+ }
380
+ else if (*p == ',')
381
+ {
382
+ // printf("ascii_parse comma, %d\n", ascii_num);
383
+ if (ascii_raw_data_count > 9)
384
+ goto fail;
385
+ ascii_cal_data[ascii_raw_data_count] +=
386
+ (float)ascii_num / powf(10.0f, ascii_count);
387
+ if (ascii_neg)
388
+ ascii_cal_data[ascii_raw_data_count] *= -1.0f;
389
+ ascii_raw_data_count++;
390
+ ascii_num = 0;
391
+ ascii_neg = 0;
392
+ ascii_count = 0;
393
+ }
394
+ else if (*p == 13)
395
+ {
396
+ // printf("ascii_parse newline\n");
397
+ if ((ascii_state == ASCII_STATE_CAL1 && ascii_raw_data_count != 9) || (ascii_state == ASCII_STATE_CAL2 && ascii_raw_data_count != 8))
398
+ goto fail;
399
+ ascii_cal_data[ascii_raw_data_count] +=
400
+ (float)ascii_num / powf(10.0f, ascii_count);
401
+ if (ascii_neg)
402
+ ascii_cal_data[ascii_raw_data_count] *= -1.0f;
403
+ if (ascii_state == ASCII_STATE_CAL1)
404
+ {
405
+ cal1_data(ascii_cal_data);
406
+ }
407
+ else if (ascii_state == ASCII_STATE_CAL2)
408
+ {
409
+ cal2_data(ascii_cal_data);
410
+ }
411
+ ret = 1;
412
+ ascii_raw_data_count = 0;
413
+ ascii_num = 0;
414
+ ascii_neg = 0;
415
+ ascii_count = 0;
416
+ ascii_state = ASCII_STATE_WORD;
417
+ }
418
+ else if (*p == 10)
419
+ {
420
+ }
421
+ else
422
+ {
423
+ goto fail;
424
+ }
425
+ }
426
+ }
427
+ return ret;
428
+ fail:
429
+ // printf("ascii FAIL\n");
430
+ ascii_state = ASCII_STATE_WORD;
431
+ ascii_raw_data_count = 0;
432
+ ascii_num = 0;
433
+ ascii_neg = 0;
434
+ ascii_count = 0;
435
+ return 0;
436
+ }
437
+
438
+ static void newdata(const unsigned char *data, int len)
439
+ {
440
+ packet_parse(data, len);
441
+ ascii_parse(data, len);
442
+ // TODO: learn which one and skip the other
443
+ }
444
+
445
+ // PhiEs start =======
446
+ void clear_file(const char *filename) {
447
+ FILE *file = fopen(filename, "w");
448
+ if (file != NULL)
449
+ {
450
+ fclose(file);
451
+ }
452
+ }
453
+
454
+ int read_ipc_file_data(const char *filename)
455
+ {
456
+ char buf[256];
457
+ FILE *inFile = fopen(filename, "rb");
458
+ if(inFile) {
459
+ if (fgets(buf,sizeof(buf),inFile) != NULL)
460
+ {
461
+ clear_file(filename);
462
+ // Conver to uchar
463
+ unsigned char uchar_data[256];
464
+ for (size_t i = 0; i < strlen(buf); i++) {
465
+ uchar_data[i] = (unsigned char)buf[i];
466
+ }
467
+ uchar_data[strlen(buf)] = '\0';
468
+ newdata(uchar_data, sizeof(uchar_data));
469
+ }
470
+ fclose(inFile);
471
+ return sizeof(buf);
472
+ }
473
+ return 0;
474
+ }
475
+
476
+ static char result_filename[512];
477
+ int write_ipc_file_data(const void *ptr, int len)
478
+ {
479
+ FILE *file = fopen(result_filename, "wb");
480
+ if (!file) {
481
+ perror("Error opening file");
482
+ return -1;
483
+ }
484
+
485
+ int written = fwrite(ptr, 1, len, file);
486
+ if (written < len) {
487
+ perror("Error writing to file");
488
+ fclose(file);
489
+ return -1;
490
+ }
491
+
492
+ fclose(file);
493
+ return written;
494
+ }
495
+
496
+ // PhiEs end =======
497
+
498
+ void set_result_filename(const char *filename) {
499
+ strncpy(result_filename, filename, sizeof(result_filename) - 1);
500
+ result_filename[sizeof(result_filename) - 1] = '\0';
501
+ }
@@ -0,0 +1,131 @@
1
+ #include "imuread.h"
2
+
3
+ MagCalibration_t magcal;
4
+
5
+ Quaternion_t current_orientation;
6
+
7
+ static float draw_points[MAGBUFFSIZE * 3]; // Each point has x,y,z coordinates
8
+
9
+ void apply_calibration(int16_t rawx, int16_t rawy, int16_t rawz, Point_t *out)
10
+ {
11
+ float x, y, z;
12
+
13
+ x = ((float)rawx * UT_PER_COUNT) - magcal.V[0];
14
+ y = ((float)rawy * UT_PER_COUNT) - magcal.V[1];
15
+ z = ((float)rawz * UT_PER_COUNT) - magcal.V[2];
16
+ out->x = x * magcal.invW[0][0] + y * magcal.invW[0][1] + z * magcal.invW[0][2];
17
+ out->y = x * magcal.invW[1][0] + y * magcal.invW[1][1] + z * magcal.invW[1][2];
18
+ out->z = x * magcal.invW[2][0] + y * magcal.invW[2][1] + z * magcal.invW[2][2];
19
+ }
20
+
21
+ static void quad_to_rotation(const Quaternion_t *quat, float *rmatrix)
22
+ {
23
+ float qw = quat->q0;
24
+ float qx = quat->q1;
25
+ float qy = quat->q2;
26
+ float qz = quat->q3;
27
+ rmatrix[0] = 1.0f - 2.0f * qy * qy - 2.0f * qz * qz;
28
+ rmatrix[1] = 2.0f * qx * qy - 2.0f * qz * qw;
29
+ rmatrix[2] = 2.0f * qx * qz + 2.0f * qy * qw;
30
+ rmatrix[3] = 2.0f * qx * qy + 2.0f * qz * qw;
31
+ rmatrix[4] = 1.0f - 2.0f * qx * qx - 2.0f * qz * qz;
32
+ rmatrix[5] = 2.0f * qy * qz - 2.0f * qx * qw;
33
+ rmatrix[6] = 2.0f * qx * qz - 2.0f * qy * qw;
34
+ rmatrix[7] = 2.0f * qy * qz + 2.0f * qx * qw;
35
+ rmatrix[8] = 1.0f - 2.0f * qx * qx - 2.0f * qy * qy;
36
+ }
37
+
38
+ static void rotate(const Point_t *in, Point_t *out, const float *rmatrix)
39
+ {
40
+ out->x = in->x * rmatrix[0] + in->y * rmatrix[1] + in->z * rmatrix[2];
41
+ out->y = in->x * rmatrix[3] + in->y * rmatrix[4] + in->z * rmatrix[5];
42
+ out->z = in->x * rmatrix[6] + in->y * rmatrix[7] + in->z * rmatrix[8];
43
+ }
44
+
45
+ int invert_q0=0;
46
+ int invert_q1=0;
47
+ int invert_q2=0;
48
+ int invert_q3=1;
49
+ int invert_x=0;
50
+ int invert_y=0;
51
+ int invert_z=0;
52
+
53
+ void display_callback(void)
54
+ {
55
+ int i;
56
+ float xscale, yscale, zscale;
57
+ float xoff, yoff, zoff;
58
+ float rotation[9];
59
+ Point_t point, draw;
60
+ Quaternion_t orientation;
61
+
62
+ quality_reset();
63
+
64
+ xscale = 0.05;
65
+ yscale = 0.05;
66
+ zscale = 0.05;
67
+ xoff = 0.0;
68
+ yoff = 0.0;
69
+ zoff = -7.0;
70
+
71
+ memcpy(&orientation, &current_orientation, sizeof(orientation));
72
+ if (invert_q0) orientation.q0 *= -1.0f;
73
+ if (invert_q1) orientation.q1 *= -1.0f;
74
+ if (invert_q2) orientation.q2 *= -1.0f;
75
+ if (invert_q3) orientation.q3 *= -1.0f;
76
+ quad_to_rotation(&orientation, rotation);
77
+ for (i=0; i < MAGBUFFSIZE; i++) {
78
+ draw_points[i*3] = 0.0f; // Fix indexing
79
+ draw_points[i*3+1] = 0.0f; // Fix indexing
80
+ draw_points[i*3+2] = 0.0f; // Fix indexing
81
+ if (magcal.valid[i]) {
82
+ apply_calibration(magcal.BpFast[0][i], magcal.BpFast[1][i], magcal.BpFast[2][i], &point);
83
+ quality_update(&point);
84
+ rotate(&point, &draw, rotation);
85
+ if (invert_x) draw.x *= -1.0f;
86
+ if (invert_y) draw.y *= -1.0f;
87
+ if (invert_z) draw.z *= -1.0f;
88
+ draw_points[i*3] = draw.x * xscale + xoff;
89
+ draw_points[i*3+1] = draw.z * yscale + yoff;
90
+ draw_points[i*3+2] = draw.y * zscale + zoff;
91
+ }
92
+ }
93
+ }
94
+
95
+ float* get_draw_points(void)
96
+ {
97
+ return draw_points;
98
+ }
99
+
100
+ int get_draw_points_count(void)
101
+ {
102
+ return MAGBUFFSIZE;
103
+ }
104
+
105
+ void clear_draw_points(void)
106
+ {
107
+ memset(draw_points, 0, sizeof(draw_points));
108
+ }
109
+
110
+ // Implementation of MagCalibration_t property accessor functions
111
+ void get_hard_iron_offset(float V[3])
112
+ {
113
+ V[0] = magcal.V[0];
114
+ V[1] = magcal.V[1];
115
+ V[2] = magcal.V[2];
116
+ }
117
+
118
+ void get_soft_iron_matrix(float invW[3][3])
119
+ {
120
+ int i, j;
121
+ for (i = 0; i < 3; i++) {
122
+ for (j = 0; j < 3; j++) {
123
+ invW[i][j] = magcal.invW[i][j];
124
+ }
125
+ }
126
+ }
127
+
128
+ float get_geomagnetic_field_magnitude(void)
129
+ {
130
+ return magcal.B;
131
+ }