当前位置:网站首页>Commonly used functions -- spineros:: and spineros::)
Commonly used functions -- spineros:: and spineros::)
2022-04-23 17:38:00 【Cai Xukun, houchangcun Road】
( One )ros::ok()
Used to check system status , Apply to while Judge the state in the loop
grammar :
while(ros::ok())
{
//...
}
ros::ok() Returns... In the following cases false:
1、 Press down Ctrl-C when .
2、 We were kicked out of the network by a node with the same name .
3、ros::shutdown() Called by another part of the application .
4、 be-all ros::NodeHandles It's all destroyed .
5、 once ros::ok() return false, be-all ROS Calls fail
( Two )ros::Rate
Used to set the cycle frequency , Apply to Publisher Program infinite loop
ros::Rate You can specify the frequency of the loop
ros::Rate loop_rate(10);//10Hz
//...
loop_rate.sleep();
( 3、 ... and )ros::spin() and ros::spinOnce()
Used for processing ROS Callback function for , Apply to Subscriber Processing callback data .
The difference is ros::spin() After calling, it will not return , and ros::spinOnce() After the call, you can continue to execute the subsequent program .
ros::spin() For acyclic scenes ,ros::spinOnce() For scenes with loops .
When to use ros::spin() and ros::spinOnce() Well , If it's just a response topic, Just use ros::spin(). When the program has other repetitive work besides the response callback function , Then do the work in the loop , And then call ros::spinOnce().
1、ros::spin()
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
ros::spin();
return 0;
}
2、ros::spinOnce()
This sentence means to monitor the feedback function (callback). Only listen for feedback , You can't cycle . So when you need to monitor , Just call this function .
This function is more flexible , Especially when I want to control the receiving speed . coordination ros::ok() Excellent results .
ros::Rate loop_rate(10);
while(ros::ok())
{
ros::spinOnce();
loop_rate.sleep();
}
版权声明
本文为[Cai Xukun, houchangcun Road]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231736284895.html
边栏推荐
- 超分之TDAN
- MySQL installation
- JS failed to change all variables and changed to the return method. Finally, the problem was solved
- 198. 打家劫舍-动态规划
- Use of Shell sort command
- flink 学习(十二)Allowed Lateness和 Side Output
- Solution of Navicat connecting Oracle library is not loaded
- 圆环回原点问题-字节跳动高频题
- JVM class loading mechanism
- Change Oracle to MySQL
猜你喜欢
随机推荐
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
In ancient Egypt and Greece, what base system was used in mathematics
If you start from zero according to the frame
Construction of functions in C language programming
470. Rand10() is implemented with rand7()
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
C listens for WMI events
Use of shell cut command
Model problems of stock in and stock out and inventory system
读《Software Engineering at Google》(15)
[WPF binding 3] listview basic binding and data template binding
[difference between Oracle and MySQL]
给 el-dialog 增加拖拽功能
Learning record of uni app dark horse yougou project (Part 2)
圆环回原点问题-字节跳动高频题
Excel quickly and automatically fills the contents of a row on a blank cell
Tdan over half
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
[related to zhengheyuan cutting tools]
Sword finger offer 22 The penultimate node in the linked list - speed pointer