Ricbot realsense

From Rsewiki
Revision as of 09:43, 15 May 2026 by Jca (talk | contribs) (→‎Solution)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Back to Ricbot

Intel RealSense

Install

sudo apt-get install automake libtool libusb-1.0-0-dev libx11-dev xorg-dev libglu1-mesa-dev
sudo apt install libssl-dev

There is a script to download and compile, e.g. on Raspberry Pi here: https://github.com/realsenseai/librealsense/blob/master/doc/libuvc_installation.md

To install pyrealsense2 at the same time as librealsense, line 46 of the 'libuvc_installation.sh' build script should be changed from this:

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release

to this:

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release -DBUILD_PYTHON_BINDINGS:bool=true

From MartyG-RealSense on a pose here: https://github.com/realsenseai/librealsense/issues/13373

Library and examples

This is an alternative to the script above.

cd ~/git
git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense
mkdir build
cd build
cmake ..
make -j3
sudo make install

Copy udev rules to udev

sudo cp ~/git/librealsense/config/99-realsense*.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules

All example commands start with rs-, e.g.:

rs-capture
rs-pointcloud

Intel Librealsense

Installing support for Intel librealsense.

sudo apt install libssl-dev
sudo apt-get install freeglut3-dev
sudo apt-get install xorg-dev
cd git
git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense
mkdir build
cd build
cmake ..

I also needed to install libusb-1.0-0-dev

sudo apt install libusb-1.0-0-dev

This path was not included in the CMakeLists.txt, so I added this line at the beginning of the CMakeLists.txt:

cd librealsense
nano CMakeLists.txt

add

include_directories( /usr/include/libusb-1.0/ )

like here:

cmake_minimum_required(VERSION 3.10)

set( LRS_TARGET realsense2 )
project( ${LRS_TARGET} LANGUAGES CXX C )

# Allow librealsense2 and all of the nested project to include the main repo folder
set(REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${REPO_ROOT})
include_directories( /usr/include/libusb-1.0/ )

include(CMake/lrs_options.cmake)
include(CMake/connectivity_check.cmake)
...

D435 failed at reboot

The RealSense D435 is connected to a powered USB3 hub. The Raspberry is powered by a 5V supply through expansion pins. It is a default 64-bit Raspberry Pi OS:

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian

The error

At times (after reboot), I can no longer enumerate RealSense devices, and I get:

$ rs-enumerate-devices 
15/05 09:00:33,247 ERROR [140732254925120] (handle-libusb.h:125) failed to claim usb interface: 0, error: RS2_USB_STATUS_BUSY
15/05 09:00:33,249 ERROR [140732304337472] (uvc-sensor.cpp:428) acquire_power failed: failed to set power state
15/05 09:00:33,251 ERROR [140732304337472] (rs.cpp:280) [rs2_create_device( info_list:0x555598c13730, index:0 ) UNKNOWN] failed to set power state
15/05 09:00:33,251 ERROR [140732304337472] (rs.cpp:280) [rs2_delete_device( device:nullptr ) UNKNOWN] null pointer passed for argument "device"
Could not create device - failed to set power state . Check SDK logs for details
No device detected. Is it plugged in?

lsusb

But lsusb finds the device

$ lsusb
Bus 004 Device 004: ID 8086:0b07 Intel Corp. RealSense D435
Bus 004 Device 005: ID 2676:ba05 Basler AG Vision Camera
Bus 004 Device 003: ID 05e3:0626 Genesys Logic, Inc. Hub
Bus 004 Device 002: ID 05e3:0626 Genesys Logic, Inc. Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 003 Device 002: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Solution

It seems to be a boot conflict of some sort, but resetting the USB seems to work.

From the usbutils package, run the command:

$ usbreset 8086:0b07
Resetting Intel(R) RealSense(TM) Depth Camera 435 ... ok

Then the device works again:

$ rs-enumerate-devices -s

Device Name Serial Number Firmware Version Intel RealSense D435 013222070878 5.17.0.10

In a script

If one Realsense only, then this will do

#!/bin/bash
DEVICE_ID=$(lsusb | grep "RealSense" | awk '{print $6}')
if [ -z "$DEVICE_ID" ]; then
    echo "Error: RealSense device not found."
else
    echo "RealSense Device ID found: $DEVICE_ID"
    usbreset $DEVICE_ID
fi

With more than one, then this is more appropriate:

#!/bin/bash
# Get all RealSense IDs into an array
mapfile -t DEVICE_IDS < <(lsusb | grep "RealSense" | awk '{print $6}')
# Check if any devices were found
if [ ${#DEVICE_IDS[@]} -eq 0 ]; then
    echo "No RealSense devices found."
    exit 1
fi
echo "Found ${#DEVICE_IDS[@]} RealSense device(s):"
# Loop through the array
for i in "${!DEVICE_IDS[@]}"; do
    ID="${DEVICE_IDS[$i]}"
    usbreset $ID
done

Both suggested by AI Gemini

Script to automate solution