@wemap/positioning 2.1.0 → 2.2.0

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 (53) hide show
  1. package/debug/arcore.html +16 -0
  2. package/package.json +2 -1
  3. package/src/components/ArCoreComponent.jsx +74 -0
  4. package/src/components/GnssWifiComponent.jsx +14 -2
  5. package/src/components/GnssWifiPdrComponent.jsx +9 -0
  6. package/src/components/MapComponent.jsx +226 -0
  7. package/src/components/PdrComponent.jsx +9 -0
  8. package/src/components/PoseComponent.jsx +7 -0
  9. package/src/components/PositioningPoseComponent.jsx +9 -0
  10. package/src/components/Utils.js +18 -0
  11. package/src/components/index.js +2 -0
  12. package/src/errors/MissingArCoreError.js +9 -0
  13. package/src/errors/MissingNativeInterfaceError.js +9 -0
  14. package/src/providers/Provider.js +15 -3
  15. package/src/providers/pose/ArCoreProvider.js +127 -0
  16. package/src/providers/pose/pdr/PdrProvider.js +1 -1
  17. package/webpack/webpack.common.js +1 -1
  18. package/src.old/Constants.js +0 -11
  19. package/src.old/NavigationHandler.js +0 -244
  20. package/src.old/Pose.js +0 -8
  21. package/src.old/attitude/AttitudeHandler.js +0 -342
  22. package/src.old/attitude/EkfAttitude.js +0 -238
  23. package/src.old/attitude/EkfAttitude.spec.js +0 -116
  24. package/src.old/components/AbsoluteAttitude.jsx +0 -136
  25. package/src.old/components/Imu.jsx +0 -89
  26. package/src.old/components/LocationSource.jsx +0 -434
  27. package/src.old/components/Logger.jsx +0 -113
  28. package/src.old/components/NavigationDebugApp.jsx +0 -106
  29. package/src.old/components/Others.jsx +0 -121
  30. package/src.old/components/RelativeAttitude.jsx +0 -104
  31. package/src.old/components/Utils.js +0 -35
  32. package/src.old/components/index.js +0 -13
  33. package/src.old/index.js +0 -7
  34. package/src.old/providers/FixedLocationImuLocationSource.js +0 -66
  35. package/src.old/providers/GnssLocationSource.js +0 -118
  36. package/src.old/providers/GnssPdrLocationSource.js +0 -182
  37. package/src.old/providers/IPLocationSource.js +0 -96
  38. package/src.old/providers/LocationSource.js +0 -290
  39. package/src.old/providers/PdrLocationSource.js +0 -320
  40. package/src.old/providers/ProvidersLogger.js +0 -77
  41. package/src.old/providers/pdr/HeadingUnlocker.js +0 -41
  42. package/src.old/providers/pdr/HeadingUnlocker.spec.js +0 -26
  43. package/src.old/providers/pdr/Smoother.js +0 -90
  44. package/src.old/providers/pdr/Smoother.spec.js +0 -424
  45. package/src.old/providers/pdr/ThugDetector.js +0 -37
  46. package/src.old/providers/steps/StepDetection.js +0 -7
  47. package/src.old/providers/steps/StepDetectionLadetto.js +0 -67
  48. package/src.old/providers/steps/StepDetectionMinMaxPeaks.js +0 -80
  49. package/src.old/providers/steps/StepDetectionMinMaxPeaks2.js +0 -108
  50. package/src.old/sensors/SensorsCompatibility.js +0 -486
  51. package/src.old/sensors/SensorsCompatibility.spec.js +0 -270
  52. package/src.old/sensors/SensorsLogger.js +0 -94
  53. package/src.old/sensors/SensorsLoggerUtils.js +0 -35
