-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathaction_server.html
More file actions
82 lines (69 loc) · 2.22 KB
/
action_server.html
File metadata and controls
82 lines (69 loc) · 2.22 KB
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="/roslib/importmap.js"></script>
<script type="module">
import * as ROSLIB from "roslib";
// Connecting to ROS
// -----------------
var ros = new ROSLIB.Ros({
url: "ws://localhost:9090",
});
// If there is an error on the backend, an 'error' emit will be emitted.
ros.on("error", function (error) {
console.log(error);
});
ros.on("connection", function () {
console.log("Connection made!");
});
// The ActionServer
// ----------------
const fibonacciServer = new ROSLIB.SimpleActionServer({
ros: ros,
serverName: "/fibonacci",
actionName: "actionlib_tutorials/FibonacciAction",
});
var canceled = false;
//handle fibonacci action request.
fibonacciServer.on("goal", function (goalMessage) {
console.log(goalMessage);
fibonacciSequence = [];
fibonacciSequence.push(0);
fibonacciSequence.push(1);
for (var i = 1; i < goalMessage.order; i++) {
fibonacciSequence.push(
fibonacciSequence[i] + fibonacciSequence[i - 1],
);
if (canceled === true) {
console.log("Action server preempted");
fibonacciServer.setPreempted();
}
console.log(fibonacciSequence);
//send feedback
var feedback = { sequence: fibonacciSequence };
fibonacciServer.sendFeedback(fibonacciSequence);
}
//send result
var result = { sequence: fibonacciSequence };
fibonacciServer.setSucceeded(result);
});
fibonacciServer.on("cancel", function (goalMessage) {
canceled = true;
});
</script>
</head>
<body>
<h1>Fibonacci ActionClient Example</h1>
<p>
Run the following commands in the terminal then refresh this page. Check
the JavaScript console for the output.
</p>
<ol>
<li><tt>roscore</tt></li>
<li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li>
<li><tt>refresh this page</tt></li>
<li><tt>rosrun actionlib_tutorials fibonacci_client</tt></li>
</ol>
</body>
</html>