@wemap/providers 4.0.1 → 4.0.3

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 (35) hide show
  1. package/debug/dist/index.html +1 -0
  2. package/debug/dist/turn-detection.html +19 -0
  3. package/debug/index.js +2 -0
  4. package/debug/src/AbsoluteAttitudeComponent.jsx +0 -10
  5. package/debug/src/StepDetectionComponent.jsx +3 -3
  6. package/debug/src/TurnDetectionComponent.jsx +47 -0
  7. package/debug/src/Utils.js +20 -0
  8. package/package.json +7 -9
  9. package/src/Providers.js +5 -4
  10. package/src/ProvidersInterface.js +5 -6
  11. package/src/events/EventType.js +5 -1
  12. package/src/events/ProviderEvent.js +7 -0
  13. package/src/mapmatching/MapMatchingHandler.js +332 -54
  14. package/src/providers/Provider.js +42 -8
  15. package/src/providers/Provider.spec.js +3 -4
  16. package/src/providers/attitude/TurnDectector.js +71 -0
  17. package/src/providers/attitude/absolute/AbsoluteAttitude.js +123 -65
  18. package/src/providers/attitude/relative/RelativeAttitude.js +1 -3
  19. package/src/providers/attitude/relative/RelativeAttitudeFromBrowser.js +1 -2
  20. package/src/providers/attitude/relative/RelativeAttitudeFromEkf.js +1 -2
  21. package/src/providers/attitude/relative/RelativeAttitudeFromInertial.js +19 -2
  22. package/src/providers/imu/HighRotationsDetector.js +62 -0
  23. package/src/providers/inclination/Inclination.js +2 -2
  24. package/src/providers/others/CameraNative.js +2 -2
  25. package/src/providers/others/CameraProjectionMatrix.js +2 -2
  26. package/src/providers/position/absolute/AbsolutePosition.js +112 -82
  27. package/src/providers/position/relative/GeoRelativePosition.js +2 -2
  28. package/src/providers/position/relative/Pdr.js +4 -4
  29. package/src/providers/steps/{StepDetection.js → StepDetector.js} +4 -4
  30. package/src/providers/steps/StraightLineDetector.js +80 -0
  31. package/src/smoothers/AttitudeSmoother.js +94 -59
  32. package/src/providers/MetaProvider.js +0 -44
  33. package/src/providers/attitude/absolute/AbsoluteAttitudeFromRelAtt.js +0 -133
  34. package/src/providers/attitude/absolute/AbsoluteAttitudeFused.js +0 -166
  35. package/src/providers/position/absolute/AbsolutePositionFromRel.js +0 -106
