Installation on TX2 - Pitt-RAS/iarc7_common GitHub Wiki

Introduction

Instructions for setting up a Jetson TX2 to the run the Pitt RAS 2016-2018 flight stack.

These instructions are not intended to be a step by step guide. They are notes for the people who normally set the TX2 up on the 2017-18 IARC team.

  • Linux for Tegra 28.1
  • Jetson TX2
  • Orbitty Carrier Board

Flashing

Download Jetpack and install the Connect Tech BSP.

Follow Connect Techs instructions to disable the serial console on /dev/ttyS0 as its needed for the control board.

Flash the TX2. Look here and here if you are having trouble.

NOTE: Do not specify the configuration extension when trying to use flash.sh. Just the file name without the extension.

It's best if you don't install anything you don't have to when running the Jetpack installer.

Only install CUDA. The media package may have been installed as well. Do not flash the image again since that was done when following the Connect Tech BSP instructions.

Hostname

sudo vi /etc/hostname

Set the hostname to tegra2-iarc

i2c access

sudo usermod -aG i2c ubuntu

Serial port

sudo usermod -aG dialout ubuntu && \
sudo apt-get purge modemmanager;

Modem manger is purged because it attempts to control serial ports randomly.

Update all packages

Update everything till everything is updated and autoremoved etc etc.

At the end run this or software and updates won't open

sudo apt-get install --reinstall apt apt-utils aptdaemon aptdaemon-data update-manager update-manager-core dbus

Enable VNC

Ubuntu comes with a built in VNC server. Connect the Jetson to a display and check a box to enable it. Also allow automatic login so that the server can always be accessed. Command line setup of Vino is technically possible but its way easier to just connect the display.

Search for "remote desktop" in applications to find and enable. Also enable automatic login of the "nvidia" user.

Use this to enable a higher resolution for the default display.

Disable automatic updating

Uninstall update manager

sudo apt-get remove update-manager

Disable automatic updates using the software and updates dialog. Unless you want the drone to update the kernel while flying.

Set "Automatically Check for Updates" to "Never". Set "When there are security updates" to "Display Immediately". Set "Notify me of a new Ubuntu version" to "Never".

Also enable "community" packages in software and updates.

Uninstall packages that the team doesn't like (working list)

sudo apt-get purge thunderbird libreoffice-*

Install packages that the team likes (working list)

sudo apt-get install htop git python-pip tmux && \
git config --global user.email "[email protected]" && \
git config --global user.name "pittras";

Install ROS

Use standard instructions

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" >  /etc/apt/sources.list.d/ros-latest.list' && \
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 0xB01FA116 && \
sudo apt-get update && \
sudo apt-get install ros-kinetic-ros-base -y && \
sudo rosdep init && \
rosdep update;

Installing gcc6

Run the following, you can copy and paste as one command:

sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-snapshot -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5;

This snippet was originally derived from here: https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91

Jetson High Performance

Setting up Jetson list card: Max performance is enabled by a systemd service (high-performance.service) that calls a shell script (/home/ubuntu/high_performance.sh). Note that the script pauses for 65 seconds to avoid conflicting with NVIDIA messing with the clocks and performance levels. This means that if you log in immediately after rebooting only four cores will be initially available.

high_performance.sh

Make sure to: chmod +x ~/high_performance.sh

#!/usr/bin/env sh
sleep 65
echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online
echo 1 > /sys/devices/system/cpu/cpu4/online
echo 1 > /sys/devices/system/cpu/cpu5/online

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

echo 1120000000 > /sys/devices/17000000.gp10b/devfreq/17000000.gp10b/min_freq

echo 1600000000 > /sys/kernel/debug/bpmp/debug/clk/emc/rate
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked

# disable wifi power saving
iw dev wlan0 set power_save off

See this forum post on wifi power saving.

For the Jetson TX1 using the following script.

#!/usr/bin/env sh
sleep 65

sh /home/ubuntu/jetson_clocks.sh
# disable wifi power saving
iw dev wlan0 set power_save off

high-performance.service

Systemd files are located in /etc/systemd/system/

It can be activated with systemctl enable high-performance.service

[Unit]
Description=Turn up performance

[Service]
Type=oneshot
ExecStart=/home/ubuntu/high_performance.sh

[Install]
WantedBy=multi-user.target

Install gstreamer

sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev

https://devtalk.nvidia.com/default/topic/1018967/jetson-tx2/how-to-install-gstreamer-1-12-2-/post/5188410/#5188410