@@ -1,342 +0,0 @@
1
- import geomagnetism from 'geomagnetism';
2
-
3
- import { Attitude } from '@wemap/geo';
4
- import {
5
- deg2rad, Quaternion
6
- } from '@wemap/maths';
7
-
8
- import EkfAttitude from './EkfAttitude';
9
- import SensorsCompatibility from '../sensors/SensorsCompatibility';
10
-
11
-
12
- const RelativeMethod = {
13
- AUTOMATIC: 0,
14
- BROWSER: 1,
15
- INTERNAL_EKF: 2
16
- };
17
-
18
- const AbsoluteMethod = {
19
- AUTOMATIC: 0,
20
- BROWSER: 1,
21
- INTERNAL_EKF: 2,
22
- INTERNAL_CUSTOM: 3
23
- };
24
-
25
-
26
- class AttitudeHandler {
27
-
28
- isRelativeStarted = false;
29
-
30
- constructor() {
31
- this.sensorsCompatibility = new SensorsCompatibility();
32
- this.relativeOffsetQuaternion = [1, 0, 0, 0];
33
- this.ekfAttitude = new EkfAttitude();
34
- }
35
-
36
- static get RelativeMethod() {
37
- return RelativeMethod;
38
- }
39
-
40
- static get AbsoluteMethod() {
41
- return AbsoluteMethod;
42
- }
43
-
44
- setLogger(logger) {
45
- this.sensorsCompatibility.setLogger(logger);
46
- }
47
-
48
- startRelative(callback, method = RelativeMethod.INTERNAL_EKF) {
49
-
50
- if (method === RelativeMethod.AUTOMATIC) {
51
- throw new Error('Do not use automatic method for the moment');
52
- }
53
-
54
- let promise;
55
-
56
- this.relativeMethodAnswer = false;
57
-
58
- const fn = (quaternion, timestamp) => {
59
- if (quaternion) {
60
- callback(new Attitude(quaternion), timestamp);
61
- }
62
- };
63
-
64
- this.relativeMethod = method;
65
-
66
- if (method === RelativeMethod.AUTOMATIC) {
67
-
68
- promise = new Promise((resolve, reject) => {
69
- // Try internal EKF first
70
- this.startRelative(callback, RelativeMethod.INTERNAL_EKF)
71
- .then(resolve)
72
- .catch(() => {
73
- this.stopRelative();
74
- // If EKF did not work, try Browser method
75
- this.startRelative(callback, RelativeMethod.BROWSER)
76
- .then(resolve)
77
- .catch(() => {
78
- this.stopRelative();
79
- reject();
80
- });
81
- });
82
- });
83
-
84
- } else if (method === RelativeMethod.BROWSER) {
85
-
86
- promise = this.sensorsCompatibility.startRelativeOrientation((quaternion, timestamp) => {
87
- quaternion = Quaternion.multiply(this.relativeOffsetQuaternion, quaternion);
88
- fn(quaternion, timestamp);
89
- });
90
-
91
- } else if (method === RelativeMethod.INTERNAL_EKF) {
92
-
93
- let lastTimestamp = 0;
94
- promise = this.sensorsCompatibility.startImu(accGyrEvent => {
95
- const timestamp = accGyrEvent.timestamp;
96
- const acc = accGyrEvent.acc;
97
- const gyr = accGyrEvent.gyr;
98
-
99
- // Handle timestamps and dt
100
- if (lastTimestamp === 0) {
101
- lastTimestamp = timestamp;
102
- return;
103
- }
104
- const diffTime = timestamp - lastTimestamp;
105
- lastTimestamp = timestamp;
106
- const quaternion = this.ekfAttitude.update(diffTime, acc, gyr);
107
- fn(quaternion, timestamp);
108
- }, {
109
- accelerometer: true,
110
- gyroscope: true
111
- });
112
- } else {
113
- return Promise.reject();
114
- }
115
-
116
- this.isRelativeStarted = true;
117
-
118
- return promise;
119
- }
120
-
121
-
122
- stopRelative() {
123
- this.isRelativeStarted = false;
124
-
125
- if (this.relativeMethod === RelativeMethod.BROWSER) {
126
- this.sensorsCompatibility.stopRelativeOrientation();
127
- } else if (this.relativeMethod === RelativeMethod.INTERNAL_EKF) {
128
- this.sensorsCompatibility.stopImu();
129
- }
130
- this.relativeMethod = null;
131
- }
132
-
133
-
134
- /**
135
- *
136
- * Set yaw offset, this value will be used as the filter does not use magnetometer
137
- * @param {Number} heading heading offset in radians and clockwise
138
- */
139
- setRelativeHeading(heading) {
140
-
141
- // Minus before "heading" is here because ENU attitude is counter-clockwise whereas WGS84 heading is clockwise.
142
- heading = -heading;
143
-
144
- // Offset from window orientation
145
- heading += deg2rad(window.orientation || 0);
146
-
147
- // // We don't know the method used, so we set both
148
- this.relativeOffsetQuaternion = Quaternion.fromAxisAngle([0, 0, 1], heading);
149
-
150
- // We don't know the method used, so we set both
151
- this.ekfAttitude.setOrientationYaw(heading);
152
-
153
- if (this.relativeMethod === RelativeMethod.BROWSER && this.relativeMethodAnswer) {
154
- this.stopRelative();
155
- return this.startRelative(this.relativeCallback, RelativeMethod.BROWSER);
156
- }
157
-
158
- return Promise.resolve();
159
- }
160
-
161
-
162
- startAbsolute(callback, method = AbsoluteMethod.BROWSER) {
163
-
164
- if (method === AbsoluteMethod.AUTOMATIC) {
165
- throw new Error('Do not use automatic method for the moment');
166
- }
167
-
168
- let promise;
169
-
170
- this.absoluteMethodAnswer = false;
171
-
172
- const fn = (quaternion, timestamp, externalData) => {
173
- if (!quaternion || !this.declinationQuaternion) {
174
- return;
175
- }
176
- const trueQuaternion = Quaternion.multiply(this.declinationQuaternion, quaternion);
177
- callback(new Attitude(trueQuaternion), timestamp, externalData);
178
- };
179
-
180
- this.absoluteMethod = method;
181
-
182
- if (method === AbsoluteMethod.AUTOMATIC) {
183
-
184
- promise = new Promise((resolve, reject) => {
185
-
186
- // Try internal EKF first
187
- this.startAbsolute(callback, AbsoluteMethod.INTERNAL_EKF).catch(() => {
188
- this.stopAbsolute();
189
-
190
- // If EKF did not work, try internal custom method
191
- this.startAbsolute(callback, AbsoluteMethod.INTERNAL_CUSTOM).catch(() => {
192
- this.stopAbsolute();
193
-
194
- // If internal custom did not work, try Browser method
195
- this.startAbsolute(callback, AbsoluteMethod.BROWSER).catch(() => {
196
-
197
- this.stopAbsolute();
198
- reject();
199
-
200
- }).then(resolve);
201
-
202
- }).then(resolve);
203
-
204
- }).then(resolve);
205
- });
206
-
207
- } else if (method === AbsoluteMethod.INTERNAL_CUSTOM) {
208
-
209
- let lastAttitude;
210
- let isFirst = true;
211
-
212
- promise = new Promise((resolve, reject) => {
213
-
214
- const startRelativeFn = (heading) => {
215
- this.stopAbsolute();
216
-
217
- // Mandatory, otherwise this.absoluteMethod is null and cannot be stopped
218
- this.absoluteMethod = AbsoluteMethod.INTERNAL_CUSTOM;
219
-
220
- this.startRelative(callback)
221
- .then(resolve)
222
- .catch(() => {
223
- this.stopRelative();
224
- reject();
225
- });
226
- this.setRelativeHeading(heading);
227
- };
228
-
229
- const customCallback = (attitude, timestamp, externalData) => {
230
- lastAttitude = attitude;
231
-
232
- if (isFirst) {
233
- this.timeoutAbsoluteFirstMillis = setTimeout(() => {
234
- startRelativeFn(externalData && externalData.webkitCompassHeading
235
- ? deg2rad(externalData.webkitCompassHeading)
236
- : lastAttitude.heading);
237
- }, 300);
238
-
239
- isFirst = false;
240
- }
241
-
242
- };
243
-
244
- this.startAbsolute(customCallback, AbsoluteMethod.BROWSER)
245
- .catch(() => {
246
- this.stopAbsolute();
247
- reject();
248
- });
249
- });
250
-
251
- } else if (method === AbsoluteMethod.BROWSER) {
252
- promise = this.sensorsCompatibility.startAbsoluteOrientation((quaternion, timestamp, externalData) => {
253
- fn(quaternion, timestamp, externalData);
254
- });
255
-
256
- } else if (method === AbsoluteMethod.INTERNAL_EKF) {
257
- let lastTimestamp = 0;
258
- promise = this.sensorsCompatibility.startImu(accGyrMagEvent => {
259
- const timestamp = accGyrMagEvent.timestamp;
260
- const acc = accGyrMagEvent.acc;
261
- const gyr = accGyrMagEvent.gyr;
262
- const mag = accGyrMagEvent.mag;
263
-
264
- // Handle timestamps and dt
265
- if (lastTimestamp === 0) {
266
- lastTimestamp = timestamp;
267
- return;
268
- }
269
- const diffTime = timestamp - lastTimestamp;
270
- lastTimestamp = timestamp;
271
- const quaternion = this.ekfAttitude.update(diffTime, acc, gyr, mag);
272
- fn(quaternion, timestamp);
273
- });
274
- } else {
275
- promise = Promise.reject();
276
- }
277
-
278
- return promise;
279
- }
280
-
281
- stopAbsolute() {
282
- if (this.absoluteMethod === AbsoluteMethod.BROWSER) {
283
- this.sensorsCompatibility.stopAbsoluteOrientation();
284
- } else if (this.absoluteMethod === AbsoluteMethod.INTERNAL_EKF) {
285
- this.sensorsCompatibility.stopImu();
286
- } else if (this.absoluteMethod === AbsoluteMethod.INTERNAL_CUSTOM) {
287
- this.stopRelative();
288
- }
289
- if (this.timeoutAbsoluteFirstMillis) {
290
- clearTimeout(this.timeoutAbsoluteFirstMillis);
291
- this.timeoutAbsoluteFirstMillis = null;
292
- }
293
- this.absoluteMethod = null;
294
- }
295
-
296
- // This method should be theoretically called every time the user moves.
297
- // But in reality declination does not change as much.
298
- setUserLocationForAbsolute(userLocation) {
299
- const wmmResult = geomagnetism.model().point([userLocation.lat, userLocation.lng]);
300
- // Declination is given in NED frame and our code use ENU, that is why we have: "-decl"
301
- this.declinationQuaternion = Quaternion.fromAxisAngle([0, 0, 1], - deg2rad(wmmResult.decl));
302
- }
303
-
304
- startMonitoringInclination(callback) {
305
-
306
- this.sensorsCompatibilityInclination = new SensorsCompatibility();
307
-
308
- return this.sensorsCompatibility.startImu(({ acc }) => {
309
-
310
- const screenOrientation = window.orientation || 0;
311
-
312
- const sizeAcc = Math.sqrt(acc[0] * acc[0] + acc[1] * acc[1] + acc[2] * acc[2]);
313
- const accNormalized = [acc[0] / sizeAcc, acc[1] / sizeAcc, acc[2] / sizeAcc];
314
-
315
- const q = [accNormalized[2] + 1, accNormalized[1], -accNormalized[0], 0];
316
- const qSize = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
317
- const qNormalized = [q[0] / qSize, q[1] / qSize, q[2] / qSize, 0];
318
-
319
- let inclination;
320
- if (screenOrientation === 0) {
321
- inclination = Math.asin(2 * qNormalized[1] * qNormalized[0]);
322
- } else if (screenOrientation === 90) {
323
- inclination = -Math.asin(2 * qNormalized[2] * qNormalized[0]);
324
- } else if (screenOrientation === -90) {
325
- inclination = Math.asin(2 * qNormalized[2] * qNormalized[0]);
326
- } else if (screenOrientation === 180) {
327
- inclination = -Math.asin(2 * qNormalized[1] * qNormalized[0]);
328
- }
329
-
330
- callback(inclination);
331
-
332
- }, { accelerometer: true });
333
- }
334
-
335
- stopMonitoringInclination() {
336
- if (this.sensorsCompatibilityInclination) {
337
- this.sensorsCompatibilityInclination.stopImu();
338
- }
339
- }
340
- }
341
-
342
- export default AttitudeHandler;
@@ -1,238 +0,0 @@
1
- import {
2
- Matrix, Matrix3, Matrix4, Quaternion, Vector, Vector3
3
- } from '@wemap/maths';
4
-
5
-
6
- const DEFAULT_RELATIVE_NOISES = {
7
- acc: 0.5,
8
- gyr: 0.3
9
- };
10
-
11
- const DEFAULT_ABSOLUTE_NOISES = {
12
- acc: 0.5,
13
- gyr: 0.3,
14
- yc: 2
15
- };
16
-
17
- class EkfAttitude {
18
-
19
- constructor(accRef = [0, 0, 1], ycRef = [-1, 0, 0]) {
20
-
21
- this.accRef = accRef;
22
- this.cRef = ycRef;
23
-
24
- this.P = Matrix.diag(Array(4).fill(0.1 ** 2));
25
-
26
- this.quaternion = null;
27
-
28
-
29
- this.noises = {
30
- relative: null,
31
- absolute: null
32
- };
33
- this.setRelativeNoises(DEFAULT_RELATIVE_NOISES);
34
- this.setAbsoluteNoises(DEFAULT_ABSOLUTE_NOISES);
35
- }
36
-
37
- setRelativeNoises(relativeNoises) {
38
- this.noises.relative = {
39
- accelerometer: Matrix.diag(Array(3).fill(relativeNoises.acc ** 2)),
40
- gyroscope: Matrix.diag(Array(3).fill(relativeNoises.gyr ** 2))
41
- };
42
- }
43
-
44
-
45
- setAbsoluteNoises(absoluteNoises) {
46
- this.noises.absolute = {
47
- accelerometer: Matrix.diag(Array(3).fill(absoluteNoises.acc ** 2)),
48
- gyroscope: Matrix.diag(Array(3).fill(absoluteNoises.gyr ** 2)),
49
- yc: Matrix.diag(Array(3).fill(absoluteNoises.yc ** 2))
50
- };
51
- }
52
-
53
- /**
54
- *
55
- * Set yaw offset, this value will be used if the filter does not use magnetometer
56
- * @param {Number} yaw yaw offset in radians and clockwise
57
- */
58
- setOrientationYaw(yaw) {
59
- this.offsetYawQuaternion = Quaternion.fromAxisAngle(this.accRef, yaw);
60
- this.quaternion = null;
61
- }
62
-
63
- /**
64
- * Try to initialize filter.
65
- * To initialize, we need two information: current acceleration (acc) and offset on yaw angle (given by the quaternion: this.offsetYawQuaternion)
66
- */
67
- tryInitialize(acc, mag) {
68
-
69
- const accNormalized = Vector3.normalize(acc);
70
-
71
- if (mag) {
72
- const magNormalized = Vector3.normalize(mag);
73
-
74
- const H = Vector3.normalize(Vector3.cross(magNormalized, accNormalized));
75
- const M = Vector3.cross(accNormalized, H);
76
-
77
- const R = [
78
- [H[0], M[0], accNormalized[0]],
79
- [H[1], M[1], accNormalized[1]],
80
- [H[2], M[2], accNormalized[2]]
81
- ];
82
-
83
- this.quaternion = Quaternion.fromMatrix3(R);
84
-
85
- } else {
86
-
87
- if (!this.offsetYawQuaternion) {
88
- return null;
89
- }
90
-
91
- const r = Vector3.dot(accNormalized, this.accRef) + 1;
92
- const v = Vector3.cross(accNormalized, this.accRef);
93
-
94
- let quaternionWithoutYaw = [r, v[0], v[1], v[2]];
95
- quaternionWithoutYaw = Quaternion.normalize(quaternionWithoutYaw);
96
-
97
- this.quaternion = Quaternion.multiply(this.offsetYawQuaternion, quaternionWithoutYaw);
98
- }
99
-
100
- return this.quaternion;
101
- }
102
-
103
- update(diffTime, acc, gyr, mag) {
104
-
105
- if (!this.quaternion) {
106
- return this.tryInitialize(acc, mag);
107
- }
108
-
109
- let q = this.quaternion;
110
-
111
- /* ------------
112
- * ESTIMATION
113
- * ------------*/
114
-
115
- const qArray = q;
116
- const gyrInt = Vector3.multiplyScalar(gyr, 0.5 * diffTime);
117
- const F = this.computeC([1, gyrInt[0], gyrInt[1], gyrInt[2]]);
118
- const qAPriori = Matrix.multiplyVector(F, q);
119
- const E1 = Matrix.diag([qArray[0], qArray[0], qArray[0]]);
120
- const eSkew = Matrix3.skew([qArray[1], qArray[2], qArray[3]]);
121
-
122
- const qPart = [-1 * qArray[1], -1 * qArray[2], -1 * qArray[3]];
123
- const E = Matrix.concatRow([qPart], Matrix3.add(eSkew, E1));
124
-
125
- const Qk = Matrix.multiplyScalar(
126
- Matrix.multiply(
127
- Matrix.multiply(E, this.noises[mag ? 'absolute' : 'relative'].gyroscope),
128
- Matrix.transpose(E)
129
- ),
130
- (diffTime / 2) ** 2
131
- );
132
-
133
- const pAPriori = Matrix4.add(
134
- Matrix.multiply(
135
- Matrix.multiply(F, this.P),
136
- Matrix.transpose(F)
137
- ),
138
- Qk
139
- );
140
-
141
- /* ------------
142
- * CORRECTION
143
- * ------------*/
144
-
145
- const accNormalized = Vector3.normalize(acc);
146
- let dz, K, H;
147
-
148
- if (mag) {
149
-
150
- const magNormalized = Vector3.normalize(mag);
151
- const yc = Vector3.cross(accNormalized, magNormalized);
152
- const ycNormalized = Vector3.normalize(yc);
153
-
154
- const dzYc = Vector3.subtract(ycNormalized, Quaternion.rotate(qAPriori, this.cRef));
155
- const dzAcc = Vector3.subtract(accNormalized, Quaternion.rotate(qAPriori, this.accRef));
156
- dz = Vector.concat(dzYc, dzAcc);
157
-
158
- const HYc = this.jacobianES(qAPriori, this.cRef);
159
- const HAcc = this.jacobianES(qAPriori, this.accRef);
160
- H = Matrix.concatRow(HYc, HAcc);
161
-
162
- const RYc = Matrix.concatLine(this.noises.absolute.yc, Matrix3.zeros());
163
- const RAcc = Matrix.concatLine(Matrix3.zeros(), this.noises.absolute.accelerometer);
164
- const R = Matrix.concatRow(RYc, RAcc);
165
-
166
- K = Matrix.multiply(
167
- Matrix.multiply(pAPriori, Matrix.transpose(H)),
168
- Matrix.inverse(
169
- Matrix.add(
170
- Matrix.multiply(
171
- Matrix.multiply(H, pAPriori),
172
- Matrix.transpose(H)
173
- ),
174
- R
175
- )
176
- )
177
- );
178
- } else {
179
- dz = Vector3.subtract(accNormalized, Quaternion.rotate(qAPriori, this.accRef));
180
- H = this.jacobianES(qAPriori, this.accRef);
181
- const R = this.noises.relative.accelerometer;
182
-
183
- K = Matrix.multiply(
184
- Matrix.multiply(pAPriori, Matrix.transpose(H)),
185
- Matrix3.inverse(
186
- Matrix3.add(
187
- Matrix.multiply(
188
- Matrix.multiply(H, pAPriori),
189
- Matrix.transpose(H)
190
- ),
191
- R
192
- )
193
- )
194
- );
195
- }
196
-
197
- q = Quaternion.add(
198
- qAPriori,
199
- Matrix.multiplyVector(K, dz)
200
- );
201
- const P = Matrix.multiply(
202
- Matrix4.subtract(
203
- Matrix.identity4(),
204
- Matrix.multiply(K, H)
205
- ),
206
- pAPriori
207
- );
208
-
209
- q = Quaternion.normalize(q);
210
- this.quaternion = q;
211
- this.P = P;
212
-
213
- return q;
214
- }
215
-
216
- computeC(b) {
217
- return [
218
- [b[0], -b[1], -b[2], -b[3]],
219
- [b[1], b[0], b[3], -b[2]],
220
- [b[2], -b[3], b[0], b[1]],
221
- [b[3], b[2], -b[1], b[0]]
222
- ];
223
- }
224
-
225
- jacobianES(q, v) {
226
-
227
- const [qw, qx, qy, qz] = q;
228
- const [vx, vy, vz] = v;
229
-
230
- return [
231
- [2 * qz * vy - 2 * qy * vz, 2 * qy * vy + 2 * qz * vz, 2 * qx * vy - 2 * qw * vz - 4 * qy * vx, 2 * qw * vy + 2 * qx * vz - 4 * qz * vx],
232
- [2 * qx * vz - 2 * qz * vx, 2 * qw * vz - 4 * qx * vy + 2 * qy * vx, 2 * qx * vx + 2 * qz * vz, 2 * qy * vz - 2 * qw * vx - 4 * qz * vy],
233
- [2 * qy * vx - 2 * qx * vy, 2 * qz * vx - 4 * qx * vz - 2 * qw * vy, 2 * qw * vx - 4 * qy * vz + 2 * qz * vy, 2 * qx * vx + 2 * qy * vy]
234
- ];
235
- }
236
- }
237
-
238
- export default EkfAttitude;
@@ -1,116 +0,0 @@
1
- import chai from 'chai';
2
-
3
- import { Quaternion } from '@wemap/maths';
4
-
5
- import EkfAttitude from './EkfAttitude';
6
-
7
- const expect = chai.expect;
8
-
9
- const dt = [
10
- 0.02, 0.02, 0.02, 0.02, 0.02
11
- ];
12
- const accData = [
13
- [-0.034561157, 3.81073, 8.860977],
14
- [-0.030700684, 3.814499, 8.818954],
15
- [-0.018234253, 3.8023376, 8.85762],
16
- [-0.020080566, 3.8205414, 8.8676605],
17
- [-0.054519653, 3.8456726, 8.810287]
18
- ];
19
-
20
- const gyrData = [
21
- [0.0047454834, 0.0028076172, 0.0022888184],
22
- [0.005218506, 0.0020446777, 0.0012207031],
23
- [0.0044555664, 0.0023040771, 4.4250488E-4],
24
- [0.0044555664, 0.0027618408, 0.0011444092],
25
- [0.0040893555, 0.0020446777, 0.0025787354]
26
- ];
27
-
28
- const magData = [
29
- [-7.260132, -29.21753, -30.532837],
30
- [-8.378601, -29.589844, -29.684448],
31
- [-8.784485, -29.97284, -29.86145],
32
- [-8.784485, -30.06134, -30.036926],
33
- [-8.917236, -29.666138, -28.616333]
34
- ];
35
-
36
- const expectationsAbsolute = [
37
- [0.22501367907095468, 0.048112975227173178, -0.19586497565981961, -0.95325279813673824],
38
- [0.22521836492577899, 0.048187611771482071, -0.19604062637627487, -0.953164579168738],
39
- [0.22546875479675244, 0.048146964451479861, -0.19603487950732199, -0.95310861733648156],
40
- [0.22571872218138991, 0.04816067876157637, -0.19609909097002176, -0.95303554708035731],
41
- [0.22598409746972753, 0.048415228863568645, -0.1963289784536566, -0.95291242279877153]
42
- ];
43
-
44
- const expectationsRelative = [
45
- [0.979449872594084, 0.201679452107589, 0.001829118097573, 0],
46
- [0.979412310855378, 0.201861876976980, 0.001818648953412, 0.000022005516141],
47
- [0.979416707676713, 0.201841237873455, 0.001739180982152, 0.000051642340567],
48
- [0.979405268570585, 0.201897124314688, 0.001692389320913, 0.000083114532679],
49
- [0.979351148979101, 0.202158360999907, 0.001821014027950, 0.000089325563504]
50
- ];
51
-
52
- describe('initAbsolute', () => {
53
- it('Should return the good value', () => {
54
- const ekf = new EkfAttitude();
55
- ekf.setAbsoluteNoises({
56
- acc: 0.5,
57
- gyr: 0.3,
58
- yc: 2
59
- });
60
- const result = ekf.update(dt[0], accData[0], gyrData[0], magData[0]);
61
- const distance = Quaternion.distance(result, expectationsAbsolute[0]);
62
- expect(distance).to.below(0.000001);
63
- });
64
- });
65
-
66
- describe('updateAbsolute', () => {
67
- it('Should return the good value', () => {
68
- const ekf = new EkfAttitude();
69
- ekf.setAbsoluteNoises({
70
- acc: 0.5,
71
- gyr: 0.3,
72
- yc: 2
73
- });
74
- let result;
75
- let distance;
76
-
77
- for (let i = 0; i < accData.length; i++) {
78
- result = ekf.update(dt[i], accData[i], gyrData[i], magData[i]);
79
- distance = Quaternion.distance(result, expectationsAbsolute[i]);
80
- expect(distance).to.below(0.000001);
81
- }
82
- });
83
- });
84
-
85
- describe('initRelative', () => {
86
- it('Should return the good value', () => {
87
- const ekf = new EkfAttitude();
88
- ekf.setOrientationYaw(0);
89
- ekf.setRelativeNoises({
90
- acc: 0.5,
91
- gyr: 0.3
92
- });
93
- const result = ekf.update(dt[0], accData[0], gyrData[0]);
94
- const distance = Quaternion.distance(result, expectationsRelative[0]);
95
- expect(distance).to.below(0.000001);
96
- });
97
- });
98
-
99
- describe('updateRelative', () => {
100
- it('Should return the good value', () => {
101
- const ekf = new EkfAttitude();
102
- ekf.setOrientationYaw(0);
103
- ekf.setRelativeNoises({
104
- acc: 0.5,
105
- gyr: 0.3
106
- });
107
- let result;
108
- let distance;
109
-
110
- for (let i = 0; i < accData.length; i++) {
111
- result = ekf.update(dt[i], accData[i], gyrData[i]);
112
- distance = Quaternion.distance(result, expectationsRelative[i]);
113
- expect(distance).to.below(0.000001);
114
- }
115
- });
116
- });