Installing TensorRT on Jetson Nano

Hello guys, I have a Jetson nano that it going to be installed on a drone. We’re trying to set it up now and can use some advice.
One of our requirements is to use ROS2 (foxy or humble). For that purpose we installed an Ubuntu 20.04 image that we took from here:

Supposedly it comes with TensorRT, which is another package we need to use. However, when trying to import tensorrt in Python 3.8, it says ‘no module named tensorrt’. I checked the output of dpkg -l | grep nvinfer and saw that pyhton3-libnvinfer is not installed, so I tried to install it with sudo apt install python3-libnvinfer, but it fails with the following error:

 python3-libnvinfer : Depends: python3 (< 3.7) but 3.8.2-0ubuntu2 is to be installed

I installed Python 3.6 and tried again, but the result was the same. I tried to install it from one of the wheels from the TensorRT TAR installation, but that failed because the platform was wrong. So I don’t really know how to proceed from here.

Is there a way I can have both tensorrt and ROS2 on the nano? I saw someone talking about a docker image for ROS foxy that you can use on Ubuntu 18.04, but I never used docker before so I don’t know how difficult it will be to set up, that’s why I’m curious if there are any other alternatives (even a different board that has an official 20.04 image would be great).

Thank you very much!

Hi @natanel, the officially-supported JetPack 4.x release for Jetson Nano is on Ubuntu 18.04, and it already comes with TensorRT.

As you pointed out, you can run ROS2 Foxy in a container, including support for CUDA and TensorRT. You can get pre-built container images for Foxy from https://github.com/dusty-nv/jetson-containers

If you also want PyTorch, I have variants of the Foxy container images that have PyTorch in them too. You can get them from DockerHub like the other images.

Hey, thank you for the quick reply!
Yes I think I’m gonna try that, it’s a good opportunity to learn how to use docker :). One question though, the container with Humble should work the same way right? because I need the rosbag2-py API and from what I understood it doesn’t exist in Foxy yet.

Thanks again for the help!

Unfortunately we’ve been unsuccessful getting Humble to build for Nano - see here for more info:

Hey, so I’m trying to install the Foxy container on a fresh Nano, I ran the command

./scripts/docker_build_ros.sh --distro foxy --with-pytorch

but for some reason it fails to install a lot of the packages.
Here is the output in the end:


Summary: 68 packages finished [18min 19s]
  1 package failed: rosidl_runtime_cpp
  3 packages aborted: fastrtps spdlog_vendor yaml_cpp_vendor
  25 packages had stderr output: ament_copyright ament_cppcheck ament_cpplint ament_flake8 ament_index_python ament_lint ament_lint_cmake ament_package ament_pep257 ament_uncrustify ament_xmllint cyclonedds domain_coordinator fastcdr foonathan_memory_vendor google_benchmark_vendor launch launch_testing osrf_pycommon osrf_testing_tools_cpp rosidl_runtime_cpp rpyutils spdlog_vendor uncrustify_vendor yaml_cpp_vendor
  145 packages not processed
The command '/bin/bash -c mkdir -p ${ROS_ROOT}/src &&     cd ${ROS_ROOT} &&     rosinstall_generator --deps --rosdistro ${ROS_DISTRO} ${ROS_PKG} 		launch_xml 		launch_yaml 		launch_testing 		launch_testing_ament_cmake 		demo_nodes_cpp 		demo_nodes_py 		example_interfaces 		camera_calibration_parsers 		camera_info_manager 		cv_bridge 		v4l2_camera 		vision_opencv 		vision_msgs 		image_geometry 		image_pipeline image_transport 		compressed_image_transport 		compressed_depth_image_transport 		> ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall &&     cat ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall &&     vcs import src < ros2.${ROS_DISTRO}.${ROS_PKG}.rosinstall &&     apt-get update &&     cd ${ROS_ROOT} &&     rosdep init &&     rosdep update &&     rosdep install -y     	  --ignore-src        --from-paths src 	  --rosdistro ${ROS_DISTRO} 	  --skip-keys "libopencv-dev libopencv-contrib-dev libopencv-imgproc-dev python-opencv python3-opencv" &&     rm -rf /var/lib/apt/lists/* &&     apt-get clean &&     colcon build         --merge-install         --cmake-args -DCMAKE_BUILD_TYPE=Release &&     rm -rf ${ROS_ROOT}/src &&     rm -rf ${ROS_ROOT}/logs &&     rm -rf ${ROS_ROOT}/build &&     rm ${ROS_ROOT}/*.rosinstall' returned a non-zero code: 1

And here is the output for rosidl_runtime_cpp:

--- stderr: rosidl_runtime_cpp
CMake Error at /opt/ros/foxy/install/share/performance_test_fixture/cmake/ament_cmake_export_targets-extras.cmake:18 (message):
  Failed to find exported target names in
  '/opt/ros/foxy/install/share/performance_test_fixture/cmake/performance_test_fixtureExport.cmake'
Call Stack (most recent call first):
  /opt/ros/foxy/install/share/performance_test_fixture/cmake/performance_test_fixtureConfig.cmake:41 (include)
  CMakeLists.txt:19 (find_package)


---
Failed   <<< rosidl_runtime_cpp [5.30s, exited with code 1]

Can you help me figure this out? Thanks alot.

@natanel I haven’t seen that error before and am unsure what it’s related to, sorry about that.

What version of JetPack-L4T are you running? Is there a pre-built container image built for a similar version of L4T here: https://hub.docker.com/repository/docker/dustynv/ros/tags?page=1&ordering=last_updated&name=foxy-pytorch

For example, if cat /etc/nv_tegra_release shows you are running L4T R32.7.1, then you can use dustynv/ros:foxy-pytorch-l4t-r32.7.1. You could start that container like:

cd jetson-containers
scripts/docker_run.sh -c dustynv/ros:foxy-pytorch-l4t-r32.7.1

Hi @natanel, update to this issue - we found the cause in https://github.com/dusty-nv/jetson-containers/issues/181

I’ve checked-in a fix to jetson-containers repo, so if you pull the latest you can try building Foxy again.

Hey, thank you for the notification, I actually ended up installing the Galactic image instead since that version has the rosbag2 Python API, and it’s working great :)

One quick question though, I noticed that rqt_bag is missing, even though as far as I know it is available for galactic, do you know if there is any way to add it?

Thanks again for all the help!

You would probably need to build it from source in the container. One example of building additional ROS2 packages in container is here:

https://github.com/dusty-nv/jetbot_ros/blob/d8e5ee1b17f5c66d038017b86f8920a496197ea9/Dockerfile#L72

In this example, the jetbot_ros container is using the Foxy container as it’s base container, and in the jetbot_ros dockerfile we are building/installing additional ROS packages that are needed (in this instance, gazebo plugins)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.