Ask Your Question
0

when is the callback function called

asked 2015-04-20 09:30:44 -0600

Naman gravatar image

Hi all,

I am slightly confused about when the callback functions are called from ROS Subscriber. Taking the following code as example:

#include "ros/ros.h"
#include <geometry_msgs/Vector3.h>

void callback_fn(const geometry_msgs::Vector3::ConstPtr& ticks)
{
}

int main(int argc, char **argv)
{
    ros::init(argc,argv,"test");
    ros::NodeHandle n;
    ros::Subscriber re_msg = n.subscribe("re_ticks",1000,callback_fn);
    ros::spin();
}

So my question is whenever ros::spin() is called, does it call all the callback functions or only those for which the value of the message on the corresponding topic has changed? So in the above example, Is callback_fn called every time ros::spin() is executed or only when the message on the topic "re_ticks" has changed?

Thanks in advance.
Naman Kumar

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-04-20 09:37:24 -0600

dornhege gravatar image

Messages don't "change". Messages are send from someone and the received. So, the callback will be called every time a new message is received. This is independent from how fast the loop inside ros::spin goes (unless messages arrive faster than it can handle them) and from the values of the message, i.e., if someone sends the same message 5 times with the same unchanged values, the callback should be called 5 times.

edit flag offensive delete link more

Comments

yes..that makes sense..Thanks!

Naman gravatar imageNaman ( 2015-04-20 09:58:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-20 09:30:44 -0600

Seen: 828 times

Last updated: Apr 20 '15