Rosbridge only one way on my OSX
This probably has the same underlying cause as the problem I posted in http://answers.ros.org/question/22104... , but now I have a simpler way to reproduce the problem and that uses no code from me and some extra clues.
I'm running OSX Yosemite, ROS Indigo, Rosbridge with ROSlibjs using the Chrome Browser. I can call a service from the browser, and it successfully executes on the server, but I can't get any information back to the browser. The simplest way I can reproduce this is:
In a terminal window:
$ roscore
In another terminal window:
$ rosrun rospy_tutorials add_two_ints_server (in the tutorial)
In a third terminal window:
$ roslaunch rosbridge_server rosbridge_websocket.launch (in the tutorial)
From the web page: http://wiki.ros.org/roslibjs/Tutorials/BasicRosFunctionality
copy the whole page HTML into a file, say, simple.html Here is is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" type="text/javascript">
// Connecting to ROS
// -----------------
var ros = new ROSLIB.Ros({
url : 'ws://localhost:9090'
});
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
// Publishing a Topic
// ------------------
var cmdVel = new ROSLIB.Topic({
ros : ros,
name : '/cmd_vel',
messageType : 'geometry_msgs/Twist'
});
var twist = new ROSLIB.Message({
linear : {
x : 0.1,
y : 0.2,
z : 0.3
},
angular : {
x : -0.1,
y : -0.2,
z : -0.3
}
});
cmdVel.publish(twist);
// Subscribing to a Topic
// ----------------------
var listener = new ROSLIB.Topic({
ros : ros,
name : '/listener',
messageType : 'std_msgs/String'
});
listener.subscribe(function(message) {
console.log('Received message on ' + listener.name + ': ' + message.data);
listener.unsubscribe();
});
// Calling a service
// -----------------
var addTwoIntsClient = new ROSLIB.Service({
ros : ros,
name : '/add_two_ints',
serviceType : 'rospy_tutorials/AddTwoInts'
});
var request = new ROSLIB.ServiceRequest({
a : 1,
b : 2
});
addTwoIntsClient.callService(request, function(result) {
console.log('Result for service call on '
+ addTwoIntsClient.name
+ ': '
+ result.sum);
});
// Getting and setting a param value
// ---------------------------------
ros.getParams(function(params) {
console.log(params);
});
var maxVelX = new ROSLIB.Param({
ros : ros,
name : 'max_vel_y'
});
maxVelX.set(0.8);
maxVelX.get(function(value) {
console.log('MAX VAL: ' + value);
});
</script>
</head>
<body>
<h1>Simple roslib Example</h1>
<p>Check your Web Console for output.</p>
</body>
</html>
In Chrome, browse: file:///your_dir/simple.html
Open the Chrome Development tools:
I see in the console: "Connected to websocket server"
(This is good)
but there's nothing else printed in the console (this is bad)
as the JS code indicates it should print out:
Result for service call on /add_two_ints: 3
In the rosrun terminal window, I see printed out:
Returning [1 + 2 = 3]
Indicating that the service request made it to the server and the server did the computation.
Additional info that perhaps provides some clues:
$ rosnode list
/add_two_ints_server
/rosapi
/rosbridge_websocket
/rosout
$ roswtf
Loaded plugin tf.tfwtf
Package: rospy_tutorials
================================================================================
Static ...
I would really like to help you better, but at least I can tell that the JS code is correct as your exact setup runs for me and prints the expected messages. Only difference is that I am running Ubuntu, but I have no idea how this is related to the problem.
Thanks Phillip. This is a big help. Do your environment variables and /etc/hosts also look the same as mine?
Oh, there is "(More)" button... ;) Yes, they look similar. I agree that it really sounds related to this brew thing. But since I don't have access to OSX, I don't have any experience with it, sorry!
I can reproduce what you're talking about. At first I though it was because your JS didn't wait to perform its actions until ROS was connected, but even after wrapping your logic in
ros.on('connection', ...);
it still is flakey.I also noticed that the publishing to
/cmd_vel
works but can take a very long time to show up inrostopic echo /cmd_vel
. There is definitely something fishy going on here, but I don't know what it is. There's nothing fundamentally different about OS X or Homebrew that would cause this, afaik.@ahendrix could this be related to what your problem? (I know you're not using rosbridge, but it could be some underlying issue with rospy).
Nvm, I believe the flakey behavior was because refreshing the webpage would cause the ros bridge to unadvertise and re-advertise the topic, which was messing with rostopic echo. I switched it to be a latched topic and it behaves as I would expect. Not sure about the service...
Yeah it definitely seems like communication back to the web browser is not working, neither the service nor the subscriber in JS receive data in the web browser.