@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.
Files changed (146) hide show
  1. package/dist/helpers/CustomMapProvider.d.ts +10 -0
  2. package/{index.ts → dist/index.d.ts} +0 -14
  3. package/dist/index.js +1 -3446
  4. package/dist/index.js.map +1 -1
  5. package/{src/ProvidersOptions.ts → dist/src/ProvidersOptions.d.ts} +7 -16
  6. package/dist/src/errors/AskImuOnDesktopError.d.ts +5 -0
  7. package/dist/src/errors/ContainsIgnoredProviderError.d.ts +5 -0
  8. package/dist/src/errors/GeolocationApiMissingError.d.ts +5 -0
  9. package/dist/src/errors/GeolocationPermissionDeniedError.d.ts +5 -0
  10. package/dist/src/errors/GeolocationPositionUnavailableError.d.ts +5 -0
  11. package/dist/src/errors/IpResolveServerError.d.ts +5 -0
  12. package/dist/src/errors/MissingAccelerometerError.d.ts +6 -0
  13. package/dist/src/errors/MissingArCoreError.d.ts +5 -0
  14. package/dist/src/errors/MissingGyroscopeError.d.ts +6 -0
  15. package/dist/src/errors/MissingMagnetometerError.d.ts +5 -0
  16. package/dist/src/errors/MissingNativeInterfaceError.d.ts +5 -0
  17. package/dist/src/errors/MissingPoleStarError.d.ts +5 -0
  18. package/dist/src/errors/MissingSensorError.d.ts +6 -0
  19. package/dist/src/errors/NoProviderFoundError.d.ts +5 -0
  20. package/dist/src/events/AvailabilityHelper.d.ts +5 -0
  21. package/dist/src/events/ProvidersLoggerOld.d.ts +24 -0
  22. package/dist/src/events/Types.d.ts +34 -0
  23. package/dist/src/mapmatching/MapMatchingHandler.d.ts +93 -0
  24. package/dist/src/providers/Constants.d.ts +4 -0
  25. package/{src/providers/NativeProviders.ts → dist/src/providers/NativeProviders.d.ts} +2 -23
  26. package/dist/src/providers/Provider.d.ts +64 -0
  27. package/dist/src/providers/attitude/EkfAttitude.d.ts +41 -0
  28. package/dist/src/providers/attitude/TurnProvider.d.ts +17 -0
  29. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.d.ts +60 -0
  30. package/dist/src/providers/attitude/absolute/AbsoluteAttitudeProvider.d.ts +44 -0
  31. package/dist/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.d.ts +31 -0
  32. package/dist/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.d.ts +26 -0
  33. package/dist/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.d.ts +18 -0
  34. package/dist/src/providers/attitude/relative/RelativeAttitudeProvider.d.ts +25 -0
  35. package/dist/src/providers/imu/AccelerometerProvider.d.ts +11 -0
  36. package/dist/src/providers/imu/GyroscopeProvider.d.ts +11 -0
  37. package/dist/src/providers/imu/HighRotationsProvider.d.ts +15 -0
  38. package/dist/src/providers/imu/ImuProvider.d.ts +34 -0
  39. package/dist/src/providers/imu/MagnetometerCalibrationProvider.d.ts +11 -0
  40. package/dist/src/providers/inclination/InclinationFromAccProvider.d.ts +18 -0
  41. package/dist/src/providers/inclination/InclinationFromRelativeAttitudeProvider.d.ts +19 -0
  42. package/dist/src/providers/inclination/InclinationProvider.d.ts +18 -0
  43. package/dist/src/providers/legacy/helpers/HeadingUnlocker.d.ts +12 -0
  44. package/dist/src/providers/legacy/helpers/ThugDetector.d.ts +8 -0
  45. package/dist/src/providers/others/CameraNativeProvider.d.ts +11 -0
  46. package/dist/src/providers/others/CameraProjectionMatrixProvider.d.ts +11 -0
  47. package/dist/src/providers/position/absolute/AbsolutePositionProvider.d.ts +35 -0
  48. package/dist/src/providers/position/absolute/GnssWifiProvider.d.ts +28 -0
  49. package/dist/src/providers/position/absolute/IpProvider.d.ts +16 -0
  50. package/dist/src/providers/position/absolute/PoleStarProvider.d.ts +14 -0
  51. package/dist/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.d.ts +17 -0
  52. package/dist/src/providers/position/relative/GeoRelativePositionProvider.d.ts +12 -0
  53. package/dist/src/providers/position/relative/PdrProvider.d.ts +15 -0
  54. package/dist/src/providers/steps/StepDetectionLadetto.d.ts +15 -0
  55. package/dist/src/providers/steps/StepDetectionMinMaxPeaks.d.ts +19 -0
  56. package/dist/src/providers/steps/StepDetectionMinMaxPeaks2.d.ts +27 -0
  57. package/dist/src/providers/steps/StepDetectionMinMaxPeaks3.d.ts +24 -0
  58. package/dist/src/providers/steps/StepProvider.d.ts +36 -0
  59. package/dist/src/providers/steps/StraightLineProvider.d.ts +21 -0
  60. package/dist/src/providers/vision/ArCoreProvider.d.ts +50 -0
  61. package/dist/src/providers/vision/BarcodeProvider.d.ts +11 -0
  62. package/dist/src/providers/vision/vps/ImageRelocalization.d.ts +11 -0
  63. package/dist/src/providers/vision/vps/RelativeRotationCalc.d.ts +10 -0
  64. package/dist/src/providers/vision/vps/VpsMetadata.d.ts +33 -0
  65. package/dist/src/providers/vision/vps/VpsProvider.d.ts +45 -0
  66. package/dist/src/providers/vision/vps/VpsRequest.d.ts +18 -0
  67. package/dist/src/providers/vision/vps/VpsResponse.d.ts +15 -0
  68. package/dist/src/smoothers/AttitudeSmoother.d.ts +23 -0
  69. package/dist/src/smoothers/PositionSmoother.d.ts +21 -0
  70. package/package.json +16 -12
  71. package/src/errors/AskImuOnDesktopError.ts +0 -10
  72. package/src/errors/ContainsIgnoredProviderError.ts +0 -10
  73. package/src/errors/GeolocationApiMissingError.ts +0 -10
  74. package/src/errors/GeolocationPermissionDeniedError.ts +0 -10
  75. package/src/errors/GeolocationPositionUnavailableError.ts +0 -10
  76. package/src/errors/IpResolveServerError.ts +0 -10
  77. package/src/errors/MissingAccelerometerError.ts +0 -11
  78. package/src/errors/MissingArCoreError.ts +0 -10
  79. package/src/errors/MissingGyroscopeError.ts +0 -11
  80. package/src/errors/MissingMagnetometerError.ts +0 -9
  81. package/src/errors/MissingNativeInterfaceError.ts +0 -11
  82. package/src/errors/MissingPoleStarError.ts +0 -10
  83. package/src/errors/MissingSensorError.ts +0 -15
  84. package/src/errors/NoProviderFoundError.ts +0 -10
  85. package/src/events/AvailabilityHelper.spec.ts +0 -30
  86. package/src/events/AvailabilityHelper.ts +0 -28
  87. package/src/events/ProvidersLoggerOld.ts +0 -87
  88. package/src/events/Types.ts +0 -18
  89. package/src/mapmatching/MapMatchingHandler.spec.ts +0 -142
  90. package/src/mapmatching/MapMatchingHandler.ts +0 -540
  91. package/src/providers/Constants.ts +0 -5
  92. package/src/providers/FakeProvider.spec.ts +0 -49
  93. package/src/providers/Provider.spec.ts +0 -113
  94. package/src/providers/Provider.ts +0 -244
  95. package/src/providers/attitude/EkfAttitude.spec.ts +0 -115
  96. package/src/providers/attitude/EkfAttitude.ts +0 -233
  97. package/src/providers/attitude/TurnProvider.ts +0 -58
  98. package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.ts +0 -267
  99. package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.ts +0 -268
  100. package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.ts +0 -84
  101. package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.ts +0 -89
  102. package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.ts +0 -66
  103. package/src/providers/attitude/relative/RelativeAttitudeProvider.ts +0 -70
  104. package/src/providers/imu/AccelerometerProvider.ts +0 -28
  105. package/src/providers/imu/GyroscopeProvider.ts +0 -27
  106. package/src/providers/imu/HighRotationsProvider.ts +0 -49
  107. package/src/providers/imu/ImuProvider.ts +0 -110
  108. package/src/providers/imu/MagnetometerCalibrationProvider.ts +0 -21
  109. package/src/providers/inclination/InclinationFromAccProvider.ts +0 -57
  110. package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.ts +0 -51
  111. package/src/providers/inclination/InclinationProvider.ts +0 -59
  112. package/src/providers/legacy/helpers/HeadingUnlocker.spec.ts +0 -53
  113. package/src/providers/legacy/helpers/HeadingUnlocker.ts +0 -44
  114. package/src/providers/legacy/helpers/ThugDetector.ts +0 -30
  115. package/src/providers/others/CameraNativeProvider.ts +0 -29
  116. package/src/providers/others/CameraProjectionMatrixProvider.ts +0 -25
  117. package/src/providers/position/absolute/AbsolutePositionProvider.spec.ts +0 -31
  118. package/src/providers/position/absolute/AbsolutePositionProvider.ts +0 -277
  119. package/src/providers/position/absolute/GnssWifiProvider.ts +0 -126
  120. package/src/providers/position/absolute/GnssWifiProviders.spec.ts +0 -90
  121. package/src/providers/position/absolute/IpProvider.ts +0 -47
  122. package/src/providers/position/absolute/PoleStarProvider.ts +0 -88
  123. package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.ts +0 -82
  124. package/src/providers/position/relative/GeoRelativePositionProvider.ts +0 -35
  125. package/src/providers/position/relative/PdrProvider.ts +0 -107
  126. package/src/providers/steps/StepDetectionLadetto.ts +0 -67
  127. package/src/providers/steps/StepDetectionMinMaxPeaks.ts +0 -70
  128. package/src/providers/steps/StepDetectionMinMaxPeaks2.ts +0 -99
  129. package/src/providers/steps/StepDetectionMinMaxPeaks3.ts +0 -192
  130. package/src/providers/steps/StepProvider.ts +0 -151
  131. package/src/providers/steps/StraightLineProvider.ts +0 -69
  132. package/src/providers/vision/ArCoreProvider.ts +0 -184
  133. package/src/providers/vision/BarcodeProvider.ts +0 -28
  134. package/src/providers/vision/vps/ImageRelocalization.ts +0 -98
  135. package/src/providers/vision/vps/RelativeRotationCalc.ts +0 -58
  136. package/src/providers/vision/vps/VpsMetadata.ts +0 -63
  137. package/src/providers/vision/vps/VpsProvider.ts +0 -251
  138. package/src/providers/vision/vps/VpsRequest.ts +0 -29
  139. package/src/providers/vision/vps/VpsResponse.ts +0 -43
  140. package/src/providers/vision/vps/VpsSchema.json +0 -90
  141. package/src/smoothers/AttitudeSmoother.ts +0 -110
  142. package/src/smoothers/PositionSmoother.spec.ts +0 -53
  143. package/src/smoothers/PositionSmoother.ts +0 -96
  144. package/tsconfig.json +0 -3
  145. package/vite.config.ts +0 -4
  146. /package/{src/providers/ProviderState.ts → dist/src/providers/ProviderState.d.ts} +0 -0
