librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

T265 is detected in query devices but it errors out with 'not connected' with D435i

Open yosoufe opened this issue 4 years ago • 2 comments


Required Info
Camera Model T265 / D435i
Firmware Version 0.2.0.951 / 05.12.10.00
Operating System & Version Ubuntu 18.04
Kernel Version (Linux Only) 5.5.11-050511-generic
Platform PC
SDK Version I think 2?
Language python
Segment Learning Robotics

Issue Description

I have D435i and T265 connected, and even T265 alone here does not work I feel whenever I define context object, there is a higher chance that T265 does not work. Sensors do work with the realsense-viewer. I am running on Ubutnu 18.04 and desktop. I tried both the latest release in PyPI server and also from TOT of git repo for the following example.

This does not work, What do I do wrong? I was trying to follow this tutorial but in python.

import pyrealsense2 as rs
import numpy as np 
import time 
print(rs.__file__)

import atexit

pipelines = []

@atexit.register
def cleanup():
    print('clean up')
    for p in pipelines:
        try:
            p.stop()
        except:
            pass

ctx = rs.context()

for dev in ctx.query_devices():
    print(f'device: {dev.get_info(rs.camera_info.name)}')
    p = rs.pipeline(ctx) # ctx
    cfg = rs.config()
    dev_serial = dev.get_info(rs.camera_info.serial_number)
    cfg.enable_device(dev_serial)
    p.start(cfg) ## <<<<------------------------------------ it errors out here for the T265
    pipelines.append(p)

print('pipelines started')
s = time.time()
time.sleep(1)

This generates the following output

$ python bug_example.py 
/home/yousof/Software/programming/pyenv/versions/3.7.8/lib/python3.7/site-packages/pyrealsense2/__init__.py
device: Intel RealSense D435I
device: Intel RealSense T265
Traceback (most recent call last):
  File "bug_example.py", line 27, in <module>
    p.start(cfg)
RuntimeError: No device connected
clean up

I read somewhere that T265 should get loaded to context first but I don't see any option in the python library to do that. context.query_devices returns a D435i first and T265 second. If you see the log above.

Thanks

yosoufe avatar Jan 25 '21 10:01 yosoufe

What I understood so far, when I call ctx.query_devices() and save the result in a python variable, It cannot connect to the device at the pipeline.start.

ctx.query_devices() runs the usb_messenger = usb_device->open(0); // T265 only has one interface, 0 (here) successfully in tm-device.cpp. Then when I call the pipeline.start() after ctx.query_devices(), the usb_device->open(0); is being called again but this time it is not successful and it throws exception. Do you know why?

This can give me a hint for a workaround in python script. But I would call it a hack. I think the library should work fine without such a hack. So the following works for me now. But I have to be careful to never hold a python object to the T265 device before running pipeline.start() in python. That means I need to call del dev before pipeline.start(). So the following works.

import sys
sys.path.insert(0, '/home/yousof/robotics/libs/librealsense/build_host/wrappers/python')
# To use the compiled version rather than installed from pip, for debugging.

import pyrealsense2 as rs
import numpy as np 
import time 
print(rs.__file__)

import atexit

pipelines = []

@atexit.register
def cleanup():
    print('clean up')
    for p in pipelines:
        try:
            p.stop()
        except:
            pass

ctx = rs.context()

for dev in ctx.query_devices():
    print(f'device: {dev.get_info(rs.camera_info.name)}')
    p = rs.pipeline(ctx) 
    cfg = rs.config()
    dev_serial = dev.get_info(rs.camera_info.serial_number)
    del dev  ## <<<<------------------------------------ This line is my workaround
    cfg.enable_device(dev_serial)
    p.start(cfg)
    pipelines.append(p)


print('pipelines started')
s = time.time()
time.sleep(1)

So WAR key is to call del dev to delete the pointer to the T265 device before calling the p.start(cfg)

This should give you a hint on how to fix the bug. To me is like the device pointer somehow is keeping the USB device busy so the next operation cannot be done. Deleting the device object releases the USB device. Interestingly this is only happening for T265, Not the D435i.

yosoufe avatar Jan 27 '21 03:01 yosoufe

Did you get this working without the del dev?

egeozguroglu avatar Aug 01 '24 17:08 egeozguroglu