0
$\begingroup$

Rosanswers logo

I want to have a subscriber that is able to print the rate at which a message is being sent using C++, what is the best way to do it?

The subscriber works in a really slower rate than the publisher.

Edit :

The subscriber is defined in a different process that has its own loop rate and the publisher has its own loop rate too, so basically, the callback function of a subscriber is called when a message is published but with a maximum rate of the loop of the subscriber process. (I don't know if I've explained myself well)


Originally posted by drone_lab on ROS Answers with karma: 1 on 2020-01-22

Post score: 0


Original comments

Comment by Delb on 2020-01-22:\

The subscriber works in a really slower rate than the publisher.

Can you explain this ? The callback function of a subscriber is called when a message is published on the subscribed topic. Unless you do operations that take time in your callback (which you shouldn't), it should be the same rate as the publisher.

Comment by Delb on 2020-01-22:
If I understand correctly you want to get the rate of a publisher using your current subscriber that has its loop rate slower than the publisher's one ? Can you change anything or is it fixed ? If you can't you could simply add a new node only subscribing to your publisher with a higher spin rate.By recording the time between two message received you could find the rate of your publisher.

Comment by drone_lab on 2020-01-22:
That's a good approach, but the publisher rate is unknown to me and I don't want to create a node with a high spin rate (computational cost). Is there any other aproach? (I'll think about your idea, it is actually something that could work)

Comment by Delb on 2020-01-22:
A node with only a subscriber doesn't add a lot of computational cost since you are either sleeping or either in your callback function.

But i forgot to ask : Do you want to get the rate to actually use the value found or is it simply to find out the rate because it's currently unknown ?

Comment by drone_lab on 2020-01-22:
Well, we want to get the rate as an information value, we work with drones and sometimes it's important to us to know that value for some publishers. I'm creating an interface that shows data from the drone and different process. Each different drone has different rates and sometimes things are not working properly because of that.

Comment by lucascoelho on 2020-01-22:
If you don't want to use a very high loop rate, you can then write a node using ros::spin and a timer. It will answer to callbacks of your subscriber as soon as a message is received, but will only execute your main function in the rate you have specified for your timer. Take a look here: https://yuzhangbit.github.io/tools/several-ways-of-writing-a-ros-node/

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I believe the canonical way to do this -- even from a roscpp application -- would be to use Topic statistics (and the support in rqt_graph).

This comes with a bit of overhead though: ros/ros_comm#1626.

The advantage would be this requires no additional subscribers ( @drone_lab : the "computational cost" is not in spinning, it's in serialising the messages to an additional subscriber).


Originally posted by gvdhoorn with karma: 86574 on 2020-01-22

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

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