当前位置:网站首页>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
边栏推荐
- 92. 反转链表 II-字节跳动高频题
- MySQL installation
- Change Oracle to MySQL
- SiteServer CMS5. 0 Usage Summary
- Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
- ASP. Net core configuration options (Part 1)
- [WPF binding 3] listview basic binding and data template binding
- Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
- tidb-server 的配置文件在哪里?
- Sword finger offer 22 The penultimate node in the linked list - speed pointer
猜你喜欢
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
.Net Core3. 1 use razorengine NETCORE production entity generator (MVC web version)
Halo open source project learning (II): entity classes and data tables
Kubernetes 服务发现 监控Endpoints
01 - get to know the advantages of sketch sketch
[WPF binding 3] listview basic binding and data template binding
基于51单片机红外无线通讯仿真
stm32入门开发板选野火还是正点原子呢?
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
Use of todesk remote control software
随机推荐
EF core in ASP Generate core priority database based on net entity model
C语言函数详解
Use of todesk remote control software
Using quartz under. Net core - [1] quick start
Model problems of stock in and stock out and inventory system
Read software engineering at Google (15)
Clickhouse SQL operation
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
Shell - introduction, variables, and basic syntax
C# Task. Delay and thread The difference between sleep
XTask与Kotlin Coroutine的使用对比
Manually implement call, apply and bind functions
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
C listens for WMI events
In embedded system, must the program code in flash be moved to ram to run?
JVM类加载机制
MySQL installation
Use of five routing guards
圆环回原点问题-字节跳动高频题
Halo open source project learning (II): entity classes and data tables