How do I create a ROS topic publisher/subscriber?
Hi all!
I have a sensor from which I read data via a serial communication (port is of type ttyUSB). Now I am thinking of writing two packages, "publisher_node" and "client". What I want is, publisher_node should read data from the sensor continuously, and publish it as a topic (basically just scream out the values). On the other end, in the client package, I have a specific task, during which I want to poll the device for readings.
I think that using a topic rather than a service is much more logical here. Data flow is a unidirectional stream. Its sort of like filling a cup(client) with water from a river(publisher_node). Am I thinking in the right direction?
My System: Ubuntu 11.10 64-bit
ROS version: ROS electric
Here are some of the key questions I have:
1) How do I create a topic for publisher_node? Is there any tutorial online for that? Maybe any step by step procedure..?
2) Once I know how to create a topic, I will do that in publisher_node. Then I will 'rosmake' and 'rosrun publisher_node publisher_node'. After that, I will make sure I have the topic up, by doing 'rostopic list'. All is OK. Now how do I write code/make the client "subscribe" to the topic? Any guidelines here?
3) Also, since this is serial communication, I want a special functionality with the topic. I want the user to have an option of setting the frequency of publishing (i.e how fast the data is screamed out). Is this possible with ROS?
Note: Yes, I am using a serial device, but I have not used rosserial in any way. I am implementing my own serial port by using the termios API in Linux.
Any help is greatly appreciated. Thanks in advance!
Thanks cagatay and Lorenz. The simple publisher/subscriber in the ROS tutorial is what I wanted. I have another question though. It says that spin() keeps on calling all client callback functions till Ctrl+C are pressed or the node is shut down. How can I subscribe at will (and not continuously)?
Best if you open a new question for this. I think, it has been asked recently though: http://answers.ros.org/question/37869/subscribing-and-publishing/
Yep, I will open a new question for this and include what I understood from the tip you just gave me above. Thanks Lorenz :)
Did you find the tutorials hard to locate?
Hi joq, No, in fact, to be totally true, I had skimmed over them about a month ago. I just thought that creating a topic, and listening to the messages on that topic would be a much more complex task than what was given in the tutorial. Turns out it isn't! :)