Skip to content

Commit a6ae65c

Browse files
committed
dDo not remove any ROS 1 functionality
1 parent a3f8054 commit a6ae65c

16 files changed

+1047
-61
lines changed

build/roslib.js

Lines changed: 392 additions & 50 deletions
Large diffs are not rendered by default.

build/roslib.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/action_client.html

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="https://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
6+
<script src="../build/roslib.js"></script>
7+
8+
<script>
9+
// Connecting to ROS
10+
// -----------------
11+
var ros = new ROSLIB.Ros({
12+
url : 'ws://localhost:9090'
13+
});
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+
});
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+
});
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+
});
39+
40+
// The ActionClient
41+
// ----------------
42+
43+
var fibonacciClient = new ROSLIB.ActionClient({
44+
ros : ros,
45+
serverName : '/fibonacci',
46+
actionName : 'actionlib_tutorials/FibonacciAction'
47+
});
48+
49+
// Create a goal.
50+
var goal = new ROSLIB.Goal({
51+
actionClient : fibonacciClient,
52+
goalMessage : {
53+
order : 7
54+
}
55+
});
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+
});
64+
65+
// Send the goal to the action server.
66+
goal.send();
67+
</script>
68+
</head>
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...
82+
</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>
94+
</html>

examples/action_server.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="https://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
6+
<script src="../build/roslib.js"></script>
7+
8+
<script>
9+
// Connecting to ROS
10+
// -----------------
11+
var ros = new ROSLIB.Ros({
12+
url : 'ws://localhost:9090'
13+
});
14+
15+
// If there is an error on the backend, an 'error' emit will be emitted.
16+
ros.on('error', function(error) {
17+
console.log(error);
18+
});
19+
20+
// The ActionServer
21+
// ----------------
22+
23+
this.fibonacciServer = new ROSLIB.SimpleActionServer({
24+
ros : ros,
25+
serverName : '/fibonacci',
26+
actionName : 'actionlib_tutorials/FibonacciAction'
27+
});
28+
29+
this.canceled = false;
30+
var that=this;
31+
32+
//handle fibonacci action request.
33+
this.fibonacciServer.on('goal', function(goalMessage) {
34+
console.log(goalMessage);
35+
fibonacciSequence = [];
36+
fibonacciSequence.push(0);
37+
fibonacciSequence.push(1);
38+
39+
for (var i = 1; i < goalMessage.order; i++ ) {
40+
fibonacciSequence.push( fibonacciSequence[i] + fibonacciSequence[i-1] );
41+
42+
if (that.canceled === true ) {
43+
console.log("Action server preempted");
44+
45+
that.fibonacciServer.setPreempted();
46+
}
47+
console.log(fibonacciSequence);
48+
//send feedback
49+
var feedback = { sequence: fibonacciSequence };
50+
that.fibonacciServer.sendFeedback(fibonacciSequence);
51+
}
52+
53+
//send result
54+
var result = { sequence: fibonacciSequence};
55+
that.fibonacciServer.setSucceeded(result);
56+
});
57+
58+
this.fibonacciServer.on('cancel', function(goalMessage){
59+
that.canceled = true;
60+
});
61+
</script>
62+
</head>
63+
64+
<body>
65+
<h1>Fibonacci ActionClient Example</h1>
66+
<p>Run the following commands in the terminal then refresh this page. Check the JavaScript
67+
console for the output.</p>
68+
<ol>
69+
<li><tt>roscore</tt></li>
70+
<li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li>
71+
<li><tt>refresh this page</tt></li>
72+
<li><tt>rosrun actionlib_tutorials fibonacci_client</tt></li>
73+
</ol>
74+
</body>
75+
</html>

