@wemap/providers 10.1.0 → 10.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.
package/package.json
CHANGED
|
@@ -325,6 +325,21 @@ class AbsolutePosition extends Provider {
|
|
|
325
325
|
|
|
326
326
|
MapMatchingHandler.notifyPositionFromFeed(newPositionEvent);
|
|
327
327
|
}
|
|
328
|
+
|
|
329
|
+
getBestPositionEvent(...absolutePositionEvents) {
|
|
330
|
+
return absolutePositionEvents.reduce((best, value) => {
|
|
331
|
+
if (!best) {
|
|
332
|
+
return value;
|
|
333
|
+
}
|
|
334
|
+
if (!value || value.data.accuracy === null || value.data.time === null) {
|
|
335
|
+
return best;
|
|
336
|
+
}
|
|
337
|
+
const {accuracy: curAccuracy, time: curTime} = value.data;
|
|
338
|
+
const {accuracy: bestAccuracy, time: bestTime} = best.data;
|
|
339
|
+
// 1.3888 corresponds to 1.3888 m/s (5 km/h)
|
|
340
|
+
return curAccuracy < (bestAccuracy + 1.3888 * (curTime - bestTime)) ? value : best;
|
|
341
|
+
}, null);
|
|
342
|
+
}
|
|
328
343
|
}
|
|
329
344
|
|
|
330
345
|
export default new AbsolutePosition();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable max-nested-callbacks */
|
|
2
|
+
import { UserPosition } from '@wemap/geo';
|
|
3
|
+
import chai from 'chai';
|
|
4
|
+
|
|
5
|
+
import EventType from '../../../events/EventType.js';
|
|
6
|
+
import ProviderEvent from '../../../events/ProviderEvent.js';
|
|
7
|
+
import AbsolutePosition from './AbsolutePosition.js';
|
|
8
|
+
|
|
9
|
+
const { expect } = chai;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
describe('AbsolutePosition', () => {
|
|
13
|
+
|
|
14
|
+
it('getBestPositionEvent', () => {
|
|
15
|
+
|
|
16
|
+
const createEvent = (time, accuracy) =>
|
|
17
|
+
new ProviderEvent(EventType.AbsolutePosition, new UserPosition(0, 0, null, null, time, accuracy));
|
|
18
|
+
|
|
19
|
+
const evt1 = createEvent(4, 1);
|
|
20
|
+
const evt2 = createEvent(4, 5);
|
|
21
|
+
const evt3 = createEvent(2, 1);
|
|
22
|
+
const evt4 = createEvent(2, 2);
|
|
23
|
+
|
|
24
|
+
expect(AbsolutePosition.getBestPositionEvent(evt1, evt2)).equals(evt1);
|
|
25
|
+
expect(AbsolutePosition.getBestPositionEvent(evt1, evt3)).equals(evt1);
|
|
26
|
+
expect(AbsolutePosition.getBestPositionEvent(evt2, evt4)).equals(evt4);
|
|
27
|
+
expect(AbsolutePosition.getBestPositionEvent(null, evt1)).equals(evt1);
|
|
28
|
+
expect(AbsolutePosition.getBestPositionEvent(null, evt1, null)).equals(evt1);
|
|
29
|
+
expect(AbsolutePosition.getBestPositionEvent(null, evt2, evt4)).equals(evt4);
|
|
30
|
+
expect(AbsolutePosition.getBestPositionEvent(null)).equals(null);
|
|
31
|
+
expect(AbsolutePosition.getBestPositionEvent(null, null)).equals(null);
|
|
32
|
+
expect(AbsolutePosition.getBestPositionEvent()).equals(null);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CameraUtils } from '@wemap/camera';
|
|
2
2
|
import { Attitude, Coordinates, UserPosition } from '@wemap/geo';
|
|
3
|
+
import Logger from '@wemap/logger';
|
|
3
4
|
import { TimeUtils, UserAgentUtils } from '@wemap/utils';
|
|
4
5
|
|
|
5
6
|
import VpsRequest from './VpsRequest.js';
|
|
@@ -48,25 +49,31 @@ class ImageRelocalization {
|
|
|
48
49
|
// 2. Send the request
|
|
49
50
|
let serverResponse;
|
|
50
51
|
try {
|
|
52
|
+
const body = JSON.stringify(vpsRequest.toJson());
|
|
53
|
+
Logger.debug(`[VPS] Request (${(body.length / 1024).toFixed(0)} kB) sent to server ${endpointUrl}`);
|
|
51
54
|
serverResponse = await fetch(endpointUrl, {
|
|
52
55
|
method: 'POST',
|
|
53
|
-
body
|
|
56
|
+
body,
|
|
54
57
|
headers: Object.assign(
|
|
55
58
|
{ 'Content-Type': 'application/json', 'Accept': 'application/json' },
|
|
56
59
|
customHeaders ? customHeaders : {}
|
|
57
60
|
)
|
|
58
61
|
});
|
|
59
62
|
} catch (e) {
|
|
63
|
+
Logger.debug('[VPS] Server respond error');
|
|
60
64
|
return null;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
if (serverResponse.status !== 200) {
|
|
68
|
+
Logger.debug('[VPS] Server respond error');
|
|
64
69
|
return null;
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
// 3. Parse the response
|
|
68
73
|
const json = await serverResponse.json();
|
|
69
|
-
|
|
74
|
+
const res = VpsResponse.fromJson(json, timeBeforeRequest);
|
|
75
|
+
Logger.debug(`[VPS] Server respond ${res.success ? 'success' : 'not found'}`);
|
|
76
|
+
return res;
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
static getHeadingFromQuaternion(quaternion) {
|
|
@@ -11,9 +11,11 @@ import Inclination from '../../inclination/Inclination.js';
|
|
|
11
11
|
import Provider from '../../Provider.js';
|
|
12
12
|
import ProviderState from '../../ProviderState.js';
|
|
13
13
|
import ImageRelocalization from './ImageRelocalization.js';
|
|
14
|
-
import AbsolutePosition from '../../position/absolute/AbsolutePosition.js';
|
|
15
14
|
import AbsoluteAttitude from '../../attitude/absolute/AbsoluteAttitude.js';
|
|
16
15
|
import RelativeRotationCalc from './RelativeRotationCalc.js';
|
|
16
|
+
import GnssWifi from '../../position/absolute/GnssWifi.js';
|
|
17
|
+
import AbsolutePosition from '../../position/absolute/AbsolutePosition.js';
|
|
18
|
+
import PoleStar from '../../position/absolute/PoleStar.js';
|
|
17
19
|
|
|
18
20
|
class Vps extends Provider {
|
|
19
21
|
|
|
@@ -179,20 +181,26 @@ class Vps extends Provider {
|
|
|
179
181
|
}
|
|
180
182
|
|
|
181
183
|
// 3. Get current image from camera and relocalize it.
|
|
184
|
+
|
|
185
|
+
// 3.a. Get current image and time it.
|
|
182
186
|
this._relativeRotationCalc.tickStart();
|
|
183
187
|
const image = await this._camera.currentImage;
|
|
188
|
+
|
|
189
|
+
// 3.b. Retrieve coarse position if necessary.
|
|
184
190
|
let coarsePose = null;
|
|
185
|
-
|
|
191
|
+
const bestCoarsePosition = AbsolutePosition.getBestPositionEvent(GnssWifi.lastEvent, PoleStar.lastEvent);
|
|
192
|
+
if (this._useCoarsePose && (bestCoarsePosition || AbsoluteAttitude.lastEvent)) {
|
|
186
193
|
coarsePose = {};
|
|
187
|
-
if (
|
|
188
|
-
coarsePose.position =
|
|
194
|
+
if (bestCoarsePosition) {
|
|
195
|
+
coarsePose.position = bestCoarsePosition.data;
|
|
189
196
|
}
|
|
190
197
|
if (AbsoluteAttitude.lastEvent) {
|
|
191
198
|
coarsePose.attitude = AbsoluteAttitude.lastEvent.data;
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
|
-
const res = await ImageRelocalization.relocalize(this._endpoint, image, null, coarsePose);
|
|
195
201
|
|
|
202
|
+
// 3.c. Send image and metadata.
|
|
203
|
+
const res = await ImageRelocalization.relocalize(this._endpoint, image, null, coarsePose);
|
|
196
204
|
if (!res || !res.success) {
|
|
197
205
|
continue;
|
|
198
206
|
}
|