Skip to content

Various performance optimizations #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: humble
Choose a base branch
from
Open

Conversation

DanBmh
Copy link

@DanBmh DanBmh commented Jan 29, 2025

Reduced the image grabbing/processing time by about 30% for my a2A1920-160umBAS.
Instead of 18ms per frame it now only takes 12ms per frame.

Influence of changes:

  • drop camera reconnecting and just fail (-1ms)
  • ignore encoding changes on runtime (-0.25ms)
  • default disabled status/params publishers (-4ms)
  • optimized bit shift and chunking at grab (-0.5ms and -0.5ms)

The main reason for the time improvements is that the api calls in those code snippets take a lot of time.
There should be further optimization options in other methods as well. Basically the best option might be a complete reimplementation of the parameter handling which stores/updates them as class attributes each time they are changed, so that they don't need to be requested every time.

@FrancoisPicardDTI
Copy link
Collaborator

Hello @DanBmh
Thank you for your contributions! I can understand why you did that but what annoys me is that with your version, it is not possible for the user to change the chunk mode and the encoding at runtime, and it does not allow to reconnect the camera anymore if it is disconnected. I was not the philosophy followed when the driver has been developed in the first place. I need to think about how to make it more flexible, maybe through services. I am keeping the PR opened for now.

@DanBmh
Copy link
Author

DanBmh commented Feb 25, 2025

At least with my setup (ubuntu22+docker), the camera reconnection on the humble branch does not work if i plug out and in the USB cable:

cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495885.456362582 [basler.pylon.ros2.pylon_ros2_camera_node] [INFO] Start image grabbing if node connects to topic with a spinning rate of: 50 Hz
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495885.476494357 [basler.pylon.ros2.pylon_ros2_camera_node] [INFO] Camera not calibrated

cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495950.812080644 [basler.pylon.ros2.pylon_ros2_camera_base] [ERROR] Error: 3791651074 The buffer was cancelled.
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495950.812116461 [basler.pylon.ros2.pylon_ros2_camera_base] [ERROR] Error: Grab was not successful
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495950.812394933 [basler.pylon.ros2.pylon_ros2_camera_node] [ERROR] Pylon camera has been removed, trying to reset
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495952.819122322 [basler.pylon.ros2.pylon_ros2_camera_parameter] [WARN] Gain and exposure are specified as startup parameters and hence assumed to be fixed! The specified brightness (100) can't be reached! Brightness is going to ignored by only setting gain and exposure.
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495952.819168749 [basler.pylon.ros2.pylon_ros2_camera_parameter] [INFO] Autoflash: 0, line2: 1, line3: 1
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495952.819181503 [basler.pylon.ros2.pylon_ros2_camera_parameter] [INFO] No Device User ID set -> Will connect the first available camera device
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495953.124181208 [basler.pylon.ros2.pylon_ros2_camera] [ERROR] No available camera device
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495953.124217186 [basler.pylon.ros2.pylon_ros2_camera_node] [INFO] No user id for the camera has been set
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495953.124258573 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Wait and retry to connect until the specified camera is available...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495953.429658747 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495955.428251870 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495957.430157608 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495959.441227654 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495961.441847787 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495963.441292865 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495965.441525395 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495967.441569580 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495969.441296377 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495969.441330912 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] No available camera. Keep waiting and trying...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495971.440272426 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...
cam_publisher-1    | [pylon_ros2_camera_wrapper-1] 1740495973.442528839 [basler.pylon.ros2.pylon_ros2_camera_node] [WARN] Failed to connect camera device with device user id: . Trying again in a bit...

@DanBmh
Copy link
Author

DanBmh commented Feb 25, 2025

I have retested the two branches (this and humble) again today, and interestingly the delay benefit was much lower this time.
Instead of 6ms the improvement was now only about 1ms. I don't know why...

Maybe you could test the delay difference with one of your cameras?
But even though if the improvement might be lower yet, I still think it's worth to drop some (very rarely used?) features for notable latency improvements.

I've measured delay with:

ros2 topic delay /camera01/pylon_ros2_camera_node/image_raw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants