0
$\begingroup$

Rosanswers logo

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!


Originally posted by Nishant on ROS Answers with karma: 143 on 2012-07-06

Post score: 0


Original comments

Comment by Nishant on 2012-07-06:
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)?

Comment by Lorenz on 2012-07-06:
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/

Comment by Nishant on 2012-07-06:
Yep, I will open a new question for this and include what I understood from the tip you just gave me above. Thanks Lorenz :)

Comment by joq on 2012-07-06:
Did you find the tutorials hard to locate?

Comment by Nishant on 2012-07-06:
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! :)

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

The ros tutorials are always a good starting point. In particular, there are tutorials on how to create a publisher and a subscriber.

For setting the publish frequency, you have a few choices. If it is sufficient to set the rate once, when your node is started up, you can use a ros parameter that is best set using a launch file.

If you need to change the publish rate at run time, you can either use a service or use dynamic_reconfigure. While the former one should be easier to implement, I think the latter one is more flexible. For instance, you can use a nice GUI to change the parameters which is really handy when you are trying to find a good value.


Originally posted by Lorenz with karma: 22731 on 2012-07-06

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

hello,

start from here

http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29 http://www.ros.org/wiki/ROS/Tutorials/ExaminingPublisherSubscriber

this is going to help you

here is a serialport implementation in ros & linux , this might help too

http://bazaar.launchpad.net/~fuzzgun/usbi2c-ros-pkg/trunk/view/head:/src/serialport.cpp


Originally posted by cagatay with karma: 1850 on 2012-07-06

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.