HaFred / ROS-DiLearnNavi

Yet Another Navigation Package
0 stars 0 forks source link

ROSCPP Related (e.g., rosbag, callback and spinning, and others...) #7

Open HaFred opened 2 years ago

HaFred commented 2 years ago

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.

HaFred commented 2 years ago

http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning https://www.ncnynl.com/archives/201702/1298.html

Single-threaded Spinning

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

HaFred commented 2 years ago

Chinese 中国大学MOOC

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

HaFred commented 2 years ago

Comparing roscpp & rospy

https://www.jianshu.com/p/997c6108d590

HaFred commented 2 years ago

Control the rate at which ROS updates with spinOnce()

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/

HaFred commented 2 years ago

Srv Callback vs. topic Callback

Their input params are different: Topic Callback needs to put const msg& msg_param https://blog.csdn.net/qingdu007/article/details/53688625

HaFred commented 2 years ago

Multi-threaded Spin

https://xwlu.github.io/wiki/ros/multi-thread/ https://levelup.gitconnected.com/ros-spinning-threading-queuing-aac9c0a793f https://zhuanlan.zhihu.com/p/375418691

HaFred commented 2 years ago

pkgs settup in cmakelist

HaFred commented 2 years ago

rosbag

rostopic echo -b bag_name -p topic_name > file_name.csv  # to dump csv from rosbag file

https://zhuanlan.zhihu.com/p/97148509