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

Migrate from rosbridge 1.0 to 2.0

asked 2014-05-05 05:11:15 -0500

Il_Voza gravatar image

updated 2014-05-05 05:32:40 -0500

Hello guys, I have a project where I used rosbridge 1.0 and (so) ROS Groovy. I have to move my project to Hydro, so I need of rosbridge 2.0. How can I edit this js code to migrate to rosbridge 2.0?

var ros = ros || {};

var Connection = function(url) {
  this.handlers = new Array();

  if (typeof WebSocket == 'undefined') {
    WebSocket = MozWebSocket;
  }
  this.socket = new WebSocket(url);
  this.onmessage = null;
  var ths = this;
  this.socket.onmessage = function(e) {
    if(ths.onmessage) {
      try {
        ths.onmessage(e);
      } catch(err) {
        ros_debug(err);
      }
    }

    var call = ''; 
    try {
      eval('call = ' + e.data);
    } catch(err) {
      return;
    }

    for (var i in ths.handlers[call.receiver]) {
      var handler = ths.handlers[call.receiver][i]
      handler(call.msg);
    }
  }

  this.magicServices = new Array('/rosbridge/topics','/rosbridge/services','/rosbridge/typeStringFromTopic','/rosbridge/typeStringFromService','/rosbridge/msgClassFromTypeString','/rosbridge/reqClassFromTypeString','/rosbridge/rspClassFromTypeString','/rosbridge/classFromTopic','/rosbridge/classesFromService');

}

Connection.prototype.callService = function(service, json, callback) {
  this.handlers[service] = new Array(callback);
  var call = '{"receiver":"' + service + '"';
  call += ',"msg":' + json + '}';
  this.socket.send(call);
}

Connection.prototype.publish = function(topic, typeStr, json) {
  typeStr.replace(/^\//,'');
  var call = '{"receiver":"' + topic + '"';
  call += ',"msg":' + json;
  call += ',"type":"' + typeStr + '"}';
  this.socket.send(call);
}

Connection.prototype.addHandler = function(topic, func) {
  if (!(topic in this.handlers)) {
    this.handlers[topic] = new Array();
  }
  this.handlers[topic].push(func);
}

Connection.prototype.setOnError = function(func) {
  this.socket.onerror = func;
}

Connection.prototype.setOnClose = function(func) {
  this.socket.onclose = func;
}

Connection.prototype.setOnOpen = function(func) {
  this.socket.onopen = func;
}

Connection.prototype.setOnMessage = function(func) {
  this.onmessage = func;
}

ros.Connection = Connection;

In fact, when I type rosrun rosbridge_server rosbridge_websocket, it gives me this error

[ERROR] [WallTime: 1399303416.415417] [Client 0] Received a rosbridge v1.0 message.  Please refer to rosbridge.org for the correct format of rosbridge v2.0 messages.  Original message was: {"receiver":"/rosjs/services","msg":[]}
[ERROR] [WallTime: 1399303416.415678] [Client 0] Received a rosbridge v1.0 message.  Please refer to rosbridge.org for the correct format of rosbridge v2.0 messages.  Original message was: {"receiver":"/rosjs/topics","msg":[]}

That rosjs appears in this code: h t t p://pastebin.com/eSYAEaNd (I haven`t enough karma for pub links) (I put here because is long)

Thanks guys

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-05-06 21:12:28 -0500

jihoonl gravatar image

I think the old rosjs code is not compatible anymore. Take a look roslibjs in RobotWebTools. It is new version of rosjs library with a lot more functionalities.

https://github.com/RobotWebtools/rosl...

http://robotwebtools.org/

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-05-05 05:11:15 -0500

Seen: 387 times

Last updated: May 06 '14