|
1 | | -<!DOCTYPE html> |
| 1 | +<!doctype html> |
2 | 2 | <html> |
3 | | -<head> |
4 | | -<meta charset="utf-8" /> |
5 | | -<script src="https://unpkg.com/eventemitter3@latest/dist/eventemitter3.umd.min.js"></script> |
6 | | -<script src="../dist/RosLib.umd.cjs"></script> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <script src="../importmap.js"></script> |
7 | 6 |
|
8 | | -<script> |
9 | | - // Connecting to ROS |
10 | | - // ----------------- |
11 | | - var ros = new ROSLIB.Ros({ |
12 | | - url : 'ws://localhost:9090' |
13 | | - }); |
| 7 | + <script type="module"> |
| 8 | + import * as ROSLIB from "roslib"; |
| 9 | + // Connecting to ROS |
| 10 | + // ----------------- |
| 11 | + var ros = new ROSLIB.Ros({ |
| 12 | + url: "ws://localhost:9090", |
| 13 | + }); |
14 | 14 |
|
15 | | - // If there is an error on the backend, an 'error' emit will be emitted. |
16 | | - ros.on('error', function(error) { |
17 | | - document.getElementById('connecting').style.display = 'none'; |
18 | | - document.getElementById('connected').style.display = 'none'; |
19 | | - document.getElementById('closed').style.display = 'none'; |
20 | | - document.getElementById('error').style.display = 'inline'; |
21 | | - console.log(error); |
22 | | - }); |
| 15 | + // If there is an error on the backend, an 'error' emit will be emitted. |
| 16 | + ros.on("error", function (error) { |
| 17 | + document.getElementById("connecting").style.display = "none"; |
| 18 | + document.getElementById("connected").style.display = "none"; |
| 19 | + document.getElementById("closed").style.display = "none"; |
| 20 | + document.getElementById("error").style.display = "inline"; |
| 21 | + console.log(error); |
| 22 | + }); |
23 | 23 |
|
24 | | - // Find out exactly when we made a connection. |
25 | | - ros.on('connection', function() { |
26 | | - console.log('Connection made!'); |
27 | | - document.getElementById('connecting').style.display = 'none'; |
28 | | - document.getElementById('error').style.display = 'none'; |
29 | | - document.getElementById('closed').style.display = 'none'; |
30 | | - document.getElementById('connected').style.display = 'inline'; |
31 | | - }); |
| 24 | + // Find out exactly when we made a connection. |
| 25 | + ros.on("connection", function () { |
| 26 | + console.log("Connection made!"); |
| 27 | + document.getElementById("connecting").style.display = "none"; |
| 28 | + document.getElementById("error").style.display = "none"; |
| 29 | + document.getElementById("closed").style.display = "none"; |
| 30 | + document.getElementById("connected").style.display = "inline"; |
| 31 | + }); |
32 | 32 |
|
33 | | - ros.on('close', function() { |
34 | | - console.log('Connection closed.'); |
35 | | - document.getElementById('connecting').style.display = 'none'; |
36 | | - document.getElementById('connected').style.display = 'none'; |
37 | | - document.getElementById('closed').style.display = 'inline'; |
38 | | - }); |
| 33 | + ros.on("close", function () { |
| 34 | + console.log("Connection closed."); |
| 35 | + document.getElementById("connecting").style.display = "none"; |
| 36 | + document.getElementById("connected").style.display = "none"; |
| 37 | + document.getElementById("closed").style.display = "inline"; |
| 38 | + }); |
39 | 39 |
|
40 | | - // The ActionClient |
41 | | - // ---------------- |
| 40 | + // The ActionClient |
| 41 | + // ---------------- |
42 | 42 |
|
43 | | - var fibonacciClient = new ROSLIB.ActionClient({ |
44 | | - ros : ros, |
45 | | - serverName : '/fibonacci', |
46 | | - actionName : 'actionlib_tutorials/FibonacciAction' |
47 | | - }); |
| 43 | + var fibonacciClient = new ROSLIB.ActionClient({ |
| 44 | + ros: ros, |
| 45 | + serverName: "/fibonacci", |
| 46 | + actionName: "actionlib_tutorials/FibonacciAction", |
| 47 | + }); |
48 | 48 |
|
49 | | - // Create a goal. |
50 | | - var goal = new ROSLIB.Goal({ |
51 | | - actionClient : fibonacciClient, |
52 | | - goalMessage : { |
53 | | - order : 7 |
54 | | - } |
55 | | - }); |
| 49 | + // Create a goal. |
| 50 | + var goal = new ROSLIB.Goal({ |
| 51 | + actionClient: fibonacciClient, |
| 52 | + goalMessage: { |
| 53 | + order: 7, |
| 54 | + }, |
| 55 | + }); |
56 | 56 |
|
57 | | - // Print out their output into the terminal. |
58 | | - goal.on('feedback', function(feedback) { |
59 | | - console.log('Feedback: ' + feedback.sequence); |
60 | | - }); |
61 | | - goal.on('result', function(result) { |
62 | | - console.log('Final Result: ' + result.sequence); |
63 | | - }); |
| 57 | + // Print out their output into the terminal. |
| 58 | + goal.on("feedback", function (feedback) { |
| 59 | + console.log("Feedback: " + feedback.sequence); |
| 60 | + }); |
| 61 | + goal.on("result", function (result) { |
| 62 | + console.log("Final Result: " + result.sequence); |
| 63 | + }); |
64 | 64 |
|
65 | | - // Send the goal to the action server. |
66 | | - goal.send(); |
67 | | -</script> |
68 | | -</head> |
| 65 | + // Send the goal to the action server. |
| 66 | + goal.send(); |
| 67 | + </script> |
| 68 | + </head> |
69 | 69 |
|
70 | | -<body> |
71 | | - <h1>Fibonacci ActionClient Example</h1> |
72 | | - <p>Run the following commands in the terminal then refresh this page. Check the JavaScript |
73 | | - console for the output.</p> |
74 | | - <ol> |
75 | | - <li><tt>roscore</tt></li> |
76 | | - <li><tt>rosrun actionlib_tutorials fibonacci_server</tt></li> |
77 | | - <li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li> |
78 | | - </ol> |
79 | | - <div id="statusIndicator"> |
80 | | - <p id="connecting"> |
81 | | - Connecting to rosbridge... |
| 70 | + <body> |
| 71 | + <h1>Fibonacci ActionClient Example</h1> |
| 72 | + <p> |
| 73 | + Run the following commands in the terminal then refresh this page. Check |
| 74 | + the JavaScript console for the output. |
82 | 75 | </p> |
83 | | - <p id="connected" style="color:#00D600; display:none"> |
84 | | - Connected |
85 | | - </p> |
86 | | - <p id="error" style="color:#FF0000; display:none"> |
87 | | - Error in the backend! |
88 | | - </p> |
89 | | - <p id="closed" style="display:none"> |
90 | | - Connection closed. |
91 | | - </p> |
92 | | - </div> |
93 | | -</body> |
| 76 | + <ol> |
| 77 | + <li><tt>roscore</tt></li> |
| 78 | + <li><tt>rosrun actionlib_tutorials fibonacci_server</tt></li> |
| 79 | + <li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li> |
| 80 | + </ol> |
| 81 | + <div id="statusIndicator"> |
| 82 | + <p id="connecting">Connecting to rosbridge...</p> |
| 83 | + <p id="connected" style="color: #00d600; display: none">Connected</p> |
| 84 | + <p id="error" style="color: #ff0000; display: none"> |
| 85 | + Error in the backend! |
| 86 | + </p> |
| 87 | + <p id="closed" style="display: none">Connection closed.</p> |
| 88 | + </div> |
| 89 | + </body> |
94 | 90 | </html> |
0 commit comments