IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.57k stars 4.82k forks source link

T265: SDK build instructions for Ubuntu 18.04 missing #3517

Closed dlarue closed 4 years ago

dlarue commented 5 years ago

Required Info
Camera Model T265
Firmware Version DNA
Operating System & Version Linux (Ubuntu 18)
Kernel Version (Linux Only) Linux version 4.15.0-46-generic (buildd@lgw01-amd64-038) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)
Platform PC and Raspberry Pi 3B+
SDK Version 2.0
Language C and python
Segment Robot ROS DIYRoboCar

Issue Description

I need to get the T265 working on the rPi running Ubuntu 18.04 and ROS Melodic. If anything to know if it's viable. I have validated the T265 camera on my AMD64 desktop KUbuntu 18.04.3 with precompiled binaries. Before attempting to build on/for the rPi, I was building the kernel module from source on the desktop. It resulted in stopping on loading the kernel modules. Error was that it couldn't load videodev because videobuf2_core was in use, but I expect that'll be fine since the packaged binaries worked and a reboot will likely show compiled drivers loading.

The next step was to get the sample apps running. So when I went to build the SDK 2.0, it only is setup for building on Ubuntu 14.04 using a really old version of gcc.

pedrombmachado commented 5 years ago

Hi @dlarue You can unload the module by completing the following steps: check if the module is loaded

$ lsmod | grep videobuf2_core 

if so unload the module

sudo modprobe -r uvcvideo
sudo modprobe -r videobuf2_core (imho it unwinds automatically once you release uvcvideo)
sudo modprobe -r videodev

retrieved from issue #2846 After that create a script file (e.g install.sh)

! /bin/bash

echo "Script for installing the librealsense2 on Ubuntu 18.04 LTS" echo "Updating the OS..." sudo apt update sudo apt upgrade -y echo "Installing dependencies..." sudo apt install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev -y

echo "Fetching and unpacking librealsense2 ..." mkdir -p $HOME/repositories cd $HOME/repositories if [ -d librealsense]; then cd librealsense git pull else git clone https://github.com/IntelRealSense/librealsense.git cd librealsense fi

echo "Installing udev rules ..." sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/ sudo udevadm control --reload-rules && udevadm trigger

echo "Configuring CMAKE with python support ... this will take a couple of minutes..." mkdir build cd build if [ -f install_manifest.txt ]; then echo "Removing old files." xarg sudo rm < install_manifest.txt fi if [ -f CMakeCache.txt ]; then echo "Removing CMakeCache.txt" rm CMakeCache.txt fi

export CC=/usr/local/bin/gcc-6 export CXX=/usr/local/bin/g++-6 cmake -D CMAKE_BUILD_TYPE="Release"\ -D FORCE_LIBUVC=ON \ -D BUILD_PYTHON_BINDINGS=ON \ -D BUILD_EXAMPLES=OFF ..

echo "Compiling librealsense2 ... this will take several minutes..." make -j2 sudo make install sudo ldconfig echo "Done!" This has been tested on an ARM A53. Retrieved from: https://github.com/SundanceMultiprocessorTechnology/VCS-1/blob/master/Software/Image_processing/VCS-1/install_realsense2_VCS-1.sh

dlarue commented 5 years ago

Thanks @pedrombmachado , I did unload the modules and saw the proper loading of the newly built modules. But I also figured out I could just run cmake after making a build directory and then make would build the tools/samples like realsense-viewer. That worked on my desktop so I've been going down the long road of building on the rPi using the 18.04 server image. Added 2GB of swap via USB and after a failed apt upgrade, I started without upgrading and hit a snag on v4l_vb2q_enable_media_source being unrecognized. That eventually was found out to be because the 4.15 kernel hadn't been updated so I did a selective update of u-boot and linux-image worked.

