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

Error installing Intel RealSense SDK for D405 camera on Jetson Nano with ROS2 #2661

Closed
kevinDrawn opened this issue Mar 16, 2023 · 16 comments
Closed
Labels

Comments

@kevinDrawn
Copy link

The Jetson Nano version is 20.04.06 LTS with the code name 'focal'. The ROS version is 'foxy', and when I entered the code to check the Jetpack version, it showed '#R 32, Revision: 3.1'.
The SDK installation method for Jetson Nano was only specified for Ubuntu 18.04 or earlier versions. However, the recently released D405 camera doesn't support ROS1, so I upgraded to ROS2 version. I followed the instructions on https://github.com/IntelRealSense/librealsense/blob/master/doc/installation_jetson.md to download the SDK, but I encountered the following error:
'sudo apt-get install librealsense2-utils --> E: Unable to locate package librealsense2-utils'.
How can I install the SDK for the D405 version and move on to the next step?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 16, 2023

Hi @kevinDrawn The problem in this case may be with Ubuntu rather than librealsense or the ROS wrapper. Installing librealsense from packages on Arm64 devices such as Jetson is supported on Ubuntu 18.04 but not on 20.04. There are no plans to add Arm64 packages for 20.04 in future and so librealsense should instead be built from source code on Ubuntu 20.04.

The correct order of installation is to install librealsense first and then build the ROS wrapper from source code secondly afterwards.

An instruction guide for installing librealsense on Jetson from source code can be found at IntelRealSense/librealsense#6964 (comment)

@kevinDrawn
Copy link
Author

Thank you so much for the answer! I just want to confirm the process step by step, can you check if the order I understand is correct?

  1. Download Jetpack 4.6 and revert Ubuntu 20.04 to 18.04.
  2. Install ROS (either Melodic or Noetic version should be fine, but will there be any issues using the D405 camera?)
  3. Install librealsense by following the instructions from the website you provided I want to install the latest SDK version 2.0 (v2.53.1) since I’m using the D405 camera, is that okay?)
  4. Install ROS wrapper by following the instructions from this website: https://github.com/leggedrobotics/realsense-ros-rsl.

If I understand the process correctly, I will let you know after I have completed it.
Thanks a lot!!!

@MartyG-RealSense
Copy link
Collaborator

  1. That step is correct.

  2. The RealSense ROS1 (Kinetic, Melodic or Noetic) wrapper is not compatible with D405. Only the ROS2 ros2-development wrapper supports it and development of the ROS1 wrapper has ceased so D405 compatibility will not be added to it in future..

A RealSense user disclosed at #2582 (comment) that the ROS1 wrapper can be edited to add D405 support. You could likely implement this edit by creating a custom 'forked' D405-supporting version of the ROS1 wrapper on your own GitHub account that can be built from the source code instead of the official ROS1 wrapper, similar to how the leggedrobotics wrapper page that you linked to is a fork of the official wrapper.

  1. That step is correct.

  2. Instead of using the leggedrobotics version of the ROS1 wrapper, if you wanted to add D405 support for ROS1 then you'd likely have to instead create a fork of the official wrapper on your own GitHub account and make the D405 compatibility edit, then build the wrapper from your fork.


Instead of using ROS1, it may be easier to install ROS2 Dashing and use that with Ubuntu 18.04, librealsense 2.53.1 and the ros2-development wrapper that is compatible with D405.

image

@kevinDrawn
Copy link
Author

kevinDrawn commented Mar 23, 2023

Thank you! I solved my problem! But i have another question.
When running a Python code that includes "import pyrealsense2 as rs" using "rosrun", I get an error message: "File "/home/park/catkin_ws/src/depth_camera/src/depth_publisher.py", line 3, in import pyrealsense2 as rs".
What could be causing this error?

  1. package.xml

<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>genmsg</build_depend>
<build_depend>realsense2_camera</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>genmsg</build_export_depend>
<build_export_depend>realsense2_camera</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>genmsg</exec_depend>
<exec_depend>realsense2_camera</exec_depend>

  1. CMake
    cmake_minimum_required(VERSION 3.0.2)
    project(depth_camera)
    find_package(catkin REQUIRED COMPONENTS
    roscpp,rospy,std_msgs,genmsg)
    add_message_files(FILES,depth.msg)
    generate_messages(DEPENDENCIES std_msgs)
    catkin_package()
    include_directories(include ${catkin_INCLUDE_DIRS})
    catkin_install_python(PROGRAMS
    src/depth_publisher.py
    DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )
    catkin_install_python(PROGRAMS
    src/depth_subscriber.py
    DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    )

@MartyG-RealSense
Copy link
Collaborator

In a small number of cases, 'import pyrealsense2 as rs' may need to be changed to import pyrealsense2.pyrealsense2 as rs in order for a script to work.

Also, CMake 3.8 instead of 3.0.2 is the recommended minimum for librealsense.

@kevinDrawn
Copy link
Author

Even after trying the first method and updating CMake, it still doesn't work. Do I need to make additional modifications to the package.xml or CMake files?

@kevinDrawn
Copy link
Author

Traceback (most recent call last):
File "/home/park/catkin_ws/src/robot/src/pub.py", line 8, in
import pyrealsense2.pyrealsense2 as rs
File "/home/park/librealsense-2.51.1/wrappers/python/pyrealsense2/init.py", line 2, in
from .pyrealsense2 import *
ImportError: No module named pyrealsense2

