在ros2中发布图像消息时帧率低
我有一个 ROS 节点,它从相机传感器获取图像帧并将图像消息发布到sensor_msgs::image 类型的主题。我运行一个部署节点的 ros2 可执行文件。我注意到相机传感器提供帧的速率为 30 fps,但“ros2 topic hz”返回的帧速率相对较低,即 10 Hz 左右。我使用“ros2 topic echo”的输出验证了这一点,其中仅发布了大约 10 条具有相同“sec”(秒)值的消息。
如此看来,主题发布机制涉及了很大的开销。 最有可能的是,整个图像帧都被复制,这导致了低帧率。我想确认一下是否确实如此,即ros2在发布到主题时是否复制了整个消息?如果是,有哪些解决方法?看来使用进程内通信(使用组件)可能是一种解决方法。但请注意,我只部署一个节点并将消息发布到该节点的某个主题,也就是说,还没有第二个节点正在使用这些消息。
问候
I have a ROS node that gets image frames from a camera sensor and publishes image messages to a topic of type sensor_msgs::image. I run a ros2 executable which deploys the node. I notice that the rate at which the camera sensor provides the frames is 30 fps but the frame rate returned by "ros2 topic hz" is comparatively quite low, that is, around 10 Hz. I verified this using the output of "ros2 topic echo" wherein only around 10 messages were published with the same "sec" (second) value.
So, it seems that a large overhead is involved in the topic publishing mechanism.
Most likely, entire image frames are being copied which is causing low fps. I would like to confirm whether this is indeed the case, that is, does ros2 copies the entire message while publishing to a topic? And if yes, what are the workarounds to that? It seems that using intra process communication (using components) might be a workaround. But note that I am only deploying one node and publishing messages to a topic from it, that is to say, there is no second node which is consuming those messages yet.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以想到为什么
ros2 topic hz
报告的频率低于预期的几个原因。Python 发布者和大数据(如图像)存在已知的性能问题。已经做出了改进,但旧版本的 ROS 2(Gactic 或更早版本)中仍然存在(相关 Github问题)。我不知道这些问题是否会影响 Python 订阅,但我想从 C 转换为 Python 会产生一些开销(ros2 topic hz 正在这样做)。您可以尝试使用 C++ 节点订阅,看看是否有任何区别。
底层机器人中间件 (RMW) 也可能是延迟增加的根源。在尝试发送大数据时存在各种问题。您可以查看有关针对您的用例调整中间件的文档:https://docs.ros.org/en/rolling/How-To-Guides/DDS-tuning.html
为了利用进程内通信,我建议用 C++ 编写发布者和订阅者节点作为组件,可以灵活地在自己的进程中运行或加载到一个公共进程中(让它们使用指针来传递数据)。您还可以将 RMW 配置为使用共享内存(与您如何使用 ROS 无关),但我不会在这里讨论这一点,因为这取决于您使用的 RMW。
I can think of a couple reasons why the reported frequency from
ros2 topic hz
is reporting a lower frequency than expected.There are known performance issues with Python publishers and large data (like images). Improvements have been made, but still exist in older version of ROS 2 (Galactic or earlier) (related Github issue). I don't know if these issues affect Python subscriptions, but I imagine there is some overhead in converting from C to Python (which
ros2 topic hz
is doing). You could try subscribing with a C++ node and see if that makes any difference.The underlaying robot middleware (RMW) may also be a source of increased latency. There have been various issues documented in trying to send large data. You can check out this documentation on tuning the middleware for your use-case: https://docs.ros.org/en/rolling/How-To-Guides/DDS-tuning.html
To take advantage of intraprocess communication, I recommend writing your publisher and subscriber nodes in C++ as components, which have the flexibility of being run in their own process or loaded into a common process (letting them use pointers to pass around data). You can also configure the RMW to use shared memory (agnostic to how you're using ROS), but I won't get into that here since it depends on what RMW you are using.
您可以尝试使用 usbcam pkg 来获取相机源。
该 pkg 位于 cpp 和传感器 QoS 中。所以你应该获得最佳速度。
安装:
可以回显主题:
附上image_raw/uncompressed链接。
https://index.ros.org/r/usb_cam/
You can try using usbcam pkg to get the camera feed.
This pkg is in cpp and sensor QoS. So you should get the best speed.
installation:
you can echo the topic: image_raw/uncompressed
link attached.
https://index.ros.org/r/usb_cam/