@@ -1,82 +0,0 @@
1
- import { GeoRelativePosition, RelativePosition } from '@wemap/geo';
2
-
3
- import Provider from '../../Provider.js';
4
- import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
5
- import AbsoluteAttitudeProvider from '../../attitude/absolute/AbsoluteAttitudeProvider.js';
6
- import ArCoreProvider, { ArCoreEvent } from '../../vision/ArCoreProvider.js';
7
- import { AbsoluteAttitude, RelativeAttitude } from '../../../events/Types.js';
8
-
9
- class GeoRelativePositionFromArCoreProvider extends Provider<GeoRelativePosition> {
10
-
11
- absoluteAttitudeProviderId?: number;
12
- arCoreProviderId?: number;
13
- absoluteAttitudeEvent?: AbsoluteAttitude;
14
-
15
- getName = () => 'GeoRelativePositionFromArCore';
16
-
17
- availability() {
18
- return AvailabilityHelper.every([
19
- ArCoreProvider.getAvailability(),
20
- AbsoluteAttitudeProvider.getAvailability()
21
- ]);
22
- }
23
-
24
- start() {
25
-
26
- this.arCoreProviderId = ArCoreProvider.addEventListener(
27
- this.onArCoreEvents,
28
- this.notifyError
29
- );
30
-
31
- this.absoluteAttitudeProviderId = AbsoluteAttitudeProvider.addEventListener(
32
- event => this.absoluteAttitudeEvent = event,
33
- this.notifyError
34
- );
35
- }
36
-
37
- stop() {
38
- ArCoreProvider.removeEventListener(this.arCoreProviderId);
39
- AbsoluteAttitudeProvider.removeEventListener(this.absoluteAttitudeProviderId);
40
- }
41
-
42
- onArCoreEvents = (event: ArCoreEvent) => {
43
- const relativeAttitudeEvent = event.relativeAttitude;
44
- const relativePositionEvent = event.relativePosition;
45
-
46
- if (relativeAttitudeEvent && relativePositionEvent && this.absoluteAttitudeEvent) {
47
- this.compute(relativePositionEvent, relativeAttitudeEvent, this.absoluteAttitudeEvent);
48
- }
49
- }
50
-
51
- compute(
52
- relativePosition: RelativePosition,
53
- relativeAttitude: RelativeAttitude,
54
- absoluteAttitude: AbsoluteAttitude
55
- ) {
56
-
57
- const rotation = absoluteAttitude.heading - relativeAttitude.heading;
58
-
59
- /**
60
- * Here, we transform "relativePosition" which is defined in ArCore frame to a relative "position" defined in ENU frame
61
- */
62
- const east = Math.cos(rotation) * relativePosition.x - Math.sin(rotation) * relativePosition.z;
63
- const north = -Math.sin(rotation) * relativePosition.x - Math.cos(rotation) * relativePosition.z;
64
- const up = relativePosition.y;
65
-
66
- /**
67
- * Relative position is defined in ENU frame
68
- */
69
- const position = new GeoRelativePosition(
70
- east,
71
- north,
72
- up,
73
- relativePosition.time,
74
- 0,
75
- absoluteAttitude.heading
76
- );
77
-
78
- this.notify(position);
79
- }
80
- }
81
-
82
- export default new GeoRelativePositionFromArCoreProvider();
@@ -1,35 +0,0 @@
1
- import { GeoRelativePosition } from '@wemap/geo';
2
-
3
- import Provider from '../../Provider.js';
4
- import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
5
- import GeoRelativePositionFromArCoreProvider from './GeoRelativePositionFromArCoreProvider.js';
6
- import PdrProvider from './PdrProvider.js';
7
-
8
-
9
- class GeoRelativePositionProvider extends Provider<GeoRelativePosition> {
10
-
11
- providerId?: number;
12
- geoRelativeProvider?: Provider<GeoRelativePosition>;
13
-
14
- getName = () => 'GeoRelativePosition';
15
-
16
- availability() {
17
- return AvailabilityHelper.some([
18
- PdrProvider.getAvailability(),
19
- GeoRelativePositionFromArCoreProvider.getAvailability()
20
- ]);
21
- }
22
-
23
- async start() {
24
- const availabilityError = await GeoRelativePositionFromArCoreProvider.getAvailability();
25
- this.geoRelativeProvider = availabilityError ? PdrProvider : GeoRelativePositionFromArCoreProvider;
26
- this.providerId = this.geoRelativeProvider.addEventListener(this.notify, this.notifyError);
27
- }
28
-
29
- stop() {
30
- this.geoRelativeProvider?.removeEventListener(this.providerId);
31
- delete this.geoRelativeProvider;
32
- }
33
- }
34
-
35
- export default new GeoRelativePositionProvider();
@@ -1,107 +0,0 @@
1
- import { GeoRelativePosition } from '@wemap/geo';
2
- import { deg2rad } from '@wemap/maths';
3
-
4
- import Provider from '../../Provider.js';
5
- import AvailabilityHelper from '../../../events/AvailabilityHelper.js';
6
- import StepProvider from '../../steps/StepProvider.js';
7
- import AbsoluteAttitudeProvider from '../../attitude/absolute/AbsoluteAttitudeProvider.js';
8
- import { Step, AbsoluteAttitude } from '../../../events/Types.js';
9
-
10
-
11
- class PdrProvider extends Provider<GeoRelativePosition> {
12
-
13
- private absoluteAttitudeProviderId?: number;
14
- private stepDetectionProviderId?: number;
15
- private attitudeEvent?: AbsoluteAttitude;
16
-
17
- // https://ieeexplore.ieee.org/document/7346766
18
- // private misalignment = [1, 0, 0, 0];
19
- private misalignmentError = deg2rad(3);
20
-
21
- getName = () => 'Pdr';
22
-
23
- availability() {
24
- return AvailabilityHelper.every([
25
- StepProvider.getAvailability(),
26
- AbsoluteAttitudeProvider.getAvailability()
27
- ]);
28
- }
29
-
30
-
31
- start() {
32
-
33
- this.stepDetectionProviderId = StepProvider.addEventListener(
34
- this.onStepEvent,
35
- this.notifyError
36
- );
37
-
38
- this.absoluteAttitudeProviderId = AbsoluteAttitudeProvider.addEventListener(
39
- event => (this.attitudeEvent = event),
40
- this.notifyError
41
- );
42
-
43
- }
44
-
45
- stop() {
46
- StepProvider.removeEventListener(this.stepDetectionProviderId);
47
- AbsoluteAttitudeProvider.removeEventListener(this.absoluteAttitudeProviderId);
48
- }
49
-
50
- private onStepEvent = (stepEvent: Step) => {
51
-
52
- if (!this.attitudeEvent) {
53
- return;
54
- }
55
-
56
- const stepSize = stepEvent.size;
57
-
58
- /**
59
- * There is three frames because (device heading != walking direction):
60
- *
61
- * Device frame (x-Device Right, y-Device Top, z-Device Front)
62
- * Navigation frame (x-Nav East, y-Nav North, z-Nav Up)
63
- * Earth local frame (x-East y-North z-Up)
64
- *
65
- *
66
- * For the PDR, in order to find the step direction,
67
- * we are looking for the rotation between the device frame and the navigation frame.
68
- * Attitude is the rotation from the device frame to the earth local frame.
69
- * Misalignment is the rotation from the navigation frame to the earth local frame
70
- */
71
- const deviceAttitude = this.attitudeEvent;
72
-
73
- /**
74
- * For optimisation, as we define misalignment to identity, we do not process the quat mulitply formula.
75
- */
76
- // const deviceInNavFrame = Quaternion.multiply(deviceAttitude.quaternion, this.misalignment);
77
- // const deviceDirection = new Attitude(deviceInNavFrame).heading;
78
- const deviceDirection = deviceAttitude.heading;
79
-
80
- /**
81
- * A bad accuracy from PDR is due to three things:
82
- * - Attitude accuracy
83
- * - Misalignement (device heading != walking direction)
84
- * - Step detection false positives / false negatives
85
- * Following formula only use attitude accuracy with cone formula
86
- */
87
- const deviceDirectionAccuracy = deviceAttitude.accuracy! + this.misalignmentError;
88
- const accuracy = (stepSize / 2) * Math.sin(deviceDirectionAccuracy / 2);
89
- const timestamp = deviceAttitude.time;
90
-
91
- /**
92
- * Relative position is defined in ENU frame
93
- */
94
- const position = new GeoRelativePosition(
95
- stepSize * Math.sin(deviceDirection),
96
- stepSize * Math.cos(deviceDirection),
97
- 0,
98
- timestamp,
99
- accuracy,
100
- deviceDirection
101
- );
102
-
103
- this.notify(position);
104
- }
105
- }
106
-
107
- export default new PdrProvider();
@@ -1,67 +0,0 @@
1
- import { Vector3_t } from "@wemap/maths";
2
-
3
- class StepDetectionLadetto {
4
-
5
-
6
- static MIN_TIME_BETWEEN_STEPS = 0.4; // in seconds
7
-
8
- static MAX_FRENQUENCY = 4; // in Hz
9
- static MIN_FRENQUENCY = 1; // in Hz
10
-
11
- static VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 1; // in m.s-2
12
-
13
-
14
- frequency = 0;
15
-
16
- lastVerticalAcc = 0;
17
- maxAcceleration = 0;
18
- lastStepTimestamp = -StepDetectionLadetto.MIN_TIME_BETWEEN_STEPS;
19
-
20
- compute(timestamp: number, linearAcc: Vector3_t) {
21
-
22
- let stepDetected = false;
23
-
24
- const verticalAcc = linearAcc[2];
25
- const timeInterval = timestamp - this.lastStepTimestamp;
26
-
27
- const upfront = verticalAcc > this.lastVerticalAcc;
28
-
29
- if (upfront) {
30
- if (verticalAcc > this.maxAcceleration) {
31
- this.maxAcceleration = verticalAcc;
32
- }
33
- } else if (this.maxAcceleration > StepDetectionLadetto.VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD
34
- && timeInterval > StepDetectionLadetto.MIN_TIME_BETWEEN_STEPS) {
35
- this.maxAcceleration = 0;
36
-
37
- const diffTime = timestamp - this.lastStepTimestamp;
38
- this.frequency = Math.min(Math.max((1 / diffTime), StepDetectionLadetto.MIN_FRENQUENCY), StepDetectionLadetto.MAX_FRENQUENCY);
39
-
40
- stepDetected = true;
41
- this.lastStepTimestamp = timestamp;
42
- } else {
43
- this.maxAcceleration = 0;
44
- }
45
-
46
- this.lastVerticalAcc = verticalAcc;
47
-
48
- return stepDetected;
49
- }
50
-
51
- get lastStepSize() {
52
-
53
- if (!this.frequency) {
54
- return 0;
55
- }
56
-
57
- const kParamA = 0.45;
58
- const kParamB = 0.2;
59
- return kParamA + kParamB * this.frequency;
60
- }
61
-
62
- get speed() {
63
- return this.lastStepTimestamp ? this.lastStepSize * this.frequency : 0;
64
- }
65
- }
66
-
67
- export default StepDetectionLadetto;
@@ -1,70 +0,0 @@
1
- import { Vector3_t } from "@wemap/maths";
2
-
3
-
4
- class StepDetectionMinMaxPeaks {
5
-
6
- static WINDOW_TIME = 0.3; // in seconds
7
- static MIN_TIME_BETWEEN_STEPS = 0.4; // in seconds
8
- static MAX_FRENQUENCY = 4; // in Hz
9
- static MIN_FRENQUENCY = 1; // in Hz
10
- static VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 1.5; // in m.s-2
11
- static VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -1; // in m.s-2
12
-
13
- frequency = 0;
14
- lastStepTimestamp = -StepDetectionMinMaxPeaks.MIN_TIME_BETWEEN_STEPS;
15
- slidingWindow: { timestamp: number, verticalAcc: number }[] = [];
16
-
17
- compute(timestamp: number, linearAcc: Vector3_t) {
18
-
19
- if (this.lastStepTimestamp && this.lastStepTimestamp + StepDetectionMinMaxPeaks.MIN_TIME_BETWEEN_STEPS > timestamp) {
20
- return false;
21
- }
22
-
23
- let maxValue = Number.MIN_SAFE_INTEGER;
24
- let minValue = Number.MAX_SAFE_INTEGER;
25
-
26
- const windowTime = StepDetectionMinMaxPeaks.WINDOW_TIME;
27
- this.slidingWindow.forEach((item, index, object) => {
28
- if (item.timestamp < timestamp - windowTime) {
29
- object.splice(index, 1);
30
- } else {
31
- maxValue = Math.max(item.verticalAcc, maxValue);
32
- minValue = Math.min(item.verticalAcc, minValue);
33
- }
34
- });
35
- this.slidingWindow.push({
36
- timestamp: timestamp,
37
- verticalAcc: linearAcc[2]
38
- });
39
-
40
-
41
- if (maxValue > StepDetectionMinMaxPeaks.VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD
42
- && minValue < StepDetectionMinMaxPeaks.VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD) {
43
-
44
- const timeInterval = this.lastStepTimestamp ? timestamp - this.lastStepTimestamp : 1;
45
- this.frequency = Math.min(Math.max((1 / timeInterval), StepDetectionMinMaxPeaks.MIN_FRENQUENCY), StepDetectionMinMaxPeaks.MAX_FRENQUENCY);
46
-
47
- this.lastStepTimestamp = timestamp;
48
- return true;
49
- }
50
-
51
- return false;
52
- }
53
-
54
- get lastStepSize() {
55
-
56
- if (!this.frequency) {
57
- return 0;
58
- }
59
-
60
- const kParamA = 0.45;
61
- const kParamB = 0.2;
62
- return kParamA + kParamB * this.frequency;
63
- }
64
-
65
- get speed() {
66
- return this.lastStepTimestamp ? this.lastStepSize * this.frequency : 0;
67
- }
68
- }
69
-
70
- export default StepDetectionMinMaxPeaks;
@@ -1,99 +0,0 @@
1
- import { Vector3_t } from "@wemap/maths";
2
-
3
- class StepDetectionMinMaxPeaks2 {
4
-
5
- static WINDOW_TIME = 0.3; // in seconds
6
- static MIN_TIME_BETWEEN_STEPS = 0.4; // in seconds
7
- static MAX_FRENQUENCY = 4; // in Hz
8
- static MIN_FRENQUENCY = 1; // in Hz
9
- static VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 0.75; // in m.s-2
10
- static VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -0.3; // in m.s-2
11
-
12
- frequency = 0;
13
- influence = 0.2;
14
-
15
- slidingWindow: { timestamp: number, verticalAcc: number }[] = [];
16
- lastStepTimestamp = -StepDetectionMinMaxPeaks2.MIN_TIME_BETWEEN_STEPS;
17
- previousVerticalAcc = 0;
18
-
19
- compute(timestamp: number, linearAcc: Vector3_t, angularRate: Vector3_t) {
20
-
21
- const verticalAcc = this.influence * (linearAcc[2] * 2) + (1 - this.influence) * this.previousVerticalAcc;
22
- this.previousVerticalAcc = verticalAcc;
23
-
24
-
25
- if (Math.sqrt(angularRate[0] ** 2 + angularRate[1] ** 2 + angularRate[2] ** 2) > 0.75) {
26
- return false;
27
- }
28
-
29
- if (this.lastStepTimestamp && this.lastStepTimestamp + StepDetectionMinMaxPeaks2.MIN_TIME_BETWEEN_STEPS > timestamp) {
30
- return false;
31
- }
32
-
33
- let maxValue = Number.MIN_SAFE_INTEGER;
34
- let minValue = Number.MAX_SAFE_INTEGER;
35
-
36
- this.slidingWindow.forEach((item, index, object) => {
37
- if (item.timestamp < timestamp - StepDetectionMinMaxPeaks2.WINDOW_TIME) {
38
- object.splice(index, 1);
39
- } else {
40
- maxValue = Math.max(item.verticalAcc, maxValue);
41
- minValue = Math.min(item.verticalAcc, minValue);
42
- }
43
- });
44
- this.slidingWindow.push({
45
- timestamp: timestamp,
46
- verticalAcc: verticalAcc
47
- });
48
-
49
-
50
- if (maxValue > StepDetectionMinMaxPeaks2.VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD
51
- && minValue < StepDetectionMinMaxPeaks2.VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD) {
52
-
53
- const timeInterval = this.lastStepTimestamp ? timestamp - this.lastStepTimestamp : 1;
54
- this.frequency = Math.min(Math.max((1 / timeInterval), StepDetectionMinMaxPeaks2.MIN_FRENQUENCY), StepDetectionMinMaxPeaks2.MAX_FRENQUENCY);
55
-
56
- this.lastStepTimestamp = timestamp;
57
- return true;
58
- }
59
-
60
- return false;
61
- }
62
-
63
- get lastStepSize() {
64
-
65
- if (!this.frequency) {
66
- return 0;
67
- }
68
-
69
- const kParamA = 0.45;
70
- const kParamB = 0.2;
71
- return kParamA + kParamB * this.frequency;
72
- }
73
-
74
- get speed() {
75
- return this.lastStepSize && this.frequency ? this.lastStepSize * this.frequency : 0;
76
- }
77
-
78
- mean(data: { verticalAcc: number }[]) {
79
- let sum = 0.0, mean = 0.0;
80
-
81
- for (let i = 0; i < data.length; ++i) {
82
- sum += data[i].verticalAcc;
83
- }
84
- mean = sum / data.length;
85
- return mean;
86
- }
87
-
88
- stddev(data: { verticalAcc: number }[]) {
89
- const theMean = this.mean(data);
90
- let standardDeviation = 0;
91
- for (let i = 0; i < data.length; ++i) {
92
- standardDeviation += (data[i].verticalAcc - theMean) ** 2;
93
- }
94
-
95
- return Math.sqrt(standardDeviation / data.length);
96
- }
97
- }
98
-
99
- export default StepDetectionMinMaxPeaks2;
@@ -1,192 +0,0 @@
1
- import { Vector3_t } from "@wemap/maths";
2
-
3
- class StepDetectionMinMaxPeaks3 {
4
-
5
- static WINDOW_TIME = 0.6; // in seconds
6
- static MIN_TIME_BETWEEN_STEPS = 0.6; // in seconds
7
- static MAX_FRENQUENCY = 4; // in Hz
8
- static MIN_FRENQUENCY = 1; // in Hz
9
- static VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 0.2; // in m.s-2
10
- static VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -0.1; // in m.s-2
11
-
12
- frequency = 0;
13
- influence = 0.05;
14
-
15
- slidingWindow: { timestamp: number, verticalAcc: number }[] = [];
16
- lastStepTimestamp = -StepDetectionMinMaxPeaks3.MIN_TIME_BETWEEN_STEPS;
17
- previousVerticalAcc = 0;
18
- previousHorizontalAcc = 0;
19
-
20
-
21
- compute(timestamp: number, linearAcc: Vector3_t) {
22
-
23
- const verticalAcc = this.influence * linearAcc[2] + (1 - this.influence) * this.previousVerticalAcc;
24
- this.previousVerticalAcc = verticalAcc;
25
-
26
- // let horizontalAcc = Math.sqrt(linearAcc[0] ** 2 + linearAcc[1] ** 2);
27
- // horizontalAcc = this.influence * horizontalAcc + (1 - this.influence) * this.previousHorizontalAcc;
28
- // this.previousHorizontalAcc = horizontalAcc;
29
-
30
- // const angularRateNorm = Math.sqrt(angularRate[0] ** 2 + angularRate[1] ** 2 + angularRate[2] ** 2);
31
- // horizontalAcc = this.influence * horizontalAcc + (1 - this.influence) * this.previousHorizontalAcc;
32
- // this.previousangularRateNorm = angularRateNorm;
33
-
34
- // Update sliding window
35
- this.slidingWindow = this.slidingWindow.filter(item => item.timestamp >= timestamp - StepDetectionMinMaxPeaks3.WINDOW_TIME
36
- );
37
- this.slidingWindow.push({ timestamp, verticalAcc });
38
- // , horizontalAcc });
39
-
40
- // this.horizontalAccStd = this.stddev(this.slidingWindow.map(el => el.horizontalAcc));
41
- // this.verticalAccStd = this.stddev(this.slidingWindow.map(el => el.verticalAcc));
42
-
43
-
44
- const isTooEarlyForANewStep = this.lastStepTimestamp
45
- && this.lastStepTimestamp + StepDetectionMinMaxPeaks3.MIN_TIME_BETWEEN_STEPS > timestamp;
46
- if (isTooEarlyForANewStep) {
47
- return false;
48
- }
49
-
50
- // Looking for max peak
51
- let maxValue = Number.MIN_VALUE;
52
- let maxValueIdx = -1;
53
- let foundMaxPeakHigherThanThreshold = false;
54
- this.slidingWindow.forEach((item, idx) => {
55
- if (item.verticalAcc > maxValue
56
- && item.verticalAcc >= StepDetectionMinMaxPeaks3.VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD) {
57
- maxValue = item.verticalAcc;
58
- maxValueIdx = idx;
59
- foundMaxPeakHigherThanThreshold = true;
60
- }
61
- });
62
- if (!foundMaxPeakHigherThanThreshold) {
63
- return false;
64
- }
65
-
66
- // Looking for a value lower than a threshold before the max peak
67
- let hasLowNegativeValueBeforeMaxPeak = false;
68
- let minValueBeforeMaxPeak = Number.MAX_VALUE;
69
- for (let i = 0; i < maxValueIdx; i++) {
70
- const curValue = this.slidingWindow[i].verticalAcc;
71
- minValueBeforeMaxPeak = Math.min(minValueBeforeMaxPeak, curValue);
72
- if (curValue < StepDetectionMinMaxPeaks3.VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD) {
73
- hasLowNegativeValueBeforeMaxPeak = true;
74
- break;
75
- }
76
- }
77
- if (!hasLowNegativeValueBeforeMaxPeak) {
78
- return false;
79
- }
80
-
81
- // looking for another minimum after max peak
82
- const diffMinMax = maxValue - minValueBeforeMaxPeak;
83
- const targetValue = maxValue - 0.5 * diffMinMax;
84
- let targetValueFoundAfterMaxPeak = false;
85
- for (let i = maxValueIdx + 1; i < this.slidingWindow.length; i++) {
86
- if (this.slidingWindow[i].verticalAcc <= targetValue) {
87
- targetValueFoundAfterMaxPeak = true;
88
- break;
89
- }
90
- }
91
- if (!targetValueFoundAfterMaxPeak) {
92
- return false;
93
- }
94
-
95
- // // looking for another local minimum / maximum after 100ms
96
- // let localMinimumFound = false;
97
- // let localMaximumFound = false;
98
- // let localMaxiumValue = Number.MIN_SAFE_INTEGER;
99
- // let localMinimumVal = null;
100
- // const maxPeakTimestamp = this.slidingWindow[maxValueIdx].timestamp;
101
- // for (let i = maxValueIdx + 1; i < this.slidingWindow.length; i++) {
102
- // const curVal = this.slidingWindow[i];
103
- // const prevVal = this.slidingWindow[i - 1];
104
-
105
- // if (curVal.timestamp > maxPeakTimestamp + 0.4) {
106
- // break;
107
- // }
108
-
109
- // if (!localMinimumFound) {
110
- // // if (curVal.timestamp < maxPeakTimestamp + 0.05) {
111
- // // // too early
112
- // // continue;
113
- // // }
114
-
115
- // if (curVal.verticalAcc > prevVal.verticalAcc) {
116
- // localMinimumFound = true;
117
- // localMinimumVal = prevVal;
118
- // }
119
- // continue;
120
- // }
121
-
122
- // if (!localMaximumFound) {
123
-
124
- // // if (curVal.timestamp < localMinimumVal.timestamp + 0.05) {
125
- // // // too early
126
- // // continue;
127
- // // }
128
-
129
- // if (curVal.verticalAcc < prevVal.verticalAcc) {
130
- // localMaximumFound = true;
131
- // localMaxiumValue = prevVal.verticalAcc;
132
- // break;
133
- // }
134
- // }
135
- // }
136
- // const localMinMaxFoundAfterPeak = localMinimumFound && localMaximumFound;
137
- // // && localMaxiumValue / maxValue < 0.8;
138
- // // if (!localMinMaxFoundAfterPeak) {
139
- // // return false;
140
- // // }
141
-
142
-
143
- // const highRotationDetected = angularRateNorm > 0.75;
144
- // // if (highRotationDetected) {
145
- // // return false;
146
- // // }
147
-
148
- const timeInterval = this.lastStepTimestamp ? timestamp - this.lastStepTimestamp : 1;
149
- this.frequency = Math.min(Math.max((1 / timeInterval), StepDetectionMinMaxPeaks3.MIN_FRENQUENCY), StepDetectionMinMaxPeaks3.MAX_FRENQUENCY);
150
-
151
- this.lastStepTimestamp = timestamp;
152
- return true;
153
-
154
- }
155
-
156
- get lastStepSize() {
157
-
158
- if (!this.frequency) {
159
- return 0;
160
- }
161
-
162
- const kParamA = 0.45;
163
- const kParamB = 0.2;
164
- return kParamA + kParamB * this.frequency;
165
- }
166
-
167
- get speed() {
168
- return this.lastStepSize && this.frequency ? this.lastStepSize * this.frequency : 0;
169
- }
170
-
171
- mean(data: number[]) {
172
- let sum = 0.0, mean = 0.0;
173
-
174
- for (let i = 0; i < data.length; ++i) {
175
- sum += data[i];
176
- }
177
- mean = sum / data.length;
178
- return mean;
179
- }
180
-
181
- stddev(data: number[]) {
182
- const theMean = this.mean(data);
183
- let standardDeviation = 0;
184
- for (let i = 0; i < data.length; ++i) {
185
- standardDeviation += (data[i] - theMean) ** 2;
186
- }
187
-
188
- return Math.sqrt(standardDeviation / data.length);
189
- }
190
- }
191
-
192
- export default StepDetectionMinMaxPeaks3;