-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulatenous-control.ts
89 lines (70 loc) · 2.56 KB
/
simulatenous-control.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
import {Servient} from '@node-wot/core';
import {HttpClientFactory, HttpsClientFactory} from '@node-wot/binding-http'
import { readFileSync } from 'fs';
function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}
const P1 = {
"x":192,
"y":192,
"z":70
};
const P2 = {
"x":192,
"y":-192,
"z":70
};
const startPosition = {
x: 150,
y: 0,
z: 70,
};
const uarmTD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_uarm.td.json","utf-8"))
const conveyor1TD_V = JSON.parse(readFileSync("../TDs/Virtual/virtual_conveyor_right.td.json","utf-8"))
const uarmTD_R = JSON.parse(readFileSync("../TDs/Real/Uarm.json","utf-8"))
const conveyor1TD_R = JSON.parse(readFileSync("../TDs/Real/ConveyorBelt2.json","utf-8"))
main()
async function main() {
let Consumer = new Servient();
// in the next line, we are expecting a JSON file that has {"username":"myUsername", "password":"myPassword"} structure}
const credentials = JSON.parse(readFileSync("credential.json", "utf-8"));
Consumer.addCredentials({
"urn:dev:ops:32473-ConveyorBelt-002": credentials,
"urn:dev:ops:32473-UArm-001": credentials
})
Consumer.addClientFactory(new HttpClientFactory());
Consumer.addClientFactory(new HttpsClientFactory({allowSelfSigned:true}));
const WoT = await Consumer.start();
let uarm_V = await WoT.consume(uarmTD_V)
let uarm_R = await WoT.consume(uarmTD_R)
let conveyor1_V = await WoT.consume(conveyor1TD_V)
let conveyor1_R = await WoT.consume(conveyor1TD_R)
while(true){
await delay(3000)
console.log("New loop is starting")
uarm_V.invokeAction("gripOpen");
uarm_R.invokeAction("gripOpen");
await delay(3000)
uarm_R.invokeAction("gripClose");
uarm_V.invokeAction("gripClose");
await delay(3000)
uarm_V.invokeAction("goTo",P1);
uarm_R.invokeAction("goTo",P1);
await delay(10000)
uarm_V.invokeAction("goTo", startPosition);
uarm_R.invokeAction("goTo", startPosition);
await delay(10000);
conveyor1_V.invokeAction("startBeltBackward");
conveyor1_R.invokeAction("startBeltBackward");
await delay(3000)
conveyor1_V.invokeAction("stopBelt");
conveyor1_R.invokeAction("stopBelt");
await delay(3000)
uarm_V.invokeAction("goTo",P2);
uarm_R.invokeAction("goTo",P2);
await delay(10000)
uarm_V.invokeAction("goTo", startPosition);
uarm_R.invokeAction("goTo", startPosition);
await delay(10000);
}
}