Significance of ros::spinOnce()      这个回答写的不错,挖得比较深

he roscpp overview has some background info on callbacks and spinning.

In the background, ROS monitors socket connections for any topics you've subscribed to. When a message arrives, ROS pushes your subscriber callback onto a queue. It does not call it immediately. ROS only processes your callbacks when you tell it to with ros::spinOnce().

This is all part of roscpp's "toolbox, not framework" philosophy. roscpp does not mandate a particular threading model for your node, nor does it demand to wrap your main(). ros::spin() is purely a convenience, a main loop for ROS that repeatedly calls ros::spinOnce() until your node is shut down.

There are a few cases when calling ros::spinOnce() directly is useful.

Processing callbacks at a specific time interval

In rare situations you might want to process ROS callbacks only at certain intervals. Make sure to consider your subscriber queues when doing this. If messages arrive at 100Hz, you call ros::spinOnce() every 5Hz, and your subscriber has a queue_size of 1, you'll drop 95/100 messages! That may or may not be what you want.

Usually a Timer is a better way to inject periodic processing.

Perform processing unsuitable for a ROS callback

Perhaps you are using another library that needs to do its own asynchronous event processing. In that case you need to include its analogue to ros::spinOnce() in your main loop:

ros::Rate r(100);
while (ros::ok())
{libusb_handle_events_timeout(...); // Handle USB eventsros::spinOnce();                   // Handle ROS eventsr.sleep();
}

Integrating ROS with framework X

Many frameworks for GUIs, game programming, etc. do wrap your main(). In that case you just have to play by their rules and find a suitable place to drop in ros::spinOnce().

For example, say you're writing a visualizer using OpenGL and . One way to integrate ROS would be to tell GLUT to call ros::spinOnce() from its main loop every 10ms:

void timerCb(int value) { ros::spinOnce(); }glutTimerFunc(10, timerCb, 0);
glutMainLoop(); // Never returns

ros 节点间通信貌似 也是socket

而spining机制在linux中也有相关概念,可能大概ros就是按照linux系统运行机制设计的吧


callbacks and spinning

这个ros官方对callbacks and spinning 的介绍,值得好好读读

Note: Callback queues/spinning do not have any effect on the internal network communication in roscpp. They only affect when user callbacks occur. They will have an effect on the subscription queue, since how fast you process your callbacks and how quickly messages are arriving determines whether or not messages will be dropped.

(注意Callbacks and Spinning,spinning影响的只有callbacks)

ros::spinOnce()机制 有点东西相关推荐

  1. ROS入门跟着我就够了(二)上 ROS通信机制

    由于这一章东西比较多,我分了上下两篇,下部分可以在< ROS 入门跟着我就够了>专辑中查看 ROS 中的基本通信机制主要有如下三种实现策略: 话题通信(发布订阅模式)服务通信(请求响应模式 ...

  2. ros::spin() 和 ros::spinOnce() 区别及详解

    1 函数意义 首先要知道,这俩兄弟学名叫ROS消息回调处理函数.它俩通常会出现在ROS的主循环中,程序需要不断调用ros::spin() 或 ros::spinOnce(),两者区别在于前者调用后不会 ...

  3. ROS自主导航学习———ROS通信机制

    前言 前面ROS很多都忘记了 ,现在来重新回顾一下内容 ROS 中的基本通信机制主要有如下三种实现策略: 话题通信(发布订阅模式) 服务通信(请求响应模式) 参数服务器(参数共享模式) Action通 ...

  4. ROS通信机制:话题、服务、参数

    目录 话题通信 理论模型 流程 通信样例 自定义消息的通信 服务通信 理论模型 服务通信自定义srv 参数服务器 理论模型 参数操作 话题通信 话题通信是ROS中使用频率最高的一种通信模式,话题通信是 ...

  5. ROS通信机制(一) —— 话题(topic)与msg文件

    文章目录 简述 特点 相关常用命令 通信模型 核心元素 通信过程 代码示例(发布者和订阅者) 发布者(talker.cpp) 订阅者(listener.cpp) 配置 CMakeLists.txt 编 ...

  6. ROS 通信机制(已整理)

    文章目录 节点与节点管理器 ROS通信机制 1. 话题通信 1.1 基本话题通信 1.1.1 C++实现 发布方 demo01_pub.cpp 订阅方 demo01_sub.cpp 1.1.2 Pyt ...

  7. ROS通信机制一---话题通信

    文章目录 总述 1. 话题通信模型 2. 话题通信基本实现示例 2.1 发布者 2.1.1 创建发布者topic_pub.cpp文件 2.1.2 修改CMakeLists.txt文件 2.1.3 编译 ...

  8. ros::spin() 和 ros::spinOnce()

    ROS的回调处理函数spin/spinOnce 作用 区别 使用 作用 spin/spinOnce是ROS消息回调处理函数.它俩通常会出现在ROS的主循环中,程序需要不断调用ros::spin() 或 ...

  9. ROS笔记(6) ROS通讯机制

    ROS笔记(6) ROS通讯机制 1. 通讯机制简介 2. 通讯机制基本要素 3. 通讯机制分类 1. 通讯机制简介 ROS的核心功能是提供一种软件点对点通信机制,一种基于 socket 网络连接的松 ...

最新文章

  1. 兆比特每秒和兆字节每秒_号称100兆、200兆的宽带,为什么实际下载速度只有几MB?...
  2. linux 逻辑运算符and,布尔逻辑运算符
  3. 科大讯飞cordova语音插件填坑及api介绍
  4. 杂项题的基本解题思路——2、图片隐写术
  5. find : 路径必须在表达式之前
  6. 几种机器学习算法的优缺点
  7. linux 关闭桌面环境,Ubuntu 14.04上的Cinnamon桌面环境PPA被关闭
  8. HTML5 2D平台游戏开发#4状态机
  9. Android:自定义标题栏
  10. 假设系统中共有5个{P0,P1,P2,P3,P4}和A,B,C三类资源;A类资源共有10个,B类资源共有5个,C类资源共有7个。在时刻T0,系统资源分配情况如下表8-14所示。
  11. 公募基金资格:社保、养老金、企业年金,三者有什么区别?
  12. [单片机]KeilC51简单流水灯制作与原理
  13. imap服务器怎么填写 网易邮箱,ipad设置163邮箱教程 如何设置163邮箱【详细介绍】...
  14. 开机自动启动QQ和微信,怎样设置取消
  15. MoneyBookers Manul doc
  16. 自己用C语言写RL78 serial bootloader
  17. Thinkadmin v6爆高危漏洞!
  18. Excel与PowerBI 之PowerQuery 编辑界面异同-PowerQuery 系列文章之三
  19. 绘画未来的计算机的图片,未来科技生活绘画图片欣赏
  20. 从pcap文件中解析网络数据包

热门文章

  1. Analytic Functions 分析函数(rank over)
  2. python代码该怎么简化_如何简化这个python代码(从书中分配)?
  3. c++ 终止 超时_C++ 哪里超时了啊?
  4. 为甚serve 修改dev不能跑_初探逆向将电缆调制解调器改装为SDR
  5. 如何设置文字的位置html5,怎么设置文字在表格中的位置
  6. 原生js实现点击按钮切换全屏!
  7. GTK+ 项目名终于去掉了那个加号
  8. Django(五)模型(model)系统 -- 常用字段和字段参数
  9. 浏览器保存密码后自动填充问题
  10. 翻译连载 | 第 9 章:递归(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇...