ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Rosbridge only one way on my OSX

asked 2015-11-23 00:02:31 -0600

Fry gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

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.

Philipp Schillinger gravatar image Philipp Schillinger  ( 2015-11-23 12:53:31 -0600 )edit

Thanks Phillip. This is a big help. Do your environment variables and /etc/hosts also look the same as mine?

Fry gravatar image Fry  ( 2015-11-23 22:21:48 -0600 )edit

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!

Philipp Schillinger gravatar image Philipp Schillinger  ( 2015-11-24 12:31:19 -0600 )edit

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.

William gravatar image William  ( 2015-11-24 18:53:13 -0600 )edit

I also noticed that the publishing to /cmd_vel works but can take a very long time to show up in rostopic 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.

William gravatar image William  ( 2015-11-24 18:54:34 -0600 )edit

@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).

William gravatar image William  ( 2015-11-24 18:55:49 -0600 )edit

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...

William gravatar image William  ( 2015-11-24 19:00:54 -0600 )edit

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.

William gravatar image William  ( 2015-11-24 19:02:55 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-11-24 19:16:51 -0600

William gravatar image

I can definitely reproduce this on my OS X machine (Yosemite 10.10.5) and ROS Indigo. I tried it in Chrome, Safari, and Firefox with the same behavior. Also, I ran the rospy tests and used several complex things which use rospy and didn't have any trouble. This leads me to believe this is likely a bug in the ros bridge reactor (tornado I think) or some underlying Python functionality that is different on OS X/Homebrew. Or it could be how rosbridge is using rospy and exposing some strange bug I can't trigger otherwise.

I'd open an issue against rosbridge and they can in turn open an issue against rospy if they decide that the problem doesn't seem to be theirs.

edit flag offensive delete link more

Comments

Huge thanks to William! - Its not easy for me to test this on OSX running Jade, but if that solved the problem I'd switch to Jade. - Same for me switching from Yosemite to El Capitan OSX releases. - Might it have to do with OSX websocket security blocking on various PORTs?

Fry gravatar image Fry  ( 2015-11-24 20:29:02 -0600 )edit

Just posted something about this on the rosbridge_suite issues page. Turns out (for me) that the fix is to pip install pymongo rather than bson. Same module name, different API.

jonfink gravatar image jonfink  ( 2015-11-25 09:29:35 -0600 )edit
1

answered 2016-07-24 14:55:08 -0600

Basically it seems to be related to a misconfiguration of ROS. rosbridge requires the BSON module that is delivered with MongoDB (or compatible). If doing a "pip install bson" a non compatible version is installed. rosbridge (for now) fails silently so only one way direction is possible.

Potential fixes include pip install mongodb or using the rosdep system.

As I was using a slim robot system (Intel Edison based) with only very limited functionality, I fell into this trap. I resolved it manually by copying the bson directory from the python-mongodb sources to /opt/ros/<distro>/libs/python2.7/site-packages.

After that all issues seen to be resolved :-)

Btw. this topic is also discussed on GIT HUB, but I wanted to explicitely share my findings here, so people don't have to unnecessarily waste any time.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-11-23 00:02:31 -0600

Seen: 2,455 times

Last updated: Jul 24 '16