@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,268 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
import { AbsoluteHeading, Attitude } from '@wemap/geo';
|
|
3
|
-
import { deg2rad, diffAngle, Quaternion, Quaternion_t } from '@wemap/maths';
|
|
4
|
-
|
|
5
|
-
import Provider from '../../Provider.js';
|
|
6
|
-
import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
|
|
7
|
-
import AbsoluteAttitudeFromBrowserProvider from './AbsoluteAttitudeFromBrowserProvider.js';
|
|
8
|
-
import RelativeAttitudeProvider from '../relative/RelativeAttitudeProvider.js';
|
|
9
|
-
import InclinationProvider from '../../inclination/InclinationProvider.js';
|
|
10
|
-
import HighRotationsProvider from '../../imu/HighRotationsProvider.js';
|
|
11
|
-
import VpsProvider from '../../vision/vps/VpsProvider.js';
|
|
12
|
-
import { AbsoluteAttitude, RelativeAttitude } from '../../../events/Types.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Absolute attitude provider gives the device attitude in East-North-Up (ENU) frame
|
|
16
|
-
*/
|
|
17
|
-
class AbsoluteAttitudeProvider extends Provider<AbsoluteAttitude> {
|
|
18
|
-
|
|
19
|
-
static REL_ABS_DIVERGENCE_ANGLE_THRESHOLD = deg2rad(25) // in radians;
|
|
20
|
-
static REL_ABS_DIVERGENCE_TIME_THRESHOLD = 2.5; // in seconds
|
|
21
|
-
static REL_ABS_DIVERGENCE_INCLINATION_THRESHOLD = deg2rad(15) // in radians;
|
|
22
|
-
|
|
23
|
-
private _absAttitudeFromBrowser?: AbsoluteAttitude;
|
|
24
|
-
private _vpsProviderId?: number;
|
|
25
|
-
fromBrowserProviderId?: number;
|
|
26
|
-
highRotationProviderId?: number;
|
|
27
|
-
inclinationProviderId?: number;
|
|
28
|
-
relativeAttitudeProviderId?: number;
|
|
29
|
-
|
|
30
|
-
_attitudeFromBrowserErrored = false;
|
|
31
|
-
_attitudeFromRelativeErrored = false;
|
|
32
|
-
|
|
33
|
-
/*
|
|
34
|
-
* RELATIVE
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
_relativeAttitude: RelativeAttitude | null = null;
|
|
38
|
-
_relativeAccuracy = 0; // in radians/s
|
|
39
|
-
|
|
40
|
-
_lastForcedHeadingEvent?: AbsoluteAttitude | AbsoluteHeading;
|
|
41
|
-
_relAbsQuat?: Quaternion_t;
|
|
42
|
-
_wasHighRotationInProgress = false;
|
|
43
|
-
_timeFirstDivergence: number | null = null;
|
|
44
|
-
_callbackMagCalibration?: (data: { angle: number }) => void;
|
|
45
|
-
|
|
46
|
-
getName = () => 'AbsoluteAttitude';
|
|
47
|
-
|
|
48
|
-
availability() {
|
|
49
|
-
return AvailabilityHelper.some([
|
|
50
|
-
AbsoluteAttitudeFromBrowserProvider.getAvailability(),
|
|
51
|
-
RelativeAttitudeProvider.getAvailability()
|
|
52
|
-
]);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
start() {
|
|
56
|
-
|
|
57
|
-
this.fromBrowserProviderId = AbsoluteAttitudeFromBrowserProvider.addEventListener(
|
|
58
|
-
this._onAttitudeFromBrowser,
|
|
59
|
-
error => {
|
|
60
|
-
this._attitudeFromBrowserErrored = true;
|
|
61
|
-
this._onError(error);
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// Vps
|
|
66
|
-
this._vpsProviderId = VpsProvider.addEventListener(
|
|
67
|
-
event => this._onAttitudeFromVps(event.absoluteAttitude),
|
|
68
|
-
error => this.notifyError(error),
|
|
69
|
-
false
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
this.relativeAttitudeProviderId = RelativeAttitudeProvider.addEventListener(
|
|
73
|
-
this._onRelativeAttitudeEvent,
|
|
74
|
-
error => {
|
|
75
|
-
this._attitudeFromRelativeErrored = true;
|
|
76
|
-
this._onError(error);
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
this.inclinationProviderId = InclinationProvider.addEventListener();
|
|
81
|
-
|
|
82
|
-
this.highRotationProviderId = HighRotationsProvider.addEventListener();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
stop() {
|
|
86
|
-
AbsoluteAttitudeFromBrowserProvider.removeEventListener(this.fromBrowserProviderId);
|
|
87
|
-
RelativeAttitudeProvider.removeEventListener(this.relativeAttitudeProviderId);
|
|
88
|
-
InclinationProvider.removeEventListener(this.inclinationProviderId);
|
|
89
|
-
HighRotationsProvider.removeEventListener(this.highRotationProviderId);
|
|
90
|
-
VpsProvider.removeEventListener(this._vpsProviderId);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_setCallbackMagCalibration(cb: (data: { angle: number }) => void) {
|
|
94
|
-
this._callbackMagCalibration = cb;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private _onError = (error: Error) => {
|
|
98
|
-
if (this._attitudeFromBrowserErrored && this._attitudeFromRelativeErrored) {
|
|
99
|
-
this.notifyError(error);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
_forceHeadingForRelative = (absoluteHeadingEvent: AbsoluteAttitude | AbsoluteHeading) => {
|
|
105
|
-
|
|
106
|
-
if (this.lastEvent && absoluteHeadingEvent.accuracy! > this.lastEvent.accuracy!) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const calcForceHeading = (relativeAttitude: RelativeAttitude) => {
|
|
111
|
-
const currentRelativeHeading = relativeAttitude.heading;
|
|
112
|
-
|
|
113
|
-
this._relAbsQuat = Quaternion.fromAxisAngle(
|
|
114
|
-
[0, 0, 1],
|
|
115
|
-
currentRelativeHeading - absoluteHeadingEvent.heading
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
this._relativeAccuracy = 0;
|
|
119
|
-
this._lastForcedHeadingEvent = absoluteHeadingEvent;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// If relativeAttitude does not exist yet, wait the next
|
|
123
|
-
if (this._relativeAttitude) {
|
|
124
|
-
calcForceHeading(this._relativeAttitude);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// If this._relativeAttitude does not exist, wait the first value
|
|
129
|
-
// /!\ This works only if the relative attitude event is provided rapidly.
|
|
130
|
-
const providerId = RelativeAttitudeProvider.addEventListener(
|
|
131
|
-
event => {
|
|
132
|
-
calcForceHeading(event);
|
|
133
|
-
RelativeAttitudeProvider.removeEventListener(providerId);
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
_onRelativeAttitudeEvent = (event: RelativeAttitude) => {
|
|
140
|
-
|
|
141
|
-
const { quaternion, accuracy, time } = event;
|
|
142
|
-
|
|
143
|
-
// Calculate relative accuracy
|
|
144
|
-
if (this._relativeAttitude) {
|
|
145
|
-
this._relativeAccuracy += (time! - this._relativeAttitude.time!) * accuracy!;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Keep the relative attitude event for the calculation of relAbsQuat
|
|
149
|
-
// /!\ Keep this even if forced heading is not set /!\
|
|
150
|
-
this._relativeAttitude = event;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (!this._lastForcedHeadingEvent || !this._relAbsQuat) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const accuracyWithRelative = Math.min(
|
|
158
|
-
(this._lastForcedHeadingEvent.accuracy || 0) + this._relativeAccuracy,
|
|
159
|
-
Math.PI
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const highRotationInProgress = HighRotationsProvider.isInProgress();
|
|
163
|
-
|
|
164
|
-
let divergenceDetected = false;
|
|
165
|
-
|
|
166
|
-
if (this._absAttitudeFromBrowser) {
|
|
167
|
-
|
|
168
|
-
const {
|
|
169
|
-
accuracy: accuracyWithAbsolute,
|
|
170
|
-
heading: headingFromAbsolute
|
|
171
|
-
} = this._absAttitudeFromBrowser;
|
|
172
|
-
|
|
173
|
-
if (this._wasHighRotationInProgress && !highRotationInProgress) {
|
|
174
|
-
// Update heading for relative if it the end of high rotations
|
|
175
|
-
// (probably due to a magnetometer calibratiton)
|
|
176
|
-
this._forceHeadingForRelative(this._absAttitudeFromBrowser);
|
|
177
|
-
|
|
178
|
-
} else if (accuracyWithAbsolute! < accuracyWithRelative) {
|
|
179
|
-
// Update heading for relative if:
|
|
180
|
-
// (1) accuracy from absolute is better than relative
|
|
181
|
-
// (2) heading divergence is greater than REL_ABS_DIVERGENCE_THRESHOLD
|
|
182
|
-
const relativeQuaternion = Quaternion.multiply(this._relAbsQuat, quaternion);
|
|
183
|
-
const relativeAttitude = new Attitude(relativeQuaternion);
|
|
184
|
-
const angle = Math.abs(diffAngle(relativeAttitude.heading, headingFromAbsolute));
|
|
185
|
-
const inclination = InclinationProvider.lastEvent;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (angle > AbsoluteAttitudeProvider.REL_ABS_DIVERGENCE_ANGLE_THRESHOLD
|
|
189
|
-
&& inclination !== null
|
|
190
|
-
&& Math.abs(inclination - Math.PI / 4) > AbsoluteAttitudeProvider.REL_ABS_DIVERGENCE_INCLINATION_THRESHOLD
|
|
191
|
-
) {
|
|
192
|
-
divergenceDetected = true;
|
|
193
|
-
|
|
194
|
-
// Be sure before forcing heading
|
|
195
|
-
if (this._timeFirstDivergence !== null
|
|
196
|
-
&& time! - this._timeFirstDivergence > AbsoluteAttitudeProvider.REL_ABS_DIVERGENCE_TIME_THRESHOLD) {
|
|
197
|
-
|
|
198
|
-
this._forceHeadingForRelative(this._absAttitudeFromBrowser);
|
|
199
|
-
this._callbackMagCalibration?.({ angle });
|
|
200
|
-
this._timeFirstDivergence = null;
|
|
201
|
-
} else if (this._timeFirstDivergence === null) {
|
|
202
|
-
this._timeFirstDivergence = time;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (!divergenceDetected) {
|
|
211
|
-
this._timeFirstDivergence = null;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this._wasHighRotationInProgress = highRotationInProgress;
|
|
215
|
-
|
|
216
|
-
const absoluteQuat = Quaternion.multiply(this._relAbsQuat, quaternion);
|
|
217
|
-
const attitude = new AbsoluteAttitude(absoluteQuat, time, accuracyWithRelative);
|
|
218
|
-
this.notify(attitude);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
_onAttitudeFromBrowser = (event: AbsoluteAttitude) => {
|
|
223
|
-
this._absAttitudeFromBrowser = event;
|
|
224
|
-
|
|
225
|
-
if (!this._lastForcedHeadingEvent) {
|
|
226
|
-
this._forceHeadingForRelative(event);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Absolute attitude from browser is not used anymore due to magnetometer inaccuracy on pitch and roll
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_onAttitudeFromVps = (event: AbsoluteAttitude) => {
|
|
235
|
-
this._forceHeadingForRelative(event);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
feed(data: AbsoluteHeading | AbsoluteAttitude) {
|
|
239
|
-
|
|
240
|
-
if (data instanceof AbsoluteHeading) {
|
|
241
|
-
|
|
242
|
-
if (data.time === null) {
|
|
243
|
-
throw Error('the time of the absolute heading is not defined');
|
|
244
|
-
}
|
|
245
|
-
if (data.accuracy === null) {
|
|
246
|
-
throw Error('the accuracy of the absolute heading is not defined');
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
this._forceHeadingForRelative(data);
|
|
250
|
-
|
|
251
|
-
} else if (data instanceof AbsoluteAttitude) {
|
|
252
|
-
|
|
253
|
-
if (data.time === null) {
|
|
254
|
-
throw Error('the time of the attitude is not defined');
|
|
255
|
-
}
|
|
256
|
-
if (data.accuracy === null) {
|
|
257
|
-
throw Error('the accuracy of the attitude is not defined');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
this._forceHeadingForRelative(data);
|
|
261
|
-
|
|
262
|
-
} else {
|
|
263
|
-
throw new Error('data is nor an AbsoluteHeading or an Attitude object');
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export default new AbsoluteAttitudeProvider();
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { deg2rad, Rotations } from '@wemap/maths';
|
|
2
|
-
import { BrowserUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
import Provider from '../../Provider.js';
|
|
5
|
-
import AskImuOnDesktopError from '../../../errors/AskImuOnDesktopError.js';
|
|
6
|
-
import MissingSensorError from '../../../errors/MissingSensorError.js';
|
|
7
|
-
import { RelativeAttitude } from '../../../events/Types.js';
|
|
8
|
-
|
|
9
|
-
// https://stackoverflow.com/a/73369838/2239938
|
|
10
|
-
interface DeviceOrientationEventiOS extends DeviceOrientationEvent {
|
|
11
|
-
requestPermission?: () => Promise<'granted' | 'denied'>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Relative attitude provider gives the device attitude in a custom frame (x-right, y-front, z-up) using
|
|
16
|
-
* browser deviceorientation
|
|
17
|
-
*
|
|
18
|
-
* -----------------------------------
|
|
19
|
-
* Overview of compatibilities:
|
|
20
|
-
* -----------------------------------
|
|
21
|
-
*
|
|
22
|
-
* Chrome Android (v72.0.3626): YES (via deviceorientation but deviceorientation.alpha is unreliable! Sometimes it starts at 0°, sometimes at 270°)
|
|
23
|
-
* Safari iOS (v12.0): YES (via deviceorientation)
|
|
24
|
-
* Opera Android (v50.2.2426): NO {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/ondeviceorientation}
|
|
25
|
-
* Firefox Android (v65.0.1): YES (via deviceorientation)
|
|
26
|
-
*
|
|
27
|
-
* -----------------------------------
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
class RelativeAttitudeFromBrowser extends Provider<RelativeAttitude> {
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* default relative attitude drift in rad.second-1
|
|
34
|
-
*/
|
|
35
|
-
static DEFAULT_DRIFT = deg2rad(5) / 60;
|
|
36
|
-
|
|
37
|
-
getName = () => 'RelativeAttitudeFromBrowser';
|
|
38
|
-
|
|
39
|
-
availability() {
|
|
40
|
-
return BrowserUtils.isMobile
|
|
41
|
-
? Promise.resolve()
|
|
42
|
-
: Promise.resolve(new AskImuOnDesktopError());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
start() {
|
|
46
|
-
const subscribe = () => window.addEventListener('deviceorientation', this.onDeviceOrientationEvent, true);
|
|
47
|
-
|
|
48
|
-
const requestPermission = (DeviceOrientationEvent as unknown as DeviceOrientationEventiOS).requestPermission || undefined;
|
|
49
|
-
|
|
50
|
-
if (requestPermission) {
|
|
51
|
-
requestPermission()
|
|
52
|
-
.then(response => {
|
|
53
|
-
if (response !== 'granted') {
|
|
54
|
-
throw new Error('Permission not granted');
|
|
55
|
-
}
|
|
56
|
-
subscribe();
|
|
57
|
-
})
|
|
58
|
-
.catch(error => this.notifyError(error));
|
|
59
|
-
} else {
|
|
60
|
-
subscribe();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
stop() {
|
|
65
|
-
window.removeEventListener('deviceorientation', this.onDeviceOrientationEvent, true);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
onDeviceOrientationEvent = (e: DeviceOrientationEvent) => {
|
|
69
|
-
|
|
70
|
-
if (typeof e.alpha !== 'number' || typeof e.beta !== 'number' || typeof e.gamma !== 'number') {
|
|
71
|
-
this.notifyError(new MissingSensorError().from('deviceorientation'));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const quaternion = Rotations.eulerToQuaternionZXYDegrees([e.alpha, e.beta, e.gamma]);
|
|
76
|
-
const attitude = new RelativeAttitude(quaternion,
|
|
77
|
-
e.timeStamp / 1e3,
|
|
78
|
-
RelativeAttitudeFromBrowser.DEFAULT_DRIFT
|
|
79
|
-
);
|
|
80
|
-
this.notify(attitude);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default new RelativeAttitudeFromBrowser();
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { deg2rad, Vector3_t } from '@wemap/maths';
|
|
2
|
-
|
|
3
|
-
import Provider from '../../Provider.js';
|
|
4
|
-
import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
|
|
5
|
-
import EkfAttitude from '../EkfAttitude.js';
|
|
6
|
-
import Accelerometer from '../../imu/AccelerometerProvider.js';
|
|
7
|
-
import Gyroscope from '../../imu/GyroscopeProvider.js';
|
|
8
|
-
import { Acceleration, AngularRate, RelativeAttitude } from '../../../events/Types.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Relative attitude provider gives the device attitude in East-North-Up (ENU) frame using
|
|
12
|
-
* browser deviceorientation
|
|
13
|
-
* The provider does not work until an offset is given.
|
|
14
|
-
*/
|
|
15
|
-
class RelativeAttitudeFromEkf extends Provider<RelativeAttitude> {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* default relative attitude drift in rad.second-1
|
|
19
|
-
*/
|
|
20
|
-
static DEFAULT_DRIFT = deg2rad(5) / 60;
|
|
21
|
-
|
|
22
|
-
accelerometerProviderId?: number;
|
|
23
|
-
ekfAttitude = new EkfAttitude();
|
|
24
|
-
gyroscopeEvent?: AngularRate;
|
|
25
|
-
gyroscopeProviderId?: number;
|
|
26
|
-
|
|
27
|
-
lastTimestamp = 0;
|
|
28
|
-
|
|
29
|
-
getName = () => 'RelativeAttitudeFromEkf';
|
|
30
|
-
|
|
31
|
-
availability() {
|
|
32
|
-
return AvailabilityHelper.every([
|
|
33
|
-
Accelerometer.getAvailability(),
|
|
34
|
-
Gyroscope.getAvailability()
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
start() {
|
|
39
|
-
this.accelerometerProviderId = Accelerometer.addEventListener(
|
|
40
|
-
event => this.onAccelerometerEvent(event),
|
|
41
|
-
error => this.notifyError(error)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
this.gyroscopeProviderId = Gyroscope.addEventListener(
|
|
45
|
-
event => this.gyroscopeEvent = event,
|
|
46
|
-
error => this.notifyError(error)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
stop() {
|
|
51
|
-
Accelerometer.removeEventListener(this.accelerometerProviderId);
|
|
52
|
-
Gyroscope.removeEventListener(this.gyroscopeProviderId);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private onAccelerometerEvent = (accelerationEvent: Acceleration) => {
|
|
56
|
-
|
|
57
|
-
if (!this.gyroscopeEvent) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
values: acceleration, timestamp
|
|
63
|
-
} = accelerationEvent;
|
|
64
|
-
|
|
65
|
-
// Handle timestamps and dt
|
|
66
|
-
if (this.lastTimestamp === 0) {
|
|
67
|
-
this.lastTimestamp = timestamp;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const diffTime = timestamp - this.lastTimestamp;
|
|
71
|
-
this.lastTimestamp = timestamp;
|
|
72
|
-
|
|
73
|
-
const quaternion = this.ekfAttitude.update(
|
|
74
|
-
diffTime,
|
|
75
|
-
acceleration as Vector3_t,
|
|
76
|
-
this.gyroscopeEvent.values as Vector3_t
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (quaternion) {
|
|
80
|
-
const attitude = new RelativeAttitude(quaternion,
|
|
81
|
-
timestamp,
|
|
82
|
-
RelativeAttitudeFromEkf.DEFAULT_DRIFT
|
|
83
|
-
);
|
|
84
|
-
this.notify(attitude);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export default new RelativeAttitudeFromEkf();
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { deg2rad } from '@wemap/maths';
|
|
2
|
-
|
|
3
|
-
import Provider from '../../Provider.js';
|
|
4
|
-
import RelativeAttitudeFromEkfProvider from './RelativeAttitudeFromEkfProvider.js';
|
|
5
|
-
import RelativeAttitudeFromBrowserProvider from './RelativeAttitudeFromBrowserProvider.js';
|
|
6
|
-
import HighRotationsProvider from '../../imu/HighRotationsProvider.js';
|
|
7
|
-
import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
|
|
8
|
-
import { RelativeAttitude } from '../../../events/Types.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class RelativeAttitudeFromInertial extends Provider<RelativeAttitude> {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* default relative attitude drift in rad.second-1
|
|
15
|
-
*/
|
|
16
|
-
static DEFAULT_DRIFT = deg2rad(5) / 60;
|
|
17
|
-
|
|
18
|
-
_highRotationsProviderId?: number;
|
|
19
|
-
listenerId?: number;
|
|
20
|
-
provider?: Provider<RelativeAttitude>;
|
|
21
|
-
|
|
22
|
-
getName = () => 'RelativeAttitudeFromInertial';
|
|
23
|
-
|
|
24
|
-
availability() {
|
|
25
|
-
return AvailabilityHelper.some([
|
|
26
|
-
RelativeAttitudeFromEkfProvider.getAvailability(),
|
|
27
|
-
RelativeAttitudeFromBrowserProvider.getAvailability()
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
start() {
|
|
32
|
-
|
|
33
|
-
RelativeAttitudeFromEkfProvider.getAvailability().then(availabilityError => {
|
|
34
|
-
this.provider = !availabilityError ? RelativeAttitudeFromEkfProvider : RelativeAttitudeFromBrowserProvider;
|
|
35
|
-
|
|
36
|
-
this.listenerId = this.provider.addEventListener(
|
|
37
|
-
event => this._parseEvent(event),
|
|
38
|
-
this.notifyError
|
|
39
|
-
);
|
|
40
|
-
this._highRotationsProviderId = HighRotationsProvider.addEventListener(
|
|
41
|
-
null,
|
|
42
|
-
this.notifyError
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_parseEvent(event: RelativeAttitude) {
|
|
48
|
-
const relativeAttitude = event.clone();
|
|
49
|
-
if (HighRotationsProvider.isInProgress()) {
|
|
50
|
-
let accuracy = (relativeAttitude.accuracy || 0) + (RelativeAttitudeFromInertial.DEFAULT_DRIFT * 100);
|
|
51
|
-
accuracy = Math.min(accuracy, Math.PI);
|
|
52
|
-
relativeAttitude.accuracy = accuracy;
|
|
53
|
-
}
|
|
54
|
-
this.notify(relativeAttitude);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
stop() {
|
|
58
|
-
if (this.provider) {
|
|
59
|
-
this.provider.removeEventListener(this.listenerId);
|
|
60
|
-
delete this.provider;
|
|
61
|
-
}
|
|
62
|
-
HighRotationsProvider.removeEventListener(this._highRotationsProviderId);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export default new RelativeAttitudeFromInertial();
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import Provider from '../../Provider.js';
|
|
2
|
-
import RelativeAttitudeFromInertialProvider from './RelativeAttitudeFromInertialProvider.js';
|
|
3
|
-
import ArCoreProvider from '../../vision/ArCoreProvider.js';
|
|
4
|
-
import { RelativeAttitude } from '../../../events/Types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Relative attitude provider gives the device attitude in East-North-Up (ENU) frame using
|
|
8
|
-
* browser deviceorientation
|
|
9
|
-
* The provider does not work until an offset is given.
|
|
10
|
-
*/
|
|
11
|
-
class RelativeAttitudeProvider extends Provider<RelativeAttitude> {
|
|
12
|
-
|
|
13
|
-
arCoreMonitoringId?: number;
|
|
14
|
-
arCoreProviderId?: number;
|
|
15
|
-
inertialProviderId?: number;
|
|
16
|
-
|
|
17
|
-
getName = () => 'RelativeAttitude';
|
|
18
|
-
|
|
19
|
-
availability = () => RelativeAttitudeFromInertialProvider.getAvailability();
|
|
20
|
-
|
|
21
|
-
start() {
|
|
22
|
-
this.arCoreMonitoringId = ArCoreProvider.addMonitoringListener(
|
|
23
|
-
() => {
|
|
24
|
-
this.listenArCore();
|
|
25
|
-
this.unlistenInertial();
|
|
26
|
-
}, () => {
|
|
27
|
-
this.unlistenArCore();
|
|
28
|
-
this.listenInertial();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
if (ArCoreProvider.state === 'started') {
|
|
32
|
-
this.listenArCore();
|
|
33
|
-
} else {
|
|
34
|
-
this.listenInertial();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @override
|
|
40
|
-
*/
|
|
41
|
-
stop() {
|
|
42
|
-
ArCoreProvider.removeMonitoringListener(this.arCoreMonitoringId);
|
|
43
|
-
this.unlistenArCore();
|
|
44
|
-
this.unlistenInertial();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
listenInertial = () => {
|
|
49
|
-
this.inertialProviderId = RelativeAttitudeFromInertialProvider.addEventListener(
|
|
50
|
-
this.notify,
|
|
51
|
-
this.notifyError
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
unlistenInertial = () => {
|
|
56
|
-
RelativeAttitudeFromInertialProvider.removeEventListener(this.inertialProviderId);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
listenArCore = () => {
|
|
60
|
-
this.arCoreProviderId = ArCoreProvider.addEventListener(
|
|
61
|
-
event => this.notify(event.relativeAttitude), null, false
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
unlistenArCore = () => {
|
|
66
|
-
ArCoreProvider.removeEventListener(this.arCoreProviderId);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default new RelativeAttitudeProvider();
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import ImuProvider from './ImuProvider.js';
|
|
3
|
-
import MissingAccelerometerError from '../../errors/MissingAccelerometerError.js';
|
|
4
|
-
import { Acceleration } from '../../events/Types.js';
|
|
5
|
-
|
|
6
|
-
class AccelerometerProvider extends Provider<Acceleration> {
|
|
7
|
-
|
|
8
|
-
private imuProviderId?: number;
|
|
9
|
-
|
|
10
|
-
getName = () => 'Accelerometer';
|
|
11
|
-
|
|
12
|
-
availability = () => ImuProvider.getAvailability();
|
|
13
|
-
|
|
14
|
-
start() {
|
|
15
|
-
this.imuProviderId = ImuProvider.addEventListener(event => {
|
|
16
|
-
event.acceleration
|
|
17
|
-
? this.notify(event.acceleration)
|
|
18
|
-
: this.notifyError(new MissingAccelerometerError().from('devicemotion'));
|
|
19
|
-
|
|
20
|
-
}, this.notifyError);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
stop() {
|
|
24
|
-
ImuProvider.removeEventListener(this.imuProviderId);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default new AccelerometerProvider();
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Provider from '../Provider.js';
|
|
2
|
-
import ImuProvider from './ImuProvider.js';
|
|
3
|
-
import MissingGyroscopeError from '../../errors/MissingGyroscopeError.js';
|
|
4
|
-
import { AngularRate } from '../../events/Types.js';
|
|
5
|
-
|
|
6
|
-
class GyroscopeProvider extends Provider<AngularRate> {
|
|
7
|
-
|
|
8
|
-
private imuProviderId?: number;
|
|
9
|
-
|
|
10
|
-
getName = () => 'Gyroscope';
|
|
11
|
-
|
|
12
|
-
availability = () => ImuProvider.getAvailability();
|
|
13
|
-
|
|
14
|
-
start() {
|
|
15
|
-
this.imuProviderId = ImuProvider.addEventListener(event => {
|
|
16
|
-
event.angularRate
|
|
17
|
-
? this.notify(event.angularRate)
|
|
18
|
-
: this.notifyError(new MissingGyroscopeError().from('devicemotion'));
|
|
19
|
-
}, this.notifyError);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
stop() {
|
|
23
|
-
ImuProvider.removeEventListener(this.imuProviderId);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default new GyroscopeProvider();
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Vector3, Vector3_t } from '@wemap/maths';
|
|
2
|
-
|
|
3
|
-
import Provider from '../Provider.js';
|
|
4
|
-
import GyroscopeProvider from './GyroscopeProvider.js';
|
|
5
|
-
import { AngularRate, HighRotation } from '../../events/Types.js';
|
|
6
|
-
|
|
7
|
-
class HighRotationsProvider extends Provider<HighRotation> {
|
|
8
|
-
|
|
9
|
-
static THRESHOLD = 10; // in radians by second
|
|
10
|
-
static DELAY_CONSIDERATION = 3; // in seconds
|
|
11
|
-
|
|
12
|
-
gyroscopeProviderId?: number;
|
|
13
|
-
|
|
14
|
-
getName = () => 'HighRotationsProvider';
|
|
15
|
-
|
|
16
|
-
availability = () => GyroscopeProvider.getAvailability();
|
|
17
|
-
|
|
18
|
-
start() {
|
|
19
|
-
this.gyroscopeProviderId = GyroscopeProvider.addEventListener(
|
|
20
|
-
this._parseGyroscopeEvent,
|
|
21
|
-
this.notifyError
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
stop() {
|
|
26
|
-
GyroscopeProvider.removeEventListener(this.gyroscopeProviderId);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
isInProgress() {
|
|
30
|
-
if (!this.lastEvent || !GyroscopeProvider.lastEvent) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const diffTime = GyroscopeProvider.lastEvent.timestamp - this.lastEvent.timestamp;
|
|
35
|
-
return diffTime < HighRotationsProvider.DELAY_CONSIDERATION;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private _parseGyroscopeEvent = (gyroscopeEvent: AngularRate) => {
|
|
39
|
-
|
|
40
|
-
const { values, timestamp } = gyroscopeEvent;
|
|
41
|
-
const speed = Vector3.norm(values as Vector3_t);
|
|
42
|
-
if (speed > HighRotationsProvider.THRESHOLD) {
|
|
43
|
-
this.notify({ timestamp });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default new HighRotationsProvider();
|