-
Notifications
You must be signed in to change notification settings - Fork 4
/
control.js
83 lines (69 loc) · 1.52 KB
/
control.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
HOST='10.3.65.166';
API_KEY='';
var config = {
server: 'wss://api.api.ai:4435/api/ws/query',
token: API_KEY,
sessionId: 9291787, //Just a random number
onInit: function () {
console.log("> ON INIT use config");
}
};
var ros = new ROSLIB.Ros({
url : 'ws://'+HOST+':9090'
});
var cmdVel = new ROSLIB.Topic({
ros : ros,
name : '/RosAria/cmd_vel',
messageType : 'geometry_msgs/Twist'
});
var apiAi = new ApiAi(config);
var command_it = function() {
apiAi.init();
};
apiAi.onInit = function() {
apiAi.open();
};
apiAi.onOpen = function () {
apiAi.startListening();
setTimeout(StopListen,4000);//Wait 4 seconds before stopping listening
};
var StopListen = function() {
apiAi.stopListening();
};
apiAi.onResults = function (data) {
voice_command(parseInt(data.result.parameters.steps), 0);
};
function voice_command (linear, angular) {
move(linear,angular);
setTimeout(stop,1000);// Wait 1 second before stopping
};
function move(linear,angular) {
var twist = new ROSLIB.Message({
linear: {
x : linear,
y : 0,
z : 0
} ,
angular: {
x : 0,
y : 0,
z : angular
}
});
cmdVel.publish(twist);
};
function stop() {
var twist = new ROSLIB.Message({
linear: {
x : 0,
y : 0,
z : 0
} ,
angular: {
x : 0,
y : 0,
z : 0
}
});
cmdVel.publish(twist);
};