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

Partial and inconsistent device paths listed under "Physical Port" on Raspberry Pi #11553

Closed
zackwoodruff opened this issue Mar 9, 2023 · 9 comments

Comments

@zackwoodruff
Copy link

Required Info
Camera Model D435/D455
Firmware Version 05.14.00.00/05.14.00.00
Operating System & Version Linux, RPI OS (Bullseye and Buster)
Kernel Version (Linux Only) (5.15.84 and 5.10.103)
Platform Raspberry Pi
SDK Version v2.53.1
Language C++
Segment Robot

Issue Description

  • I have multiple cameras connected to a raspberry pi and I would like to differentiate between them based on the physical USB port they are plugged into. I do not want to differentiate by serial number because cameras may be swapped between ports.
  • When I run rs-enumerate-devices -S on both Bullseye and Buster I get partial paths under "Physical Port" and these paths change when I unplug and replug a camera into the same port:
Device Name                   Serial Number       Firmware Version    
Intel RealSense D435          831612072717        05.14.00.00         
Intel RealSense D455          151422250645        05.14.00.00         
Device info: 
    Name                          : 	Intel RealSense D435
    Serial Number                 : 	831612072717
    Firmware Version              : 	05.14.00.00
    Recommended Firmware Version  : 	05.14.00.00
    Physical Port                 : 	2-1-10
    Debug Op Code                 : 	15
    Advanced Mode                 : 	YES
    Product Id                    : 	0B07
    Camera Locked                 : 	YES
    Usb Type Descriptor           : 	3.2
    Product Line                  : 	D400
    Asic Serial Number            : 	830513022942
    Firmware Update Id            : 	830513022942

Device info: 
    Name                          : 	Intel RealSense D455
    Serial Number                 : 	151422250645
    Firmware Version              : 	05.14.00.00
    Recommended Firmware Version  : 	05.14.00.00
    Physical Port                 : 	2-2-9
    Debug Op Code                 : 	15
    Advanced Mode                 : 	YES
    Product Id                    : 	0B5C
    Camera Locked                 : 	YES
    Usb Type Descriptor           : 	3.2
    Product Line                  : 	D400
    Asic Serial Number            : 	151223063319
    Firmware Update Id            : 	151223063319

  • On a Linux computer running Ubuntu 20.04 I get the the same output except the Physical Port includes the full path and is consistent when the device is unplugged and plugged back in.
Device Name                   Serial Number       Firmware Version    
Intel RealSense D435          831612072717        05.14.00.00         
Intel RealSense D455          151422250645        05.14.00.00         
Device info: 
    Name                          : 	Intel RealSense D435
    Serial Number                 : 	831612072717
    Firmware Version              : 	05.14.00.00
    Recommended Firmware Version  : 	05.14.00.00
    Physical Port                 : 	/sys/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/video4linux/video2
    Debug Op Code                 : 	15
    Advanced Mode                 : 	YES
    Product Id                    : 	0B07
    Camera Locked                 : 	YES
    Usb Type Descriptor           : 	3.2
    Product Line                  : 	D400
    Asic Serial Number            : 	830513022942
    Firmware Update Id            : 	830513022942

Device info: 
    Name                          : 	Intel RealSense D455
    Serial Number                 : 	151422250645
    Firmware Version              : 	05.14.00.00
    Recommended Firmware Version  : 	05.14.00.00
    Physical Port                 : 	/sys/devices/pci0000:00/0000:00:14.0/usb2/2-6/2-6:1.0/video4linux/video8
    Debug Op Code                 : 	15
    Advanced Mode                 : 	YES
    Product Id                    : 	0B5C
    Camera Locked                 : 	YES
    Usb Type Descriptor           : 	3.2
    Product Line                  : 	D400
    Asic Serial Number            : 	151223063319
    Firmware Update Id            : 	151223063319

Do you know what could be causing the partial paths instead of the full paths under the "Physical Port"? Thanks.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 10, 2023

Hi @zackwoodruff You may be able to set fixed port addresses for cameras by defining symbolic links via udev rules.

https://unix.stackexchange.com/questions/479302/udev-rules-for-seemingly-indistinguishable-devices

@zackwoodruff
Copy link
Author

zackwoodruff commented Mar 10, 2023

