berndpfrommer / flir_spinnaker_ros2

ros2 driver for flir spinnaker SDK
27 stars 27 forks source link

Framerate drop issues #28

Closed Thomas-Merlet closed 1 year ago

Thomas-Merlet commented 1 year ago

Hi,

I'm running into issues while testing the driver in ROS2.

I'm able to compile and launch the driver without issues, correctly connecting to a USB3 or a GiGE FLIR Blackfly BFLY-U3-23S6C. I'm trying to get the image at 20Hz.

However, I've encountered the following issues:

OS: Ubuntu 20.04 LTS ROS: ROS2 Galactic Spinnaker: 3.0.0.118 flir_spinnaker_ros2: 63e17e1

Thanks for your help

berndpfrommer commented 1 year ago

I didn't quite understand this part of your comment: "The flir_spinnaker_ros2 driver outputs drop at about 90%, from 20Hz to 5Hz.". Could you please post a sample of the driver's log to the console?

Without the driver log it's hard to say what's going on but from what you write it feels like this is a ROS2 issue more than a driver issue. A couple of other data points that would be interesting to know:

A warning about ros2 topic hz: it is not an accurate tool for measuring frequency because its code is so inefficient that it may drop data itself. Check CPU load of that process to see that it is not maxing out on CPU. To be fair at 20hz it should not be a problem, but just something to be aware of. The camera driver itself is actually fairly simple. It takes an image from the camera and publishes it. Unless it fails to call to publish(), the problem is in ROS2 land, or the way the driver is using it, i.e. the quality-of-service profile used: https://github.com/berndpfrommer/flir_spinnaker_ros2/blob/63e17e1b793b99ff0fa87d8f5009a3a041f09549/src/camera_driver.cpp#L580 Feel free to experiment with "image_queue_size". You can also try to just use the default profile by commenting out the lines that modify the default profile (following the line linked above). The following suggestion will not help you with viewer issues, but may be interesting for other subscribers in your setup. You can run the the driver as a composable node in the same address space as the consumer. This way you get better performance and bypass the middleware. The stereo launch script gives an example of how to do that: https://github.com/berndpfrommer/flir_spinnaker_ros2/blob/master/launch/stereo_synced.launch.py Lastly, maybe the nuclear option of changing the middleware will make a difference: https://docs.ros.org/en/foxy/How-To-Guides/Working-with-multiple-RMW-implementations.html

berndpfrommer commented 1 year ago

And another thing: you are the first one to report a blackfly camera working. Would you mind posting your config file (or submit a pull request). This way people will know that the driver works for that camera as well and they have a config file to start with.

Thomas-Merlet commented 1 year ago

Many thanks for your detailled explanation.

Here is the ouptut of the driver when using the default configuration and using multiple subscribers as ROS2 nodes:

[camera_driver_node-1] [INFO] [1673626296.412305334] [camera_front_center_tele]: frame rate in: 20.0089 Hz, out:4.95549 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626301.442486003] [camera_front_center_tele]: frame rate in: 20.0081 Hz, out:5.16883 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626306.471832320] [camera_front_center_tele]: frame rate in: 20.0089 Hz, out:5.16964 Hz, drop: 296%
[camera_driver_node-1] [INFO] [1673626311.509092495] [camera_front_center_tele]: frame rate in: 20.0087 Hz, out:5.16155 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626316.540432215] [camera_front_center_tele]: frame rate in: 20.0083 Hz, out:4.96883 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626321.575739543] [camera_front_center_tele]: frame rate in: 20.0088 Hz, out:5.16358 Hz, drop: 284.615%
[camera_driver_node-1] [INFO] [1673626326.415927242] [camera_front_center_tele]: frame rate in: 20.0087 Hz, out:4.95845 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626331.445957968] [camera_front_center_tele]: frame rate in: 20.0107 Hz, out:5.16895 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626336.484135379] [camera_front_center_tele]: frame rate in: 20.0108 Hz, out:5.16059 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626341.512418516] [camera_front_center_tele]: frame rate in: 20.0088 Hz, out:4.97188 Hz, drop: 296%
[camera_driver_node-1] [INFO] [1673626346.549061657] [camera_front_center_tele]: frame rate in: 20.0088 Hz, out:4.96363 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626351.579308780] [camera_front_center_tele]: frame rate in: 20.0083 Hz, out:5.16873 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626356.421895946] [camera_front_center_tele]: frame rate in: 20.009 Hz, out:5.16253 Hz, drop: 288%
[camera_driver_node-1] [INFO] [1673626361.453958466] [camera_front_center_tele]: frame rate in: 20.0089 Hz, out:4.96814 Hz, drop: 296%
[camera_driver_node-1] [INFO] [1673626366.484383825] [camera_front_center_tele]: frame rate in: 20.0092 Hz, out:4.96976 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626371.523109438] [camera_front_center_tele]: frame rate in: 20.0089 Hz, out:5.16006 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626376.554924052] [camera_front_center_tele]: frame rate in: 20.0086 Hz, out:5.1671 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626381.390647718] [camera_front_center_tele]: frame rate in: 20.0089 Hz, out:4.96307 Hz, drop: 295.833%
[camera_driver_node-1] [INFO] [1673626386.427591036] [camera_front_center_tele]: frame rate in: 20.0085 Hz, out:4.96332 Hz, drop: 300%
[camera_driver_node-1] [INFO] [1673626391.459119221] [camera_front_center_tele]: frame rate in: 20.0088 Hz, out:5.16743 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626396.495255580] [camera_front_center_tele]: frame rate in: 20.0088 Hz, out:5.1627 Hz, drop: 288.462%
[camera_driver_node-1] [INFO] [1673626401.526636468] [camera_front_center_tele]: frame rate in: 20.0084 Hz, out:5.16757 Hz, drop: 284.615%
[camera_driver_node-1] [INFO] [1673626406.561349746] [camera_front_center_tele]: frame rate in: 20.009 Hz, out:5.16411 Hz, drop: 300%

We've made other tests based on your recommandations and here are the results:

We are struggling to get a smooth visualization of the image as rqt_image_view is not implement as a composable node. As you said, we believe based on those results that the issue is more on related to ROS2 than to the driver code itself.

For the config file, we've used the blackfly_s_gige.launch.py and just changed the serial number.

berndpfrommer commented 1 year ago

After seeing the driver output I must back paddle on my claims about this being a ROS2 issue. Obviously the drop rate > 100% is nonsense. I fixed this with PR #29. However the driver is not as simple as I thought: it has the outgoing ROS2 queue (managed by the image_queue_size parameter) but also an internal queue (buffer queue) that I had forgotten about. From all I can tell it was that queue that was dropping the frames. I added a new parameter ("buffer_queue_size") so you can now configure it. Please try and see if that makes a difference. The hard coded default size before was 2 images. Now the question is why that queue fills up in your case and not for me. My laptop and can run 5 viewers (rqt_image_view) and 1 rostopic hz (which reports the right frequency btw) with my blackfly S at 66Hz. Zero drops, and all viewers look smooth. Each viewer consumes about 70%CPU. This is with ROS2 galactic running the default middleware (I presume cyclone). The fact that you are seeing drops in the buffer queue means that the call to publish() via the ROS2 framework takes an unreasonable amount of time. This feels like a setup issue. Do you have another host that you can run on, with a completely fresh ROS2 installation?

berndpfrommer commented 1 year ago

I'm hitting strange issues too, but only when the network is congested. These issues are completely in ROS2 land. I raised this as a question here.

berndpfrommer commented 1 year ago

Closing this issue because it seems to be a ROS2 middleware problem that cannot be addressed by the driver. Please re-open if new leads about the root cause of this.