ros-drivers / usb_cam

A ROS Driver for V4L2 USB Cameras
https://ros-drivers.github.io/usb_cam/main/
Other
512 stars 581 forks source link

Frames delay #319

Open BryanBetancur opened 4 months ago

BryanBetancur commented 4 months ago

Hello, thanks for your useful package, I'm having a problem with the publishing frames delay.

Hardware: Nvidia Jetson Orin AGX 64GB

Package Branch: 0.8.0

This is the command that I'm using: ros2 run usb_cam usb_cam_node_exe --remap __ns:=/gary_camera_chest --ros-args -p camera_info_url:=file:///opt/raya_os/ur_dev/ros_pkgs/gary_robot/usb_cam/config/camera_info.yaml -p image_width:=1920 -p image_height:=1080 -p pixel_format:=mjpeg2rgb -p av_device_format:=YUV422P -p framerate:=15.0 -p video_device:=/dev/video12 -p io_method:=mmap

Here is the output that I received:

[INFO] [1707758623.639212489] [gary_camera_chest.usb_cam]: Starting 'default_cam' (/dev/video12) at 1920x1080 via mmap (mjpeg2rgb) at 15 FPS
[swscaler @ 0xaaaadf95b9b0] No accelerated colorspace conversion found from yuv422p to rgb24.
This device supports the following formats:
    Motion-JPEG 1600 x 1200 (15 Hz)
    Motion-JPEG 1600 x 1200 (15 Hz)
    Motion-JPEG 2592 x 1944 (15 Hz)
    Motion-JPEG 2048 x 1536 (15 Hz)
    Motion-JPEG 1920 x 1080 (30 Hz)
    Motion-JPEG 1280 x 1024 (15 Hz)
    Motion-JPEG 1280 x 720 (30 Hz)
    Motion-JPEG 1024 x 768 (30 Hz)
    Motion-JPEG 800 x 600 (30 Hz)
    Motion-JPEG 640 x 480 (30 Hz)
    Motion-JPEG 1600 x 1200 (15 Hz)
    Motion-JPEG 1600 x 1200 (15 Hz)
    YUYV 4:2:2 1600 x 1200 (5 Hz)
    YUYV 4:2:2 1600 x 1200 (5 Hz)
    YUYV 4:2:2 2592 x 1944 (3 Hz)
    YUYV 4:2:2 2048 x 1536 (4 Hz)
    YUYV 4:2:2 1920 x 1080 (5 Hz)
    YUYV 4:2:2 1280 x 1024 (9 Hz)
    YUYV 4:2:2 1280 x 720 (5 Hz)
    YUYV 4:2:2 1024 x 768 (10 Hz)
    YUYV 4:2:2 800 x 600 (20 Hz)
    YUYV 4:2:2 640 x 480 (30 Hz)
    YUYV 4:2:2 1600 x 1200 (5 Hz)
    YUYV 4:2:2 1600 x 1200 (5 Hz)
[INFO] [1707758623.694278969] [gary_camera_chest.usb_cam]: Setting 'brightness' to 50
[INFO] [1707758623.736017760] [gary_camera_chest.usb_cam]: Setting 'white_balance_temperature_auto' to 1
[INFO] [1707758623.736138525] [gary_camera_chest.usb_cam]: Setting 'exposure_auto' to 3
[INFO] [1707758623.753004418] [gary_camera_chest.usb_cam]: Setting 'focus_auto' to 0
unknown control 'focus_auto'

[INFO] [1707758624.070062524] [gary_camera_chest.usb_cam]: Timer triggering every 66 ms

Measurements:

CPU usage: ~51-54% image

ros2 topic hz -w 10 /gary_camera_chest/image_raw
average rate: 4.426
    min: 0.067s max: 0.329s std dev: 0.08411s window: 7
average rate: 4.457
    min: 0.063s max: 1.254s std dev: 0.35312s window: 10
average rate: 2.916
    min: 0.063s max: 1.254s std dev: 0.46261s window: 10
average rate: 2.526
    min: 0.063s max: 1.254s std dev: 0.45798s window: 10
average rate: 9.484
    min: 0.063s max: 0.197s std dev: 0.05948s window: 10
average rate: 7.208
    min: 0.062s max: 0.333s std dev: 0.09574s window: 10
average rate: 9.463
    min: 0.058s max: 0.202s std dev: 0.06166s window: 10
average rate: 8.957
    min: 0.060s max: 0.261s std dev: 0.07271s window: 10
average rate: 8.894
    min: 0.060s max: 0.393s std dev: 0.10173s window: 10
average rate: 10.911
    min: 0.061s max: 0.199s std dev: 0.05287s window: 10

Movement delay is about 9 seconds, to get that time I did a movement in front of the camera and I took the time until the movement appear in camera. (This is my main problem)

When the CPU average is about 5% of usage (anything running except usb_cam) the delay is about 1 second (what is good for me).

I appreciate your help.

BryanBetancur commented 4 months ago

I was subscribing as Reliable and the frames were accumulating, changing the qos to Best Effort solves the delay, however the problem of the fps reduction continues to occur.

kodie-artner commented 4 months ago

We were seeing delays with the ros1 version having a .5 second delay. ultimately we reverted to 0.3.7 to fix the issue.

flynneva commented 4 months ago

@BryanBetancur @kodie-artner so I'd ask here to stay focused on one issue at a time per issue 😅

@BryanBetancur glad adjusting the QoS settings helped you. If you are looking to optimize your system and go for performance at high resolution then I'd recommend checking out the work the ROS 2 realtime working group does, as well as looking into enabling zero copy if you can.