@MartyG-RealSense Hi Marty, thank you for the link. The cameras do have fixed port addresses shown by the command ls -al /sys/class/video4linux below:

total 0
drwxr-xr-x  2 root root 0 Mar 10 08:35 .
drwxr-xr-x 67 root root 0 Mar  9 21:07 ..
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video0 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/video4linux/video0
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video1 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/video4linux/video1
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video10 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.3/video4linux/video10
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video11 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.3/video4linux/video11
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video2 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/video4linux/video2
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video3 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/video4linux/video3
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video4 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.3/video4linux/video4
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video5 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.3/video4linux/video5
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video6 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.0/video4linux/video6
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video7 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.0/video4linux/video7
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video8 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.0/video4linux/video8
lrwxrwxrwx  1 root root 0 Mar 10 08:36 video9 -> ../../devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.0/video4linux/video9

where the mappings are:
RGB Camera 1: /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.3/video4linux
Depth Camera 1: /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.0/video4linux
RGB Camera 2: /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.3/video4linux
Depth Camera 2: /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-2/2-2:1.0/video4linux

If I properly set up the udev rules I could have something like:

/dev/cam1_depth
/dev/cam1_rgb
/dev/cam2_depth
/dev/cam2_rgb

Either way how do I enable a specific stream using the realsense C++ sdk? On my Ubuntu Laptop I have been passing the port info, matching that to the "RS2_CAMERA_INFO_PHYSICAL_PORT" device info, then using the serial number to enable the specific device.

// Get all devices connected and print info
auto devices = ctx.query_devices();
for (size_t i = 0; i < devices.size(); i++) {
    auto device = devices[i];
  
    // Get device serial from desired port
    string devicePortTemp = device.get_info(RS2_CAMERA_INFO_PHYSICAL_PORT);
    if (devicePortTemp.find(captureCfg.devicePortDesired) != std::string::npos) {
        captureCfg.deviceSerialDesired = device.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
    }
}

rs2::config cfg;
cfg.enable_device(captureCfg.deviceSerialDesired);

That will not work with the inconsistent and changing path, how do I enable a specific device/stream (e.g. rgb or depth) when all I have is the port address of the device? I can parse the serial number from udevadm using the following command but I'm wondering if there's a simpler way to do it.

sudo udevadm info -ap /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb2/2-1/2-1:1.3/ | grep ATTRS{serial}==

@MartyG-RealSense
Copy link
Collaborator

As you said, you can enable a device by its serial number so that it does not matter which port the camera is plugged into so long as the camera is detectable. But as you also stated, that approach is not suitable for your particular project because the cameras may get swapped between ports and you want to address a specific port.

Other than your own udevadm method, the best approach may be to create a new udev rule to enforce port naming, like in the guide at the link below.

https://inegm.medium.com/persistent-names-for-usb-serial-devices-in-linux-dev-ttyusbx-dev-custom-name-fd49b5db9af1

@zackwoodruff
Copy link
Author

@MartyG-RealSense
Is there a way to enable a camera by port in the realsense SDK? I have looked through the multicam example and multiple related issues (e.g., #2219) but I have yet to see an example of enabling specific streams from specific cameras without using the serial number.

@MartyG-RealSense
Copy link
Collaborator

The RealSense ROS wrapper enables cameras to be accessed by a specific USB port ID instead of camera serial number with the USB_PORT_ID instruction. The question is whether the port address would still be changing though.

If you need to use the SDK instead of ROS, the SDK has a set of Multi-Streaming Model rules that govern access to multiple cameras and multiple streams. The available code documentation for these rules is limited though.

https://github.com/IntelRealSense/librealsense/blob/master/doc/rs400_support.md#multi-streaming-model

@zackwoodruff
Copy link
Author

Thanks @MartyG-RealSense. I am not using ROS so I will look into the Multi-Streaming Model. Worst case I should be able to parse the serial number from the part of the port that is consistent on plug/unplug and device swap.

@MartyG-RealSense
Copy link
Collaborator

Hi @zackwoodruff Do you require further assistance with this case, please? Thanks!

@zackwoodruff
Copy link
Author

@MartyG-RealSense I am good for now thanks.

@MartyG-RealSense
Copy link
Collaborator

Thanks very much @zackwoodruff for the update!

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

No branches or pull requests

2 participants