I got this error message,

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 24, 2023

Have you installed the RealSense Python wrapper pyrealsense2 please? The pyrealsense2 wrapper is not included in the ROS wrapper, so a Python script that uses import pyrealsense2 as rs would not be able to find pyrealsense2 on the computer in order to enable that instruction to work.

The pyrealsense2 wrapper can be built at the same time as the librealsense SDK if the instructions at IntelRealSense/librealsense#6964 (comment) are used to build librealsense on Jetson from source code.

If you used those instructions and successfully installed the pyrealsense2 wrapper, which Python 3 version are you using? The instruction guide uses Python 3.6. If you have a version of Python newer than 3.6 installed then you should update the version number in the installation commands. For example, for Python 3.9:

-DPYTHON_EXECUTABLE=/usr/bin/python3.9

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.9/pyrealsense2

If you are using Anaconda instead of Python 3 then the path may be different to when Python 3 is used. The command which python3 can tell you what the correct path is.

@kevinDrawn
Copy link
Author

kevinDrawn commented Mar 25, 2023

I had an issue when dealing with package restructuring between Python 2 and Python 3, specifically when executing the "9. Deal with package restructuring between Python 2 and Python 3 using this method" step. The error message "rs.path" was not found, so I had to manually find the location of "pyrealsense" and run the "cp" command.

I ran the following command:
"sudo cp ~/librealsense-2.51.1/wrappers/python/pyrealsense2/init.py /usr/local/lib/python3.6/pyrealsense2"

After that, the rest of the process was completed without any issues, and I was able to write a regular Python script (without ROS communication) that imported "pyrealsense2" and ran the code without any problems.

(It is suspected that) the Python interpreter at the top of the ROS node is looking for Python 2 by default to use packages required for ROS Melodic. This may cause it to fail to find pyrealsense installed in Python 3.

`#!/usr/bin/env python
#-- coding:utf-8 --

import rospy
from robot.msg import test_msg
import pyrealsense2 as rs
import cv2
import numpy as np
from std_msgs.msg import Float32
def main():
rospy.init_node('pub', anonymous=True)
pub = rospy.Publisher('chatter', test_msg, queue_size=10)
rate = rospy.Rate(10) # 10hz

msg = test_msg()	
count = 0		
while not rospy.is_shutdown():
    msg.stamp = rospy.Time.now()	
    msg.data = count		
    rospy.loginfo("send time(sec) = %d", msg.stamp.secs)
    rospy.loginfo("send msg = %d", msg.data)
    pub.publish(msg)
    rate.sleep()

    count += 1

if name == 'main':
try:
main()
except rospy.ROSInterruptException:
pass
`

@kevinDrawn
Copy link
Author

kevinDrawn commented Mar 25, 2023

No. I can't solve this problem...
I think that the the error occurred owing to interpreter. "#!/usr/bin/env python" on top of the publisher script is not match with pyrealsense2. While pyrealsense requires python3, rospy used for melodic refers to python2. Therefore the python interpreter can't find the pyrealsense package related to python3.

Do you know how to import different versions of python packages on a single node?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 25, 2023

The documentation for the pyrealsense2 wrapper at the link below states that when building the wrapper from source code with CMake, you can force compilation for a specific Python version on a system with both Python 2 and Python 3 installed by using the CMake build flag -DPYTHON_EXECUTABLE=[full path to the exact python executable]

https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python#building-from-source

lf it is possible to install for both Python 2 and 3, I would think that an approach for doing so would be to install librealsense without the pyrealsense2 wrapper, and then once librealsense is installed, build the pyrealsense2 wrapper on its own from source code with CMake twice, using different -DPYTHON_EXECUTABLE paths for Python 2 and 3 on each install. Doing so should in theory compile separate versions of pyrealsense2.so.

The Python 2 version would simply be called pyrealsense2.so and the Python 3 one will have a longer filename based on the version of Python 3 on your computer, such as pyrealsense2.cpython-35m-arm-linux-gnueabihf.so (where 35m refers to Python 3.5).


An alternative approach to using DPYTHON_EXECUTABLE would be to build the pyrealsense2.so files for Python 2 and 3 and then place the .so file for Python 2 or 3 in the project folder beside your pyrealsense2 project script, and also place librealsense2.so in the folder too. You could perhaps have two separate project folders for Python 2 and 3, with the appropriate pyrealsense2.so file placed in each.

@kevinDrawn
Copy link
Author

Thank you so much for the explanation! I will try it again today. But if I get stuck again, I want to try writing the code in C++. Since Librealsense is based on C++, it should be easier.
I am planning to import it with #include <librealsense2/rs.hpp>! Then there shouldn't be any version conflict issues like in Python, right? Is my thinking correct?

@MartyG-RealSense
Copy link
Collaborator

If you are writing a librealsense program that does not involve ROS then C++ can be easier, and you do not have to deal with the complications involved in installing the pyrealsense2 wrapper.

If you are using ROS and creating a librealsense node script that will be launched from ROS then Python will typically be easier than C++.

@kevinDrawn
Copy link
Author

Oh!! I solve this problem with python!! A lot of thank!! Have a good day!!

@MartyG-RealSense
Copy link
Collaborator

You are very welcome. It's great to hear that you were successful. Thanks very much for the update!

@MartyG-RealSense
Copy link
Collaborator

Case closed due to solution achieved and no further comments received.

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

No branches or pull requests

2 participants