OpenCV

sudo update-alternatives --set gcc /usr/bin/gcc-5 && \
mkdir ~/iarc7 && \
cd ~/iarc7 && \The following instructions support ROS Indigo, on Ubuntu 14.04, and ROS Kinetic, on Ubutnu 16.04.


wget https://github.com/opencv/opencv/archive/3.3.1.tar.gz && \
tar -xvsf 3.3.1.tar.gz && \
sudo apt-get install build-essential -y && \
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y && \
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y && \
sudo apt-get install libv4l-dev v4l-utils qv4l2 v4l2ucp -y && \
cd ~/iarc7/opencv-3.3.1 && \
mkdir release && \
cd release && \
cmake -D CMAKE_BUILD_TYPE=Release -D CUDA_FAST_MATH=ON -D CMAKE_INSTALL_PREFIX=/usr/local CUDA_ARCH_BIN="6.2" WITH_LIBV4L=ON ENABLE_PRECOMPILED_HEADERS=OFF ENABLE_NEON=ON BUILD_TESTS=OFF BUILD_PERF_TESTS=OFF BUILD_EXAMPLES=OFF .. && \
make -j6 && \
sudo make install && \
sudo update-alternatives --set gcc /usr/bin/gcc-6;

1-2-18 The above command segfaulted in the middle of compilation once.

http://dev.t7.ai/jetson/opencv/

https://docs.opencv.org/3.3.1/d6/d15/tutorial_building_tegra_cuda.html

Set up the workspace

sudo apt-get install python-wstool -y && \
sudo apt-get install ros-kinetic-rosserial && \
mkdir -p ~/iarc7/src && \
cd ~/iarc7 && \
git clone https://github.com/Pitt-RAS/iarc7_common.git && \
source /opt/ros/kinetic/setup.bash && \
wstool init src iarc7_common/main.rosinstall && \
cd ~/iarc7/src && \
git clone -b iarc7 https://github.com/Pitt-RAS/gscam.git && \
git clone https://github.com/robopeak/rplidar_ros.git && \
cd ~/iarc7 && \
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y && \
catkin_make && \
echo "source ~/iarc7/devel/setup.bash" >> ~/.bashrc && \
source ~/.bashrc;

Set the ROS_IP variable so that remote nodes can receiver from topics.

echo "export ROS_IP=ipaddressofjetson" >> ~/.bashrc

Set time zone

Very easy to do from the graphical settings dialog.

Realsense

Add "uvcvideo" to /etc/modules so that it is loaded on startup.

Build and install the custom librealsense branch from PittRAS. This includes a special reset function resets the program when execution ends. Without it the camera cannot be connected to again. Unfortunately this makes uvc SIGABRT and the program crashes.

We want to install from source for two reasons. The firmware reset hack and because the ros-kinetic-librealsense installs a bunch of headers that aren't needed.

The script below is derived from the linux install instructions from the legacy branch.

Note: The uvc drivers do not need to be patched as realsense docs and jetson hacks suggest. It works without it.

cd ~/iarc7/src && \
git clone https://github.com/Pitt-RAS/librealsense && \
cd librealsense && \
sudo apt-get update && sudo apt-get upgrade -y && \
sudo apt-get install libusb-1.0-0-dev pkg-config -y && \
sudo apt-get install qtcreator -y && \
sudo apt-get install cmake-curses-gui -y && \
sudo apt-get install libglfw3-dev -y && \
sudo apt-get install qdbus qmlscene qt5-default qt5-qmake qtbase5-dev-tools qtchooser qtdeclarative5-dev xbitmaps xterm libqt5svg5-dev qttools5-dev qtscript5-dev qtdeclarative5-folderlistmodel-plugin qtdeclarative5-controls-plugin -y && \
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/ && \
sudo udevadm control --reload-rules && udevadm trigger && \
mkdir build && \
cd build && \
cmake .. -DBUILD_EXAMPLES:BOOL=true && \
make -j6;

Next we need the ros-kinetic-realsense_camera package but it can't be installed from apt-get because it tries to intall librealsense from ros-kinetic-librealsense. Note: the rosdep below installs different versions of everything from vision_opencv but I think that's ok because of overlays.

cd ~/iarc7/src && \
git clone https://github.com/intel-ros/realsense.git && \
cd realsense && \
git fetch origin indigo-devel && \
git checkout indigo-devel && \
cd ~/iarc7 && \
rosdep install --from-paths src --ignore-src -r -y && \
catkin_make;

