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

Using rosbridge protocol to talk with MATLAB

asked 2013-12-07 06:53:30 -0600

mozcelikors gravatar image

updated 2013-12-13 04:29:59 -0600

Hello everybody,

I'm working on a project in which I have to communicate between MATLAB and ROS. To do this, I found rosbridge protocol easiest. The rosbridge server opens a socket on port 8080 (using customized launchfile) ( or 9090 by default).

To talk with it through MATLAB, I think it would be good to use tcpip library and send JSON string message. https://github.com/RobotWebTools/rosbridge_suite/blob/hydro-devel/ROSBRIDGE_PROTOCOL.md is the link I'm following to learn about rosbridge protocol.

But I don't know that it would work. (doesn't work for me so far) Does rosbridge protocol parses the string JSON that I sent from MATLAB and advertise/publish/subscribe topics automatically? I've greated a simple /chatter in order to test my hypothesis but I can't get it working. Anyway, I need some help figuring out rosbridge protocol and solving the problems that I've mentioned.

The procedure that I've followed is like this:

(http://wiki.ros.org/rosbridge_suite/Tutorials/RunningRosbridge)

I've installed the rosbridge using this:

sudo apt-get install ros-groovy-rosbridge-server

Then, I've launched the server:

roslaunch rosbridge_server rosbridge_websocket.launch

On the client side, I've used the tcpip MATLAB library

(http://www.mathworks.com/help/instrument/tcpip.html)

Start a TCP/IP echo server and create a TCPIP object.

echotcpip('on',8080)
t = tcpip('localhost',8080);
fopen(t)
JSON_MSG = '';
fwrite(t,JSON_MSG)
fclose(t)
echotcpip('off')

I've entered something on JSON_MSG part but I couldnt receive any data on server side (simply using rostopic echo). Can anybody please give me some ideas on how to use this json message or whether this procedure would work or not? Note that I use ROS groovy with Ubuntu 12.04. Any help will be greatly appreciated. Thank you.

UPDATE: I've tried the following JSON message, but something is wrong. No data is being received from the server side.

{ "op": "publish",  
  "topic": "/gz/cmd_vel", 
  "msg":"{ "linear": "{x : 0.8, y:0.2, z:0.3}", 
         "angular": "{x : 0, y:0, z:0}" }"
}

UPDATE2: I've installed rosbridge_tcp, and run it. Now, when I try to send data from MATLAB, I get the following error on the server side. Although, it does seem OK, when there's no data sent.

[ERROR] [WallTime: 1386952042.195641] [122.162000] Unable to accept incoming connection.  Reason: __init__() got an unexpected keyword argument 'parameters'
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 45997)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "./rosbridge_tcp", line 100, in finish
    self.protocol.finish()
AttributeError: RosbridgeTcpSocket instance has no attribute 'protocol'
----------------------------------------
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-03-25 22:37:43 -0600

mgruhler gravatar image

I know, this is actually quite old by now...

I stumbled upon the same problem recently. If you do not build the rosbridge_suite package that you clone, i guess you include the old rosbride_protocol.py (installed one) which simply does not have the parameter keyword in it's __init__ function. So you can fix it by checking out the current groovy-devel/hydro-devel branch into your workspace and build it with catkin_make (even though it is mainly python).

edit flag offensive delete link more
0

answered 2013-12-09 02:05:05 -0600

rtoris288 gravatar image

When you are launching rosbridge, you are launching a WebSocket server. However, in your question, you mention you are using a TCP client library. These are not the same thing and then rosbridge will not accept the TCP connection (WebSockets are an extension of HTTP). Instead, try using the TCP server version of rosbridge (https://github.com/RobotWebTools/rosbridge_suite/blob/groovy-devel/rosbridge_server/scripts/rosbridge_tcp.py).

edit flag offensive delete link more

Comments

Ah, you're right. I will check that out and get back to you. Thanks for the answer.

mozcelikors gravatar image mozcelikors  ( 2013-12-09 09:56:27 -0600 )edit

Strangely, when I do git clone this, rosbridge_tcp does not appear in scripts folder

mozcelikors gravatar image mozcelikors  ( 2013-12-13 03:40:26 -0600 )edit

The default branch is hydro-devel, make sure you check out groovy-devel.

rtoris288 gravatar image rtoris288  ( 2013-12-13 03:44:00 -0600 )edit

sorry that i'm a beginner but where do i check exactly?

mozcelikors gravatar image mozcelikors  ( 2013-12-13 03:45:36 -0600 )edit

Ah, I got what you say, i'll check

mozcelikors gravatar image mozcelikors  ( 2013-12-13 03:57:08 -0600 )edit

Okay, rosbridge_tcp is ready. When I send the data I get an error, (at least connection is now correct). Please see the UPDATE2

mozcelikors gravatar image mozcelikors  ( 2013-12-13 04:28:31 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-12-07 06:53:30 -0600

Seen: 1,715 times

Last updated: Mar 25 '14