examples/ros2_simple.html

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="https://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
6+
<script src="../build/roslib.js"></script>
7+
8+
<script>
9+
// Connecting to ROS
10+
// -----------------
11+
var ros = new ROSLIB.Ros();
12+
13+
// If there is an error on the backend, an 'error' emit will be emitted.
14+
ros.on('error', function(error) {
15+
document.getElementById('connecting').style.display = 'none';
16+
document.getElementById('connected').style.display = 'none';
17+
document.getElementById('closed').style.display = 'none';
18+
document.getElementById('error').style.display = 'inline';
19+
console.log(error);
20+
});
21+
22+
// Find out exactly when we made a connection.
23+
ros.on('connection', function() {
24+
console.log('Connection made!');
25+
document.getElementById('connecting').style.display = 'none';
26+
document.getElementById('error').style.display = 'none';
27+
document.getElementById('closed').style.display = 'none';
28+
document.getElementById('connected').style.display = 'inline';
29+
});
30+
31+
ros.on('close', function() {
32+
console.log('Connection closed.');
33+
document.getElementById('connecting').style.display = 'none';
34+
document.getElementById('connected').style.display = 'none';
35+
document.getElementById('closed').style.display = 'inline';
36+
});
37+
38+
// Create a connection to the rosbridge WebSocket server.
39+
ros.connect('ws://localhost:9090');
40+
41+
// Publishing a Topic
42+
// ------------------
43+
44+
// First, we create a Topic object with details of the topic's name and message type.
45+
var cmdVel = new ROSLIB.Topic({
46+
ros : ros,
47+
name : '/cmd_vel',
48+
messageType : 'geometry_msgs/Twist'
49+
});
50+
51+
// Then we create the payload to be published. The object we pass in to ros.Message matches the
52+
// fields defined in the geometry_msgs/Twist.msg definition.
53+
var twist = new ROSLIB.Message({
54+
linear : {
55+
x : 0.1,
56+
y : 0.2,
57+
z : 0.3
58+
},
59+
angular : {
60+
x : -0.1,
61+
y : -0.2,
62+
z : -0.3
63+
}
64+
});
65+
66+
// And finally, publish.
67+
cmdVel.publish(twist);
68+
69+
// Subscribing to a Topic
70+
// ----------------------
71+
72+
// Like when publishing a topic, we first create a Topic object with details of the topic's name
73+
// and message type. Note that we can call publish or subscribe on the same topic object.
74+
var listener = new ROSLIB.Topic({
75+
ros : ros,
76+
name : '/listener',
77+
messageType : 'std_msgs/String'
78+
});
79+
80+
// Then we add a callback to be called every time a message is published on this topic.
81+
listener.subscribe(function(message) {
82+
console.log('Received message on ' + listener.name + ': ' + message.data);
83+
84+
// If desired, we can unsubscribe from the topic as well.
85+
listener.unsubscribe();
86+
});
87+
88+
// Calling a service
89+
// -----------------
90+
91+
// First, we create a Service client with details of the service's name and service type.
92+
var addTwoIntsClient = new ROSLIB.Service({
93+
ros : ros,
94+
name : '/add_two_ints',
95+
serviceType : 'example_interfaces/AddTwoInts'
96+
});
97+
98+
// Then we create a Service Request. The object we pass in to ROSLIB.ServiceRequest matches the
99+
// fields defined in the rospy_tutorials AddTwoInts.srv file.
100+
var request = new ROSLIB.ServiceRequest({
101+
a : 1,
102+
b : 2
103+
});
104+
105+
// Finally, we call the /add_two_ints service and get back the results in the callback. The result
106+
// is a ROSLIB.ServiceResponse object.
107+
addTwoIntsClient.callService(request, function(result) {
108+
console.log('Result for service call on ' + addTwoIntsClient.name + ': ' + result.sum);
109+
});
110+
111+
// Advertising a Service
112+
// ---------------------
113+
114+
// The Service object does double duty for both calling and advertising services
115+
var setBoolServer = new ROSLIB.Service({
116+
ros : ros,
117+
name : '/set_bool',
118+
serviceType : 'std_srvs/SetBool'
119+
});
120+
121+
// Use the advertise() method to indicate that we want to provide this service
122+
setBoolServer.advertise(function(request, response) {
123+
console.log('Received service request on ' + setBoolServer.name + ': ' + request.data);
124+
response['success'] = true;
125+
response['message'] = 'Set successfully';
126+
return true;
127+
});
128+
</script>
129+
</head>
130+
131+
<body>
132+
<h1>Simple roslib Example</h1>
133+
<p>Run the following commands in the terminal then refresh this page. Check the JavaScript
134+
console for the output.</p>
135+
<ol>
136+
<li><tt>ros2 topic pub /listener std_msgs/msg/String "{ data: 'hello world' }" </tt></li>
137+
<li><tt>ros2 topic echo /cmd_vel</tt></li>
138+
<li><tt>ros2 run demo_nodes_py add_two_ints_server</tt></li>
139+
<li><tt>ros2 launch rosbridge_server rosbridge_websocket_launch.xml</tt></li>
140+
</ol>
141+
<div id="statusIndicator">
142+
<p id="connecting">
143+
Connecting to rosbridge...
144+
</p>
145+
<p id="connected" style="color:#00D600; display:none">
146+
Connected
147+
</p>
148+
<p id="error" style="color:#FF0000; display:none">
149+
Error in the backend!
150+
</p>
151+
<p id="closed" style="display:none">
152+
Connection closed.
153+
</p>
154+
</div>
155+
</body>
156+
</html>