Realsense Resources

Relevant github repo (not the default)

Video modes

Realsense Camera

Jetson Hacks article on setting up realsense cameras. Do not use this, it uses an old release when the legacy branch should be used. It also says the uvc module needs to be updated which is incorrect for the TX2.

Jetson Hacks article on using the realsense r200 with ROS on the TX2. Mentions the ros-kinetic-librealsense and ros-kinetic-realsense_camera packages. We don't install ros-kinetic-librealsense because it installs a bunch of headers that are incorrect and the firmware reset hack is needed. We do use ros-kinetic-realsense_camera directly from apt-get.

Discussion on UVC detection removal. Discussion on firmware reset.

Update camera firmware.

Enabling CDC ACM

CDC ACM is a communication protocol for usb serial devices that is used in the RPLidar and SPF3EVO board. It needs to be enabled by building a kernel module.

cd ~ && \
sudo apt-get install libncurses5-dev libncursesw5-dev && \
mkdir kernel && \
cd kernel && \
wget https://developer.nvidia.com/embedded/dlc/l4t-sources-28-1 && \
mv l4t-sources-28-1 l4t-sources-28-1.tbz2 && \
tar -xvf l4t-sources-28-1.tbz2 sources/kernel_src-tx2.tbz2 && \
tar -xvf sources/kernel_src-tx2.tbz2 && \
cd kernel/kernel-4.4 && \
zcat /proc/config.gz > .config && \
echo CONFIG_USB_ACM=m >> .config && \
cp /usr/src/linux-headers-4.4.38-tegra/Module.symvers . && \
sed -i "s/CONFIG_LOCALVERSION=\"\"/CONFIG_LOCALVERSION=\"+\"/" .config && \
make prepare && \
make SUBDIRS=scripts/mod && \
make SUBDIRS=drivers/usb/class modules && \
sudo cp drivers/usb/class/cdc-acm.ko /lib/modules/4.4.38+/kernel/drivers/usb/class && \
sudo bash -c "echo cdc-acm >> /etc/modules" && \
sudo depmod -a;

Passwordless sudo

https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html

Use visudo and add "ubuntu ALL=(ALL) NOPASSWD: ALL" at the bottom.

Cloning

Make an image

  • Put Jetson into recovery mode.

  • Goto jetpack installation

    sudo ./flash.sh -r -k APP -G system.img jetson-tx2 mmcblk0p1

Restore an image

  • Place a system.img in Jetpack/64_TX2/Linux_for_Tegra_tx2/bootloader

  • Run the below command in the same directory as flash.sh

    sudo ./flash.sh -r orbitty mmcblk0p1

https://elinux.org/Jetson/TX2_Cloning

Old notes kept for historical value

Enable CP210x for rplidar A2

https://developer.nvidia.com/embedded/develop/software Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light

DTB Editing

http://elinux.org/Jetson/TX2_DTB https://devtalk.nvidia.com/default/topic/1001443/jetson-tx2/extlinux-conf-fdt-no-longer-used-for-dtb-file-specification-/1

https://devtalk.nvidia.com/default/topic/1001771/jetson-tx2/no-usb-support-on-custom-base-carrier-board/2

dtc -I dtb -o dts extracted.dts /boot/tegra186-quill-p3310-1000-c03-00-base.dtb

The guys device tree compiler commands are wrong but the idea is correct

https://devtalk.nvidia.com/default/topic/1001264/jetson-tx2/tx2-uarts/post/5125725/#5125725

http://elinux.org/Jetson/TX1_SPI#Patching_the_New_DTS

tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb

dtc -I dtb -O dts -o ~/i2c_change/extracted.dts /boot/tegra210-jetson-tx1-p2597-2180-a01-devkit.dtb

dtc -I dts -O dtb -o ~/i2c_change/modified-i2c-100Khz.dtb ~/i2c_change/edited100Khz_i2c1.dts

sudo cp /home/ubuntu/i2c_change/modified-i2c-100Khz.dtb /boot/tegra210-jetson-tx1-p2597-2180-a01-devkit-i2c-100Khz.dtb

Change dtb to new one sudo vim /boot/extlinux/extlinux.conf sudo reboot

i2c notes

sudo usermod -aG i2c ubuntu

and reboot to access the i2c device

You HAVE TO USE sudo i2cdetect -y -r 1 on the jetson. You have to have the -r

You also need to own the serial port or something. chown works but there must be a better solution