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

TCP socket with ROS

asked 2013-11-30 16:35:42 -0600

crpizarr gravatar image

updated 2014-01-28 17:18:41 -0600

ngrennan gravatar image

Hi.I have to make a node that publishes a service and its callback is a function that communicates with an embedded device (non running ROS) through TCP, send some bytes and close the connection. I want to make the node in C++, so I' have to write the code to create and use a socket. But, as far as I know, ROS uses TCP to communicate nodes, so:

Is there a way to use ROS functionalities to communicate through TCP, instead of code my own sockets?

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-12-01 11:23:44 -0600

mirzashah gravatar image

updated 2013-12-07 13:35:09 -0600

Your question is a bit confusing. "Sockets" are an abstraction provided by the operating system for a variety of networking protocols -- the most common of which tend to be TCP/IP or UDP/IP sockets. In other words, to communicate over TCP you have to create a socket.

ROS nodes inherently already communicate through TCP by default. When you subscribe to a topic, your node sends an XMLRPC request (which is HTTP over TCP btw) to the ROS master looking for nodes which publish the topic. If one exists, the master returns the host and port for the node which is advertising the topic. Likewise when one advertises a topic, XMLRPC is used to register with the master the host/port pair. When a subscribing node receives the host IP + port, it connects to that address over XMLRPC (the node has an internal XMLRPC server) which is used to negotiate a straight TCP connection with ROS with that node. For more details see the technical overview: http://wiki.ros.org/ROS/Technical%20Overview

Once the TCP connection is established, the communication protocol is dictated by "TCPROS" -- i.e. the transport protocol for ROS on top of TCP (similarly there's UDPROS). You can find details of this protocol here if you choose to reimplement it. http://wiki.ros.org/ROS/TCPROS

All of the TCP code has already been taken care of in "roscpp". I would attempt to port roscpp to your embedded device before attempting to reimplement TCPROS. Not only would you have to reimplement TCPROS, you would also have to deal with the ROS master which requires XMLRPC.

Another option is having an "adapter" process running on a machine communicating with your embedded device. This adapter process communicates with the embedded device using a straight TCP socket. The adapter can subscribe to any topics the embedded device is interested in and translate them to messages in the protocol you dictate. Likewise the adapter can convert messages sent by the embedded device into ROS messages that can then be published once received and translated by the adapter.

edit flag offensive delete link more

Comments

Thanks for your answer. In fact, the software I want to build is an "adapter", as you say.Unfortunately, I can't program the embedded device.But, My point is, given that TCPROS uses TCP it creates connections and so, is there a way to use that code to create raw TCP connections?

crpizarr gravatar image crpizarr  ( 2013-12-01 12:33:12 -0600 )edit

TCPROS is just a protocol...the implementation of this is specific to the client library for each language (e.g.. roscpp, rospy, rosjava, roslisp, etc). If you're asking if there's a TCP abstraction provided by ROS that can be used directly (as in a layer above sockets)...you might be able to grab the code from one of the many client libraries...but I doubt that an effort was made to make those easily reusable. If you just want a higher level api than sockets, you can try things like Boost ASIO.

mirzashah gravatar image mirzashah  ( 2013-12-01 13:24:53 -0600 )edit

Ok. I thought ROS offered easy TCP connections, but I looked into roscpp source code and the code is very ugly, indeed. Thanks anyway for your answer, I guess I will have to code my own little tcp library or study Boost ASIO.

crpizarr gravatar image crpizarr  ( 2013-12-01 15:00:58 -0600 )edit

Well there really isn't much to a TCP socket...there are 4 or 5 functions that you really deal with. Here's a wrapper specifically for TCP sockets i wrote many years back that you could possibly use for reference that has been tested on Linux and Windows: https://github.com/mirzashah/TastySocket The library takes care of managing the connection behind the scenes and provides you with two calls "Send" and "Receive". It also is not tied to any specific protocol.

mirzashah gravatar image mirzashah  ( 2013-12-01 15:43:42 -0600 )edit
0

answered 2015-12-06 14:16:56 -0600

mrtwister gravatar image

Hi@all,

I also need to implement something that could send data from a not-ROS-running System(A) to a ROS-running System(Z) and later sending data from Z back to A, via using a Socket.

Did you caught some new experience since the last post about this topic?

Thanks Lars

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-11-30 16:35:42 -0600

Seen: 14,796 times

Last updated: Dec 07 '13