@wemap/providers 9.1.1 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/package.json +8 -8
- package/src/providers/steps/StepDetectionMinMaxPeaks3.js +201 -0
- package/src/providers/steps/StepDetector.js +32 -1
- package/src/providers/steps/StepDetectorLadetto.js +108 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks.js +108 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks2.js +108 -0
- package/src/providers/steps/StepDetectorMinMaxPeaks3.js +108 -0
- package/dist/wemap-providers.es.js +0 -5284
- package/dist/wemap-providers.es.js.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Constants as GeoConstants } from '@wemap/geo';
|
|
2
|
+
import { Quaternion } from '@wemap/maths';
|
|
3
|
+
|
|
4
|
+
import EventType from '../../events/EventType.js';
|
|
5
|
+
import RelativeAttitudeFromInertial from '../attitude/relative/RelativeAttitudeFromInertial.js';
|
|
6
|
+
import Accelerometer from '../imu/Accelerometer.js';
|
|
7
|
+
import Gyroscope from '../imu/Gyroscope.js';
|
|
8
|
+
import Provider from '../Provider.js';
|
|
9
|
+
import StepDetectionMinMaxPeaks3 from './StepDetectionMinMaxPeaks3.js';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StepDetectorMinMaxPeaks3 extends Provider {
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.stepDetector = new StepDetectionMinMaxPeaks3();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @override
|
|
21
|
+
*/
|
|
22
|
+
static get pname() {
|
|
23
|
+
return 'StepDetectorMinMaxPeaks3';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @override
|
|
28
|
+
*/
|
|
29
|
+
get _availability() {
|
|
30
|
+
return Promise.all([
|
|
31
|
+
Accelerometer.availability,
|
|
32
|
+
Gyroscope.availability,
|
|
33
|
+
RelativeAttitudeFromInertial.availability
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @override
|
|
39
|
+
*/
|
|
40
|
+
start() {
|
|
41
|
+
|
|
42
|
+
this.numOfSteps = 0;
|
|
43
|
+
|
|
44
|
+
this.accelerometerProviderId = Accelerometer.addEventListener(
|
|
45
|
+
events => this.onAccelerometerEvent(events[0]),
|
|
46
|
+
error => this.notifyError(error)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this.gyroscopeProviderId = Gyroscope.addEventListener(
|
|
50
|
+
events => (this.angularRateEvent = events[0]),
|
|
51
|
+
error => this.notifyError(error)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
this.attitudeProviderId = RelativeAttitudeFromInertial.addEventListener(
|
|
55
|
+
events => (this.attitudeEvent = events[0]),
|
|
56
|
+
error => this.notifyError(error)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @override
|
|
62
|
+
*/
|
|
63
|
+
stop() {
|
|
64
|
+
Accelerometer.removeEventListener(this.accelerometerProviderId);
|
|
65
|
+
Gyroscope.removeEventListener(this.gyroscopeProviderId);
|
|
66
|
+
RelativeAttitudeFromInertial.removeEventListener(this.attitudeProviderId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onAccelerometerEvent(accelerationEvent) {
|
|
70
|
+
|
|
71
|
+
if (!this.attitudeEvent || !this.angularRateEvent) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const {
|
|
76
|
+
values: acceleration, timestamp
|
|
77
|
+
} = accelerationEvent.data;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Step Detection and Step Size Detection
|
|
81
|
+
*/
|
|
82
|
+
const linearAcc = this.constructor.computeLinearAcceleration(
|
|
83
|
+
this.attitudeEvent.data.quaternion, acceleration);
|
|
84
|
+
const stepDetected = this.stepDetector.compute(timestamp, linearAcc, this.angularRateEvent.data.values);
|
|
85
|
+
|
|
86
|
+
if (stepDetected) {
|
|
87
|
+
const size = this.stepDetector.lastStepSize;
|
|
88
|
+
this.numOfSteps++;
|
|
89
|
+
this.notify(this.createEvent(
|
|
90
|
+
EventType.Step, {
|
|
91
|
+
size,
|
|
92
|
+
number: this.numOfSteps
|
|
93
|
+
},
|
|
94
|
+
[accelerationEvent, this.angularRateEvent, this.attitudeEvent]
|
|
95
|
+
));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Linear acceleration in ENU
|
|
100
|
+
static computeLinearAcceleration(quaternion, acc) {
|
|
101
|
+
const linearAcc = Quaternion.rotateMatlab(Quaternion.inverse(quaternion), acc);
|
|
102
|
+
linearAcc[2] -= GeoConstants.EARTH_GRAVITY;
|
|
103
|
+
return linearAcc;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default new StepDetectorMinMaxPeaks3();
|