Skip to content
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

Tool to set a USB Camera Symlink #89

Merged
merged 7 commits into from
Feb 4, 2024
Merged

Conversation

hello-fazil
Copy link
Contributor

@hello-fazil hello-fazil commented Jan 26, 2024

This PR adds the new tool REx_camera_set_symlink.py that allows the user create a USB symlink to any USB camera that is plugged into the robot. The symlink is assigned by generating an Udev rule that records the following USB attributes of the plugged in camera [idVendor,idProduct,serial].

$ REx_camera_set_symlink.py -h
For use with S T R E T C H (R) from Hello Robot Inc.
---------------------------------------------------------------------

usage: REx_camera_set_symlink.py [-h] [--port PORT | --name NAME] [--symlink SYMLINK] [--list]

Tool to assign an camera symlink to a plugged-in USB camera by generating an UDEV rule. Example Usage:
REx_camera_set_symlink.py --port /dev/video6 --symlink hello-navigation-camera

options:
  -h, --help         show this help message and exit
  --port PORT        Plugged in USB camera video device port. E.g. --port /dev/video4
  --name NAME        Plugged in USB camera video device's name pattern. E.g. --name Logitech
  --symlink SYMLINK  Symlink to be created E.g. --symlink hello-navigation-camera
  --list             List all the enumerated Video devices

Example Usage:
By addressing a camera port:

$ REx_camera_set_symlink.py --port /dev/video6 --symlink hello-new-camera
For use with S T R E T C H (R) from Hello Robot Inc.
---------------------------------------------------------------------

Assing usb port: /dev/video6 to symlink port: /dev/hello-new-camera
Successfully generated udev rule at path: /etc/udev/rules.d/86-hello-new-camera.rules
Successfully Identified device at port: /dev/hello-new-camera

By addressing a camera's name pattern:

$ REx_camera_set_symlink.py --name Arducam --symlink hello-new-camera
For use with S T R E T C H (R) from Hello Robot Inc.
---------------------------------------------------------------------

Found Camera=Arducam OV9782 USB Camera: Ardu (usb-0000:00:14.0-1.1.1): at port=/dev/video6 
Assing usb port: /dev/video6 to symlink port: /dev/hello-new-camera
Successfully generated udev rule at path: /etc/udev/rules.d/86-hello-new-camera.rules
Successfully Identified device at port: /dev/hello-new-camera

@hello-binit
Copy link
Contributor

This is great to see @hello-fazil! Thanks for creating this. Should the udev rule be backed up to the "~/stretch_user/stretch-xxx-yyyy/udev/" and "/etc/hello-robot/stretch-xxx-yyyy/udev/" directories?

@hello-fazil
Copy link
Contributor Author

hello-fazil commented Jan 26, 2024

This is great to see @hello-fazil! Thanks for creating this. Should the udev rule be backed up to the "~/stretch_user/stretch-xxx-yyyy/udev/" and "/etc/hello-robot/stretch-xxx-yyyy/udev/" directories?

Yes, It is a good idea. I have updated the code to do the backup.

@aedsinger aedsinger changed the base branch from master to features/se3_test2 January 30, 2024 01:58
Copy link
Contributor

@hello-binit hello-binit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing this script with the beta teleop kit cameras. Each of the uvc cameras show up as two devices. For example, the gripper uvc camera shows up as /dev/video6 and /dev/video7. The first is the actual camera that can stream imagery, and the second is purely for metadata and can't stream imagery. The udev rules generated by this script are symlinking to both devices, and so tools like stretch_camera_streams_check.py --usb_cam_port /dev/hello-gripper-camera don't function properly. Here's the udevadm info for video6 and video7

