Hello, I know that in general a callback function is executed when its associated topic has published values.
What I am wondering is how do the commands spin() and spinOnce() in main affect the callback's execution, because I noticed that when the spin() command is in practice not executed like in the code below the callback is also never executed even though messages are published to the topic
ros::Rate loop_rate(0.1);
while(ros::ok()){
ROS_INFO("Loop: %d\n",stop_msg.data);
stop_pub.publish(stop_msg);
loop_rate.sleep();
}
ros::spin();
on the other hand, when I changed the code in main to the following everything worked perfectly:
ros::Rate loop_rate(0.1);
while(ros::ok()){
ROS_INFO("Loop: %d\n",stop_msg.data);
stop_pub.publish(stop_msg);
loop_rate.sleep();
ros::spinOnce();
}
Could somebody enlighten me? Thank you
Originally posted by smarn on ROS Answers with karma: 54 on 2020-03-16
Post score: 0