Open HaFred opened 2 years ago
http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning https://www.ncnynl.com/archives/201702/1298.html
The easiest way of doing that is to do the ros::spin()
which will hang the program.
Or call the ros::spinOnce()
periodically.
ros::spinOnce()
will call all the callbacks waiting to be called at that point in time. It helps on reducing the competition (racing) of different threads in the program.
https://ithelp.ithome.com.tw/articles/10238734
This MOOC also talks about the callback function. The whole series of MOOC is good with sample src, worthy for a try for sure! https://sychaichangkun.gitbooks.io/ros-tutorial-icourse163/content/chapter6/6.3.html
int main()
{
ros::Rate loop_rate(5); // 5Hz
while (ros::ok())
{
Myclass.saveDataToFile();
loop_rate.sleep();
ros::spinOnce();
}
}
https://answers.ros.org/question/11887/significance-of-rosspinonce/
Their input params are different:
Topic Callback needs to put const msg& msg_param
https://blog.csdn.net/qingdu007/article/details/53688625
rostopic echo -b bag_name -p topic_name > file_name.csv # to dump csv from rosbag file
roscpp does not try to specify a threading model for your application. This means that while roscpp may use threads behind the scenes to do network management, scheduling etc., it will never expose its threads to your application. roscpp does, however, allow your callbacks to be called from any number of threads if that's what you want.