sudo apt install u-boot-rpi u-boot-tools linux-firmware-raspi2 linux-image-raspi2 linux-headers-raspi2 u-boot-rpi u-boot-tools sudo apt-get install cmake libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev

It is taking quite a while to build but I'm hopeful it'll build and I will try it using X11 forwarding to see if realsense-viewer and the camera will work on rPi with Ubuntu 18.04. X11 forwarding since it's headless.

Thanks for your input.

pedrombmachado commented 5 years ago

Hi @dlarue , make sure you are using gcc-6 and g++-6. I spent almost two days to figure it out that the problem was trying to compile using gcc-7 and g++-7. make sure you have done

export CC=/usr/local/bin/gcc-6 export CXX=/usr/local/bin/g++-6 before the cmake. I also had to mount an external usb stick of 4GB for compiling using only 2 cores. I hope it helps.

dorodnic commented 5 years ago

Hi @pedrombmachado @dlarue Sorry if the instructions are somewhat confusing at the moment. We need to explain more clearly which part is needed for what. The important point is that you don't need any kernel patches to use the T265. You do still need udev rules and obviously building everything with GCC and CMake.

dlarue commented 5 years ago

Ya, I kinda figured that out when I was not seeing a kernel being built but instead kernel modules. It's still been a royal PIA trying to get this working headless. I can't find any commandline tool which validates the drivers and camera are operational. Only the GL visualization ones work but when headless, getting the client to render on the remote server is being a problem since Ubuntu 18.04 images are server only that I've found and Raspbian stretch uses kernel 4.14 which is between the 4.13 and 4.15 which are supported by RealSense software.

dlarue commented 5 years ago

Closer... I installed the uSD image using this since I wanted the performance of the 3B+: ubuntu-18.04.2-preinstalled-server-armhf+raspi3-b-plus.img.xz installed lxdesktop-core and then all the libs for building the drivers using the patch-realsense-ubuntu-ltsp.sh script. and those built and installed. I then built the examples using cmake and now the realsense-viewer loads and sees the T265 but crashes as soon as I enable the device.

Going to install gcc-6 and rebuild the apps and see if that's the magic sauce needed.

dlarue commented 5 years ago

Sorry but even after building with gcc-6 the realsense-viewer still core dumps as soon as I try to switch the T265 on in the application. dmesg output: [ 442.717163] usb 1-1.1.3: new high-speed USB device number 10 using dwc_otg [ 442.817890] usb 1-1.1.3: New USB device found, idVendor=03e7, idProduct=2150 [ 442.817907] usb 1-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 442.817919] usb 1-1.1.3: Product: Movidius MA2X5X [ 442.817928] usb 1-1.1.3: Manufacturer: Movidius Ltd. [ 442.817938] usb 1-1.1.3: SerialNumber: 03e72150 [ 473.213556] usb 1-1.1.3: USB disconnect, device number 10 [ 473.545204] usb 1-1.1.3: new high-speed USB device number 11 using dwc_otg [ 473.646042] usb 1-1.1.3: New USB device found, idVendor=8087, idProduct=0b37 [ 473.646052] usb 1-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 473.646057] usb 1-1.1.3: Product: Intel(R) RealSense(TM) Tracking Camera T265 [ 473.646061] usb 1-1.1.3: Manufacturer: Intel(R) Corporation [ 473.646065] usb 1-1.1.3: SerialNumber: 8454121109810000 [ 477.692433] Alignment trap: not handling instruction edd30b00 at [<76347772>] [ 477.692449] Unhandled fault: alignment exception (0x001) at 0x02a98fe5 [ 477.692457] pgd = 376c3cf5 [ 477.692463] [02a98fe5] pgd=389fe835, pte=112a175f, *ppte=112a1c7f

dorodnic commented 5 years ago

There is also no need for kernel modules patching. T265 is operated entirely via libusb right now. There is rs-pose headless utility (and also rs-save-to-disk I think) that you can use. If the crash is on the Pi due to illegal instruction, it might be related to #3490 and caused by the compiler emitting neon instructions.

