-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmashup_virtual_platform.ts
133 lines (113 loc) · 3.47 KB
/
mashup_virtual_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
import { readFileSync } from "fs";
import { Servient } from "@node-wot/core";
import { HttpClientFactory, HttpsClientFactory } from "@node-wot/binding-http";
function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// virtual devices TDs
const uarmTD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_uarm.td.json", "utf-8"));
const dobotTD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_dobot.td.json", "utf-8"));
const conveyor1TD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_conveyor_right.td.json", "utf-8"));
const conveyor2TD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_conveyor_left.td.json", "utf-8"));
const sensor1TD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_infrared_sensor1.td.json", "utf-8"));
const sensor2TD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_infrared_sensor2.td.json", "utf-8"));
const colorsensorTD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_color_sensor.td.json", "utf-8"));
async function main() {
let Consumer = new Servient();
Consumer.addClientFactory(new HttpClientFactory());
Consumer.addClientFactory(new HttpsClientFactory());
const WoT = await Consumer.start();
// Consume Things
const uarm = await WoT.consume(uarmTD_V);
const dobot = await WoT.consume(dobotTD_V);
const conveyor1 = await WoT.consume(conveyor1TD_V);
const conveyor2 = await WoT.consume(conveyor2TD_V);
const infraredSensor1 = await WoT.consume(sensor1TD_V);
const infraredSensor2 = await WoT.consume(sensor2TD_V);
const colorSensor = await WoT.consume(colorsensorTD_V);
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(10000);
await conveyor1.invokeAction("startBeltForward");
while (true) {
const sensor2Read = await infraredSensor2.readProperty("objectPresence");
if (await sensor2Read.value() == true) {
await delay(500);
await conveyor1.invokeAction("stopBelt");
break;
}
await delay(800);
}
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(4000);
const colorRead = await colorSensor.readProperty("color");
console.log("current color RGB is");
console.log(await colorRead.value());
await delay(2000);
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 conveyor2.invokeAction("startBeltBackward");
while (true) {
const sensor1Read = await infraredSensor1.readProperty("objectPresence");
if (await sensor1Read.value() == true) {
await delay(600);
await conveyor2.invokeAction("stopBelt");
break;
}
await delay(1500);
}
await delay(4000);
await dobot.invokeAction("returnCube");
}
main();