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

Revision history [back]

This is not something to be done with ROS internals only.

Have a look at the Boost::Thread Library which provides excellent tools for doing this. (Obviously, there are many other tools available.)

To your questions:

1) I guess this cannot be done the way you propose it here. Spawn a new thread (using e.g. Boost) and read the TCP socket therein.

2) This is what boost::mutex and boost::lock is for.

3) I guess the solution you proposed is fine. To achieve this, the thread reading the TCP socket just needs to be running faster than the one publishing the data. If you then write to a (well protected, see question 2) ) member variable, you can use this variable to sync the data and only publish the latest one.

As an example how to do this, (even though they have it basically the other way round, publishing data from a thread) see the old slam_karto node (again, there are probably many other examples out there or directly in boost).

(During my questions, I assumed you'd be using C++ as language of choice. If you plan to do this using pyhton see the Python Threading module)