-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
84 lines (56 loc) · 1.65 KB
/
test.js
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
const boost = require('movehub-async');
boost.on('ble-ready', status => {
console.log('ble-ready', status);
});
async function Robot() {
const hub = await boost.getHubAsync();
await hub.ledAsync('red');
await hub.ledAsync('yellow');
await hub.ledAsync('green');
//await hub.motorTimeAsync('C', 3, -45, true);
return hub;
};
async function ShakingHead(hub, speed){
let locSpeed = (speed ? speed : 60);
await hub.motorAngleAsync('C', 45, locSpeed, true);
await hub.motorAngleAsync('C', 90, -locSpeed, true);
await hub.motorAngleAsync('C', 52, locSpeed, true);
return hub;
}
async function DriveSquary(hub, distance){
let locDistance = (distance ? distance : 50);
await hub.drive(locDistance);
await hub.turn(90);
await hub.drive(locDistance);
await hub.turn(90);
await hub.drive(locDistance);
await hub.turn(90);
await hub.drive(locDistance);
await hub.turn(90);
return hub;
}
async function DriveRoutine(hub,distance){
let locDistance = (distance ? distance : 50);
await hub.drive(locDistance);
await hub.turn(360);
await hub.drive(locDistance);
await hub.turn(-90);
await hub.drive(locDistance);
await hub.turn(-90);
await hub.drive(locDistance);
await hub.turn(360);
await hub.drive(locDistance);
await hub.turn(-180);
await hub.drive(locDistance);
await hub.turn(90);
return hub;
}
Robot().then((hub) => {
console.log("Connected");
return ShakingHead(hub, 30);
}).then((hub) => {
console.log("Done Shaking");
return DriveRoutine(hub, 75);
}).then((hub) => {
console.log("Done Shaking");
});