IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.58k stars 4.82k forks source link

RuntimeError: get_xu(ctrl=1) failed! Last Error: Device or resource busy #13421

Open ravil99 opened 4 days ago

ravil99 commented 4 days ago
System Info
Camera Model D415
Firmware Version [5.16.0.1]
Operating System & Version Ubuntu 22.04.5 LTS
Kernel Version (Linux Only) 6.8.0-45-generic
Platform PC
SDK Version 2.56.1
Language Python
Segment CV

Issue Description

Hello everyone. I met a problem with using librealsense. He are having an experimental setup with 4 D415 cameras connected to one Ubuntu machine. Each camera is plugged in to separate USB port via 5 meter active cable. We are using v4l USB backend.

Our project is written in Python and initially we try to load our custom .json camera preset sequentially. Here is a code example:

preset_path: str = "path_to_desired_preset" # just example of a path des_preset: dict = json.load(preset_path) advanced_mode = rs.rs400_advanced_mode(device) advanced_mode.load_json(json.dumps(des_preset))

This code is run in loop to cover all 4 cameras. But sometimes executing advanced_mode.load_json(json.dumps(des_preset)) resuts in the following error:

RuntimeError: get_xu(ctrl=1) failed! Last Error: Device or resource busy.

Error text suggests, that something is trying to access the camera and some conflict occurs. But it's not the case - only my code is trying to access camera.

And behavior of this error is not stable. Usually it appears during loading of preset to first or second camera. And it takes 4-5 code restarts to load all 4 presets at the same time.

Originally this error occurred with presets generated with "fw version": "05.12.07.150". After that presets were regenerated with "fw version": "5.16.0.1", but it didn't fixed the error.

Surprisingly, this error doesn't appear if before running my project all cameras' Depth Stream was opened in realsense-viewer.

Do you know what does this Runtime Error means and how to fix it?

I will be glad to any suggestion.

MartyG-RealSense commented 4 days ago

Hi @ravil99 The librealsense SDK operates under a set of rules called the Multi-Streaming Model that means that once a particular camera stream has been accessed, it becomes locked from being used again until the lock is released.

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

So if the loop tried to access a camera in your multiple camera set that had already been started then a busy error could occur.

The link below has an example of using the ctx instruction to automatically access multiple cameras without having to manually specify a serial number for each camera to distinguish them from each other.

https://github.com/ivomarvan/samples_and_experiments/blob/master/Multiple_realsense_cameras/multiple_realsense_cameras.py

In regard to loading a custom json configuration file via Advanced Mode, doing so is complex and prone to errors occurring. I therefore recommend avoiding doing so if you are able to do so. Instead, I would suggest loading one of the pre-made Visual Presets (which are actually jsons) if one of these existing presets can provide a configuration that is suitable for your project. The method used to load the built-in presets is different from loading a custom json with Advanced Mode and so does not experience the problems that custom jsons do.

https://github.com/IntelRealSense/librealsense/issues/2577#issuecomment-432137634 has an example of Python code for loading a built-in preset.

The available preset names are:

Default Hand High Accuracy High Density Medium Density