@wemap/providers 7.5.0 → 8.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/index.js +2 -0
- package/package.json +6 -6
- package/src/Providers.js +1 -0
- package/src/errors/MissingPoleStarError.js +10 -0
- package/src/mapmatching/MapMatchingHandler.js +18 -9
- package/src/providers/Provider.js +14 -3
- package/src/providers/attitude/EkfAttitude.js +4 -4
- package/src/providers/position/absolute/PoleStar.js +112 -0
- package/src/providers/steps/StepDetector.js +1 -1
- package/src/providers/vision/Vps.js +22 -6
- package/dist/wemap-providers.es.js +0 -6007
- package/dist/wemap-providers.es.js.map +0 -1
package/index.js
CHANGED
|
@@ -5,6 +5,8 @@ export * as Providers from './src/Providers.js';
|
|
|
5
5
|
export { default as ProvidersInterface } from './src/ProvidersInterface.js';
|
|
6
6
|
export { default as ProvidersOptions } from './src/ProvidersOptions.js';
|
|
7
7
|
|
|
8
|
+
export { default as MapMatchingHandler } from './src/mapmatching/MapMatchingHandler.js';
|
|
9
|
+
|
|
8
10
|
export { default as PositionSmoother } from './src/smoothers/PositionSmoother.js';
|
|
9
11
|
export { default as AttitudeSmoother } from './src/smoothers/AttitudeSmoother.js';
|
|
10
12
|
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@wemap/camera": "^7.0.0",
|
|
12
|
-
"@wemap/geo": "^
|
|
12
|
+
"@wemap/geo": "^8.0.0-alpha.0",
|
|
13
13
|
"@wemap/geomagnetism": "^0.1.1",
|
|
14
14
|
"@wemap/logger": "^7.0.0",
|
|
15
|
-
"@wemap/map": "^
|
|
16
|
-
"@wemap/maths": "^
|
|
17
|
-
"@wemap/osm": "^
|
|
15
|
+
"@wemap/map": "^8.0.0-alpha.0",
|
|
16
|
+
"@wemap/maths": "^8.0.0-alpha.0",
|
|
17
|
+
"@wemap/osm": "^8.0.0-alpha.0",
|
|
18
18
|
"@wemap/utils": "^7.0.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "A package using different geoloc systems",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"url": "git+https://github.com/wemap/wemap-modules-js.git"
|
|
42
42
|
},
|
|
43
43
|
"type": "module",
|
|
44
|
-
"version": "
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"version": "8.0.0",
|
|
45
|
+
"gitHead": "d22587d4aa616ff930742d34b6b14803863475e4"
|
|
46
46
|
}
|
package/src/Providers.js
CHANGED
|
@@ -29,6 +29,7 @@ export { default as GeoRelativePositionFromArCore } from './providers/position/r
|
|
|
29
29
|
export { default as GeoRelativePosition } from './providers/position/relative/GeoRelativePosition.js';
|
|
30
30
|
|
|
31
31
|
export { default as GnssWifi } from './providers/position/absolute/GnssWifi.js';
|
|
32
|
+
export { default as PoleStar } from './providers/position/absolute/PoleStar.js';
|
|
32
33
|
export { default as Ip } from './providers/position/absolute/Ip.js';
|
|
33
34
|
export { default as AbsolutePosition } from './providers/position/absolute/AbsolutePosition.js';
|
|
34
35
|
|
|
@@ -23,19 +23,19 @@ import ProvidersOptions from '../ProvidersOptions.js';
|
|
|
23
23
|
class MapMatchingHandler extends Provider {
|
|
24
24
|
|
|
25
25
|
/** @type {number} in radians */
|
|
26
|
-
static
|
|
26
|
+
static DEFAULT_MM_MAX_ANGLE = deg2rad(30);
|
|
27
27
|
|
|
28
28
|
/** @type {number} in meters */
|
|
29
|
-
static
|
|
29
|
+
static DEFAULT_MM_MAX_DIST = 30;
|
|
30
30
|
|
|
31
31
|
/** @type {number} in meters */
|
|
32
|
-
static
|
|
32
|
+
static DEFAULT_MM_MIN_DIST = 0;
|
|
33
33
|
|
|
34
34
|
/** @type {boolean} */
|
|
35
|
-
static
|
|
35
|
+
static DEFAULT_USE_ITINERARY_START_AS_POSITION = false;
|
|
36
36
|
|
|
37
37
|
/** @type {boolean} */
|
|
38
|
-
static
|
|
38
|
+
static ORIENTATION_MATCHING = true;
|
|
39
39
|
|
|
40
40
|
/** @type {number} in meters */
|
|
41
41
|
static MM_HUGE_JUMP_DISTANCE = 3;
|
|
@@ -84,9 +84,10 @@ class MapMatchingHandler extends Provider {
|
|
|
84
84
|
super();
|
|
85
85
|
|
|
86
86
|
this._mapMatching = new MapMatching();
|
|
87
|
-
this._mapMatching.maxDistance = MapMatchingHandler.
|
|
88
|
-
this._mapMatching.maxAngleBearing = MapMatchingHandler.
|
|
89
|
-
this._mapMatchingMinDistance = MapMatchingHandler.
|
|
87
|
+
this._mapMatching.maxDistance = MapMatchingHandler.DEFAULT_MM_MAX_DIST;
|
|
88
|
+
this._mapMatching.maxAngleBearing = MapMatchingHandler.DEFAULT_MM_MAX_ANGLE;
|
|
89
|
+
this._mapMatchingMinDistance = MapMatchingHandler.DEFAULT_MM_MIN_DIST;
|
|
90
|
+
this._useItineraryStartAsPosition = MapMatchingHandler.DEFAULT_USE_ITINERARY_START_AS_POSITION;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -187,7 +188,7 @@ class MapMatchingHandler extends Provider {
|
|
|
187
188
|
*/
|
|
188
189
|
_notifyPositionFromItineraryInput(itinerary) {
|
|
189
190
|
|
|
190
|
-
if (!
|
|
191
|
+
if (!this._useItineraryStartAsPosition || itinerary.start) {
|
|
191
192
|
return;
|
|
192
193
|
}
|
|
193
194
|
|
|
@@ -508,6 +509,14 @@ class MapMatchingHandler extends Provider {
|
|
|
508
509
|
set maxAngleBearing(maxAngleBearing) {
|
|
509
510
|
this._mapMatching.maxAngleBearing = maxAngleBearing;
|
|
510
511
|
}
|
|
512
|
+
|
|
513
|
+
get useItineraryStartAsPosition() {
|
|
514
|
+
return this._useItineraryStartAsPosition;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
set useItineraryStartAsPosition(useItineraryStartAsPosition) {
|
|
518
|
+
this._useItineraryStartAsPosition = useItineraryStartAsPosition;
|
|
519
|
+
}
|
|
511
520
|
}
|
|
512
521
|
|
|
513
522
|
export default new MapMatchingHandler();
|
|
@@ -119,6 +119,17 @@ class Provider {
|
|
|
119
119
|
return typeof window !== 'undefined' ? (window.__nativeProviders || null) : null;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
get nativeJsInterface() {
|
|
123
|
+
if (typeof window === 'undefined') {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (!window.__nativeJsProviders) {
|
|
127
|
+
window.__nativeJsProviders = {};
|
|
128
|
+
}
|
|
129
|
+
return window.__nativeJsProviders;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
122
133
|
get useCameraNatively() {
|
|
123
134
|
return false;
|
|
124
135
|
}
|
|
@@ -137,7 +148,7 @@ class Provider {
|
|
|
137
148
|
* @param {Boolean} startIfNecessary
|
|
138
149
|
* @returns {Number}
|
|
139
150
|
*/
|
|
140
|
-
addEventListener(onEvents = () => {}, onError = () => {}, startIfNecessary = true) {
|
|
151
|
+
addEventListener(onEvents = () => { }, onError = () => { }, startIfNecessary = true) {
|
|
141
152
|
const id = ++Provider._callbackUniqueId;
|
|
142
153
|
|
|
143
154
|
/**
|
|
@@ -186,7 +197,7 @@ class Provider {
|
|
|
186
197
|
this.notifyError(e);
|
|
187
198
|
})
|
|
188
199
|
// notifyError can throw an error if onStop is not defined
|
|
189
|
-
.catch(() => {});
|
|
200
|
+
.catch(() => { });
|
|
190
201
|
|
|
191
202
|
return id;
|
|
192
203
|
}
|
|
@@ -239,7 +250,7 @@ class Provider {
|
|
|
239
250
|
* @param {Function} onStopped
|
|
240
251
|
* @returns {Number}
|
|
241
252
|
*/
|
|
242
|
-
addMonitoringListener(onStarted = () => {}, onStopped = () => {}) {
|
|
253
|
+
addMonitoringListener(onStarted = () => { }, onStopped = () => { }) {
|
|
243
254
|
const id = ++this.constructor._callbackUniqueId;
|
|
244
255
|
this._monitoringCallbacks.push({
|
|
245
256
|
id,
|
|
@@ -70,7 +70,7 @@ class EkfAttitude {
|
|
|
70
70
|
[H[2], M[2], accNormalized[2]]
|
|
71
71
|
];
|
|
72
72
|
|
|
73
|
-
this.quaternion = Quaternion.
|
|
73
|
+
this.quaternion = Quaternion.fromMatrix3Matlab(R);
|
|
74
74
|
|
|
75
75
|
} else {
|
|
76
76
|
|
|
@@ -137,8 +137,8 @@ class EkfAttitude {
|
|
|
137
137
|
const yc = Vector3.cross(accNormalized, magNormalized);
|
|
138
138
|
const ycNormalized = Vector3.normalize(yc);
|
|
139
139
|
|
|
140
|
-
const dzYc = Vector3.subtract(ycNormalized, Quaternion.
|
|
141
|
-
const dzAcc = Vector3.subtract(accNormalized, Quaternion.
|
|
140
|
+
const dzYc = Vector3.subtract(ycNormalized, Quaternion.rotateMatlab(qAPriori, this.cRef));
|
|
141
|
+
const dzAcc = Vector3.subtract(accNormalized, Quaternion.rotateMatlab(qAPriori, this.accRef));
|
|
142
142
|
dz = Vector.concat(dzYc, dzAcc);
|
|
143
143
|
|
|
144
144
|
const HYc = this.jacobianES(qAPriori, this.cRef);
|
|
@@ -162,7 +162,7 @@ class EkfAttitude {
|
|
|
162
162
|
)
|
|
163
163
|
);
|
|
164
164
|
} else {
|
|
165
|
-
dz = Vector3.subtract(accNormalized, Quaternion.
|
|
165
|
+
dz = Vector3.subtract(accNormalized, Quaternion.rotateMatlab(qAPriori, this.accRef));
|
|
166
166
|
H = this.jacobianES(qAPriori, this.accRef);
|
|
167
167
|
const R = this.noises.relative.accelerometer;
|
|
168
168
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
|
|
3
|
+
import { Level, UserPosition } from '@wemap/geo';
|
|
4
|
+
import { TimeUtils } from '@wemap/utils';
|
|
5
|
+
|
|
6
|
+
import Provider from '../../Provider.js';
|
|
7
|
+
import EventType from '../../../events/EventType.js';
|
|
8
|
+
import MissingPoleStarError from '../../../errors/MissingPoleStarError.js';
|
|
9
|
+
import MissingNativeInterfaceError from '../../../errors/MissingNativeInterfaceError.js';
|
|
10
|
+
import Constants from '../../Constants.js';
|
|
11
|
+
|
|
12
|
+
class PoleStar extends Provider {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @override
|
|
16
|
+
*/
|
|
17
|
+
static get pname() {
|
|
18
|
+
return 'PoleStar';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @override
|
|
23
|
+
*/
|
|
24
|
+
static get eventsType() {
|
|
25
|
+
return [EventType.AbsolutePosition];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
this.addMethodsToNativeJsProvider();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} apiKey
|
|
35
|
+
*/
|
|
36
|
+
setApiKey(apiKey) {
|
|
37
|
+
this.nativeProvider.setApiKey(apiKey);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @override
|
|
42
|
+
*/
|
|
43
|
+
start() {
|
|
44
|
+
this.nativeProvider.start();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @override
|
|
49
|
+
*/
|
|
50
|
+
stop() {
|
|
51
|
+
this.nativeProvider.stop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @type {?{setApiKey : (key: String) => {}, start: () => {}, stop: () => {}, checkAvailability: () => boolean }} */
|
|
55
|
+
get nativeProvider() {
|
|
56
|
+
|
|
57
|
+
if (!this.nativeInterface) {
|
|
58
|
+
throw new MissingNativeInterfaceError();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const nativeProvider = this.nativeInterface.getPoleStarProvider();
|
|
62
|
+
if (!nativeProvider) {
|
|
63
|
+
throw new MissingPoleStarError();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return nativeProvider;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @override
|
|
71
|
+
*/
|
|
72
|
+
get _availability() {
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
this.nativeProvider.checkAvailability();
|
|
75
|
+
resolve();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addMethodsToNativeJsProvider() {
|
|
80
|
+
|
|
81
|
+
if (!this.nativeJsInterface) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.nativeJsInterface.polestar = {
|
|
86
|
+
callbackError: errorMessage => this.notifyError(new Error(errorMessage)),
|
|
87
|
+
callbackPosition: jsonString => {
|
|
88
|
+
|
|
89
|
+
const json = JSON.parse(jsonString);
|
|
90
|
+
|
|
91
|
+
const timestamp = TimeUtils.unixTimestampToPreciseTime(json.time) / 1e3;
|
|
92
|
+
|
|
93
|
+
const position = new UserPosition(
|
|
94
|
+
json.lat,
|
|
95
|
+
json.lng,
|
|
96
|
+
Constants.DEFAULT_ALTITUDE,
|
|
97
|
+
new Level(json.alt / 5),
|
|
98
|
+
timestamp,
|
|
99
|
+
json.accuracy,
|
|
100
|
+
json.bearing,
|
|
101
|
+
this.pname);
|
|
102
|
+
|
|
103
|
+
this.notify(this.createEvent(
|
|
104
|
+
EventType.AbsolutePosition, position
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default new PoleStar();
|
|
@@ -98,7 +98,7 @@ class StepDetector extends Provider {
|
|
|
98
98
|
|
|
99
99
|
// Linear acceleration in ENU
|
|
100
100
|
static computeLinearAcceleration(quaternion, acc) {
|
|
101
|
-
const linearAcc = Quaternion.
|
|
101
|
+
const linearAcc = Quaternion.rotateMatlab(Quaternion.inverse(quaternion), acc);
|
|
102
102
|
linearAcc[2] -= GeoConstants.EARTH_GRAVITY;
|
|
103
103
|
return linearAcc;
|
|
104
104
|
}
|
|
@@ -12,9 +12,6 @@ import ProviderState from '../ProviderState.js';
|
|
|
12
12
|
|
|
13
13
|
class Vps extends Provider {
|
|
14
14
|
|
|
15
|
-
// static SERVICE_URL = 'http://localhost:45678/';
|
|
16
|
-
static SERVICE_URL = 'https://vps.maaap.it/';
|
|
17
|
-
static MAP_ID = 'wemap';
|
|
18
15
|
static MIN_TIME_BETWEEN_TWO_REQUESTS = 1000;
|
|
19
16
|
|
|
20
17
|
/** @type {boolean} */
|
|
@@ -26,6 +23,10 @@ class Vps extends Provider {
|
|
|
26
23
|
/** @type {Camera} */
|
|
27
24
|
_camera = null;
|
|
28
25
|
|
|
26
|
+
/** @type {?string} */
|
|
27
|
+
_endpoint = null;
|
|
28
|
+
// _endpoint = 'https://vps.maaap.it/wemap';
|
|
29
|
+
|
|
29
30
|
/**
|
|
30
31
|
* @override
|
|
31
32
|
*/
|
|
@@ -76,6 +77,12 @@ class Vps extends Provider {
|
|
|
76
77
|
this._camera = null;
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} endpoint
|
|
82
|
+
*/
|
|
83
|
+
setEndpoint(endpoint) {
|
|
84
|
+
this._endpoint = endpoint;
|
|
85
|
+
}
|
|
79
86
|
|
|
80
87
|
_onCameraDetected = ({ camera }) => {
|
|
81
88
|
if (this._camera) {
|
|
@@ -114,6 +121,13 @@ class Vps extends Provider {
|
|
|
114
121
|
|
|
115
122
|
this._serverError = false;
|
|
116
123
|
|
|
124
|
+
if (!this._endpoint) {
|
|
125
|
+
this._serverError = true;
|
|
126
|
+
Logger.error('VPS endpoint has not been set before calling start()');
|
|
127
|
+
this.stop();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
117
131
|
while (this.state !== ProviderState.STOPPPED) {
|
|
118
132
|
|
|
119
133
|
if (this.lastEvent) {
|
|
@@ -126,7 +140,7 @@ class Vps extends Provider {
|
|
|
126
140
|
break;
|
|
127
141
|
}
|
|
128
142
|
|
|
129
|
-
const url = Vps.SERVICE_URL + Vps.MAP_ID;
|
|
143
|
+
// const url = Vps.SERVICE_URL + Vps.MAP_ID;
|
|
130
144
|
|
|
131
145
|
// 1. Prepare the request
|
|
132
146
|
if (!this._camera || this._camera.state !== Camera.State.STARTED) {
|
|
@@ -139,7 +153,7 @@ class Vps extends Provider {
|
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
// 2. Send the request
|
|
142
|
-
const serverResponse = await fetch(
|
|
156
|
+
const serverResponse = await fetch(this._endpoint, {
|
|
143
157
|
method: 'POST',
|
|
144
158
|
body: JSON.stringify(payload),
|
|
145
159
|
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }
|
|
@@ -150,7 +164,7 @@ class Vps extends Provider {
|
|
|
150
164
|
}
|
|
151
165
|
|
|
152
166
|
// 3. Parse the response
|
|
153
|
-
const events = await this._parseResponse(serverResponse,
|
|
167
|
+
const events = await this._parseResponse(serverResponse, this._endpoint, payload.time);
|
|
154
168
|
if (this._serverError || this.state === ProviderState.STOPPPED) {
|
|
155
169
|
break;
|
|
156
170
|
}
|
|
@@ -245,6 +259,8 @@ class Vps extends Provider {
|
|
|
245
259
|
quaternion[2] /= quaternionNorm;
|
|
246
260
|
quaternion[3] /= quaternionNorm;
|
|
247
261
|
|
|
262
|
+
// TODO: Move camera to smartphone rotation here instead of server
|
|
263
|
+
|
|
248
264
|
const quaternionWithScreenRotation = Quaternion.multiply(
|
|
249
265
|
Quaternion.fromAxisAngle([0, 0, 1], deg2rad(window.orientation || 0)), quaternion
|
|
250
266
|
);
|