@robotical/webapp-types 3.13.9 → 3.14.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.
@@ -10,6 +10,7 @@ interface CogState {
10
10
  buttonClick: "none" | "click" | "release";
11
11
  objectSense: "none" | "left" | "right" | "both";
12
12
  lightSense: "none" | "high" | "mid" | "low";
13
+ steering: "none" | "left" | "right";
13
14
  }
14
15
  declare class PublishedDataAnalyser extends EventEmitter {
15
16
  private cog;
@@ -21,6 +22,7 @@ declare class PublishedDataAnalyser extends EventEmitter {
21
22
  tiltDetection: TiltDetection;
22
23
  objectSenseDetection: ObjectSenseDetection;
23
24
  lightSenseDetection: LightSenseDetection;
25
+ steeringDetection: SteeringDetection;
24
26
  eventsMap: {
25
27
  tilt: {
26
28
  [key in CogState["tilt"]]: string;
@@ -40,6 +42,9 @@ declare class PublishedDataAnalyser extends EventEmitter {
40
42
  lightSense: {
41
43
  [key in CogState["lightSense"]]: string;
42
44
  };
45
+ steering: {
46
+ [key in CogState["steering"]]: string;
47
+ };
43
48
  };
44
49
  TiltDetection: typeof TiltDetection;
45
50
  constructor(cog: RAFT);
@@ -52,6 +57,28 @@ declare class PublishedDataAnalyser extends EventEmitter {
52
57
  setButtonClick(buttonClick: CogState["buttonClick"]): void;
53
58
  setObjectSense(objectSense: CogState["objectSense"]): void;
54
59
  setLightSense(lightSense: CogState["lightSense"]): void;
60
+ setSteering(steering: CogState["steering"]): void;
61
+ }
62
+ declare class SteeringDetection {
63
+ private DELAY_FOR_NEXT_STEERING;
64
+ private STEER_LEFT_THRESHOLD;
65
+ private STEER_RIGHT_THRESHOLD;
66
+ private lastSteeringDetectionTime;
67
+ private steeringWheelAlpha;
68
+ private steeringWheelThreshold;
69
+ isHeldAsSteeringWheelProp: boolean;
70
+ gravity: {
71
+ x: number;
72
+ y: number;
73
+ z: number;
74
+ };
75
+ constructor();
76
+ /**
77
+ * Returns true if the device-plane is vertical (like a steering wheel).
78
+ */
79
+ isHeldAsSteeringWheel(acc: SimplifiedCogStateInfo["accelerometer"]): boolean;
80
+ detectSteering(acc: SimplifiedCogStateInfo["accelerometer"], analyser: PublishedDataAnalyser): void;
81
+ calculateMetric(acc: SimplifiedCogStateInfo["accelerometer"]): number;
55
82
  }
56
83
  declare class TiltDetection {
57
84
  distance(a: number, b: number): number;
@@ -67,9 +94,7 @@ declare class RotationDetection {
67
94
  private bufferSize;
68
95
  private DELAY_FOR_ROTATION;
69
96
  private ROTATION_THRESHOLD;
70
- private rotationDetected;
71
97
  private lastRotationDetectionTime;
72
- private rotationTimer;
73
98
  constructor();
74
99
  addToBuffer(data: number): void;
75
100
  detectRotation(gz: number, isMoving: boolean | undefined, analyser: PublishedDataAnalyser): void;
@@ -66,6 +66,7 @@ var PublishedDataAnalyser = /** @class */ (function (_super) {
66
66
  _this.tiltDetection = new TiltDetection();
67
67
  _this.objectSenseDetection = new ObjectSenseDetection();
68
68
  _this.lightSenseDetection = new LightSenseDetection();
69
+ _this.steeringDetection = new SteeringDetection();
69
70
  _this.eventsMap = {
70
71
  tilt: {
71
72
  forward: "tiltForward",
@@ -101,6 +102,11 @@ var PublishedDataAnalyser = /** @class */ (function (_super) {
101
102
  low: "lowLightSense",
102
103
  none: "noLightSense"
103
104
  },
105
+ steering: {
106
+ left: "steeringLeft",
107
+ right: "steeringRight",
108
+ none: "noSteering"
109
+ }
104
110
  };
105
111
  _this.TiltDetection = TiltDetection;
106
112
  _this.cog = cog;
@@ -111,6 +117,7 @@ var PublishedDataAnalyser = /** @class */ (function (_super) {
111
117
  buttonClick: "none",
112
118
  objectSense: "none",
113
119
  lightSense: "none",
120
+ steering: "none"
114
121
  };
115
122
  _this.pubSub = null;
116
123
  _this.subscribeToPublishedData();
@@ -141,6 +148,7 @@ var PublishedDataAnalyser = /** @class */ (function (_super) {
141
148
  lightData && this.buttonClickDetection.detectButtonClick(lightData.ir2, this, this.cog.getRaftVersion());
142
149
  lightData && this.objectSenseDetection.detectObjectSense([lightData.ir0, lightData.ir1], this);
143
150
  lightData && this.lightSenseDetection.detectLightSense(lightData.amb0, this);
151
+ accelData && this.steeringDetection.detectSteering(accelData, this);
144
152
  };
145
153
  PublishedDataAnalyser.prototype.setTilt = function (tilt) {
146
154
  this.cogState.tilt = tilt;
@@ -166,8 +174,75 @@ var PublishedDataAnalyser = /** @class */ (function (_super) {
166
174
  this.cogState.lightSense = lightSense;
167
175
  this.emit(this.eventsMap.lightSense[lightSense]);
168
176
  };
177
+ PublishedDataAnalyser.prototype.setSteering = function (steering) {
178
+ this.cogState.steering = steering;
179
+ this.emit(this.eventsMap.steering[steering]);
180
+ };
169
181
  return PublishedDataAnalyser;
170
182
  }(EventEmitter));
183
+ var SteeringDetection = /** @class */ (function () {
184
+ function SteeringDetection() {
185
+ this.DELAY_FOR_NEXT_STEERING = 800; // delay between steering detection
186
+ this.STEER_LEFT_THRESHOLD = -0.5; // threshold for steering left
187
+ this.STEER_RIGHT_THRESHOLD = 0.5; // threshold for steering right
188
+ this.lastSteeringDetectionTime = 0;
189
+ this.steeringWheelAlpha = 0.8; // smoothing factor for steering wheel detection
190
+ this.steeringWheelThreshold = 0.6; // threshold for steering wheel detection
191
+ this.isHeldAsSteeringWheelProp = false;
192
+ this.gravity = { x: 0, y: 0, z: 0 };
193
+ }
194
+ /**
195
+ * Returns true if the device-plane is vertical (like a steering wheel).
196
+ */
197
+ SteeringDetection.prototype.isHeldAsSteeringWheel = function (acc) {
198
+ this.gravity.x = this.steeringWheelAlpha * this.gravity.x + (1 - this.steeringWheelAlpha) * acc.ax;
199
+ this.gravity.y = this.steeringWheelAlpha * this.gravity.y + (1 - this.steeringWheelAlpha) * acc.ay;
200
+ this.gravity.z = this.steeringWheelAlpha * this.gravity.z + (1 - this.steeringWheelAlpha) * acc.az;
201
+ var _a = this.gravity, gx = _a.x, gy = _a.y, gz = _a.z;
202
+ var gNorm = Math.hypot(gx, gy, gz);
203
+ if (gNorm === 0)
204
+ return false; // not yet initialized
205
+ // ratio of gravity on z axis
206
+ var zRatio = Math.abs(gz) / gNorm;
207
+ // if zRatio is small, the z-axis is nearly horizontal → plane is vertical
208
+ this.isHeldAsSteeringWheelProp = zRatio < this.steeringWheelThreshold;
209
+ return this.isHeldAsSteeringWheelProp;
210
+ };
211
+ SteeringDetection.prototype.detectSteering = function (acc, analyser) {
212
+ var currentTime = Date.now();
213
+ var heldAsSteeringWheel = this.isHeldAsSteeringWheel(acc);
214
+ if (!heldAsSteeringWheel) {
215
+ analyser.setSteering("none");
216
+ // this.dataBuffer = [];
217
+ return; // Not held as a steering wheel, no need to detect steering
218
+ }
219
+ if (currentTime - this.lastSteeringDetectionTime < this.DELAY_FOR_NEXT_STEERING) {
220
+ return; // Delay not elapsed, skip this detection
221
+ }
222
+ var metric = this.calculateMetric(acc);
223
+ // Check if the magnitude of the rate of change is above the threshold
224
+ if (metric > this.STEER_RIGHT_THRESHOLD || metric < this.STEER_LEFT_THRESHOLD) {
225
+ this.lastSteeringDetectionTime = currentTime;
226
+ console.log("Steering detected. Steering: ", metric > this.STEER_RIGHT_THRESHOLD ? "right" : "left");
227
+ if (metric > this.STEER_RIGHT_THRESHOLD) {
228
+ // console.log("Clockwise rotation detected:", metric);
229
+ analyser.setSteering("right");
230
+ }
231
+ else if (metric < this.STEER_LEFT_THRESHOLD) {
232
+ // console.log("Counter-clockwise rotation detected:", metric);
233
+ analyser.setSteering("left");
234
+ }
235
+ }
236
+ else {
237
+ analyser.setSteering("none");
238
+ }
239
+ };
240
+ SteeringDetection.prototype.calculateMetric = function (acc) {
241
+ var raw = Math.atan2(acc.ay, -acc.ax); // radians, zero=right, CCW+
242
+ return raw - Math.PI / 2;
243
+ };
244
+ return SteeringDetection;
245
+ }());
171
246
  var TiltDetection = /** @class */ (function () {
172
247
  function TiltDetection() {
173
248
  }
@@ -235,9 +310,7 @@ var RotationDetection = /** @class */ (function () {
235
310
  this.bufferSize = 20; // buffer size for rotation detection
236
311
  this.DELAY_FOR_ROTATION = 500; // delay between rotation detection
237
312
  this.ROTATION_THRESHOLD = 8; // threshold for rotation detection
238
- this.rotationDetected = false;
239
313
  this.lastRotationDetectionTime = 0;
240
- this.rotationTimer = null;
241
314
  }
242
315
  RotationDetection.prototype.addToBuffer = function (data) {
243
316
  this.dataBuffer.push(data);
@@ -261,7 +334,7 @@ var RotationDetection = /** @class */ (function () {
261
334
  if (metric > this.ROTATION_THRESHOLD || metric < -this.ROTATION_THRESHOLD) {
262
335
  this.lastRotationDetectionTime = currentTime;
263
336
  this.dataBuffer = [];
264
- console.log("Rotation detected. Rotation: ", metric > this.ROTATION_THRESHOLD ? "clockwise" : "counter-clockwise");
337
+ // console.log("Rotation detected. Rotation: ", metric > this.ROTATION_THRESHOLD ? "clockwise" : "counter-clockwise");
265
338
  if (metric > this.ROTATION_THRESHOLD) {
266
339
  // console.log("Clockwise rotation detected:", metric);
267
340
  analyser.setRotation("clockwise");
@@ -161,7 +161,9 @@ var resources = {
161
161
  "jumping_game_title": "Jumping Game",
162
162
  "maze_title": "Maze",
163
163
  "robofly_game_title": "RoboFly Game",
164
- "skiing_game_title": "Skiing Game"
164
+ "skiing_game_title": "Skiing Game",
165
+ "space_shooter_title": "Space Shooter",
166
+ "cog_shooter_title": "Cog Shooter",
165
167
  },
166
168
  "hello": "Hello, World!",
167
169
  "help": {
@@ -441,7 +443,9 @@ var resources = {
441
443
  "jumping_game_title": "Παιχνίδι Άλματος",
442
444
  "maze_title": "Λαβύρινθος",
443
445
  "robofly_game_title": "Παιχνίδι RoboFly",
444
- "skiing_game_title": "Παιχνίδι Σκι"
446
+ "skiing_game_title": "Παιχνίδι Σκι",
447
+ "space_shooter_title": "Παιχνίδι Space Shooter",
448
+ "cog_shooter_title": "Παιχνίδι Cog Shooter",
445
449
  },
446
450
  "hello": "Γειά σου, Κόσμε!",
447
451
  "help": {
@@ -721,7 +725,9 @@ var resources = {
721
725
  "jumping_game_title": "Springen Spel",
722
726
  "maze_title": "Doolhof",
723
727
  "robofly_game_title": "RoboFly-spel",
724
- "skiing_game_title": "Skiën Spel"
728
+ "skiing_game_title": "Skiën Spel",
729
+ "space_shooter_title": "Ruimte Shooter Spel",
730
+ "cog_shooter_title": "Cog Shooter Spel"
725
731
  },
726
732
  "hello": "Hallo mensen!",
727
733
  "help": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "3.13.9",
3
+ "version": "3.14.0",
4
4
  "description": "Type definitions for the Application Manager",
5
5
  "main": "dist/application-manager.d.ts",
6
6
  "types": "dist/application-manager.d.ts",