@wemap/providers 5.4.9 → 5.6.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.
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@wemap/geo": "^5.
|
|
11
|
+
"@wemap/geo": "^5.6.0",
|
|
12
12
|
"@wemap/geomagnetism": "^0.1.1",
|
|
13
13
|
"@wemap/logger": "^5.0.0",
|
|
14
|
-
"@wemap/map": "^5.
|
|
15
|
-
"@wemap/maths": "^5.
|
|
16
|
-
"@wemap/osm": "^5.
|
|
14
|
+
"@wemap/map": "^5.6.1",
|
|
15
|
+
"@wemap/maths": "^5.6.0",
|
|
16
|
+
"@wemap/osm": "^5.6.1",
|
|
17
17
|
"@wemap/utils": "^5.0.0"
|
|
18
18
|
},
|
|
19
19
|
"description": "A package using different geoloc systems",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
"url": "git+https://github.com/wemap/wemap-modules-js.git"
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
|
-
"version": "5.
|
|
43
|
-
"gitHead": "
|
|
42
|
+
"version": "5.6.1",
|
|
43
|
+
"gitHead": "d3836758ae0b8dbbd76f5f466575a856461a8284"
|
|
44
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbsoluteHeading, Attitude } from '@wemap/geo';
|
|
2
|
-
import { Quaternion } from '@wemap/maths';
|
|
2
|
+
import { deg2rad, diffAngle, Quaternion } from '@wemap/maths';
|
|
3
3
|
import { PromiseUtils } from '@wemap/utils';
|
|
4
4
|
|
|
5
5
|
import Provider from '../../Provider.js';
|
|
@@ -7,12 +7,16 @@ import EventType from '../../../events/EventType.js';
|
|
|
7
7
|
import AbsoluteAttitudeFromBrowser from './AbsoluteAttitudeFromBrowser.js';
|
|
8
8
|
import RelativeAttitude from '../relative/RelativeAttitude.js';
|
|
9
9
|
import ProviderEvent from '../../../events/ProviderEvent.js';
|
|
10
|
+
import HighRotationsDetector from '../../imu/HighRotationsDetector.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Absolute attitude provider gives the device attitude in East-North-Up (ENU) frame
|
|
13
14
|
*/
|
|
14
15
|
class AbsoluteAttitude extends Provider {
|
|
15
16
|
|
|
17
|
+
/** @type {number} */
|
|
18
|
+
static REL_ABS_DIVERGENCE_THRESHOLD = deg2rad(25);
|
|
19
|
+
|
|
16
20
|
/** @type {boolean} */
|
|
17
21
|
_attitudeFromBrowserErrored = false;
|
|
18
22
|
|
|
@@ -35,6 +39,9 @@ class AbsoluteAttitude extends Provider {
|
|
|
35
39
|
/** @type {number[]} quaternion offset from relative to absolute */
|
|
36
40
|
_relAbsQuat;
|
|
37
41
|
|
|
42
|
+
/** @type {boolean} */
|
|
43
|
+
_wasHighRotationInProgress = false;
|
|
44
|
+
|
|
38
45
|
|
|
39
46
|
constructor() {
|
|
40
47
|
super();
|
|
@@ -88,6 +95,7 @@ class AbsoluteAttitude extends Provider {
|
|
|
88
95
|
}
|
|
89
96
|
);
|
|
90
97
|
|
|
98
|
+
this.highRotationDetectorId = HighRotationsDetector.addEventListener();
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
/**
|
|
@@ -96,6 +104,7 @@ class AbsoluteAttitude extends Provider {
|
|
|
96
104
|
stop() {
|
|
97
105
|
AbsoluteAttitudeFromBrowser.removeEventListener(this.fromBrowserProviderId);
|
|
98
106
|
RelativeAttitude.removeEventListener(this.relativeAttitudeProviderId);
|
|
107
|
+
HighRotationsDetector.removeEventListener(this.highRotationDetectorId);
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
onError(error) {
|
|
@@ -173,8 +182,7 @@ class AbsoluteAttitude extends Provider {
|
|
|
173
182
|
Math.PI
|
|
174
183
|
);
|
|
175
184
|
|
|
176
|
-
|
|
177
|
-
let relAbsQuat = this._relAbsQuat;
|
|
185
|
+
const highRotationInProgress = HighRotationsDetector.isInProgress();
|
|
178
186
|
|
|
179
187
|
if (this._eventFromBrowser) {
|
|
180
188
|
|
|
@@ -183,14 +191,29 @@ class AbsoluteAttitude extends Provider {
|
|
|
183
191
|
heading: headingFromAbsolute
|
|
184
192
|
} = this._eventFromBrowser.data;
|
|
185
193
|
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
if (this._wasHighRotationInProgress && !highRotationInProgress) {
|
|
195
|
+
// Update heading for relative if it the end of high rotations
|
|
196
|
+
// (probably due to a magnetometer calibratiton)
|
|
197
|
+
this._forceHeadingForRelative(this._eventFromBrowser);
|
|
198
|
+
|
|
199
|
+
} else if (accuracyWithAbsolute < accuracyWithRelative) {
|
|
200
|
+
// Update heading for relative if:
|
|
201
|
+
// (1) accuracy from absolute is better than relative
|
|
202
|
+
// (2) heading divergence is greater than REL_ABS_DIVERGENCE_THRESHOLD
|
|
203
|
+
const relativeQuaternion = Quaternion.multiply(this._relAbsQuat, quaternion);
|
|
204
|
+
const relativeAttitude = new Attitude(relativeQuaternion);
|
|
205
|
+
const angle = Math.abs(diffAngle(relativeAttitude.heading, headingFromAbsolute));
|
|
206
|
+
if (angle > AbsoluteAttitude.REL_ABS_DIVERGENCE_THRESHOLD) {
|
|
207
|
+
this._forceHeadingForRelative(this._eventFromBrowser);
|
|
208
|
+
}
|
|
189
209
|
}
|
|
210
|
+
|
|
190
211
|
}
|
|
191
212
|
|
|
192
|
-
|
|
193
|
-
|
|
213
|
+
this._wasHighRotationInProgress = highRotationInProgress;
|
|
214
|
+
|
|
215
|
+
const absoluteQuat = Quaternion.multiply(this._relAbsQuat, quaternion);
|
|
216
|
+
const attitude = new Attitude(absoluteQuat, time, accuracyWithRelative);
|
|
194
217
|
|
|
195
218
|
this.notify(this.createEvent(
|
|
196
219
|
EventType.AbsoluteAttitude,
|