-
Notifications
You must be signed in to change notification settings - Fork 0
/
mashup_real_platform.ts
148 lines (123 loc) · 3.75 KB
/
mashup_real_platform.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { Servient, Helpers } from '@node-wot/core';
import { HttpClientFactory, HttpsClientFactory } from '@node-wot/binding-http'
import { readFileSync } from "fs";
import { ThingDescription } from 'wot-typescript-definitions';
function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
// TDs of Real Devices
const uarmTD = JSON.parse(
readFileSync("../TDs/Real/Uarm.json", "utf-8")
);
const dobotTD = JSON.parse(
readFileSync("../TDs/Real/Warehouse Dobot.json", "utf-8")
);
const conveyor1TD = JSON.parse(
readFileSync("../TDs/Real/ConveyorBelt1.json", "utf-8")
);
const conveyor2TD = JSON.parse(
readFileSync("../TDs/Real/ConveyorBelt2.json", "utf-8")
);
const sensor1TD = JSON.parse(
readFileSync("../TDs/Real/InfraredSensor1.json", "utf-8")
);
const sensor2TD = JSON.parse(
readFileSync("../TDs/Real/InfraredSensor2.json", "utf-8")
);
const colorsensorTD = JSON.parse(
readFileSync("../TDs/Real/ColorSensor.json", "utf-8")
);
async function main() {
const controller = new Servient()
controller.addClientFactory(new HttpClientFactory());
controller.addClientFactory(new HttpsClientFactory({allowSelfSigned:true}))
const credentials = JSON.parse(readFileSync("credential.json", "utf-8"));
controller.addCredentials({
"urn:dev:ops:32473-InfraredSensor-001": credentials,
"urn:dev:ops:32473-InfraredSensor-002": credentials,
"urn:dev:ops:32473-ConveyorBelt-001": credentials,
"urn:dev:ops:32473-ConveyorBelt-002": credentials,
"urn:dev:ops:32473-UArm-001": credentials,
"de:tum:ei:esi:dobot": credentials,
"de:tum:ei:esi:flora": credentials,
});
const WoT = await controller.start();
const dobot = await WoT.consume(dobotTD);
const uarm = await WoT.consume(uarmTD);
const conveyor2 = await WoT.consume(conveyor2TD);
const conveyor1 = await WoT.consume(conveyor1TD);
const color = await WoT.consume(colorsensorTD);
// sensor1, sensor2 could not work now, so skip it
const startPosition = {
"x": 150,
"y": 0,
"z": 70
};
let P1 = {
"x":192,
"y":192,
"z":87
};
let P4 = {
"x":192,
"y":192,
"z":52
};
let P2 = {
"x":200,
"y":-200,
"z":90
};
let P3 = {
"x":180,
"y":0,
"z":60
};
let P5 = {
"x":200,
"y":0,
"z":80
};
let P6 = {
"x":200,
"y":-200,
"z":70
};
console.log("Starting Mashup");
uarm.invokeAction("goTo", startPosition);
await dobot.invokeAction("getCube");
await delay(35000);
await conveyor2.invokeAction("startBeltForward");
await delay(5500);
await conveyor2.invokeAction("stopBelt");
await uarm.invokeAction("gripOpen");
await uarm.invokeAction("goTo",P1);
await delay(6000);
await uarm.invokeAction("goTo",P4);
await delay(6000);
await uarm.invokeAction("gripClose");
await delay(4000);
await uarm.invokeAction("goTo",P1);
await delay(4000);
await uarm.invokeAction("goTo",P3);
await delay(6000);
console.log("current color RGB is");
const colorData = await color.readProperty("color");
console.log(await colorData.value());
await delay(12000);
await uarm.invokeAction("goTo",P2);
await delay(4000);
await uarm.invokeAction("goTo",P6);
await delay(4000);
await uarm.invokeAction("gripOpen");
await delay(4000);
await uarm.invokeAction("goTo",P5);
await delay(4000);
await conveyor1.invokeAction("startBeltForward");
await delay(9000);
await conveyor1.invokeAction("stopBelt");
await delay(4000);
await dobot.invokeAction("returnCube");
await controller.shutdown()
}
main();