ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size

2023-05-16

ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size

ref  link

===============

queue_size: publish() behavior and queuing

publish() in rospy is synchronous by default (for backward compatibility reasons) which means that the invocation is blocking until:

  • the messages has been serialized into a buffer
  • and that buffer has been written to the transport of every current subscriber

If any of the connections has connectivity problems that might lead to publish() blocking for an indefinite amount of time. This is a common problem when subscribing to topics via a wireless connection.

(sonictl: publish() 在rospy 里是同步进行的,为了向老版兼容。这就意味着对消息的调用会出现阻塞。直到:
      >> message 序列性地进入 buffer
      >> 并且buffer 已经被写入每一个subscriber的 transport(运输机)
如果这些连接出现任何连接性问题, 会导致 publish() 函数阻塞长达一个不确定的时间。这是通过无线网连接时,常见的问题。)

自从 hydro 以后,推荐使用新的 asynchronous ,异步的,发布机制,它更像是roscpp的做法。

为了使用新的发布机制,the keyword queue_size 就要传给 subscribe() ,它定义了在消息丢失之前的最大队列大小。
当publish()被调用时,会把串行化了的数据发到每一个subscriber,连接会异步地发生自不同的线程,但串行化仍将同步地发生。这就使得只有出现连接问题的subscriber会接收不到新的消息。
如果你发布消息的速度快于rospy能发送出去的速度,rospy会把老的messges丢掉。
注意,传输层上还会有个操作系统级的序列,比如TCP/IP发送buffer.

如何选择queue_size值:

  • 0 - 无限长的buffer,直到被取走,不扔掉。可能会导致取不过来,内存耗尽掉~不推荐。
  • 1, 2, 3, - 基本上1秒能有10次数据处理能力的话(),这种小的buffer 就够了。对于只关心最新的值的情况,最适用。
  • 10或更多 - 用户界面msg 是比较好的例子,这种东东不能丢失。另一个例子就是当你想要记录所有的值,这样的值又是高速发布的。

Choosing a good queue_size

It is hard to provide a rule of thumb for what queue size is best for your application, as it depends on many variables of your system. Still, for beginners who do not care much about message passing, here we provide some guidelines.

If you're just sending one message at a fixed rate it is fine to use a queue size as small as the frequency of the publishing.

If you are sending multiple messages in a burst you should make sure that the queue size is big enough to contain all those messages. Otherwise it is likely to lose messages.

Generally speaking using a bigger queue_size will only use more memory when you are actually behind with the processing - so it is recommended to pick a value which is bigger than it needs to be rather than a too small value.

But if your queue is much larger than it needs to be that will queue up a lot of messages if a subscriber is lagging behind. This might lead to messages arriving with large latency since all messages will be delivered in FIFO order to the subscriber once it catches up.

queue_size Omitted

If the keyword argument is omitted, None is passed or for Groovy and older ROS distributions the publishing is handled synchronously. As of Indigo not passing the keyword argument queue_size will result in a warning being printed to the console.

queue_size None

Not recommended. Publishing is handled synchronously which means that one blocking subscriber will block all publishing. As of Indigo passing None will result in a warning being printed to the console.

queue_size Zero

While a value of 0 means an infinite queue, this can be dangerous since the memory usage can grow infinitely and is therefore not recommended.

queue_size One, Two, Three

If your system is not overloaded you could argue that a queued message should be picked up by the dispatcher thread within a tenth of a second. So a queue size of 1 / 2 / 3 would be absolutely fine when using 10 Hz.

Setting the queue_size to 1 is a valid approach if you want to make sure that a new published value will always prevent any older not yet sent values to be dropped. This is good for, say, a sensor that only cares about the latest measurement. e.g. never send older measurements if a newer one exists.

queue_size Ten or More