dlarue commented 5 years ago

It worked after I turned debug on. cmake -D CMAKE_BUILD_TYPE="RelWithDebInfo" -D FORCE_LIBUVC=ON -D BUILD_PYTHON_BINDINGS=ON -D BUILD_EXAMPLES=ON ..

And thankyou @dorodnic for the rs-pose mention. I had thought I'd tried that on my desktop build and it hadn't worked. Regardless, it was functioning on the rPi build with debugging info on.

Probably right on the NEON instructions since I think optimizations are down graded with debugging info turned on. Looks like 02 instead of 03.

pedrombmachado commented 5 years ago

@dlarue what version of gcc and g++ did you use?

dlarue commented 5 years ago

it was built with v6 but I'm now building with CC and CXX unset so v7.3 is being used with the -O2 optimization to see if it works with the default compiler. I will post the results.

It takes about two hours or more to build with debugging info turned on. I'll be testing with just the compiler change first. Then I will see if i can figure out where to change the default optimization setting for cmake and build without debugging info and test that.

pedrombmachado commented 5 years ago

@dlarue , Have you tried to cross-compile? @dorodnic it could be interesting to have instructions for cross-compiling the librealsense2. It is really painful having to compile it on the ARM. BTW, it is important not restricting to the RPI because in my case I am targetting the Xilinx UltraScale+

dlarue commented 5 years ago

It ran with debug on and using the O2 optimizations with the default gcc v7.3 compiler. So setting up for v6 of the compiler seems unnecessary.

@pedrombmachado I have not tried cross compiling yet. yes it is painfully long compiling on the rPi but I think debug info adds lots of time and I had started with -j3 and ran out of swap( 2G ) so I increased swap to 3G. Just started compiling without debug, using O2 optimizations and the 7.3 compiler.

dlarue commented 5 years ago

By changing the optimization level from -O3 to -O2 in the CMakeCache.txt file after running the initial CMake command, it builds and run using the default compiler( v7.3 ).

Now I think I need to start from scratch again and document the minimum required steps to get the command line tools and python bindings built in a headless environment.

pedrombmachado commented 5 years ago

Hi @dlarue , Great news. I will try it tomorrow as well.

pedrombmachado commented 5 years ago

Hi @dlarue , Compiled, using gcc-7, with success following your suggestions.

dlarue commented 5 years ago

Great news @pedrombmachado ! Today I will take @dorodnic for his word and try to compile and run on Raspbian Stretch without any kernel modules, using only udev rules setup. It was the kernel model patching which had me chasing down a compatible kernel and Raspbian wasn't in the list.

dlarue commented 5 years ago

I'm a cofounder of the San Diego DIYRoboCar group so the plan is to try the camera(T265) to get odometry along with localization combined with our CNN.

dlarue commented 5 years ago

@dorodnic The non-graphical examples( except pose) build and run on Raspbian Stretch without running the kernel module patches. Well, I've tested rs-posepredict and after fixing the build system rs-pose works too.

Regarding rs-pose not building, it's a cmake config issues: The CMakeLists.txt file in librealsense/examples/pose incorrectly is dependent on if(BUILD_GRAPHICAL_EXAMPLES)

should be: if(BUILD_EXAMPLES)

I created the make system for commandline-only with: cmake -D CMAKE_BUILD_TYPE="Release" -D FORCE_LIBUVC=ON \ -D BUILD_PYTHON_BINDINGS=ON -D BUILD_EXAMPLES=ON \ -D BUILD_GRAPHICAL_EXAMPLES=OFF ..

dorodnic commented 5 years ago

Hi @dlarue Thanks for the feedback, we need to update this

RealSenseSupport commented 4 years ago

Thank you again for highlighting the issues with the build instructions for T265. We have moved our focus to our next generation of products and consequently, we will not be addressing this issue for the T265.