@robotical/webapp-types 0.6.58
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/application-manager.ts +20 -0
- package/dist-types/src/analytics/AnalyticsManager.d.ts +28 -0
- package/dist-types/src/analytics/AnalyticsManager.js +171 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.d.ts +117 -0
- package/dist-types/src/application/ApplicationManager/ApplicationManager.js +567 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.d.ts +50 -0
- package/dist-types/src/application/RAFTs/Cog/Cog.js +223 -0
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.d.ts +120 -0
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.js +533 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.d.ts +42 -0
- package/dist-types/src/application/RAFTs/Marty/Marty.js +187 -0
- package/dist-types/src/application/RAFTs/RAFT.d.ts +114 -0
- package/dist-types/src/application/RAFTs/RAFT.js +341 -0
- package/dist-types/src/application/RAFTs/RAFTInterface.d.ts +13 -0
- package/dist-types/src/application/RAFTs/RAFTInterface.js +6 -0
- package/dist-types/src/application/RAFTs/RaftObserver.d.ts +10 -0
- package/dist-types/src/application/RAFTs/RaftObserver.js +1 -0
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.d.ts +63 -0
- package/dist-types/src/application/RAFTs/raft-subscription-helpers.js +355 -0
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.d.ts +10 -0
- package/dist-types/src/application/communicators/SelfdestructiveMessagePromise.js +31 -0
- package/dist-types/src/application/communicators/WrapperCommunicator.d.ts +24 -0
- package/dist-types/src/application/communicators/WrapperCommunicator.js +137 -0
- package/dist-types/src/components/disposables/LoadingSpinner/index.d.ts +7 -0
- package/dist-types/src/components/disposables/LoadingSpinner/index.js +29 -0
- package/dist-types/src/components/disposables/buttons/SVGImageButton/index.d.ts +14 -0
- package/dist-types/src/components/disposables/buttons/SVGImageButton/index.js +19 -0
- package/dist-types/src/components/disposables/buttons/SimpleButton/index.d.ts +14 -0
- package/dist-types/src/components/disposables/buttons/SimpleButton/index.js +18 -0
- package/dist-types/src/components/modals/ SensorsDashboardModal/index.d.ts +2 -0
- package/dist-types/src/components/modals/ SensorsDashboardModal/index.js +61 -0
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.d.ts +3 -0
- package/dist-types/src/components/modals/ConnectingLoadingSpinnerModal/index.js +16 -0
- package/dist-types/src/components/modals/DetailedFeedbackModal/index.d.ts +5 -0
- package/dist-types/src/components/modals/DetailedFeedbackModal/index.js +37 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.d.ts +1 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/index.js +8 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/styles.d.ts +1 -0
- package/dist-types/src/components/modals/DisconnectConfirmation/styles.js +7 -0
- package/dist-types/src/components/modals/InUnplugged/index.d.ts +1 -0
- package/dist-types/src/components/modals/InUnplugged/index.js +12 -0
- package/dist-types/src/components/modals/InUnplugged/styles.d.ts +5 -0
- package/dist-types/src/components/modals/InUnplugged/styles.js +11 -0
- package/dist-types/src/components/modals/VerificationModal/index.d.ts +6 -0
- package/dist-types/src/components/modals/VerificationModal/index.js +124 -0
- package/dist-types/src/components/modals/VerificationModalPhoneApp/index.d.ts +6 -0
- package/dist-types/src/components/modals/VerificationModalPhoneApp/index.js +195 -0
- package/dist-types/src/components/oneoffs/LEDs/index.d.ts +8 -0
- package/dist-types/src/components/oneoffs/LEDs/index.js +39 -0
- package/dist-types/src/components/oneoffs/RaftSignal/index.d.ts +7 -0
- package/dist-types/src/components/oneoffs/RaftSignal/index.js +29 -0
- package/dist-types/src/services/logger/Logger.d.ts +8 -0
- package/dist-types/src/services/logger/Logger.js +25 -0
- package/dist-types/src/state-observables/modal/DraggableModalState.d.ts +16 -0
- package/dist-types/src/state-observables/modal/DraggableModalState.js +52 -0
- package/dist-types/src/state-observables/modal/ModalObserver.d.ts +18 -0
- package/dist-types/src/state-observables/modal/ModalObserver.js +1 -0
- package/dist-types/src/state-observables/modal/ModalState.d.ts +25 -0
- package/dist-types/src/state-observables/modal/ModalState.js +71 -0
- package/dist-types/src/store/SelectedRaftContext.d.ts +19 -0
- package/dist-types/src/store/SelectedRaftContext.js +84 -0
- package/dist-types/src/styles/colors.d.ts +35 -0
- package/dist-types/src/styles/colors.js +42 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.d.ts +48 -0
- package/dist-types/src/types/communication-between-apps/wrapper-communication.js +28 -0
- package/dist-types/src/types/events/raft-info.d.ts +10 -0
- package/dist-types/src/types/events/raft-info.js +11 -0
- package/dist-types/src/types/phone-app-communicator.d.ts +20 -0
- package/dist-types/src/types/phone-app-communicator.js +5 -0
- package/dist-types/src/types/raft.d.ts +18 -0
- package/dist-types/src/types/raft.js +14 -0
- package/dist-types/src/utils/Toaster.d.ts +13 -0
- package/dist-types/src/utils/Toaster.js +38 -0
- package/dist-types/src/utils/helpers/compare-version.d.ts +2 -0
- package/dist-types/src/utils/helpers/compare-version.js +19 -0
- package/dist-types/src/utils/helpers/randomHashGenerator.d.ts +1 -0
- package/dist-types/src/utils/helpers/randomHashGenerator.js +10 -0
- package/dist-types/src/utils/helpers/rescale-range.d.ts +2 -0
- package/dist-types/src/utils/helpers/rescale-range.js +4 -0
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.d.ts +3 -0
- package/dist-types/src/utils/helpers/wifi-configuration-subtitle-gen.js +34 -0
- package/dist-types/src/utils/phone-app-communication/is-phone-app.d.ts +5 -0
- package/dist-types/src/utils/phone-app-communication/is-phone-app.js +7 -0
- package/dist-types/src/wrapper-app/WrapperAppManager.d.ts +58 -0
- package/dist-types/src/wrapper-app/WrapperAppManager.js +176 -0
- package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.d.ts +24 -0
- package/dist-types/src/wrapper-app/communicators/WebAppCommunicator.js +243 -0
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.d.ts +40 -0
- package/dist-types/src/wrapper-app/connectors/CogConnector/CogConnector.js +209 -0
- package/dist-types/src/wrapper-app/connectors/Connector.d.ts +72 -0
- package/dist-types/src/wrapper-app/connectors/Connector.js +314 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.d.ts +15 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorFactory.js +99 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorInterface.d.ts +10 -0
- package/dist-types/src/wrapper-app/connectors/ConnectorInterface.js +6 -0
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.d.ts +40 -0
- package/dist-types/src/wrapper-app/connectors/MartyConnector/MartyConnector.js +243 -0
- package/dist-types/types-package/application-manager.d.ts +17 -0
- package/dist-types/types-package/application-manager.js +5 -0
- package/package.json +13 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
+
function step(op) {
|
|
30
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
32
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
+
switch (op[0]) {
|
|
35
|
+
case 0: case 1: t = op; break;
|
|
36
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
+
default:
|
|
40
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
+
if (t[2]) _.ops.pop();
|
|
45
|
+
_.trys.pop(); continue;
|
|
46
|
+
}
|
|
47
|
+
op = body.call(thisArg, _);
|
|
48
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
import { raftPubSubscriptionHelper } from "../raft-subscription-helpers";
|
|
53
|
+
import { isVersionGreater_errorCatching } from "../../../utils/helpers/compare-version";
|
|
54
|
+
import EventEmitter from "events";
|
|
55
|
+
import Logger from "../../../services/logger/Logger";
|
|
56
|
+
var SHOW_LOGS = true;
|
|
57
|
+
var TAG = "PublishedDataAnalyser";
|
|
58
|
+
var PublishedDataAnalyser = /** @class */ (function (_super) {
|
|
59
|
+
__extends(PublishedDataAnalyser, _super);
|
|
60
|
+
function PublishedDataAnalyser(cog) {
|
|
61
|
+
var _this = _super.call(this) || this;
|
|
62
|
+
_this.cog = cog;
|
|
63
|
+
_this.rotationDetection = new RotationDetection();
|
|
64
|
+
_this.shakeDetector = new ShakeDetector();
|
|
65
|
+
_this.buttonClickDetection = new ButtonClickDetection();
|
|
66
|
+
_this.tiltDetection = new TiltDetection();
|
|
67
|
+
_this.objectSenseDetection = new ObjectSenseDetection();
|
|
68
|
+
_this.lightSenseDetection = new LightSenseDetection();
|
|
69
|
+
_this.eventsMap = {
|
|
70
|
+
tilt: {
|
|
71
|
+
forward: "tiltForward",
|
|
72
|
+
backward: "tiltBackward",
|
|
73
|
+
left: "tiltLeft",
|
|
74
|
+
right: "tiltRight",
|
|
75
|
+
none: "noTilt"
|
|
76
|
+
},
|
|
77
|
+
movementType: {
|
|
78
|
+
shake: "shake",
|
|
79
|
+
move: "move",
|
|
80
|
+
none: "noMovement"
|
|
81
|
+
},
|
|
82
|
+
rotation: {
|
|
83
|
+
clockwise: "rotationClockwise",
|
|
84
|
+
counterClockwise: "rotationCounterClockwise",
|
|
85
|
+
none: "noRotation"
|
|
86
|
+
},
|
|
87
|
+
buttonClick: {
|
|
88
|
+
click: "buttonClick",
|
|
89
|
+
release: "buttonRelease",
|
|
90
|
+
none: "noButtonClick"
|
|
91
|
+
},
|
|
92
|
+
objectSense: {
|
|
93
|
+
left: "objectSenseLeft",
|
|
94
|
+
right: "objectSenseRight",
|
|
95
|
+
none: "noObjectSense"
|
|
96
|
+
},
|
|
97
|
+
lightSense: {
|
|
98
|
+
high: "highLightSense",
|
|
99
|
+
mid: "midLightSense",
|
|
100
|
+
low: "lowLightSense",
|
|
101
|
+
none: "noLightSense"
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
_this.TiltDetection = TiltDetection;
|
|
105
|
+
_this.cog = cog;
|
|
106
|
+
_this.cogState = {
|
|
107
|
+
tilt: "none",
|
|
108
|
+
movementType: "none",
|
|
109
|
+
rotation: "none",
|
|
110
|
+
buttonClick: "none",
|
|
111
|
+
objectSense: "none",
|
|
112
|
+
lightSense: "none",
|
|
113
|
+
};
|
|
114
|
+
_this.pubSub = null;
|
|
115
|
+
_this.subscribeToPublishedData();
|
|
116
|
+
return _this;
|
|
117
|
+
}
|
|
118
|
+
PublishedDataAnalyser.prototype.subscribeToPublishedData = function () {
|
|
119
|
+
var _this = this;
|
|
120
|
+
this.pubSub = raftPubSubscriptionHelper(this.cog);
|
|
121
|
+
this.pubSub.subscribe(function (data) {
|
|
122
|
+
_this.analyse(data.stateInfo);
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
PublishedDataAnalyser.prototype.unsubscribeFromPublishedData = function () {
|
|
126
|
+
var _a;
|
|
127
|
+
(_a = this.pubSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
128
|
+
};
|
|
129
|
+
PublishedDataAnalyser.prototype.analyse = function (data) {
|
|
130
|
+
if (!data)
|
|
131
|
+
return;
|
|
132
|
+
var accelData = data.accelerometer;
|
|
133
|
+
var gyroData = data.gyroscope;
|
|
134
|
+
var lightData = data.light;
|
|
135
|
+
var isMoving;
|
|
136
|
+
if (accelData)
|
|
137
|
+
isMoving = this.shakeDetector.detectShake(accelData.ax, accelData.ay, accelData.az, Date.now(), this);
|
|
138
|
+
accelData && this.tiltDetection.detectTilt(accelData.ax, accelData.ay, accelData.az, isMoving, this, this.cog.getRaftVersion());
|
|
139
|
+
gyroData && this.rotationDetection.detectRotation(gyroData.gz, isMoving, this);
|
|
140
|
+
lightData && this.buttonClickDetection.detectButtonClick(lightData.ir2, this, this.cog.getRaftVersion());
|
|
141
|
+
lightData && this.objectSenseDetection.detectObjectSense([lightData.ir0, lightData.ir1], this);
|
|
142
|
+
lightData && this.lightSenseDetection.detectLightSense(lightData.amb0, this);
|
|
143
|
+
};
|
|
144
|
+
PublishedDataAnalyser.prototype.setTilt = function (tilt) {
|
|
145
|
+
this.cogState.tilt = tilt;
|
|
146
|
+
this.emit(this.eventsMap.tilt[tilt]);
|
|
147
|
+
};
|
|
148
|
+
PublishedDataAnalyser.prototype.setMovementType = function (movementType) {
|
|
149
|
+
this.cogState.movementType = movementType;
|
|
150
|
+
this.emit(this.eventsMap.movementType[movementType]);
|
|
151
|
+
};
|
|
152
|
+
PublishedDataAnalyser.prototype.setRotation = function (rotation) {
|
|
153
|
+
this.cogState.rotation = rotation;
|
|
154
|
+
this.emit(this.eventsMap.rotation[rotation]);
|
|
155
|
+
};
|
|
156
|
+
PublishedDataAnalyser.prototype.setButtonClick = function (buttonClick) {
|
|
157
|
+
this.cogState.buttonClick = buttonClick;
|
|
158
|
+
this.emit(this.eventsMap.buttonClick[buttonClick]);
|
|
159
|
+
};
|
|
160
|
+
PublishedDataAnalyser.prototype.setObjectSense = function (objectSense) {
|
|
161
|
+
this.cogState.objectSense = objectSense;
|
|
162
|
+
this.emit(this.eventsMap.objectSense[objectSense]);
|
|
163
|
+
};
|
|
164
|
+
PublishedDataAnalyser.prototype.setLightSense = function (lightSense) {
|
|
165
|
+
this.cogState.lightSense = lightSense;
|
|
166
|
+
this.emit(this.eventsMap.lightSense[lightSense]);
|
|
167
|
+
};
|
|
168
|
+
return PublishedDataAnalyser;
|
|
169
|
+
}(EventEmitter));
|
|
170
|
+
var TiltDetection = /** @class */ (function () {
|
|
171
|
+
function TiltDetection() {
|
|
172
|
+
}
|
|
173
|
+
TiltDetection.prototype.distance = function (a, b) { return Math.sqrt((Math.pow(a, 2) + Math.pow(b, 2))); };
|
|
174
|
+
TiltDetection.rotateAccelData = function (x, y, z, degrees) {
|
|
175
|
+
// Convert degrees to radians
|
|
176
|
+
var radians = degrees * (Math.PI / 180);
|
|
177
|
+
// First rotate by 180 degrees about y axis
|
|
178
|
+
var rotatedX = 0 - x;
|
|
179
|
+
var rotatedY = y;
|
|
180
|
+
var rotatedZ = 0 - z;
|
|
181
|
+
var initialRotatedX = rotatedX;
|
|
182
|
+
// Calculate cosine and sine of the rotation angle
|
|
183
|
+
var cosTheta = Math.cos(radians);
|
|
184
|
+
var sinTheta = Math.sin(radians);
|
|
185
|
+
// Rotate around the z-axis
|
|
186
|
+
rotatedX = initialRotatedX * cosTheta - rotatedY * sinTheta;
|
|
187
|
+
rotatedY = initialRotatedX * sinTheta + rotatedY * cosTheta;
|
|
188
|
+
rotatedZ = rotatedZ; // z remains unchanged as the rotation is around the z-axis
|
|
189
|
+
return { x: rotatedX, y: rotatedY, z: rotatedZ };
|
|
190
|
+
};
|
|
191
|
+
TiltDetection.prototype.detectTilt = function (ax, ay, az, isMoving, analyser, cogVersion) {
|
|
192
|
+
if (isMoving === void 0) { isMoving = false; }
|
|
193
|
+
if (isMoving)
|
|
194
|
+
return;
|
|
195
|
+
var tiltCorrectionForOlderCog = 30;
|
|
196
|
+
var tiltCorrectionForNewerCog = -90;
|
|
197
|
+
var correctionCutOffVersion = "1.2.0";
|
|
198
|
+
var tiltCorrection = tiltCorrectionForOlderCog;
|
|
199
|
+
if (isVersionGreater_errorCatching(cogVersion, correctionCutOffVersion)) {
|
|
200
|
+
tiltCorrection = tiltCorrectionForNewerCog;
|
|
201
|
+
}
|
|
202
|
+
var _a = TiltDetection.rotateAccelData(ax, ay, az * -1, tiltCorrection), x = _a.x, y = _a.y, z = _a.z;
|
|
203
|
+
var pitch = Math.atan2(x, this.distance(y, z));
|
|
204
|
+
var roll = Math.atan2(y, this.distance(x, z));
|
|
205
|
+
var yaw = Math.atan2(z, this.distance(x, y));
|
|
206
|
+
// no tilt example values: pitch: 0.00, roll: 0.00, yaw: 1.50
|
|
207
|
+
// tilt left example values: pitch: 0.00, roll: -1.00, yaw: 0.50
|
|
208
|
+
// tilt right example values: pitch: 0.00, roll: 1.00, yaw: 0.50
|
|
209
|
+
// tilt forward example values: pitch: -1.00, roll: 0.00, yaw: 0.50
|
|
210
|
+
// tilt backward example values: pitch: 1.00, roll: 0.00, yaw: 0.50
|
|
211
|
+
var forwardBackwardThreshold = 20 * (Math.PI / 180); // threshold for forward and backward tilt
|
|
212
|
+
var leftRightThreshold = 20 * (Math.PI / 180); // threshold for left and right tilt
|
|
213
|
+
var upDownThreshold = 0.5; // threshold for up and down tilt
|
|
214
|
+
var tiltDirection = "none";
|
|
215
|
+
if (pitch < -forwardBackwardThreshold) { // && Math.abs(yaw) < upDownThreshold) {
|
|
216
|
+
tiltDirection = "forward";
|
|
217
|
+
}
|
|
218
|
+
if (pitch > forwardBackwardThreshold) { // && Math.abs(yaw) < upDownThreshold) {
|
|
219
|
+
tiltDirection = "backward";
|
|
220
|
+
}
|
|
221
|
+
if (roll < -leftRightThreshold) { // && Math.abs(yaw) < upDownThreshold) {
|
|
222
|
+
tiltDirection = "left";
|
|
223
|
+
}
|
|
224
|
+
if (roll > leftRightThreshold) { // && Math.abs(yaw) < upDownThreshold) {
|
|
225
|
+
tiltDirection = "right";
|
|
226
|
+
}
|
|
227
|
+
analyser.setTilt(tiltDirection);
|
|
228
|
+
};
|
|
229
|
+
return TiltDetection;
|
|
230
|
+
}());
|
|
231
|
+
var RotationDetection = /** @class */ (function () {
|
|
232
|
+
function RotationDetection() {
|
|
233
|
+
this.dataBuffer = [];
|
|
234
|
+
this.bufferSize = 20; // buffer size for rotation detection
|
|
235
|
+
this.DELAY_FOR_ROTATION = 500; // delay between rotation detection
|
|
236
|
+
this.ROTATION_THRESHOLD = 8; // threshold for rotation detection
|
|
237
|
+
this.rotationDetected = false;
|
|
238
|
+
this.lastRotationDetectionTime = 0;
|
|
239
|
+
this.rotationTimer = null;
|
|
240
|
+
}
|
|
241
|
+
RotationDetection.prototype.addToBuffer = function (data) {
|
|
242
|
+
this.dataBuffer.push(data);
|
|
243
|
+
if (this.dataBuffer.length > this.bufferSize) {
|
|
244
|
+
this.dataBuffer.shift();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
RotationDetection.prototype.detectRotation = function (gz, isMoving, analyser) {
|
|
248
|
+
if (isMoving === void 0) { isMoving = false; }
|
|
249
|
+
var currentTime = Date.now();
|
|
250
|
+
this.addToBuffer(gz);
|
|
251
|
+
if (this.dataBuffer.length < this.bufferSize) {
|
|
252
|
+
return; // Wait until buffer is full
|
|
253
|
+
}
|
|
254
|
+
if (currentTime - this.lastRotationDetectionTime < this.DELAY_FOR_ROTATION || isMoving) {
|
|
255
|
+
// Ensure there is a minimum time between detections
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
var metric = this.calculateMetric();
|
|
259
|
+
// Check if the magnitude of the rate of change is above the threshold
|
|
260
|
+
if (metric > this.ROTATION_THRESHOLD || metric < -this.ROTATION_THRESHOLD) {
|
|
261
|
+
this.lastRotationDetectionTime = currentTime;
|
|
262
|
+
this.dataBuffer = [];
|
|
263
|
+
console.log("Rotation detected. Rotation: ", metric > this.ROTATION_THRESHOLD ? "clockwise" : "counter-clockwise");
|
|
264
|
+
if (metric > this.ROTATION_THRESHOLD) {
|
|
265
|
+
// console.log("Clockwise rotation detected:", metric);
|
|
266
|
+
analyser.setRotation("clockwise");
|
|
267
|
+
}
|
|
268
|
+
else if (metric < -this.ROTATION_THRESHOLD) {
|
|
269
|
+
// console.log("Counter-clockwise rotation detected:", metric);
|
|
270
|
+
analyser.setRotation("counterClockwise");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
analyser.setRotation("none");
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
RotationDetection.prototype.calculateMetric = function () {
|
|
278
|
+
//let gzArray = [];
|
|
279
|
+
var sum = 0;
|
|
280
|
+
for (var i = 0; i < this.dataBuffer.length; i++) {
|
|
281
|
+
//sum += this.dataBuffer[i].LSM6DS.gz;
|
|
282
|
+
sum += this.dataBuffer[i];
|
|
283
|
+
//gzArray.push(this.dataBuffer[i]);
|
|
284
|
+
}
|
|
285
|
+
//console.log("gz buffer (" + gzArray.length + " elements avg. " + (sum / this.dataBuffer.length) + "): " + gzArray);
|
|
286
|
+
//console.log(this.dataBuffer);
|
|
287
|
+
return sum / this.dataBuffer.length;
|
|
288
|
+
};
|
|
289
|
+
return RotationDetection;
|
|
290
|
+
}());
|
|
291
|
+
var ShakeDetector = /** @class */ (function () {
|
|
292
|
+
function ShakeDetector() {
|
|
293
|
+
this.thresholdAccelerationMove = 0.3;
|
|
294
|
+
this.thresholdAcceleration = 1; // how much acceleration is needed to consider shaking
|
|
295
|
+
this.thresholdShakeNumber = 1; // how many shakes are needed
|
|
296
|
+
this.interval = 400; // how much time between shakes
|
|
297
|
+
this.maxShakeDuration = 1500; // Maximum duration between first and last shakes in a sequence
|
|
298
|
+
this.coolOffPeriod = 1500; // how much time to wait before detecting another shake
|
|
299
|
+
this.lastTime = 0;
|
|
300
|
+
this.lastTimeShakeDetected = 0;
|
|
301
|
+
this.sensorBundles = [];
|
|
302
|
+
this.gravityVector = [0, 0, 0];
|
|
303
|
+
this.lastVector = [0, 0, 0];
|
|
304
|
+
this.shakeInProgress = false;
|
|
305
|
+
this.moveInProgress = false;
|
|
306
|
+
}
|
|
307
|
+
ShakeDetector.prototype.detectShake = function (xAcc, yAcc, zAcc, timestamp, analyser) {
|
|
308
|
+
this.thresholdAcceleration = this.thresholdAcceleration;
|
|
309
|
+
this.thresholdAccelerationMove = this.thresholdAccelerationMove;
|
|
310
|
+
this.thresholdShakeNumber = this.thresholdShakeNumber;
|
|
311
|
+
this.interval = this.interval;
|
|
312
|
+
this.maxShakeDuration = this.maxShakeDuration;
|
|
313
|
+
this.coolOffPeriod = this.coolOffPeriod;
|
|
314
|
+
var magAcc = Math.sqrt(xAcc * xAcc + yAcc * yAcc + zAcc * zAcc);
|
|
315
|
+
if (magAcc > 0.9 && magAcc < 1.1) {
|
|
316
|
+
// device is stationary-ish, log direction of acc values to get a rough reading on where down is
|
|
317
|
+
this.gravityVector = [xAcc, yAcc, zAcc];
|
|
318
|
+
if (this.moveInProgress) {
|
|
319
|
+
// console.log("move detected");
|
|
320
|
+
// analyser.setMovementType("move");
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// console.log("no move detected");
|
|
324
|
+
analyser.setMovementType("none");
|
|
325
|
+
}
|
|
326
|
+
this.moveInProgress = false;
|
|
327
|
+
this.shakeInProgress = false;
|
|
328
|
+
this.sensorBundles = [];
|
|
329
|
+
return this.shakeInProgress;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
//console.log("move in progrss. prev state: ", this.moveInProgress);
|
|
333
|
+
// potentially threshold this with thresholeAccelerationMove if we want it to be less trigger happy
|
|
334
|
+
this.moveInProgress = true;
|
|
335
|
+
// this assumes that the orientation of the device doesn't change during the movement, so it's not ideal
|
|
336
|
+
var x = xAcc - this.gravityVector[0];
|
|
337
|
+
var y = yAcc - this.gravityVector[1];
|
|
338
|
+
var z = zAcc - this.gravityVector[2];
|
|
339
|
+
var mag = Math.sqrt(x * x + y * y + z * z);
|
|
340
|
+
if (mag > this.thresholdAcceleration || this.shakeInProgress) {
|
|
341
|
+
this.shakeInProgress = true;
|
|
342
|
+
var diffThresh = this.thresholdAcceleration;
|
|
343
|
+
if (mag > this.thresholdAcceleration) {
|
|
344
|
+
// console.log('large magnitude movement ', x, y, z, this.gravityVector);
|
|
345
|
+
// check if the acc vector is significantly changed from the previous large value
|
|
346
|
+
if (!this.sensorBundles.length || Math.sqrt(Math.pow(this.lastVector[0] - x, 2) + Math.pow(this.lastVector[1] - y, 2) + Math.pow(this.lastVector[2] - z, 2)) > this.thresholdAcceleration) {
|
|
347
|
+
this.sensorBundles.push({ x: x, y: y, z: z, timestamp: timestamp });
|
|
348
|
+
//console.log(this.sensorBundles);
|
|
349
|
+
this.lastVector = [x, y, z];
|
|
350
|
+
// todo - call performCheck() to do a more detailed analysis of the readings? Might need some tweaks
|
|
351
|
+
if (this.sensorBundles.length > this.thresholdShakeNumber) {
|
|
352
|
+
// console.log("Shake detected!");
|
|
353
|
+
this.sensorBundles = [];
|
|
354
|
+
this.shakeInProgress = true;
|
|
355
|
+
analyser.setMovementType("shake");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// this.noMoveCallback();
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
if (!this.sensorBundles.length || (timestamp - this.sensorBundles[this.sensorBundles.length - 1].timestamp) > this.interval) {
|
|
362
|
+
this.shakeInProgress = false;
|
|
363
|
+
this.sensorBundles = [];
|
|
364
|
+
// console.log("resetting shake detector. Move detected");
|
|
365
|
+
// fire move detector
|
|
366
|
+
analyser.setMovementType("none");
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return this.shakeInProgress;
|
|
371
|
+
/*
|
|
372
|
+
if (this.sensorBundles.length === 0 || timestamp - this.lastTime > this.interval) {
|
|
373
|
+
// Check if we should reset based on time since last recorded shake
|
|
374
|
+
if (this.sensorBundles.length > 0 && (timestamp - this.sensorBundles[0].timestamp) > this.maxShakeDuration) {
|
|
375
|
+
this.sensorBundles = []; // Reset the sensor data if the shakes are too far apart
|
|
376
|
+
}
|
|
377
|
+
this.sensorBundles.push({ xAcc, yAcc, zAcc, timestamp });
|
|
378
|
+
this.lastTime = timestamp;
|
|
379
|
+
this.performCheck();
|
|
380
|
+
}
|
|
381
|
+
*/
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
ShakeDetector.prototype.performCheck = function (analyser) {
|
|
385
|
+
var _this = this;
|
|
386
|
+
var matrix = [
|
|
387
|
+
[0, 0],
|
|
388
|
+
[0, 0],
|
|
389
|
+
[0, 0] // Z axis positive and negative
|
|
390
|
+
];
|
|
391
|
+
for (var _i = 0, _a = this.sensorBundles; _i < _a.length; _i++) {
|
|
392
|
+
var bundle = _a[_i];
|
|
393
|
+
this.updateAxis(0, bundle.x, matrix);
|
|
394
|
+
this.updateAxis(1, bundle.y, matrix);
|
|
395
|
+
this.updateAxis(2, bundle.z, matrix, -1);
|
|
396
|
+
}
|
|
397
|
+
// check if any of the negatives and the positives are greater than the threshold
|
|
398
|
+
var negativesTotal = matrix.reduce(function (acc, axis) { return acc + axis[1]; }, 0);
|
|
399
|
+
var positivesTotal = matrix.reduce(function (acc, axis) { return acc + axis[0]; }, 0);
|
|
400
|
+
if (matrix.some(function (axis) { return axis[0] >= _this.thresholdShakeNumber && axis[1] >= _this.thresholdShakeNumber; })) {
|
|
401
|
+
// if (positivesTotal >= this.thresholdShakeNumber && negativesTotal >= this.thresholdShakeNumber) {
|
|
402
|
+
if (Date.now() - this.lastTimeShakeDetected < this.coolOffPeriod) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this.lastTimeShakeDetected = Date.now();
|
|
406
|
+
// console.log("Shake detected!", JSON.stringify(matrix));
|
|
407
|
+
analyser.setMovementType("shake");
|
|
408
|
+
this.sensorBundles = [];
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
ShakeDetector.prototype.updateAxis = function (index, acceleration, matrix, adjustment) {
|
|
412
|
+
if (adjustment === void 0) { adjustment = 0; }
|
|
413
|
+
var accelerationAdjusted = acceleration + adjustment;
|
|
414
|
+
if (accelerationAdjusted > this.thresholdAcceleration) {
|
|
415
|
+
matrix[index][0]++;
|
|
416
|
+
// console.log(JSON.stringify(matrix));
|
|
417
|
+
}
|
|
418
|
+
else if (accelerationAdjusted < -this.thresholdAcceleration) {
|
|
419
|
+
matrix[index][1]++;
|
|
420
|
+
// console.log(JSON.stringify(matrix));
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
return ShakeDetector;
|
|
424
|
+
}());
|
|
425
|
+
var ButtonClickDetection = /** @class */ (function () {
|
|
426
|
+
function ButtonClickDetection() {
|
|
427
|
+
/*
|
|
428
|
+
When the threshold is exceeded, the button is clicked, but we want to send the event when the button is released
|
|
429
|
+
so that the event is triggered only once.
|
|
430
|
+
*/
|
|
431
|
+
this.clickThreshold = 1600;
|
|
432
|
+
this.releaseThreshold = 1590;
|
|
433
|
+
this.lastTime = 0;
|
|
434
|
+
this.buttonClicked = false;
|
|
435
|
+
}
|
|
436
|
+
ButtonClickDetection.prototype.detectButtonClick = function (buttonValue, analyser, cogVersion) {
|
|
437
|
+
var currentTime = Date.now();
|
|
438
|
+
if (buttonValue > this.clickThreshold && !this.buttonClicked) {
|
|
439
|
+
// console.log("Button clicked", buttonValue);
|
|
440
|
+
this.buttonClicked = true;
|
|
441
|
+
this.lastTime = currentTime;
|
|
442
|
+
Logger.info(SHOW_LOGS, TAG, "Button clicked");
|
|
443
|
+
analyser.setButtonClick("click");
|
|
444
|
+
}
|
|
445
|
+
else if (buttonValue < this.releaseThreshold && this.buttonClicked) {
|
|
446
|
+
// console.log("Button released", buttonValue);
|
|
447
|
+
this.buttonClicked = false;
|
|
448
|
+
Logger.info(SHOW_LOGS, TAG, "Button released");
|
|
449
|
+
analyser.setButtonClick("release");
|
|
450
|
+
}
|
|
451
|
+
// } else {
|
|
452
|
+
// this.buttonClicked = false;
|
|
453
|
+
// this.buttonReleaseCallback();
|
|
454
|
+
// }
|
|
455
|
+
};
|
|
456
|
+
return ButtonClickDetection;
|
|
457
|
+
}());
|
|
458
|
+
export { ButtonClickDetection };
|
|
459
|
+
var ObjectSenseDetection = /** @class */ (function () {
|
|
460
|
+
function ObjectSenseDetection() {
|
|
461
|
+
this.objectSensed0Threshold = 2500; // left of the arrow
|
|
462
|
+
this.objectSensed1Threshold = 2500; // right of the arrow
|
|
463
|
+
this.objectSensed2Threshold = 1500; // button
|
|
464
|
+
}
|
|
465
|
+
ObjectSenseDetection.prototype.detectObjectSense = function (objectSenseValue, analyser) {
|
|
466
|
+
if (objectSenseValue[0] > this.objectSensed0Threshold) {
|
|
467
|
+
analyser.setObjectSense("left");
|
|
468
|
+
}
|
|
469
|
+
else if (objectSenseValue[1] > this.objectSensed1Threshold) {
|
|
470
|
+
analyser.setObjectSense("right");
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
analyser.setObjectSense("none");
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
return ObjectSenseDetection;
|
|
477
|
+
}());
|
|
478
|
+
var LightSenseDetection = /** @class */ (function () {
|
|
479
|
+
function LightSenseDetection() {
|
|
480
|
+
this.lowLightThreshold = 5;
|
|
481
|
+
this.midLightThreshold = 250;
|
|
482
|
+
this.highLightThreshold = 450;
|
|
483
|
+
}
|
|
484
|
+
LightSenseDetection.prototype.detectLightSense = function (lightSenseValue, analyser) {
|
|
485
|
+
if (lightSenseValue > this.highLightThreshold) {
|
|
486
|
+
analyser.setLightSense("high");
|
|
487
|
+
}
|
|
488
|
+
else if (lightSenseValue > this.midLightThreshold) {
|
|
489
|
+
analyser.setLightSense("mid");
|
|
490
|
+
}
|
|
491
|
+
else if (lightSenseValue > this.lowLightThreshold) {
|
|
492
|
+
analyser.setLightSense("low");
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
analyser.setLightSense("none");
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
return LightSenseDetection;
|
|
499
|
+
}());
|
|
500
|
+
export var setButtonThresholdsUtil = function (connectedCog) { return __awaiter(void 0, void 0, void 0, function () {
|
|
501
|
+
var lightResponse, irMin, irMax, buttonClickDetection, error_1;
|
|
502
|
+
return __generator(this, function (_a) {
|
|
503
|
+
switch (_a.label) {
|
|
504
|
+
case 0:
|
|
505
|
+
Logger.info(SHOW_LOGS, TAG, "Setting button thresholds");
|
|
506
|
+
_a.label = 1;
|
|
507
|
+
case 1:
|
|
508
|
+
_a.trys.push([1, 3, , 4]);
|
|
509
|
+
return [4 /*yield*/, connectedCog.sendRestMessage('light')];
|
|
510
|
+
case 2:
|
|
511
|
+
lightResponse = _a.sent();
|
|
512
|
+
if (lightResponse && lightResponse.rslt === "ok" && lightResponse.light.irMax4) {
|
|
513
|
+
irMin = lightResponse.light.irMin4;
|
|
514
|
+
irMax = lightResponse.light.irMax4;
|
|
515
|
+
Logger.info(SHOW_LOGS, TAG, "Got button thresholds: irMin: ".concat(irMin, ", irMax: ").concat(irMax));
|
|
516
|
+
buttonClickDetection = connectedCog.publishedDataAnalyser.buttonClickDetection;
|
|
517
|
+
buttonClickDetection.clickThreshold = irMin + (irMax - irMin) / 2;
|
|
518
|
+
buttonClickDetection.releaseThreshold = buttonClickDetection.clickThreshold - 10;
|
|
519
|
+
Logger.info(SHOW_LOGS, TAG, "Set button thresholds: clickThreshold: ".concat(buttonClickDetection.clickThreshold, ", releaseThreshold: ").concat(buttonClickDetection.releaseThreshold));
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
Logger.warn(SHOW_LOGS, TAG, "Couldn't get button thresholds, probably older fw version");
|
|
523
|
+
}
|
|
524
|
+
return [3 /*break*/, 4];
|
|
525
|
+
case 3:
|
|
526
|
+
error_1 = _a.sent();
|
|
527
|
+
Logger.warn(SHOW_LOGS, TAG, "Couldn't get button thresholds, probably older fw version");
|
|
528
|
+
return [3 /*break*/, 4];
|
|
529
|
+
case 4: return [2 /*return*/];
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
}); };
|
|
533
|
+
export default PublishedDataAnalyser;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import RICInterface from "../RAFTInterface";
|
|
2
|
+
import { RaftTypeE } from "../../../types/raft";
|
|
3
|
+
import RAFT from "../RAFT";
|
|
4
|
+
import { RaftConnEvent, RaftPublishEvent, RaftSystemInfo, RaftUpdateEvent } from "@robotical/raftjs";
|
|
5
|
+
import { RaftInfoEvents } from "../../../types/events/raft-info";
|
|
6
|
+
import { RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs";
|
|
7
|
+
export declare class Marty extends RAFT implements RICInterface {
|
|
8
|
+
id: string;
|
|
9
|
+
type: RaftTypeE;
|
|
10
|
+
raftStateInfo: RICStateInfo | null;
|
|
11
|
+
systemInfo: RaftSystemInfo | null;
|
|
12
|
+
_ledLcdColours: RICLedLcdColours;
|
|
13
|
+
private rssiValues;
|
|
14
|
+
private MAX_RSSI_VALUES_N;
|
|
15
|
+
constructor(id: string);
|
|
16
|
+
get ledLcdColours(): RICLedLcdColours;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the RSSI of the RAFT
|
|
19
|
+
*/
|
|
20
|
+
getRSSI(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the battery strength of the RAFT
|
|
23
|
+
*/
|
|
24
|
+
getBatteryStrength(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Highlights Marty by flashing the LED and playing a tune
|
|
27
|
+
*/
|
|
28
|
+
highlight(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* This methods handles RAFT events coming from the RICConnector of the wrapper
|
|
31
|
+
*/
|
|
32
|
+
handleRaftEvent(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void;
|
|
33
|
+
/**
|
|
34
|
+
* Pub Event Handler
|
|
35
|
+
*/
|
|
36
|
+
pubEventHandler(eventEnum: RaftPublishEvent, eventName: string, data: any): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Raft Info Event Handler
|
|
39
|
+
*/
|
|
40
|
+
raftInfoEventHandler(eventEnum: RaftInfoEvents, eventName: string, data: any): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export default Marty;
|