An example of when to use a large queue size, such as 10 or greater, is user interface messages (e.g. digital_io, a push button status) that would benefit from a larger queue_size to prevent missing a change in value. Another example is when you want to record all published values including the ones which would be dropped when publishing with a high rate / small queue size.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size 的相关文章

  • 如何在 Kivy 中设置小部件/布局的最小允许宽度/高度?

    我有包含 3 个元素的 BoxLayout 我需要第一个和最后一个元素占据最小的可用空间 中间元素具有固定比例 1 1 因此当我调整窗口大小时 侧面元素变得太小并且内容会超出其中 我需要例如标签 或按钮 甚至不同元素的集合 文本始终insi
  • 如何使用 Swift 从资源中加载特定图像[重复]

    这个问题在这里已经有答案了 我是 Swift 新手 我想从资源中加载特殊图像 例如我有 image 1 for iphone 4s email protected cdn cgi l email protection image 2 for
  • 如何设置按钮的大小?

    我将按钮放在带有 GridLayout 的 JPane 中 然后我用 BoxLayout Y AXIS 将 JPanel 放入另一个 JPanel 中 我希望 GridLayout 中的按钮是方形的 我使用 tmp setSize 30 3
  • Tensorflow lite 目标检测示例中相机的屏幕尺寸 [水平屏幕]

    在tensorflow lite示例对象检测中 相机不会拍摄整个屏幕 而只会拍摄一部分 我试图在 CameraActivity CameraConnectionFragment 和 Size 类中找到一些常量 但没有结果 所以我只是想要一种
  • Java Reflection - 获取数组对象的大小

    我想知道是否有人知道如何使用反射获取数组对象的大小 我有一个Vehicles包含类型数组对象的组件Car 车辆 java public class Vehicles private Car cars Getter and Setters C
  • Node Js:Redis 作业在完成其任务后未完成

    希望你们做得很好 我在我的 Nodejs 项目中实现了 BullMQ Bull 的下一个主要版本 来安排发送电子邮件的作业 例如 发送忘记密码请求的电子邮件 所以 我编写了如下所示的代码 用户服务 await resetPasswordJo
  • C# Marshal.SizeOf

    我使用 Marshal SizeOf 来了解我的结构的大小 struct loginStruct public string userName public string password public loginStruct string
  • Nodejs 异步 Promise 队列

    我需要使用速率受限的 API 例如 我一秒钟只能进行 10 个 API 调用 因此我需要等待当前秒结束才能进行另一个 API 调用 为了实现这一目标 我想创建一个可以自行管理的异步队列 它的主要功能是让我向队列添加一个新的 Promise
  • 如何在html中设置按钮的文本大小

    您好 我想在我的网站上有一个按钮 并且我想调整按钮上的文本大小 我该怎么做呢 我的代码如下
  • 如何在Windows上安装机器人操作系统ROSJava?

    ROS 的文档很糟糕 一个很大的讽刺是 ROS 的 Groovy 和 ROSJava 版本的创建是为了让 Windows 等平台上的开发人员能够利用出色的机器人 SDK 而所有安装说明仍然面向 Linux ubuntu 用户 The ROS
  • Laravel 异常队列最大尝试次数超出

    我创建了一个应用程序来向多个用户发送电子邮件 但在处理大量收件人时遇到问题 该错误出现在failed jobs table Illuminate Queue MaxAttemptsExceededException App Jobs ESe
  • 分配给 SQLite 内存数据库的内存大小

    如果使用下面的语法创建一个内存中的sqlite数据库 那么分配给它的最大内存大小是多少 my dbh DBI gt connect dbi SQLite dbname memory 如果内存数据库的大小大于最大可用内存 将会发生什么情况 假
  • 是否可以更改队列中的元素?

    假设我有一个整数队列 或任何 T 类 我可以更改队列中元素的值吗 更具体地说 如果我将队列定义如下 Queue
  • 如何将队列引用传递给 pool.map_async() 管理的函数?

    我想要一个长时间运行的进程通过队列 或类似的东西 返回其进度 我将其提供给进度栏对话框 当过程完成时我还需要结果 这里的测试示例失败并显示RuntimeError Queue objects should only be shared be
  • queue.empty 并在空时执行 put

    假设我有一个包含两个元素的队列 我使用 get 循环遍历队列弹出项目 我担心一旦弹出第二个元素 循环就会停止循环 并且由于某些错误 我需要重新处理它 所以我把它放回队列中 但它不会 因为那时队列是空的 My loop while not q
  • iOS游戏大小问题[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我开发了一款 iOS 通用游戏 我想
  • Dart 中的 DoubleLinkedQueue 和 ListQueue 有什么区别?

    Dart 核心 API 有两个类实现Queue
  • Java Toolkit 获取第二个屏幕尺寸

    我的计算机上插入了两个屏幕 想知道 JFrame 或 Toolkit 中是否有方法可以检测窗口位于哪个屏幕上 我有这个代码 java awt Toolkit getDefaultToolkit getScreenSize 它获取主屏幕的屏幕
  • 为什么 AbstractCollection 没有实现 size() ?

    When sub classing AbstractCollection I must still implement size even though I believe there is a reasonable correct tho
  • 使用 Matplotlib、PyQt 和 Threading 进行实时绘图导致 python 崩溃

    我一直在努力研究我的 Python 应用程序 但找不到任何答案 我有 PyQT GUI 应用程序 它使用 Matplotlib 小部件 GUI 启动一个新线程来处理 mpl 小部件的绘图 恐怕我现在通过从另一个线程访问 matplotlib

随机推荐