当前位置:网站首页>Usage and difference between ros:: spinonce() and ros:: spin()
Usage and difference between ros:: spinonce() and ros:: spin()
2022-06-26 18:13:00 【Maccy37】
When running the program , subscribe /scan The topic information has not been transmitted into the laser data , Later, I struggled to ask my friend and found that he didn't write ros::spinOnce(), Unable to call the callback function to pass in laser data . The following is after solving the problem , Refer to other people's blogs , Written study notes .
1. About ros Tutorial on message publishers and subscribers :http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber(c++)
2. After reading the tutorial in the link , We know :
The message publisher is in a while It has been sending circularly “hello world” To the topic (topic)chatter On . Once the message subscriber knows chatter It has data, I'll put this data Pass in as a parameter callback Function , But it has not been implemented yet callback function , But the callback Function is placed in a callback function queue . So when the publisher keeps sending data To chatter Up there , There will be corresponding callback Function into the queue , They have the same function name , But the arguments are different .
So when will it be implemented callback Function? ?
Namely ros::spinOnce() and ros::spin() Thing .
ros::spinOnce()
This sentence means to monitor the feedback function (callback). Only listen for feedback , You can't cycle . When spinOnce When the function is called ,spinOnce Will call the first in the callback function queue callback function , here callback Function is executed , Then wait until next time spinOnce When the function is called again , The second in the callback function queue callback The function will be called , And so on .
therefore , There will be a problem . Because the length of the callback function queue is limited , If the publisher sends data too fast ,spinOnce Too few function calls , This will cause the queue to overflow , some callback Functions will be squeezed out , As a result, it is not implemented to .
ros::spin()
Loop and listen to feedback functions (callback). Once entered spin function , It will not return , It's like it's looping in its own function . As long as the callback function queue has callback Function in , It will immediately execute callback function . If not , It will block , Will not occupy CPU.
for example :
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();
}Can be controlled 10Hz Speed , function callback function , Very convenient .
If only
while(ros::ok())
{
ros::spinOnce();
}This is equal to ros::spin().
Be careful :
These two functions are only related to the receive callback function (callback) of , It has nothing to do with the release . If you want to publish circularly , Can only write circularly publish().
边栏推荐
- KDD 2022 | 如何在跨域推荐中使用对比学习?
- Detailed explanation of MySQL mvcc mechanism
- MYSQL的下载与配置 mysql远程操控
- (multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition
- Applet setting button sharing function
- sql中的几种删除操作
- Comparing the size relationship between two objects turns out to be so fancy
- Boyun, standing at the forefront of China's container industry
- 临时关闭MySQL缓存
- Map和List<Map>转相应的对象
猜你喜欢

Padding percentage operation

深入理解MySQL锁与事务隔离级别

VCD-影音光碟

ISO文件

DoS及攻击方法详解

爬取豆瓣读书Top250,导入sqlist数据库(或excel表格)中

无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!

非对称密码体制详解

RSA概念详解及工具推荐大全 - lmn

Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance!
随机推荐
wm_concat()和group_concat()函数
Procedure steps for burning a disc
properties文件乱码
Properties file garbled
RSA concept explanation and tool recommendation - LMN
In and exceptions, count (*) query optimization
DoS及攻擊方法詳解
A little experience of next (ITER (dataloader))
Eigen库计算两个向量夹角
非对称密码体制详解
CLion断点单步调试
RuntimeError: CUDA error: out of memory自己的解决方法(情况比较特殊估计对大部分人不适用)
No manual prior is required! HKU & Tongji & lunarai & Kuangshi proposed self supervised visual representation learning based on semantic grouping, which significantly improved the tasks of target dete
新手炒股开户选哪个证券公司比较好?怎样炒股比较安全??
Tencent qianzhiming: Exploration and application of pre training methods in information flow business
Chinese (Simplified) language pack
[unity] use C in unity to execute external files, such as Exe or bat
KDD 2022 | how to use comparative learning in cross domain recommendation?
Connected to surface test questions
基于tensorflow的手写数字识别