examples/simple.html

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
var addTwoIntsClient = new ROSLIB.Service({
9393
ros : ros,
9494
name : '/add_two_ints',
95-
serviceType : 'example_interfaces/AddTwoInts'
95+
serviceType : 'rospy_tutorials/AddTwoInts'
9696
});
9797

9898
// Then we create a Service Request. The object we pass in to ROSLIB.ServiceRequest matches the
@@ -125,6 +125,38 @@
125125
response['message'] = 'Set successfully';
126126
return true;
127127
});
128+
129+
// Setting a param value
130+
// ---------------------
131+
132+
ros.getParams(function(params) {
133+
console.log(params);
134+
});
135+
136+
// First, we create a Param object with the name of the param.
137+
var maxVelX = new ROSLIB.Param({
138+
ros : ros,
139+
name : 'max_vel_y'
140+
});
141+
142+
// Then we set the value of the param, which is sent to the ROS Parameter Server.
143+
maxVelX.set(0.8);
144+
maxVelX.get(function(value) {
145+
console.log('MAX VAL: ' + value);
146+
});
147+
148+
// Getting a param value
149+
// ---------------------
150+
151+
var favoriteColor = new ROSLIB.Param({
152+
ros : ros,
153+
name : 'favorite_color'
154+
});
155+
156+
favoriteColor.set('red');
157+
favoriteColor.get(function(value) {
158+
console.log('My robot\'s favorite color is ' + value);
159+
});
128160
</script>
129161
</head>
130162

@@ -133,10 +165,11 @@ <h1>Simple roslib Example</h1>
133165
<p>Run the following commands in the terminal then refresh this page. Check the JavaScript
134166
console for the output.</p>
135167
<ol>
136-
<li><tt>ros2 topic pub /listener std_msgs/msg/String "{ data: 'hello world' }" </tt></li>
137-
<li><tt>ros2 topic echo /cmd_vel</tt></li>
138-
<li><tt>ros2 run demo_nodes_py add_two_ints_server</tt></li>
139-
<li><tt>ros2 launch rosbridge_server rosbridge_websocket_launch.xml</tt></li>
168+
<li><tt>roscore</tt></li>
169+
<li><tt>rostopic pub /listener std_msgs/String "Hello, World"</tt></li>
170+
<li><tt>rostopic echo /cmd_vel</tt></li>
171+
<li><tt>rosrun rospy_tutorials add_two_ints_server</tt></li>
172+
<li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li>
140173
</ol>
141174
<div id="statusIndicator">
142175
<p id="connecting">

0 commit comments

Comments
 (0)