How can I know the rate the publisher is sending a msg with c++?
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)
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.
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.
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)
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 ?
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.
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/se...