@robotical/webapp-types 1.0.6 → 1.0.7
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/dist-types/src/application/RAFTs/Cog/Cog.js +19 -4
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.d.ts +18 -6
- package/dist-types/src/application/RAFTs/Cog/PublishedDataAnalyser.js +31 -24
- package/dist-types/src/application/RAFTs/Cog/PublishedDataGetter.d.ts +23 -0
- package/dist-types/src/application/RAFTs/Cog/PublishedDataGetter.js +65 -0
- package/package.json +1 -1
|
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
};
|
|
52
52
|
import RAFT from "../RAFT";
|
|
53
53
|
import { RaftTypeE } from "../../../types/raft";
|
|
54
|
-
import { RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
|
|
54
|
+
import { deviceAttrGetLatestFormatted, RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
|
|
55
55
|
import { RaftInfoEvents } from "../../../types/events/raft-info";
|
|
56
56
|
import PublishedDataAnalyser from "./PublishedDataAnalyser";
|
|
57
57
|
var Cog = /** @class */ (function (_super) {
|
|
@@ -91,8 +91,23 @@ var Cog = /** @class */ (function (_super) {
|
|
|
91
91
|
* Gets the battery strength of the RAFT
|
|
92
92
|
*/
|
|
93
93
|
Cog.prototype.getBatteryStrength = function () {
|
|
94
|
-
var _a;
|
|
95
|
-
|
|
94
|
+
var _a, _b, _c, _d;
|
|
95
|
+
/* check if usb is connected */
|
|
96
|
+
var usbAttr = (_b = (_a = this.raftStateInfo) === null || _a === void 0 ? void 0 : _a.deviceManager.getDeviceState('RoboCogPowerV1_00')) === null || _b === void 0 ? void 0 : _b.deviceAttributes['USB'];
|
|
97
|
+
if (!usbAttr)
|
|
98
|
+
return 0.1;
|
|
99
|
+
var usb = deviceAttrGetLatestFormatted(usbAttr);
|
|
100
|
+
if (usb === 'yes')
|
|
101
|
+
return 0; // 0 indicates USB is connected
|
|
102
|
+
/* if usb is not connected, check battery voltage */
|
|
103
|
+
var battVAttr = (_d = (_c = this.raftStateInfo) === null || _c === void 0 ? void 0 : _c.deviceManager.getDeviceState('RoboCogPowerV1_00')) === null || _d === void 0 ? void 0 : _d.deviceAttributes['battV'];
|
|
104
|
+
if (!battVAttr)
|
|
105
|
+
return 0.1;
|
|
106
|
+
var battV = deviceAttrGetLatestFormatted(battVAttr);
|
|
107
|
+
if (!isNaN(+battV)) {
|
|
108
|
+
return Math.round(+battV * 100);
|
|
109
|
+
}
|
|
110
|
+
return 0;
|
|
96
111
|
};
|
|
97
112
|
/**
|
|
98
113
|
* This methods handles RAFT events coming from the RICConnector of the wrapper
|
|
@@ -121,7 +136,7 @@ var Cog = /** @class */ (function (_super) {
|
|
|
121
136
|
return __generator(this, function (_a) {
|
|
122
137
|
switch (eventEnum) {
|
|
123
138
|
case RaftConnEvent.CONN_DISCONNECTED:
|
|
124
|
-
this.publishedDataAnalyser.unsubscribeFromPublishedData();
|
|
139
|
+
// this.publishedDataAnalyser.unsubscribeFromPublishedData();
|
|
125
140
|
break;
|
|
126
141
|
default:
|
|
127
142
|
break;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CogStateInfo } from "@robotical/roboticaljs";
|
|
2
2
|
import RAFT from "../RAFT";
|
|
3
|
+
import PublishedDataGetter from "./PublishedDataGetter";
|
|
3
4
|
interface CogState {
|
|
4
5
|
tilt: boolean | "forward" | "backward" | "left" | "right";
|
|
5
6
|
movementType: boolean | "shake" | "move";
|
|
@@ -13,16 +14,27 @@ declare class PublishedDataAnalyser {
|
|
|
13
14
|
private cog;
|
|
14
15
|
cogState: CogState;
|
|
15
16
|
private pubSub;
|
|
17
|
+
TiltDetection: typeof TiltDetection;
|
|
18
|
+
PublishedDataGetter: typeof PublishedDataGetter;
|
|
16
19
|
constructor(cog: RAFT);
|
|
17
20
|
subscribeToPublishedData(): void;
|
|
18
21
|
unsubscribeFromPublishedData(): void;
|
|
19
22
|
analyse(data: CogStateInfo): void;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
detectRotation(
|
|
23
|
-
detectButtonClick(
|
|
24
|
-
detectObjectSense(
|
|
25
|
-
detectLightSense(
|
|
23
|
+
detectMovement(ax: number, ay: number, az: number): boolean;
|
|
24
|
+
detectTilt(ax: number, ay: number, az: number, isMoving: boolean): void;
|
|
25
|
+
detectRotation(gz: number, isMoving: boolean): void;
|
|
26
|
+
detectButtonClick(buttonLightValue: number): void;
|
|
27
|
+
detectObjectSense(leftIRValue: number, rightIRValue: number): void;
|
|
28
|
+
detectLightSense(ambientLightValue: number): void;
|
|
26
29
|
detectIRMessage(data: CogStateInfo): void;
|
|
27
30
|
}
|
|
31
|
+
declare class TiltDetection {
|
|
32
|
+
distance(a: number, b: number): number;
|
|
33
|
+
static rotateAccelData(x: number, y: number, z: number, degrees: number): {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
z: number;
|
|
37
|
+
};
|
|
38
|
+
detectTilt(ax: number, ay: number, az: number, isMoving: boolean | undefined, cogState: CogState, cogVersion: string): void;
|
|
39
|
+
}
|
|
28
40
|
export default PublishedDataAnalyser;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { raftPubSubscriptionHelper } from "../raft-subscription-helpers";
|
|
2
2
|
import { isVersionGreater_errorCatching } from "../../../utils/helpers/compare-version";
|
|
3
|
+
import PublishedDataGetter from "./PublishedDataGetter";
|
|
3
4
|
var PublishedDataAnalyser = /** @class */ (function () {
|
|
4
5
|
function PublishedDataAnalyser(cog) {
|
|
5
6
|
this.cog = cog;
|
|
7
|
+
this.TiltDetection = TiltDetection;
|
|
8
|
+
this.PublishedDataGetter = PublishedDataGetter;
|
|
6
9
|
this.cog = cog;
|
|
7
10
|
this.cogState = {
|
|
8
11
|
tilt: false,
|
|
@@ -28,33 +31,37 @@ var PublishedDataAnalyser = /** @class */ (function () {
|
|
|
28
31
|
(_a = this.pubSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
29
32
|
};
|
|
30
33
|
PublishedDataAnalyser.prototype.analyse = function (data) {
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
34
|
+
var accelData = PublishedDataGetter.getAccelerometerData(data.deviceManager);
|
|
35
|
+
var gyroData = PublishedDataGetter.getGyroscopeData(data.deviceManager);
|
|
36
|
+
var lightData = PublishedDataGetter.getLightData(data.deviceManager);
|
|
37
|
+
var isMoving;
|
|
38
|
+
if (accelData)
|
|
39
|
+
isMoving = this.detectMovement(accelData.ax, accelData.ay, accelData.az);
|
|
40
|
+
accelData && this.detectTilt(accelData.ax, accelData.ay, accelData.az, !!isMoving);
|
|
41
|
+
gyroData && this.detectRotation(gyroData.gz, !!isMoving);
|
|
42
|
+
lightData && this.detectButtonClick(lightData === null || lightData === void 0 ? void 0 : lightData.ir2);
|
|
43
|
+
lightData && this.detectObjectSense(lightData.ir0, lightData.ir1);
|
|
44
|
+
lightData && this.detectLightSense(lightData.amb0);
|
|
45
|
+
// this.detectIRMessage(data);
|
|
38
46
|
};
|
|
39
|
-
PublishedDataAnalyser.prototype.
|
|
40
|
-
|
|
47
|
+
PublishedDataAnalyser.prototype.detectMovement = function (ax, ay, az) {
|
|
48
|
+
return shakeDetector.detectShake(ax, ay, az, Date.now(), this.cogState);
|
|
41
49
|
};
|
|
42
|
-
PublishedDataAnalyser.prototype.
|
|
43
|
-
|
|
50
|
+
PublishedDataAnalyser.prototype.detectTilt = function (ax, ay, az, isMoving) {
|
|
51
|
+
tiltDetection.detectTilt(ax, ay, az, isMoving, this.cogState, this.cog.getRaftVersion());
|
|
44
52
|
};
|
|
45
|
-
PublishedDataAnalyser.prototype.detectRotation = function (
|
|
46
|
-
rotationDetection.detectRotation(
|
|
53
|
+
PublishedDataAnalyser.prototype.detectRotation = function (gz, isMoving) {
|
|
54
|
+
rotationDetection.detectRotation(gz, isMoving, this.cogState);
|
|
47
55
|
};
|
|
48
|
-
PublishedDataAnalyser.prototype.detectButtonClick = function (
|
|
49
|
-
buttonClickDetection.detectButtonClick(
|
|
56
|
+
PublishedDataAnalyser.prototype.detectButtonClick = function (buttonLightValue) {
|
|
57
|
+
buttonClickDetection.detectButtonClick(buttonLightValue, this.cogState, this.cog.getRaftVersion());
|
|
50
58
|
};
|
|
51
|
-
PublishedDataAnalyser.prototype.detectObjectSense = function (
|
|
52
|
-
var objectSenseValueArray =
|
|
59
|
+
PublishedDataAnalyser.prototype.detectObjectSense = function (leftIRValue, rightIRValue) {
|
|
60
|
+
var objectSenseValueArray = [leftIRValue, rightIRValue];
|
|
53
61
|
objectSenseDetection.detectObjectSense(objectSenseValueArray, this.cogState);
|
|
54
62
|
};
|
|
55
|
-
PublishedDataAnalyser.prototype.detectLightSense = function (
|
|
56
|
-
|
|
57
|
-
lightSenseDetection.detectLightSense(lightSenseValue, this.cogState);
|
|
63
|
+
PublishedDataAnalyser.prototype.detectLightSense = function (ambientLightValue) {
|
|
64
|
+
lightSenseDetection.detectLightSense(ambientLightValue, this.cogState);
|
|
58
65
|
};
|
|
59
66
|
PublishedDataAnalyser.prototype.detectIRMessage = function (data) {
|
|
60
67
|
var irMessageData = data;
|
|
@@ -83,7 +90,7 @@ var TiltDetection = /** @class */ (function () {
|
|
|
83
90
|
rotatedZ = rotatedZ; // z remains unchanged as the rotation is around the z-axis
|
|
84
91
|
return { x: rotatedX, y: rotatedY, z: rotatedZ };
|
|
85
92
|
};
|
|
86
|
-
TiltDetection.prototype.detectTilt = function (
|
|
93
|
+
TiltDetection.prototype.detectTilt = function (ax, ay, az, isMoving, cogState, cogVersion) {
|
|
87
94
|
if (isMoving === void 0) { isMoving = false; }
|
|
88
95
|
if (isMoving)
|
|
89
96
|
return;
|
|
@@ -94,7 +101,7 @@ var TiltDetection = /** @class */ (function () {
|
|
|
94
101
|
if (isVersionGreater_errorCatching(cogVersion, correctionCutOffVersion)) {
|
|
95
102
|
tiltCorrection = tiltCorrectionForNewerCog;
|
|
96
103
|
}
|
|
97
|
-
var _a = TiltDetection.rotateAccelData(
|
|
104
|
+
var _a = TiltDetection.rotateAccelData(ax, ay, az, tiltCorrection), x = _a.x, y = _a.y, z = _a.z;
|
|
98
105
|
var pitch = Math.atan2(x, this.distance(y, z));
|
|
99
106
|
var roll = Math.atan2(y, this.distance(x, z));
|
|
100
107
|
var yaw = Math.atan2(z, this.distance(x, y));
|
|
@@ -139,13 +146,13 @@ var RotationDetection = /** @class */ (function () {
|
|
|
139
146
|
this.dataBuffer.shift();
|
|
140
147
|
}
|
|
141
148
|
};
|
|
142
|
-
RotationDetection.prototype.detectRotation = function (
|
|
149
|
+
RotationDetection.prototype.detectRotation = function (gz, isMoving, cogState) {
|
|
143
150
|
if (isMoving === void 0) { isMoving = false; }
|
|
144
151
|
this.bufferSize = this.bufferSize;
|
|
145
152
|
this.DELAY_FOR_ROTATION = this.DELAY_FOR_ROTATION;
|
|
146
153
|
this.ROTATION_THRESHOLD = this.ROTATION_THRESHOLD;
|
|
147
154
|
var currentTime = Date.now();
|
|
148
|
-
this.addToBuffer(
|
|
155
|
+
this.addToBuffer(gz);
|
|
149
156
|
if (this.dataBuffer.length < this.bufferSize) {
|
|
150
157
|
return; // Wait until buffer is full
|
|
151
158
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DeviceManager } from "@robdobsn/raftjs/dist/web/RaftDeviceManager";
|
|
2
|
+
export default class PublishedDataGetter {
|
|
3
|
+
static getPowerData(deviceManager: DeviceManager): {
|
|
4
|
+
battV: number;
|
|
5
|
+
usb: "yes" | "no";
|
|
6
|
+
} | undefined;
|
|
7
|
+
static getAccelerometerData(deviceManager: DeviceManager): {
|
|
8
|
+
ax: number;
|
|
9
|
+
ay: number;
|
|
10
|
+
az: number;
|
|
11
|
+
} | undefined;
|
|
12
|
+
static getGyroscopeData(deviceManager: DeviceManager): {
|
|
13
|
+
gx: number;
|
|
14
|
+
gy: number;
|
|
15
|
+
gz: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
static getLightData(deviceManager: DeviceManager): {
|
|
18
|
+
amb0: number;
|
|
19
|
+
ir0: number;
|
|
20
|
+
ir1: number;
|
|
21
|
+
ir2: number;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { deviceAttrGetLatestFormatted } from "@robdobsn/raftjs";
|
|
2
|
+
/* LIGHT ATTRIBUTES */
|
|
3
|
+
var COG_LIGHT_ATTR_KEY = 'RoboCogLightV1_0';
|
|
4
|
+
var AMB0_KEY = 'amb0';
|
|
5
|
+
var IR0_KEY = 'ir0';
|
|
6
|
+
var IR1_KEY = 'ir1';
|
|
7
|
+
var IR2_KEY = 'ir2';
|
|
8
|
+
/* POWER ATTRIBUTES */
|
|
9
|
+
var COG_POWER_ATTR_KEY = 'RoboCogPowerV1_00';
|
|
10
|
+
var BATTV_KEY = 'battV';
|
|
11
|
+
var USB_KEY = 'UST';
|
|
12
|
+
/* I2CA ATTRIBUTES */
|
|
13
|
+
var COG_I2CA_ATTR_KEY = 'I2CA_6a';
|
|
14
|
+
var AX_KEY = 'ax';
|
|
15
|
+
var AY_KEY = 'ay';
|
|
16
|
+
var AZ_KEY = 'az';
|
|
17
|
+
var GX_KEY = 'gx';
|
|
18
|
+
var GY_KEY = 'gy';
|
|
19
|
+
var GZ_KEY = 'gz';
|
|
20
|
+
var PublishedDataGetter = /** @class */ (function () {
|
|
21
|
+
function PublishedDataGetter() {
|
|
22
|
+
}
|
|
23
|
+
PublishedDataGetter.getPowerData = function (deviceManager) {
|
|
24
|
+
var powerAttr = deviceManager.getDeviceState(COG_POWER_ATTR_KEY);
|
|
25
|
+
var battV = deviceAttrGetLatestFormatted(powerAttr === null || powerAttr === void 0 ? void 0 : powerAttr.deviceAttributes[BATTV_KEY]);
|
|
26
|
+
var usb = deviceAttrGetLatestFormatted(powerAttr === null || powerAttr === void 0 ? void 0 : powerAttr.deviceAttributes[USB_KEY]);
|
|
27
|
+
return { battV: convertStringToNumber(battV), usb: usb };
|
|
28
|
+
};
|
|
29
|
+
PublishedDataGetter.getAccelerometerData = function (deviceManager) {
|
|
30
|
+
var i2caAttr = deviceManager.getDeviceState(COG_I2CA_ATTR_KEY);
|
|
31
|
+
if (!i2caAttr)
|
|
32
|
+
return;
|
|
33
|
+
var i2ca = i2caAttr.deviceAttributes;
|
|
34
|
+
var ax = deviceAttrGetLatestFormatted(i2ca[AX_KEY]);
|
|
35
|
+
var ay = deviceAttrGetLatestFormatted(i2ca[AY_KEY]);
|
|
36
|
+
var az = deviceAttrGetLatestFormatted(i2ca[AZ_KEY]);
|
|
37
|
+
return { ax: convertStringToNumber(ax), ay: convertStringToNumber(ay), az: convertStringToNumber(az) };
|
|
38
|
+
};
|
|
39
|
+
PublishedDataGetter.getGyroscopeData = function (deviceManager) {
|
|
40
|
+
var i2caAttr = deviceManager.getDeviceState(COG_I2CA_ATTR_KEY);
|
|
41
|
+
if (!i2caAttr)
|
|
42
|
+
return;
|
|
43
|
+
var i2ca = i2caAttr.deviceAttributes;
|
|
44
|
+
var gx = deviceAttrGetLatestFormatted(i2ca[GX_KEY]);
|
|
45
|
+
var gy = deviceAttrGetLatestFormatted(i2ca[GY_KEY]);
|
|
46
|
+
var gz = deviceAttrGetLatestFormatted(i2ca[GZ_KEY]);
|
|
47
|
+
return { gx: convertStringToNumber(gx), gy: convertStringToNumber(gy), gz: convertStringToNumber(gz) };
|
|
48
|
+
};
|
|
49
|
+
PublishedDataGetter.getLightData = function (deviceManager) {
|
|
50
|
+
var lightAttr = deviceManager.getDeviceState(COG_LIGHT_ATTR_KEY);
|
|
51
|
+
if (!lightAttr)
|
|
52
|
+
return;
|
|
53
|
+
var light = lightAttr.deviceAttributes;
|
|
54
|
+
var amb0 = deviceAttrGetLatestFormatted(light[AMB0_KEY]);
|
|
55
|
+
var ir0 = deviceAttrGetLatestFormatted(light[IR0_KEY]);
|
|
56
|
+
var ir1 = deviceAttrGetLatestFormatted(light[IR1_KEY]);
|
|
57
|
+
var ir2 = deviceAttrGetLatestFormatted(light[IR2_KEY]);
|
|
58
|
+
return { amb0: convertStringToNumber(amb0), ir0: convertStringToNumber(ir0), ir1: convertStringToNumber(ir1), ir2: convertStringToNumber(ir2) };
|
|
59
|
+
};
|
|
60
|
+
return PublishedDataGetter;
|
|
61
|
+
}());
|
|
62
|
+
export default PublishedDataGetter;
|
|
63
|
+
var convertStringToNumber = function (str) {
|
|
64
|
+
return isNaN(+str) ? 0 : +str;
|
|
65
|
+
};
|