当前位置:网站首页>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().
边栏推荐
- 博云,站在中国容器潮头
- properties文件乱码
- [unity] use C in unity to execute external files, such as Exe or bat
- Which securities company is better for a novice to open a stock trading account? How is it safer to speculate in stocks??
- 腾讯钱智明:信息流业务中的预训练方法探索与应用实践
- 陈强:阿里千亿级大规模数字商业知识图谱助力业务增长
- vutils. make_ A little experience of grid () in relation to black and white images
- How does Guosen Securities open an account? Is it safe to open a stock account through the link
- Procedure steps for burning a disc
- 带你解决哈希冲突,并实现一个简单hash表,
猜你喜欢

DoS及攻击方法详解

Lm06 the mystery of constructing the bottom and top trading strategy only by trading volume

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

Get and set settings in 26class

LM06丨仅用成交量构造抄底摸顶策略的奥秘

Binary search-1

VCD-影音光碟

wechat_微信小程序中解决navigator进行页面跳转并传递参数问题

Plt How to keep show() not closed

Do you know how to compare two objects
随机推荐
How about opening an account at Guojin securities? Is it safe to open an account?
Lm06 the mystery of constructing the bottom and top trading strategy only by trading volume
wechat_ Solve the problem of page Jump and parameter transfer by navigator in wechat applet
next(iter(dataloader))的一点点体会
让torch.cuda.is_available()从false变成true的一点经验
你了解如何比较两个对象吗
Idea collection code, quickly open favorites collection window
同花顺开户怎么样安全吗?怎么炒股开户
小程序设置按钮分享功能
Clion编译catkin_ws(ROS工作空间包的简称)加载CMakeLists.txt出现的问题
Handwritten promise all
贝叶斯网络详解
I want to know. I am in Zhaoqing. Where can I open an account? Is it safe to open an account online?
vutils.make_grid()与黑白图像有关的一个小体会
陈强:阿里千亿级大规模数字商业知识图谱助力业务增长
RuntimeError: CUDA error: out of memory自己的解决方法(情况比较特殊估计对大部分人不适用)
pycharm如何修改多行注释快捷键
Tsinghua & Shangtang & Shanghai AI & CUHK proposed Siamese image modeling, which has both linear probing and intensive prediction performance!
数据加密标准(DES)概念及工作原理
RSA概念详解及工具推荐大全 - lmn