hello-robot@stretch-re2-2002:~$ udevadm info -n /dev/video6
P: /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1.3/3-2.1.3.1/3-2.1.3.1:1.0/video4linux/video6
N: video6
L: 0
S: hello-gripper-camera
S: v4l/by-path/pci-0000:00:14.0-usb-0:2.1.3.1:1.0-video-index0
S: v4l/by-id/usb-Generic_USB_CAMERA_SN221101003-video-index0
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1.3/3-2.1.3.1/3-2.1.3.1:1.0/video4linux/video6
E: DEVNAME=/dev/video6
E: MAJOR=81
E: MINOR=6
E: SUBSYSTEM=video4linux
E: USEC_INITIALIZED=415284931
E: ID_V4L_VERSION=2
E: ID_V4L_PRODUCT=USB CAMERA: USB CAMERA
E: ID_V4L_CAPABILITIES=:capture:
E: ID_VENDOR=Generic
E: ID_VENDOR_ENC=Generic
E: ID_VENDOR_ID=10bb
E: ID_MODEL=USB_CAMERA
E: ID_MODEL_ENC=USB\x20CAMERA
E: ID_MODEL_ID=2b08
E: ID_REVISION=0001
E: ID_SERIAL=Generic_USB_CAMERA_SN221101003
E: ID_SERIAL_SHORT=SN221101003
E: ID_TYPE=video
E: ID_BUS=usb
E: ID_USB_INTERFACES=:0e0100:0e0200:010100:010200:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=uvcvideo
E: ID_PATH=pci-0000:00:14.0-usb-0:2.1.3.1:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_3_1_1_0
E: ID_FOR_SEAT=video4linux-pci-0000_00_14_0-usb-0_2_1_3_1_1_0
E: COLORD_DEVICE=1
E: COLORD_KIND=camera
E: DEVLINKS=/dev/hello-gripper-camera /dev/v4l/by-path/pci-0000:00:14.0-usb-0:2.1.3.1:1.0-video-index0 /dev/v4l/by-id/usb-Generic_USB_CAMERA_SN221101003-video-index0
E: TAGS=:uaccess:snap_chromium_chromium:snap_chromium_chromedriver:seat:

hello-robot@stretch-re2-2002:~$ udevadm info -n /dev/video7
P: /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1.3/3-2.1.3.1/3-2.1.3.1:1.0/video4linux/video7
N: video7
L: 0
S: v4l/by-id/usb-Generic_USB_CAMERA_SN221101003-video-index1
S: hello-gripper-camera
S: v4l/by-path/pci-0000:00:14.0-usb-0:2.1.3.1:1.0-video-index1
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2.1/3-2.1.3/3-2.1.3.1/3-2.1.3.1:1.0/video4linux/video7
E: DEVNAME=/dev/video7
E: MAJOR=81
E: MINOR=7
E: SUBSYSTEM=video4linux
E: USEC_INITIALIZED=415286839
E: ID_V4L_VERSION=2
E: ID_V4L_PRODUCT=USB CAMERA: USB CAMERA
E: ID_V4L_CAPABILITIES=:
E: ID_VENDOR=Generic
E: ID_VENDOR_ENC=Generic
E: ID_VENDOR_ID=10bb
E: ID_MODEL=USB_CAMERA
E: ID_MODEL_ENC=USB\x20CAMERA
E: ID_MODEL_ID=2b08
E: ID_REVISION=0001
E: ID_SERIAL=Generic_USB_CAMERA_SN221101003
E: ID_SERIAL_SHORT=SN221101003
E: ID_TYPE=video
E: ID_BUS=usb
E: ID_USB_INTERFACES=:0e0100:0e0200:010100:010200:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=uvcvideo
E: ID_PATH=pci-0000:00:14.0-usb-0:2.1.3.1:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_2_1_3_1_1_0
E: ID_FOR_SEAT=video4linux-pci-0000_00_14_0-usb-0_2_1_3_1_1_0
E: COLORD_DEVICE=1
E: COLORD_KIND=camera
E: DEVLINKS=/dev/v4l/by-id/usb-Generic_USB_CAMERA_SN221101003-video-index1 /dev/hello-gripper-camera /dev/v4l/by-path/pci-0000:00:14.0-usb-0:2.1.3.1:1.0-video-index1
E: TAGS=:snap_chromium_chromium:seat:uaccess:snap_chromium_chromedriver:

It seems like INDEX is one attribute the udev rule can use to select between the two video devices. https://unix.stackexchange.com/a/581838

To fix this PR, the udev rules will need to be able to symlink to the first device instead of both of them.

UVC Cameras, such as the cameras from the Beta Teleop Kit, or popular
webcams, appear as two devices in the /dev/ folder. For example, the
gripper uvc camera from the teleop kit appears as /dev/video6 and
/dev/video7. The first is usually a capture device and can stream
imagery, and the second is usually purely for metadata and cannot
stream imagery. Therefore, it's very important that UVC camera UDEV
rules trigger on the first device. The critical attribute
differentiating these two devices is called ID_V4L_CAPABILITIES,
where video4linux seems to recognize which device can actually
stream imagery and marks it as "capture:". In this commit, we use
this attribute to trigger the UDEV rules on the correct device.
Copy link
Contributor

@hello-binit hello-binit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the fix in commit 0a700ce, the two video ports issue is solved. This PR is ready to merge.

@hello-binit hello-binit changed the base branch from features/se3_test2 to master February 4, 2024 02:19
@hello-binit hello-binit merged commit a908b43 into master Feb 4, 2024
@hello-binit hello-binit deleted the feature/set_camera_symlink branch February 4, 2024 02:19
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