@wemap/providers 12.10.8 → 12.10.9
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/helpers/CustomMapProvider.d.ts +10 -0
- package/{index.ts → dist/index.d.ts} +0 -14
- package/dist/index.js +1 -3446
- package/dist/index.js.map +1 -1
- package/{src/ProvidersOptions.ts → dist/src/ProvidersOptions.d.ts} +7 -16
- package/dist/src/errors/AskImuOnDesktopError.d.ts +5 -0
- package/dist/src/errors/ContainsIgnoredProviderError.d.ts +5 -0
- package/dist/src/errors/GeolocationApiMissingError.d.ts +5 -0
- package/dist/src/errors/GeolocationPermissionDeniedError.d.ts +5 -0
- package/dist/src/errors/GeolocationPositionUnavailableError.d.ts +5 -0
- package/dist/src/errors/IpResolveServerError.d.ts +5 -0
- package/dist/src/errors/MissingAccelerometerError.d.ts +6 -0
- package/dist/src/errors/MissingArCoreError.d.ts +5 -0
- package/dist/src/errors/MissingGyroscopeError.d.ts +6 -0
- package/dist/src/errors/MissingMagnetometerError.d.ts +5 -0
- package/dist/src/errors/MissingNativeInterfaceError.d.ts +5 -0
- package/dist/src/errors/MissingPoleStarError.d.ts +5 -0
- package/dist/src/errors/MissingSensorError.d.ts +6 -0
- package/dist/src/errors/NoProviderFoundError.d.ts +5 -0
- package/dist/src/events/AvailabilityHelper.d.ts +5 -0
- package/dist/src/events/ProvidersLoggerOld.d.ts +24 -0
- package/dist/src/events/Types.d.ts +34 -0
- package/dist/src/mapmatching/MapMatchingHandler.d.ts +93 -0
- package/dist/src/providers/Constants.d.ts +4 -0
- package/{src/providers/NativeProviders.ts → dist/src/providers/NativeProviders.d.ts} +2 -23
- package/dist/src/providers/Provider.d.ts +64 -0
- package/dist/src/providers/attitude/EkfAttitude.d.ts +41 -0
- package/dist/src/providers/attitude/TurnProvider.d.ts +17 -0
- package/dist/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.d.ts +60 -0
- package/dist/src/providers/attitude/absolute/AbsoluteAttitudeProvider.d.ts +44 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.d.ts +31 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.d.ts +26 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.d.ts +18 -0
- package/dist/src/providers/attitude/relative/RelativeAttitudeProvider.d.ts +25 -0
- package/dist/src/providers/imu/AccelerometerProvider.d.ts +11 -0
- package/dist/src/providers/imu/GyroscopeProvider.d.ts +11 -0
- package/dist/src/providers/imu/HighRotationsProvider.d.ts +15 -0
- package/dist/src/providers/imu/ImuProvider.d.ts +34 -0
- package/dist/src/providers/imu/MagnetometerCalibrationProvider.d.ts +11 -0
- package/dist/src/providers/inclination/InclinationFromAccProvider.d.ts +18 -0
- package/dist/src/providers/inclination/InclinationFromRelativeAttitudeProvider.d.ts +19 -0
- package/dist/src/providers/inclination/InclinationProvider.d.ts +18 -0
- package/dist/src/providers/legacy/helpers/HeadingUnlocker.d.ts +12 -0
- package/dist/src/providers/legacy/helpers/ThugDetector.d.ts +8 -0
- package/dist/src/providers/others/CameraNativeProvider.d.ts +11 -0
- package/dist/src/providers/others/CameraProjectionMatrixProvider.d.ts +11 -0
- package/dist/src/providers/position/absolute/AbsolutePositionProvider.d.ts +35 -0
- package/dist/src/providers/position/absolute/GnssWifiProvider.d.ts +28 -0
- package/dist/src/providers/position/absolute/IpProvider.d.ts +16 -0
- package/dist/src/providers/position/absolute/PoleStarProvider.d.ts +14 -0
- package/dist/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.d.ts +17 -0
- package/dist/src/providers/position/relative/GeoRelativePositionProvider.d.ts +12 -0
- package/dist/src/providers/position/relative/PdrProvider.d.ts +15 -0
- package/dist/src/providers/steps/StepDetectionLadetto.d.ts +15 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks.d.ts +19 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks2.d.ts +27 -0
- package/dist/src/providers/steps/StepDetectionMinMaxPeaks3.d.ts +24 -0
- package/dist/src/providers/steps/StepProvider.d.ts +36 -0
- package/dist/src/providers/steps/StraightLineProvider.d.ts +21 -0
- package/dist/src/providers/vision/ArCoreProvider.d.ts +50 -0
- package/dist/src/providers/vision/BarcodeProvider.d.ts +11 -0
- package/dist/src/providers/vision/vps/ImageRelocalization.d.ts +11 -0
- package/dist/src/providers/vision/vps/RelativeRotationCalc.d.ts +10 -0
- package/dist/src/providers/vision/vps/VpsMetadata.d.ts +33 -0
- package/dist/src/providers/vision/vps/VpsProvider.d.ts +45 -0
- package/dist/src/providers/vision/vps/VpsRequest.d.ts +18 -0
- package/dist/src/providers/vision/vps/VpsResponse.d.ts +15 -0
- package/dist/src/smoothers/AttitudeSmoother.d.ts +23 -0
- package/dist/src/smoothers/PositionSmoother.d.ts +21 -0
- package/package.json +16 -12
- package/src/errors/AskImuOnDesktopError.ts +0 -10
- package/src/errors/ContainsIgnoredProviderError.ts +0 -10
- package/src/errors/GeolocationApiMissingError.ts +0 -10
- package/src/errors/GeolocationPermissionDeniedError.ts +0 -10
- package/src/errors/GeolocationPositionUnavailableError.ts +0 -10
- package/src/errors/IpResolveServerError.ts +0 -10
- package/src/errors/MissingAccelerometerError.ts +0 -11
- package/src/errors/MissingArCoreError.ts +0 -10
- package/src/errors/MissingGyroscopeError.ts +0 -11
- package/src/errors/MissingMagnetometerError.ts +0 -9
- package/src/errors/MissingNativeInterfaceError.ts +0 -11
- package/src/errors/MissingPoleStarError.ts +0 -10
- package/src/errors/MissingSensorError.ts +0 -15
- package/src/errors/NoProviderFoundError.ts +0 -10
- package/src/events/AvailabilityHelper.spec.ts +0 -30
- package/src/events/AvailabilityHelper.ts +0 -28
- package/src/events/ProvidersLoggerOld.ts +0 -87
- package/src/events/Types.ts +0 -18
- package/src/mapmatching/MapMatchingHandler.spec.ts +0 -142
- package/src/mapmatching/MapMatchingHandler.ts +0 -540
- package/src/providers/Constants.ts +0 -5
- package/src/providers/FakeProvider.spec.ts +0 -49
- package/src/providers/Provider.spec.ts +0 -113
- package/src/providers/Provider.ts +0 -244
- package/src/providers/attitude/EkfAttitude.spec.ts +0 -115
- package/src/providers/attitude/EkfAttitude.ts +0 -233
- package/src/providers/attitude/TurnProvider.ts +0 -58
- package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.ts +0 -267
- package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.ts +0 -268
- package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.ts +0 -84
- package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.ts +0 -89
- package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.ts +0 -66
- package/src/providers/attitude/relative/RelativeAttitudeProvider.ts +0 -70
- package/src/providers/imu/AccelerometerProvider.ts +0 -28
- package/src/providers/imu/GyroscopeProvider.ts +0 -27
- package/src/providers/imu/HighRotationsProvider.ts +0 -49
- package/src/providers/imu/ImuProvider.ts +0 -110
- package/src/providers/imu/MagnetometerCalibrationProvider.ts +0 -21
- package/src/providers/inclination/InclinationFromAccProvider.ts +0 -57
- package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.ts +0 -51
- package/src/providers/inclination/InclinationProvider.ts +0 -59
- package/src/providers/legacy/helpers/HeadingUnlocker.spec.ts +0 -53
- package/src/providers/legacy/helpers/HeadingUnlocker.ts +0 -44
- package/src/providers/legacy/helpers/ThugDetector.ts +0 -30
- package/src/providers/others/CameraNativeProvider.ts +0 -29
- package/src/providers/others/CameraProjectionMatrixProvider.ts +0 -25
- package/src/providers/position/absolute/AbsolutePositionProvider.spec.ts +0 -31
- package/src/providers/position/absolute/AbsolutePositionProvider.ts +0 -277
- package/src/providers/position/absolute/GnssWifiProvider.ts +0 -126
- package/src/providers/position/absolute/GnssWifiProviders.spec.ts +0 -90
- package/src/providers/position/absolute/IpProvider.ts +0 -47
- package/src/providers/position/absolute/PoleStarProvider.ts +0 -88
- package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.ts +0 -82
- package/src/providers/position/relative/GeoRelativePositionProvider.ts +0 -35
- package/src/providers/position/relative/PdrProvider.ts +0 -107
- package/src/providers/steps/StepDetectionLadetto.ts +0 -67
- package/src/providers/steps/StepDetectionMinMaxPeaks.ts +0 -70
- package/src/providers/steps/StepDetectionMinMaxPeaks2.ts +0 -99
- package/src/providers/steps/StepDetectionMinMaxPeaks3.ts +0 -192
- package/src/providers/steps/StepProvider.ts +0 -151
- package/src/providers/steps/StraightLineProvider.ts +0 -69
- package/src/providers/vision/ArCoreProvider.ts +0 -184
- package/src/providers/vision/BarcodeProvider.ts +0 -28
- package/src/providers/vision/vps/ImageRelocalization.ts +0 -98
- package/src/providers/vision/vps/RelativeRotationCalc.ts +0 -58
- package/src/providers/vision/vps/VpsMetadata.ts +0 -63
- package/src/providers/vision/vps/VpsProvider.ts +0 -251
- package/src/providers/vision/vps/VpsRequest.ts +0 -29
- package/src/providers/vision/vps/VpsResponse.ts +0 -43
- package/src/providers/vision/vps/VpsSchema.json +0 -90
- package/src/smoothers/AttitudeSmoother.ts +0 -110
- package/src/smoothers/PositionSmoother.spec.ts +0 -53
- package/src/smoothers/PositionSmoother.ts +0 -96
- package/tsconfig.json +0 -3
- package/vite.config.ts +0 -4
- /package/{src/providers/ProviderState.ts → dist/src/providers/ProviderState.d.ts} +0 -0
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { deg2rad, Vector3_t } from '@wemap/maths';
|
|
2
|
-
import { Browser, BrowserUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
import Provider from '../Provider.js';
|
|
5
|
-
import AskImuOnDesktopError from '../../errors/AskImuOnDesktopError.js';
|
|
6
|
-
import { Acceleration, AngularRate } from '../../events/Types.js';
|
|
7
|
-
|
|
8
|
-
// https://stackoverflow.com/a/73369838/2239938
|
|
9
|
-
interface DeviceMotionEventiOS extends DeviceMotionEvent {
|
|
10
|
-
requestPermission?: () => Promise<'granted' | 'denied'>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Imu (Inertial Measurement Unit) provider retrieve acceleration data
|
|
15
|
-
* and/or angular rate data from inertial sensors.
|
|
16
|
-
*
|
|
17
|
-
* -----------------------------------
|
|
18
|
-
* Overview of compatibilities:
|
|
19
|
-
* -----------------------------------
|
|
20
|
-
*
|
|
21
|
-
* Chrome Android (v72.0.3626): YES (via devicemotion)
|
|
22
|
-
* Safari iOS (v12.0): YES (via devicemotion)
|
|
23
|
-
* Opera Android (v50.2.2426): NO {@link https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent}
|
|
24
|
-
* Firefox Android (v65.0.1): YES (via devicemotion)
|
|
25
|
-
*
|
|
26
|
-
* -----------------------------------
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
type ImuEvent = { readonly acceleration?: Acceleration, readonly angularRate?: AngularRate };
|
|
30
|
-
class ImuProvider extends Provider<ImuEvent> {
|
|
31
|
-
|
|
32
|
-
getName = () => 'IMU';
|
|
33
|
-
|
|
34
|
-
availability() {
|
|
35
|
-
return BrowserUtils.isMobile
|
|
36
|
-
? Promise.resolve()
|
|
37
|
-
: Promise.resolve(new AskImuOnDesktopError());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
start() {
|
|
41
|
-
const subscribe = () => window.addEventListener('devicemotion', this.parseDeviceMotionEvent, true);
|
|
42
|
-
|
|
43
|
-
const requestPermission = (DeviceMotionEvent as unknown as DeviceMotionEventiOS).requestPermission || undefined;
|
|
44
|
-
|
|
45
|
-
if (requestPermission) {
|
|
46
|
-
requestPermission()
|
|
47
|
-
.then(response => {
|
|
48
|
-
if (response !== 'granted') {
|
|
49
|
-
throw new Error('Permission not granted');
|
|
50
|
-
}
|
|
51
|
-
subscribe();
|
|
52
|
-
})
|
|
53
|
-
.catch(this.notifyError);
|
|
54
|
-
} else {
|
|
55
|
-
subscribe();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
stop() {
|
|
60
|
-
window.removeEventListener('devicemotion', this.parseDeviceMotionEvent, true);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* devicemotion callback
|
|
65
|
-
*/
|
|
66
|
-
private parseDeviceMotionEvent = (e: DeviceMotionEvent) => {
|
|
67
|
-
|
|
68
|
-
const timestamp = e.timeStamp / 1e3;
|
|
69
|
-
|
|
70
|
-
let acc: Vector3_t | undefined;
|
|
71
|
-
if (e.accelerationIncludingGravity) {
|
|
72
|
-
const {
|
|
73
|
-
x, y, z
|
|
74
|
-
} = e.accelerationIncludingGravity;
|
|
75
|
-
|
|
76
|
-
if (typeof x === 'number' && typeof y === 'number' && typeof z === 'number') {
|
|
77
|
-
acc = [x, y, z];
|
|
78
|
-
|
|
79
|
-
if (BrowserUtils.getName() === Browser.SAFARI
|
|
80
|
-
|| BrowserUtils.getName() === Browser.IOS_WEBVIEW) {
|
|
81
|
-
acc[0] *= -1;
|
|
82
|
-
acc[1] *= -1;
|
|
83
|
-
acc[2] *= -1;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let gyr: [number, number, number] | undefined;
|
|
89
|
-
if (e.rotationRate) {
|
|
90
|
-
const {
|
|
91
|
-
alpha, beta, gamma
|
|
92
|
-
} = e.rotationRate;
|
|
93
|
-
|
|
94
|
-
if (typeof alpha === 'number' && typeof beta === 'number' && typeof gamma === 'number') {
|
|
95
|
-
gyr = [deg2rad(alpha), deg2rad(beta), deg2rad(gamma)];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (acc || gyr) {
|
|
101
|
-
this.notify({
|
|
102
|
-
...(acc && { acceleration: { timestamp, values: acc } }),
|
|
103
|
-
...(gyr && { angularRate: { timestamp, values: gyr } })
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export default new ImuProvider();
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import AbsoluteAttitudeProvider from '../attitude/absolute/AbsoluteAttitudeProvider.js';
|
|
3
|
-
import { MagnetometerNeedCalibration } from '../../events/Types.js';
|
|
4
|
-
|
|
5
|
-
class MagnetometerCalibrationProvider extends Provider<MagnetometerNeedCalibration> {
|
|
6
|
-
|
|
7
|
-
getName = () => 'MagnetometerCalibrationProvider';
|
|
8
|
-
|
|
9
|
-
availability = () => AbsoluteAttitudeProvider.getAvailability();
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
AbsoluteAttitudeProvider._setCallbackMagCalibration(e => this.state === 'started' && this.notify(e));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
start() { /* do nothing */ }
|
|
17
|
-
stop() { /* do nothing */ }
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default new MagnetometerCalibrationProvider();
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import AccelerometerProvider from '../imu/AccelerometerProvider.js';
|
|
3
|
-
import { Acceleration, Inclination } from '../../events/Types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Inclination provider gives the inclination of the device using Imu Sensor
|
|
7
|
-
* For example, when the top of the device is pointing the sky, inclination = Math.PI/2
|
|
8
|
-
* when the device is layed on a table, inclination = 0
|
|
9
|
-
* This provider use window.orientation to return a result in function of screen orientation
|
|
10
|
-
*/
|
|
11
|
-
class InclinationFromAccProvider extends Provider<Inclination> {
|
|
12
|
-
|
|
13
|
-
providerId?: number;
|
|
14
|
-
|
|
15
|
-
getName = () => 'InclinationFromAcc';
|
|
16
|
-
|
|
17
|
-
availability = () => AccelerometerProvider.getAvailability();
|
|
18
|
-
|
|
19
|
-
start() {
|
|
20
|
-
this.providerId = AccelerometerProvider.addEventListener(
|
|
21
|
-
this.onAccelerometerEvent,
|
|
22
|
-
this.notifyError
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
stop() {
|
|
27
|
-
AccelerometerProvider.removeEventListener(this.providerId);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private onAccelerometerEvent = (accelerometerEvent: Acceleration) => {
|
|
31
|
-
const acc = accelerometerEvent.values;
|
|
32
|
-
|
|
33
|
-
const screenOrientation = window.orientation || 0;
|
|
34
|
-
|
|
35
|
-
const sizeAcc = Math.sqrt(acc[0] * acc[0] + acc[1] * acc[1] + acc[2] * acc[2]);
|
|
36
|
-
const accNormalized = [acc[0] / sizeAcc, acc[1] / sizeAcc, acc[2] / sizeAcc];
|
|
37
|
-
|
|
38
|
-
const q = [accNormalized[2] + 1, accNormalized[1], -accNormalized[0], 0];
|
|
39
|
-
const qSize = Math.sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2]);
|
|
40
|
-
const qNormalized = [q[0] / qSize, q[1] / qSize, q[2] / qSize, 0];
|
|
41
|
-
|
|
42
|
-
let inclination;
|
|
43
|
-
if (screenOrientation === 0) {
|
|
44
|
-
inclination = Math.asin(2 * qNormalized[1] * qNormalized[0]);
|
|
45
|
-
} else if (screenOrientation === 90) {
|
|
46
|
-
inclination = -Math.asin(2 * qNormalized[2] * qNormalized[0]);
|
|
47
|
-
} else if (screenOrientation === -90) {
|
|
48
|
-
inclination = Math.asin(2 * qNormalized[2] * qNormalized[0]);
|
|
49
|
-
} else { // if (screenOrientation === 180) {
|
|
50
|
-
inclination = -Math.asin(2 * qNormalized[1] * qNormalized[0]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.notify(inclination);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default new InclinationFromAccProvider();
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Quaternion_t } from '@wemap/maths';
|
|
2
|
-
|
|
3
|
-
import Provider from '../Provider.js';
|
|
4
|
-
import RelativeAttitudeFromInertialProvider from '../attitude/relative/RelativeAttitudeFromInertialProvider.js';
|
|
5
|
-
import { Inclination } from '../../events/Types.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Inclination provider gives the inclination of the device using Relative Attitude
|
|
10
|
-
* For example, when the top of the device is pointing the sky, inclination = Math.PI/2
|
|
11
|
-
* when the device is layed on a table, inclination = 0
|
|
12
|
-
* This provider use window.orientation to return a result in function of screen orientation
|
|
13
|
-
*/
|
|
14
|
-
class InclinationFromRelativeAttitudeProvider extends Provider<Inclination> {
|
|
15
|
-
|
|
16
|
-
providerId?: number;
|
|
17
|
-
|
|
18
|
-
getName = () => 'InclinationFromRelativeAttitude';
|
|
19
|
-
|
|
20
|
-
availability = () => RelativeAttitudeFromInertialProvider.getAvailability();
|
|
21
|
-
|
|
22
|
-
start() {
|
|
23
|
-
this.providerId = RelativeAttitudeFromInertialProvider.addEventListener(
|
|
24
|
-
attitudeEvent => {
|
|
25
|
-
const inclination = this.enuQuatToInclination(attitudeEvent.quaternion);
|
|
26
|
-
this.notify(inclination);
|
|
27
|
-
},
|
|
28
|
-
this.notifyError
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
stop() {
|
|
33
|
-
RelativeAttitudeFromInertialProvider.removeEventListener(this.providerId);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
enuQuatToInclination(q: Quaternion_t) {
|
|
37
|
-
const screenOrientation = window.orientation || 0;
|
|
38
|
-
|
|
39
|
-
if (screenOrientation === 0) {
|
|
40
|
-
return Math.asin(2 * (q[2] * q[3] + q[1] * q[0]));
|
|
41
|
-
} else if (screenOrientation === 90) {
|
|
42
|
-
return Math.asin(2 * (q[1] * q[3] - q[2] * q[0]));
|
|
43
|
-
} else if (screenOrientation === -90) {
|
|
44
|
-
return Math.asin(2 * (q[2] * q[0] - q[1] * q[3]));
|
|
45
|
-
}
|
|
46
|
-
// else if (screenOrientation === 180)
|
|
47
|
-
return -Math.asin(2 * (q[2] * q[3] + q[1] * q[0]));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default new InclinationFromRelativeAttitudeProvider();
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import InclinationFromAccProvider from './InclinationFromAccProvider.js';
|
|
3
|
-
import InclinationFromRelativeAttitudeProvider from './InclinationFromRelativeAttitudeProvider.js';
|
|
4
|
-
import AvailabilityHelper from '../../events/AvailabilityHelper.js';
|
|
5
|
-
import { Inclination } from '../../events/Types.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Inclination provider gives the inclination of the device using Imu Sensor
|
|
9
|
-
* For example, when the top of the device is pointing the sky, inclination = Math.PI/2
|
|
10
|
-
* when the device is layed on a table, inclination = 0
|
|
11
|
-
* This provider use window.orientation to return a result in function of screen orientation
|
|
12
|
-
*/
|
|
13
|
-
class InclinationProvider extends Provider<Inclination> {
|
|
14
|
-
|
|
15
|
-
provider?: Provider<Inclination>;
|
|
16
|
-
providerId?: number;
|
|
17
|
-
|
|
18
|
-
getName = () => 'Inclination';
|
|
19
|
-
|
|
20
|
-
availability() {
|
|
21
|
-
return AvailabilityHelper.some([
|
|
22
|
-
InclinationFromAccProvider.getAvailability(),
|
|
23
|
-
InclinationFromRelativeAttitudeProvider.getAvailability()
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async start() {
|
|
28
|
-
|
|
29
|
-
const startInclinationFromAcc = () => {
|
|
30
|
-
this.provider = InclinationFromAccProvider;
|
|
31
|
-
this.providerId = this.provider.addEventListener(
|
|
32
|
-
this.notify,
|
|
33
|
-
this.notifyError
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (await InclinationFromRelativeAttitudeProvider.getAvailability()) {
|
|
38
|
-
this.provider = InclinationFromRelativeAttitudeProvider;
|
|
39
|
-
this.providerId = this.provider.addEventListener(
|
|
40
|
-
this.notify,
|
|
41
|
-
() => {
|
|
42
|
-
InclinationFromRelativeAttitudeProvider.removeEventListener(this.providerId);
|
|
43
|
-
startInclinationFromAcc();
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
} else {
|
|
47
|
-
startInclinationFromAcc();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
stop() {
|
|
53
|
-
if (this.provider) {
|
|
54
|
-
this.provider.removeEventListener(this.providerId);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export default new InclinationProvider();
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import chaiAlmost from 'chai-almost';
|
|
3
|
-
|
|
4
|
-
import { deg2rad } from '@wemap/maths';
|
|
5
|
-
|
|
6
|
-
import HeadingUnlocker from './HeadingUnlocker.js';
|
|
7
|
-
|
|
8
|
-
const expect = chai.expect;
|
|
9
|
-
chai.use(chaiAlmost());
|
|
10
|
-
|
|
11
|
-
describe('HeadingUnlocker', () => {
|
|
12
|
-
|
|
13
|
-
it('lock & feed', () => {
|
|
14
|
-
|
|
15
|
-
const headingUnlocker = new HeadingUnlocker();
|
|
16
|
-
headingUnlocker.lock(deg2rad(102));
|
|
17
|
-
|
|
18
|
-
headingUnlocker.feedHeading(deg2rad(0));
|
|
19
|
-
expect(headingUnlocker.locked).to.be.true;
|
|
20
|
-
|
|
21
|
-
headingUnlocker.feedHeading(deg2rad(130));
|
|
22
|
-
expect(headingUnlocker.locked).to.be.true;
|
|
23
|
-
|
|
24
|
-
headingUnlocker.feedHeading(deg2rad(100));
|
|
25
|
-
expect(headingUnlocker.locked).to.be.false;
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('lock & unlock', () => {
|
|
30
|
-
|
|
31
|
-
const headingUnlocker = new HeadingUnlocker();
|
|
32
|
-
headingUnlocker.lock(deg2rad(102));
|
|
33
|
-
|
|
34
|
-
expect(headingUnlocker.locked).to.be.true;
|
|
35
|
-
|
|
36
|
-
headingUnlocker.unlock();
|
|
37
|
-
expect(headingUnlocker.locked).to.be.false;
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('fails', () => {
|
|
42
|
-
|
|
43
|
-
const headingUnlocker = new HeadingUnlocker();
|
|
44
|
-
|
|
45
|
-
expect(() => headingUnlocker.feedHeading(0)).throw(Error);
|
|
46
|
-
|
|
47
|
-
headingUnlocker.lock(deg2rad(10));
|
|
48
|
-
headingUnlocker.feedHeading(deg2rad(20));
|
|
49
|
-
expect(headingUnlocker.locked).to.be.false;
|
|
50
|
-
expect(() => headingUnlocker.feedHeading(0)).throw(Error);
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { diffAngle, deg2rad } from '@wemap/maths';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* HeadingUnlocker is designed to block Pdr Step Detection until user is aiming in the right direction
|
|
5
|
-
*/
|
|
6
|
-
class HeadingUnlocker {
|
|
7
|
-
|
|
8
|
-
static LO_ANGLE = deg2rad(15); // in radians
|
|
9
|
-
|
|
10
|
-
// HeadingUnlocker status, by default it is unlocked
|
|
11
|
-
locked = false;
|
|
12
|
-
|
|
13
|
-
waitingOrientation: number | null = null;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unlock() {
|
|
17
|
-
this.locked = false;
|
|
18
|
-
this.waitingOrientation = null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
lock(waitingOrientation: number) {
|
|
22
|
-
this.waitingOrientation = waitingOrientation;
|
|
23
|
-
this.locked = true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
feedHeading(heading: number) {
|
|
27
|
-
|
|
28
|
-
if (this.waitingOrientation === null) {
|
|
29
|
-
throw new Error('HeadingUnlocker has not been initialized by lock');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!this.locked) {
|
|
33
|
-
throw new Error('HeadingUnlocker is already unlocked');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (Math.abs(diffAngle(heading, this.waitingOrientation)) < HeadingUnlocker.LO_ANGLE) {
|
|
37
|
-
this.locked = false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return this.locked;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default HeadingUnlocker;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Constants as GeoConstants } from '@wemap/geo';
|
|
2
|
-
import { Vector3, Vector3_t } from '@wemap/maths';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class ThugDetector {
|
|
6
|
-
|
|
7
|
-
static MIN_TIME_BETWEEN_DETECTIONS = 0.5; // in seconds
|
|
8
|
-
static EXT_ACC_NORM_THRESHOLD = 4; // in m.s^-2
|
|
9
|
-
|
|
10
|
-
lastDetectionTimestamp = 0;
|
|
11
|
-
|
|
12
|
-
compute(timestamp: number, acceleration: Vector3_t) {
|
|
13
|
-
|
|
14
|
-
let detection = false;
|
|
15
|
-
|
|
16
|
-
if (timestamp - this.lastDetectionTimestamp < ThugDetector.MIN_TIME_BETWEEN_DETECTIONS) {
|
|
17
|
-
return detection;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const extAccNorm = Vector3.norm(acceleration) - GeoConstants.EARTH_GRAVITY;
|
|
21
|
-
if (Math.abs(extAccNorm) > ThugDetector.EXT_ACC_NORM_THRESHOLD) {
|
|
22
|
-
detection = true;
|
|
23
|
-
this.lastDetectionTimestamp = timestamp;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return detection;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default ThugDetector;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import ArCoreProvider from '../vision/ArCoreProvider.js';
|
|
3
|
-
import { CameraNativeState } from '../../events/Types.js';
|
|
4
|
-
|
|
5
|
-
class CameraNativeProvider extends Provider<CameraNativeState> {
|
|
6
|
-
|
|
7
|
-
providerId?: number;
|
|
8
|
-
|
|
9
|
-
getName = () => 'CameraNative';
|
|
10
|
-
|
|
11
|
-
availability = () => Promise.resolve();
|
|
12
|
-
|
|
13
|
-
start() {
|
|
14
|
-
|
|
15
|
-
if (ArCoreProvider.state !== 'stopped') {
|
|
16
|
-
this.notify('started');
|
|
17
|
-
}
|
|
18
|
-
this.providerId = ArCoreProvider.addMonitoringListener(
|
|
19
|
-
() => this.notify('started'),
|
|
20
|
-
() => this.notify('stopped')
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
stop() {
|
|
25
|
-
ArCoreProvider.removeMonitoringListener(this.providerId);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default new CameraNativeProvider();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import ArCoreProvider from '../vision/ArCoreProvider.js';
|
|
3
|
-
import { CameraProjectionMatrix } from '../../events/Types.js';
|
|
4
|
-
|
|
5
|
-
class CameraProjectionMatrixProvider extends Provider<CameraProjectionMatrix> {
|
|
6
|
-
|
|
7
|
-
providerId?: number;
|
|
8
|
-
|
|
9
|
-
getName = () => 'CameraProjectionMatrix';
|
|
10
|
-
|
|
11
|
-
availability = () => ArCoreProvider.getAvailability();
|
|
12
|
-
|
|
13
|
-
start() {
|
|
14
|
-
this.providerId = ArCoreProvider.addEventListener(
|
|
15
|
-
event => event.cameraProjection && this.notify(event.cameraProjection),
|
|
16
|
-
this.notifyError
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
stop() {
|
|
21
|
-
ArCoreProvider.removeEventListener(this.providerId);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default new CameraProjectionMatrixProvider();
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
|
|
3
|
-
import AbsolutePositionProvider from './AbsolutePositionProvider.js';
|
|
4
|
-
import { AbsolutePosition } from '../../../events/Types.js';
|
|
5
|
-
|
|
6
|
-
const { expect } = chai;
|
|
7
|
-
|
|
8
|
-
describe('AbsolutePositionProvider', () => {
|
|
9
|
-
|
|
10
|
-
it('getBestPositionEvent', () => {
|
|
11
|
-
|
|
12
|
-
const createPosition = (time: number, accuracy: number) =>
|
|
13
|
-
new AbsolutePosition(0, 0, null, null, time, accuracy);
|
|
14
|
-
|
|
15
|
-
const evt1 = createPosition(4, 1);
|
|
16
|
-
const evt2 = createPosition(4, 5);
|
|
17
|
-
const evt3 = createPosition(2, 1);
|
|
18
|
-
const evt4 = createPosition(2, 2);
|
|
19
|
-
|
|
20
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(evt1, evt2)).equals(evt1);
|
|
21
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(evt1, evt3)).equals(evt1);
|
|
22
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(evt2, evt4)).equals(evt4);
|
|
23
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(null, evt1)).equals(evt1);
|
|
24
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(null, evt1, null)).equals(evt1);
|
|
25
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(null, evt2, evt4)).equals(evt4);
|
|
26
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(null)).equals(null);
|
|
27
|
-
expect(AbsolutePositionProvider.getBestPositionEvent(null, null)).equals(null);
|
|
28
|
-
expect(AbsolutePositionProvider.getBestPositionEvent()).equals(null);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
});
|