@wemap/providers 10.0.0-alpha.8 → 10.0.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.
- package/dist/wemap-providers.es.js +5284 -0
- package/dist/wemap-providers.es.js.map +1 -0
- package/index.js +1 -0
- package/package.json +10 -10
- package/src/errors/MissingNativeInterfaceError.js +2 -1
- package/src/events/AvailabilityHelper.js +26 -0
- package/src/events/AvailabilityHelper.spec.js +30 -0
- package/src/mapmatching/MapMatchingHandler.js +7 -0
- package/src/providers/FakeProvider.spec.js +1 -1
- package/src/providers/Provider.js +6 -6
- package/src/providers/Provider.spec.js +5 -5
- package/src/providers/attitude/EkfAttitude.js +5 -5
- package/src/providers/attitude/absolute/AbsoluteAttitude.js +27 -7
- package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowser.js +1 -1
- package/src/providers/attitude/relative/RelativeAttitudeFromBrowser.js +1 -1
- package/src/providers/attitude/relative/RelativeAttitudeFromEkf.js +2 -1
- package/src/providers/attitude/relative/RelativeAttitudeFromInertial.js +6 -7
- package/src/providers/imu/Imu.js +2 -2
- package/src/providers/inclination/Inclination.js +2 -3
- package/src/providers/others/CameraNative.js +5 -4
- package/src/providers/position/absolute/AbsolutePosition.js +11 -10
- package/src/providers/position/absolute/GnssWifi.js +1 -1
- package/src/providers/position/absolute/PoleStar.js +5 -3
- package/src/providers/position/relative/GeoRelativePosition.js +4 -6
- package/src/providers/position/relative/GeoRelativePositionFromArCore.js +5 -1
- package/src/providers/position/relative/Pdr.js +2 -1
- package/src/providers/steps/StepDetectionMinMaxPeaks3.js +201 -0
- package/src/providers/steps/StepDetector.js +34 -2
- package/src/providers/steps/StepDetectorLadetto.js +109 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks.js +109 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks2.js +109 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks3.js +109 -0
- package/src/providers/steps/StraightLineDetector.js +11 -0
- package/src/providers/vision/ArCore.js +2 -2
- package/src/providers/vision/vps/ImageRelocalization.js +1 -1
- package/src/providers/vision/vps/RelativeRotationCalc.js +60 -0
- package/src/providers/vision/vps/Vps.js +41 -9
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Constants as GeoConstants } from '@wemap/geo';
|
|
2
|
+
import { Quaternion } from '@wemap/maths';
|
|
3
|
+
|
|
4
|
+
import AvailabilityHelper from '../../events/AvailabilityHelper.js';
|
|
5
|
+
import EventType from '../../events/EventType.js';
|
|
6
|
+
import RelativeAttitudeFromInertial from '../attitude/relative/RelativeAttitudeFromInertial.js';
|
|
7
|
+
import Accelerometer from '../imu/Accelerometer.js';
|
|
8
|
+
import Gyroscope from '../imu/Gyroscope.js';
|
|
9
|
+
import Provider from '../Provider.js';
|
|
10
|
+
import StepDetectionMinMaxPeaks3 from './StepDetectionMinMaxPeaks3.js';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class StepDetectorMinMaxPeaks3 extends Provider {
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.stepDetector = new StepDetectionMinMaxPeaks3();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @override
|
|
22
|
+
*/
|
|
23
|
+
static get pname() {
|
|
24
|
+
return 'StepDetectorMinMaxPeaks3';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @override
|
|
29
|
+
*/
|
|
30
|
+
get _availability() {
|
|
31
|
+
return AvailabilityHelper.every([
|
|
32
|
+
Accelerometer.availability,
|
|
33
|
+
Gyroscope.availability,
|
|
34
|
+
RelativeAttitudeFromInertial.availability
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @override
|
|
40
|
+
*/
|
|
41
|
+
start() {
|
|
42
|
+
|
|
43
|
+
this.numOfSteps = 0;
|
|
44
|
+
|
|
45
|
+
this.accelerometerProviderId = Accelerometer.addEventListener(
|
|
46
|
+
events => this.onAccelerometerEvent(events[0]),
|
|
47
|
+
error => this.notifyError(error)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
this.gyroscopeProviderId = Gyroscope.addEventListener(
|
|
51
|
+
events => (this.angularRateEvent = events[0]),
|
|
52
|
+
error => this.notifyError(error)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
this.attitudeProviderId = RelativeAttitudeFromInertial.addEventListener(
|
|
56
|
+
events => (this.attitudeEvent = events[0]),
|
|
57
|
+
error => this.notifyError(error)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @override
|
|
63
|
+
*/
|
|
64
|
+
stop() {
|
|
65
|
+
Accelerometer.removeEventListener(this.accelerometerProviderId);
|
|
66
|
+
Gyroscope.removeEventListener(this.gyroscopeProviderId);
|
|
67
|
+
RelativeAttitudeFromInertial.removeEventListener(this.attitudeProviderId);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
onAccelerometerEvent(accelerationEvent) {
|
|
71
|
+
|
|
72
|
+
if (!this.attitudeEvent || !this.angularRateEvent) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
values: acceleration, timestamp
|
|
78
|
+
} = accelerationEvent.data;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Step Detection and Step Size Detection
|
|
82
|
+
*/
|
|
83
|
+
const linearAcc = this.constructor.computeLinearAcceleration(
|
|
84
|
+
this.attitudeEvent.data.quaternion, acceleration);
|
|
85
|
+
const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.data.values);
|
|
86
|
+
|
|
87
|
+
if (stepDetected) {
|
|
88
|
+
const size = this.stepDetector.lastStepSize;
|
|
89
|
+
this.numOfSteps++;
|
|
90
|
+
this.notify(this.createEvent(
|
|
91
|
+
EventType.Step, {
|
|
92
|
+
size,
|
|
93
|
+
number: this.numOfSteps
|
|
94
|
+
},
|
|
95
|
+
[accelerationEvent, this.angularRateEvent, this.attitudeEvent]
|
|
96
|
+
));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Linear acceleration in ENU
|
|
101
|
+
static computeLinearAcceleration(quaternion, acc) {
|
|
102
|
+
const linearAcc = Quaternion.rotateMatlab(Quaternion.inverse(quaternion), acc);
|
|
103
|
+
linearAcc[2] -= GeoConstants.EARTH_GRAVITY;
|
|
104
|
+
return linearAcc;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default new StepDetectorMinMaxPeaks3();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import AvailabilityHelper from '../../events/AvailabilityHelper.js';
|
|
1
2
|
import Provider from '../Provider.js';
|
|
2
3
|
import StepDetector from './StepDetector.js';
|
|
3
4
|
import TurnDectector from '../attitude/TurnDectector.js';
|
|
@@ -27,6 +28,16 @@ class StraightLineDetector extends Provider {
|
|
|
27
28
|
return 'StraightLineDetector';
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @override
|
|
33
|
+
*/
|
|
34
|
+
get _availability() {
|
|
35
|
+
return AvailabilityHelper.every([
|
|
36
|
+
TurnDectector.availability,
|
|
37
|
+
StepDetector.availability
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
/**
|
|
31
42
|
* @override
|
|
32
43
|
*/
|
|
@@ -162,11 +162,11 @@ class ArCore extends Provider {
|
|
|
162
162
|
const nativeProvider = this.nativeProvider;
|
|
163
163
|
|
|
164
164
|
if (!nativeProvider.checkAvailability()) {
|
|
165
|
-
return Promise.
|
|
165
|
+
return Promise.resolve(new MissingArCoreError());
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
} catch (e) {
|
|
169
|
-
return Promise.
|
|
169
|
+
return Promise.resolve(e);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
return Promise.resolve();
|
|
@@ -35,7 +35,7 @@ class ImageRelocalization {
|
|
|
35
35
|
* @param {{intrinsic:number[], distortions:number[]}} calibration
|
|
36
36
|
* @param {{position: Coordinates, attitude?: Attitude}} coarsePose
|
|
37
37
|
* @param {Record<string, string> | null} customHeaders
|
|
38
|
-
* @returns {{position: UserPosition, attitude: Attitude}|null}
|
|
38
|
+
* @returns {Promise<{position: UserPosition, attitude: Attitude}|null>}
|
|
39
39
|
*/
|
|
40
40
|
static async relocalize(endpointUrl, imageCanvas, calibration = null,
|
|
41
41
|
coarsePose = null, customHeaders = null) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Attitude } from '@wemap/geo';
|
|
2
|
+
import Logger from '@wemap/logger';
|
|
3
|
+
import RelativeAttitudeFromBrowser from '../../attitude/relative/RelativeAttitudeFromBrowser.js';
|
|
4
|
+
|
|
5
|
+
export default class RelativeRotationCalc {
|
|
6
|
+
|
|
7
|
+
_isRunning = false;
|
|
8
|
+
_dataOnStart = null;
|
|
9
|
+
|
|
10
|
+
tickStart() {
|
|
11
|
+
this._dataOnStart = null;
|
|
12
|
+
|
|
13
|
+
if (this._isRunning) {
|
|
14
|
+
// Do not start the provider if tickStart() has already been called without tickEnd()
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this._isRunning = true;
|
|
19
|
+
|
|
20
|
+
this._providerId = RelativeAttitudeFromBrowser.addEventListener(events => {
|
|
21
|
+
if (!this._dataOnStart) {
|
|
22
|
+
this._dataOnStart = events[0].data;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns {Attitude|null}
|
|
29
|
+
*/
|
|
30
|
+
tickEnd() {
|
|
31
|
+
if (!this._isRunning) {
|
|
32
|
+
Logger.warn('You have to call tickStart before tickEnd');
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this._internalStop();
|
|
37
|
+
|
|
38
|
+
if (!this._dataOnStart) {
|
|
39
|
+
Logger.warn('Delay was too short between tickStart and tickEnd '
|
|
40
|
+
+ 'or RelativeAttitude cannot be retrieved.');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const dataOnEnd = RelativeAttitudeFromBrowser.lastEvent.data;
|
|
45
|
+
return Attitude.diff(this._dataOnStart, dataOnEnd);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_internalStop() {
|
|
49
|
+
RelativeAttitudeFromBrowser.removeEventListener(this._providerId);
|
|
50
|
+
this._providerId = null;
|
|
51
|
+
this._isRunning = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
release() {
|
|
55
|
+
if (this._isRunning) {
|
|
56
|
+
this._internalStop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
1
2
|
/* eslint-disable max-statements */
|
|
2
3
|
import { SharedCameras, Camera } from '@wemap/camera';
|
|
3
4
|
import { Attitude } from '@wemap/geo';
|
|
@@ -12,6 +13,7 @@ import ProviderState from '../../ProviderState.js';
|
|
|
12
13
|
import ImageRelocalization from './ImageRelocalization.js';
|
|
13
14
|
import AbsolutePosition from '../../position/absolute/AbsolutePosition.js';
|
|
14
15
|
import AbsoluteAttitude from '../../attitude/absolute/AbsoluteAttitude.js';
|
|
16
|
+
import RelativeRotationCalc from './RelativeRotationCalc.js';
|
|
15
17
|
|
|
16
18
|
class Vps extends Provider {
|
|
17
19
|
|
|
@@ -21,6 +23,8 @@ class Vps extends Provider {
|
|
|
21
23
|
|
|
22
24
|
static DEFAULT_WAIT_TIME_MIN_INCLINATION_FOR_REQUEST = 200;
|
|
23
25
|
|
|
26
|
+
static DEFAULT_USE_COARSE_POSE = true;
|
|
27
|
+
|
|
24
28
|
static CAMERA_TO_SMARTPHONE_ROT = Quaternion.fromAxisAngle([1, 0, 0], Math.PI);
|
|
25
29
|
|
|
26
30
|
/** @type {boolean} */
|
|
@@ -44,6 +48,9 @@ class Vps extends Provider {
|
|
|
44
48
|
/** @type {number} */
|
|
45
49
|
_waitTimeMinInclinationForRequest = Vps.DEFAULT_WAIT_TIME_MIN_INCLINATION_FOR_REQUEST;
|
|
46
50
|
|
|
51
|
+
/** @type {number} */
|
|
52
|
+
_useCoarsePose = Vps.DEFAULT_USE_COARSE_POSE;
|
|
53
|
+
|
|
47
54
|
/**
|
|
48
55
|
* @override
|
|
49
56
|
*/
|
|
@@ -70,11 +77,17 @@ class Vps extends Provider {
|
|
|
70
77
|
*/
|
|
71
78
|
start() {
|
|
72
79
|
|
|
73
|
-
// 1.
|
|
80
|
+
// 1. Inclination
|
|
81
|
+
this._inclinationProviderId = Inclination.addEventListener();
|
|
82
|
+
|
|
83
|
+
// 2. Relative Rotation Calc
|
|
84
|
+
this._relativeRotationCalc = new RelativeRotationCalc();
|
|
85
|
+
|
|
86
|
+
// 3. Add listeners on shared cameras to detect new cameras
|
|
74
87
|
SharedCameras.on('added', this._onCameraDetected);
|
|
75
88
|
SharedCameras.on('removed', this._onCameraRemoved);
|
|
76
89
|
|
|
77
|
-
//
|
|
90
|
+
// 4. If a camera already exists, use it
|
|
78
91
|
if (SharedCameras.list.length) {
|
|
79
92
|
if (SharedCameras.list.length > 1) {
|
|
80
93
|
Logger.warn('It seems that more than 1 camera has been detected'
|
|
@@ -82,21 +95,21 @@ class Vps extends Provider {
|
|
|
82
95
|
}
|
|
83
96
|
this._useCamera(SharedCameras.list[0].camera);
|
|
84
97
|
}
|
|
85
|
-
|
|
86
|
-
// 3. Inclination
|
|
87
|
-
this._inclinationProviderId = Inclination.addEventListener();
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
101
|
* @override
|
|
92
102
|
*/
|
|
93
103
|
stop() {
|
|
104
|
+
|
|
105
|
+
Inclination.removeEventListener(this._inclinationProviderId);
|
|
106
|
+
|
|
107
|
+
this._relativeRotationCalc.release();
|
|
108
|
+
|
|
94
109
|
SharedCameras.off('added', this._onCameraDetected);
|
|
95
110
|
SharedCameras.off('removed', this._onCameraRemoved);
|
|
96
111
|
|
|
97
112
|
this._camera = null;
|
|
98
|
-
|
|
99
|
-
Inclination.removeEventListener(this._inclinationProviderId);
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
_onCameraDetected = ({ camera }) => {
|
|
@@ -166,9 +179,10 @@ class Vps extends Provider {
|
|
|
166
179
|
}
|
|
167
180
|
|
|
168
181
|
// 3. Get current image from camera and relocalize it.
|
|
182
|
+
this._relativeRotationCalc.tickStart();
|
|
169
183
|
const image = await this._camera.currentImage;
|
|
170
184
|
let coarsePose = null;
|
|
171
|
-
if (AbsolutePosition.lastEvent || AbsoluteAttitude.lastEvent) {
|
|
185
|
+
if (this._useCoarsePose && (AbsolutePosition.lastEvent || AbsoluteAttitude.lastEvent)) {
|
|
172
186
|
coarsePose = {};
|
|
173
187
|
if (AbsolutePosition.lastEvent) {
|
|
174
188
|
coarsePose.position = AbsolutePosition.lastEvent.data;
|
|
@@ -194,7 +208,17 @@ class Vps extends Provider {
|
|
|
194
208
|
Quaternion.fromAxisAngle([0, 0, 1], deg2rad(window.orientation || 0)),
|
|
195
209
|
enuToSmartphoneRot
|
|
196
210
|
);
|
|
197
|
-
|
|
211
|
+
|
|
212
|
+
const diffAttitude = this._relativeRotationCalc.tickEnd() || new Attitude([1, 0, 0, 0]);
|
|
213
|
+
const deviceQuaternionWithRelOffset = Quaternion.multiply(
|
|
214
|
+
deviceQuaternion,
|
|
215
|
+
diffAttitude.quaternion
|
|
216
|
+
);
|
|
217
|
+
const attitude = new Attitude(
|
|
218
|
+
deviceQuaternionWithRelOffset,
|
|
219
|
+
res.attitude.time,
|
|
220
|
+
res.attitude.accuracy
|
|
221
|
+
);
|
|
198
222
|
|
|
199
223
|
// [16/06/22] Force VPS accuracy to 5m if the information does not exist
|
|
200
224
|
// this allows to correctly fuse positions from different providers (VPS,
|
|
@@ -247,6 +271,14 @@ class Vps extends Provider {
|
|
|
247
271
|
set waitTimeMinInclinationForRequest(waitTimeMinInclinationForRequest) {
|
|
248
272
|
this._waitTimeMinInclinationForRequest = waitTimeMinInclinationForRequest;
|
|
249
273
|
}
|
|
274
|
+
|
|
275
|
+
get useCoarsePose() {
|
|
276
|
+
return this._useCoarsePose;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
set useCoarsePose(useCoarsePose) {
|
|
280
|
+
this._useCoarsePose = useCoarsePose;
|
|
281
|
+
}
|
|
250
282
|
}
|
|
251
283
|
|
|
252
284
|
export default new Vps();
|