@@ -1,133 +0,0 @@
1
- import { Quaternion } from '@wemap/maths';
2
- import { Attitude } from '@wemap/geo';
3
-
4
- import Provider from '../../Provider.js';
5
- import EventType from '../../../events/EventType.js';
6
- import RelativeAttitude from '../relative/RelativeAttitude.js';
7
- import AbsoluteAttitude from './AbsoluteAttitude.js';
8
- import AbsoluteAttitudeFromBrowser from './AbsoluteAttitudeFromBrowser.js';
9
- import AbsoluteAttitudeFused from './AbsoluteAttitudeFused.js';
10
-
11
- /**
12
- * Absolute attitude provider gives the device attitude in East-North-Up (ENU) frame
13
- */
14
- class AbsoluteAttitudeFromRelAtt extends Provider {
15
-
16
- accuracy = 0;
17
-
18
- /**
19
- * @override
20
- */
21
- static get pname() {
22
- return 'AbsoluteAttitudeFromRelAtt';
23
- }
24
-
25
- /**
26
- * @override
27
- */
28
- static get eventsType() {
29
- return [EventType.AbsoluteAttitude];
30
- }
31
-
32
- /**
33
- * @override
34
- */
35
- get _availability() {
36
- return RelativeAttitude.availability;
37
- }
38
-
39
- /**
40
- * @override
41
- */
42
- start() {
43
-
44
- this.relativeAttitudeProviderId = RelativeAttitude.addEventListener(
45
- events => this.onRelativeAttitudeEvent(events[0]),
46
- error => this.notifyError(error)
47
- );
48
-
49
-
50
- this.onAbsoluteAttitudeEvent(AbsoluteAttitude.lastEvent);
51
- this.absoluteAttitudeProviderId = AbsoluteAttitude.addEventListener(
52
- events => this.onAbsoluteAttitudeEvent(events[0]),
53
- error => this.notifyError(error),
54
- false
55
- );
56
- }
57
-
58
- /**
59
- * @override
60
- */
61
- stop() {
62
- RelativeAttitude.removeEventListener(this.relativeAttitudeProviderId);
63
- AbsoluteAttitude.removeEventListener(this.absoluteAttitudeProviderId);
64
- }
65
-
66
-
67
- onRelativeAttitudeEvent(relativeAttitudeEvent) {
68
-
69
- /**
70
- * Calculate relative accuracy
71
- */
72
- if (this.relativeAttitudeEvent) {
73
- const {
74
- accuracy, time
75
- } = relativeAttitudeEvent.data;
76
- const diffTime = time - this.relativeAttitudeEvent.data.time;
77
- this.accuracy += diffTime * accuracy;
78
- }
79
-
80
- this.relativeAttitudeEvent = relativeAttitudeEvent;
81
- this.compute();
82
- }
83
-
84
-
85
- onAbsoluteAttitudeEvent = absoluteAttitudeEvent => {
86
-
87
- if (!absoluteAttitudeEvent) {
88
- return;
89
- }
90
-
91
- /**
92
- * Use absolute attitude events only when they are not from this provider
93
- */
94
- if (absoluteAttitudeEvent.providersStack.includes(this.pname)
95
- || absoluteAttitudeEvent.providersStack.includes(AbsoluteAttitudeFromBrowser.pname)
96
- || absoluteAttitudeEvent.providersStack.includes(AbsoluteAttitudeFused.pname)) {
97
- return;
98
- }
99
- this.absoluteAttitudeEvent = absoluteAttitudeEvent;
100
- this.accuracy = 0;
101
-
102
- // preprocess zOffset for "compute" function
103
- const currentHeading = this.relativeAttitudeEvent ? this.relativeAttitudeEvent.data.heading : 0;
104
- this.zOffset = Quaternion.fromAxisAngle([0, 0, 1], -absoluteAttitudeEvent.data.heading + currentHeading);
105
- };
106
-
107
-
108
- compute() {
109
- if (!this.absoluteAttitudeEvent || !this.relativeAttitudeEvent) {
110
- return;
111
- }
112
-
113
- const {
114
- quaternion, time
115
- } = this.relativeAttitudeEvent.data;
116
-
117
- const absoluteAttitudeAccuracy = this.absoluteAttitudeEvent.data.accuracy;
118
-
119
- const absoluteQuat = Quaternion.multiply(this.zOffset, quaternion);
120
- const newAccuracy = Math.min(absoluteAttitudeAccuracy + this.accuracy, Math.PI);
121
- const attitude = new Attitude(absoluteQuat, time, newAccuracy, this.pname);
122
-
123
- this.notify(this.createEvent(
124
- EventType.AbsoluteAttitude,
125
- attitude,
126
- [this.relativeAttitudeEvent, this.absoluteAttitudeEvent]
127
- ));
128
-
129
- }
130
-
131
- }
132
-
133
- export default new AbsoluteAttitudeFromRelAtt();
@@ -1,166 +0,0 @@
1
- import { Attitude, Edge } from '@wemap/geo';
2
- import {
3
- Quaternion, diffAngle
4
- } from '@wemap/maths';
5
-
6
- import Provider from '../../Provider.js';
7
- import EventType from '../../../events/EventType.js';
8
- import ProviderState from '../../ProviderState.js';
9
- import RelativeAttitude from '../relative/RelativeAttitude.js';
10
-
11
- /**
12
- * Absolute attitude provider gives the device attitude in East-North-Up (ENU) frame
13
- */
14
- class AbsoluteAttitudeFused extends Provider {
15
-
16
- accuracy = 0;
17
- isInitialized = false;
18
-
19
- /** @type {number[]} quaternion */
20
- zOffset = null;
21
-
22
- /**
23
- * @override
24
- */
25
- static get pname() {
26
- return 'AbsoluteAttitudeFused';
27
- }
28
-
29
- /**
30
- * @override
31
- */
32
- static get eventsType() {
33
- return [EventType.AbsoluteAttitude];
34
- }
35
-
36
- /**
37
- * @override
38
- */
39
- get _availability() {
40
- // TODO Enhance
41
- return RelativeAttitude.availability;
42
- }
43
-
44
- /**
45
- * @override
46
- */
47
- start() {
48
-
49
- this.relativeAttitudeProviderId = RelativeAttitude.addEventListener(
50
- events => this.onRelativeAttitudeEvent(events[0]),
51
- error => this.notifyError(error)
52
- );
53
-
54
-
55
- // this.onAbsoluteAttitudeEvent(AbsoluteAttitude.lastEvent);
56
- // this.absoluteAttitudeProviderId = AbsoluteAttitude.addEventListener(
57
- // events => this.onAbsoluteAttitudeEvent(events[0]),
58
- // error => this.notifyError(error),
59
- // false
60
- // );
61
- }
62
-
63
- /**
64
- * @override
65
- */
66
- stop() {
67
- RelativeAttitude.removeEventListener(this.relativeAttitudeProviderId);
68
- // AbsoluteAttitude.removeEventListener(this.absoluteAttitudeProviderId);
69
- }
70
-
71
- mapMatching(projection) {
72
-
73
- if (this.state !== ProviderState.STARTED) {
74
- return;
75
- }
76
-
77
- const {
78
- nearestElement, origin
79
- } = projection;
80
- if (!(nearestElement instanceof Edge)) {
81
- return;
82
- }
83
-
84
- let matchingDirection;
85
- const matchingDirectionAngle1 = diffAngle(nearestElement.bearing, origin.bearing);
86
- const matchingDirectionAngle2 = diffAngle(nearestElement.bearing + Math.PI, origin.bearing);
87
-
88
- if (Math.abs(matchingDirectionAngle1) < Math.abs(matchingDirectionAngle2)) {
89
- matchingDirection = nearestElement.bearing;
90
- } else {
91
- matchingDirection = (nearestElement.bearing + Math.PI) % (2 * Math.PI);
92
- }
93
-
94
- this.accuracy = 0;
95
-
96
- // preprocess zOffset for "compute" function
97
- const currentHeading = this.relativeAttitudeEvent ? this.relativeAttitudeEvent.data.heading : 0;
98
- this.zOffset = Quaternion.fromAxisAngle([0, 0, 1], -matchingDirection + currentHeading);
99
-
100
- this.compute();
101
- }
102
-
103
- onRelativeAttitudeEvent(relativeAttitudeEvent) {
104
-
105
- /**
106
- * Calculate relative accuracy
107
- */
108
- if (this.relativeAttitudeEvent) {
109
- const {
110
- accuracy, time
111
- } = relativeAttitudeEvent.data;
112
- const diffTime = time - this.relativeAttitudeEvent.data.time;
113
- this.accuracy += diffTime * accuracy;
114
- }
115
-
116
- this.relativeAttitudeEvent = relativeAttitudeEvent;
117
- this.compute();
118
- }
119
-
120
-
121
- // onAbsoluteAttitudeEvent = absoluteAttitudeEvent => {
122
-
123
- // if (!absoluteAttitudeEvent) {
124
- // return;
125
- // }
126
-
127
- // /**
128
- // * Use absolute attitude events only when they are not from this provider
129
- // */
130
- // if (absoluteAttitudeEvent.providersStack.includes(this.pname)
131
- // || absoluteAttitudeEvent.providersStack.includes(AbsoluteAttitudeFromBrowser.pname)) {
132
- // return;
133
- // }
134
- // this.absoluteAttitudeEvent = absoluteAttitudeEvent;
135
- // this.accuracy = 0;
136
-
137
- // // preprocess zOffset for "compute" function
138
- // const currentHeading = this.relativeAttitudeEvent ? this.relativeAttitudeEvent.data.heading : 0;
139
- // this.zOffset = Quaternion.fromAxisAngle([0, 0, 1], -absoluteAttitudeEvent.data.heading + currentHeading);
140
- // };
141
-
142
-
143
- compute() {
144
- if (!this.zOffset || !this.relativeAttitudeEvent) {
145
- return;
146
- }
147
-
148
- const {
149
- quaternion, time
150
- } = this.relativeAttitudeEvent.data;
151
-
152
- const absoluteQuat = Quaternion.multiply(this.zOffset, quaternion);
153
- const newAccuracy = Math.min(this.accuracy, Math.PI);
154
- const attitude = new Attitude(absoluteQuat, time, newAccuracy, this.pname);
155
-
156
- this.notify(this.createEvent(
157
- EventType.AbsoluteAttitude,
158
- attitude,
159
- [this.relativeAttitudeEvent]
160
- ));
161
-
162
- }
163
-
164
- }
165
-
166
- export default new AbsoluteAttitudeFused();
@@ -1,106 +0,0 @@
1
- import Provider from '../../Provider.js';
2
- import EventType from '../../../events/EventType.js';
3
- import ProviderEvent from '../../../events/ProviderEvent.js';
4
- import GeoRelativePosition from '../relative/GeoRelativePosition.js';
5
- import AbsolutePosition from './AbsolutePosition.js';
6
-
7
- class AbsolutePositionFromRel extends Provider {
8
-
9
- position = null;
10
-
11
- /**
12
- * @override
13
- */
14
- static get pname() {
15
- return 'AbsolutePositionFromRel';
16
- }
17
-
18
- /**
19
- * @override
20
- */
21
- static get eventsType() {
22
- return [EventType.AbsolutePosition];
23
- }
24
-
25
- /**
26
- * @override
27
- */
28
- get _availability() {
29
- return GeoRelativePosition.availability;
30
- }
31
-
32
-
33
- /**
34
- * @override
35
- */
36
- start() {
37
-
38
- this.providerId = GeoRelativePosition.addEventListener(
39
- events => this.onRelativePositionEvent(events[0]),
40
- error => this.notifyError(error)
41
- );
42
-
43
- this.onAbsolutePositionEvent(AbsolutePosition.lastEvent);
44
- this.absolutePositionProviderId = AbsolutePosition.addEventListener(
45
- events => this.onAbsolutePositionEvent(events[0]),
46
- error => this.notifyError(error),
47
- false
48
- );
49
-
50
- }
51
-
52
-
53
- /**
54
- * @override
55
- */
56
- stop() {
57
- GeoRelativePosition.removeEventListener(this.providerId);
58
- AbsolutePosition.removeEventListener(this.absolutePositionProviderId);
59
- }
60
-
61
- onAbsolutePositionEvent(absolutePositionEvent) {
62
-
63
- if (!absolutePositionEvent) {
64
- return;
65
- }
66
-
67
- /**
68
- * Use absolute position events only when they are not from this provider
69
- */
70
- if (absolutePositionEvent.data === this.position) {
71
- return;
72
- }
73
-
74
- this.position = absolutePositionEvent.data;
75
- }
76
-
77
-
78
- /**
79
- * @param {ProviderEvent} event
80
- */
81
- onRelativePositionEvent(event) {
82
-
83
- if (this.position) {
84
-
85
- const offsetPos = event.data;
86
-
87
- const dist = Math.sqrt(offsetPos.x ** 2 + offsetPos.y ** 2);
88
- const bearing = Math.atan2(offsetPos.x, offsetPos.y);
89
- const alt = this.position.alt !== null ? offsetPos.z : null;
90
-
91
- this.position = this.position.destinationPoint(dist, bearing, alt);
92
- this.position.bearing = offsetPos.bearing;
93
- this.position.time = offsetPos.time;
94
- this.position.accuracy += offsetPos.accuracy;
95
-
96
- this.notify(this.createEvent(
97
- EventType.AbsolutePosition,
98
- this.position,
99
- [event]
100
- ));
101
- }
102
- }
103
-
104
- }
105
-
106
- export default new AbsolutePositionFromRel();