Realsense RuntimeError: No device connected

Hello,

We are running into this issue where if we run stretch_realsense_visualizer.py twice, it will work successfully on the first attempt, but the file throws an error on all successive attempts. The only method the students in my course have found to overcome this is to restart the robot after every use of the RealSense camera. The error is below:

hello-robot@stretch-re1:~$ stretch_realsense_visualizer.py 
For use with S T R E T C H (TM) RESEARCH EDITION from Hello Robot Inc.

Traceback (most recent call last):
  File "/home/hello-robot/.local/bin/stretch_realsense_visualizer.py", line 132, in <module>
    pipeline.start(config)
RuntimeError: No device connected

Hi @Zackory, this is definitely abnormal behavior from the Realsense camera. The likely reason the camera becomes inaccessible after running once is that it does not shutdown correctly, instead remaining in a busy state and causing startup issues on subsequent runs. Power cycling the robot remains the best way to hard reset the camera, but many Realsense users have also found success with adding software reset procedures1 2 to the camera’s initialization.

We’ve heard similar issues with using the camera from ROS, so we’re experimenting with adding a reset to our ROS Realsense launch files. The stretch_realsense_visualizer.py script hasn’t included a reset yet, but it seems like including one would help in this case. Here’s a branch that includes a software reset of the camera in the visualizer tool. Please let me know if helps resolve this issue. If it does not, we can go one step further by issuing a USB hub reset in the script.

In order to test this branch, you can use the following commands:

$ cd ~/repos
$ git clone https://github.com/hello-robot/stretch_body.git
$ cd stretch_body
$ git pull
$ git checkout bugfix/realsense_reset
$ cd tools/bin/
$ python stretch_realsense_visualizer.py

Please let me know if you need any help.