Jetson TK1與ROS調教手記

前言

近期入手了一塊NVIDIA TK1開發板,想用這塊開發板結合ROS做機器人開發,在此處記錄下一些折騰記錄,方便日后查詢。

Flash TK1

這一部分可以參考JetPack 2.0 – NVIDIA Jetson Development Pack – Jetson TK1這篇文章。

通過JetPack安裝

首先在Ubuntu Host上下載最新的JetPack TK1最新的安裝文件:JetPack-<VERSION>.run,其中<VERSION>對應的是相應的版本,比如截止本文寫作時,最新版為:L4T-2.1-linux-x64,因此安裝文件的文件名即為:JetPack-L4T-2.1-linux-x64.run。

下載地址:https://developer.nvidia.com/embedded/jetpack

假設該文件所在位置為Home目錄,打開Terminal,改變文件權限:

$ chmod +x JetPack-L4T-2.1-linux-x64.run

在運行該安裝文件前,最好檢查一下Ubuntu Host的IP地址,最好設為: 192.168.1.101,因為筆者在安裝過程中發現,如果不設置為這個地址,后續傳輸文件就容易卡住甚至出錯,具體原因還在探尋中。檢查IP地址的方法很簡單,在Terminal中輸入ifconfig命令即可:

ip_set_ifconfig

然后以管理員身份運行此文件,注意,一定要以管理員身份運行,不然后面可能會提示權限錯誤。

$ sudo ./JetPack-L4T-2.1-linux-x64.run

下面是安裝過程的一些截圖:

首先是安裝包選擇界面,一般默認即可。檢查下是否選擇上了CUDA Toolkit和OpenCV for Tegra,這兩個包一定要裝。

jetpack_component_manager

下面是安裝確認界面,確認無誤后,點擊“Next”即可。

post_installation

根據提示,設置TK1為Force USB Recovery Mode。

tk1_recovery_mode

打開另一個Terminal,輸入lsusb命令,檢查TK1是否進入Force USB Recovery Mode。看到打印出來Nvidia Corp.信息即可。

tk1_recovery_mode_2

然后在Post Installation窗口按下Enter鍵即進入安裝,安裝過程根據網絡狀況不同時間不一。

tk1_recovery_mode_3

手動安裝(不推薦)

JetPack安裝過程中可能會出錯,這時可以采用手動安裝。

安裝CUDA

$ cd cuda-l4t  // 理論上 Jetpack 會把 CUDA 檔案放在這,請自行確認
# Install the CUDA repo metadata that you downloaded manually for L4T
$ sudo dpkg -i cuda-repo-l4t-r21.3-6-5-local_6.5-50_armhf.deb
$ sudo apt-get install cuda-toolkit-6-5

檢查CUDA是否安裝成功:

$ nvcc -V   // 正常會跳出版本資訊
cuda_check

安裝OpenCV4Tegra

安裝OpenCV4Tegra前要先安裝CUDA。

$ cd OpenCV4Tegra  // 理論上 Jetpack 會把檔案放在這,請自行確認
$ sudo dpkg -i libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.deb
$ sudo apt-get update
$ sudo apt-get install libopencv4tegra libopencv4tegra-dev

檢查是否安裝成功:

$ sudo apt–get install libopencv4tegra–python // 要先安裝程式,連結 python

在Terminal中輸入:

$ python
>>> import cv2             // 呼叫 library,如果出現 ERROR ,代表 … 革命尚未成功 …
>>> print cv2.__version__  // Check 一下版本,OpenCV4Tegra再 JetPack 21 為2.4.12.2
opencv4tegra_check

After Flash Setup

這一部分主要參考了以下這篇博客:

After LT4 21.3 Flash Setup – NVIDIA Jetson TK1

以及以下git中的代碼:

https://github.com/jetsonhacks/postFlash

首先安裝git:

$ sudo apt-get update
$ sudo apt-get install git

查看Jetson TK1 L4T版本:

head -n 1 /etc/nv_tegra_release
tk1_L4T_version

配置postFlash腳本:

$ git clone https://github.com/jetsonhacks/postFlash.git
$ cd postFlash
$ ./configureSystem.sh

這個腳本主要幫我們完成了一下一些事:

  • Chromium is installed as a browser. Firefox has issues downloading .zip files, so Chromium is a good alternative. Two other applications are also installed, aptitude and git.
  • USB 3.0 is enabled. The default is USB 2.0, /boot/extlinux/extlinux.conf must be modified to enable USB 3.0.
  • Two scripts are installed in /usr/local/bin. To conserve power, by default the Jetson suspends power to the USB ports when they are not in use. In a desktop environment, this can lead to issues with devices such as cameras and webcams. The first script disables USB autosuspend.
  • Also to conserve power, the Jetson manipulates the CPU cores and GPU clock speeds. The second script sets everything up for maximum performance.

安裝Grinch Kernel

這一部分主要參考了以下這篇博客:

Install Grinch Kernel for L4T 21.3 on NVIDIA Jetson TK1

以及以下git中的代碼:

https://github.com/jetsonhacks/installGrinch

關于Grinch是什么,為什么Nvidia沒有默認安裝Grinch:

Many people, especially those coming from desktop platforms, wonder why the Jetson lacks initial support for a wide variety of external peripherals when removed from the box. The reason is that the Jetson is an embedded development kit, which means its main initial intent was to help developers build devices that include the Tegra K1 chip. If you think about it from that perspective, it wouldn’t make much sense to have extra drivers and cruft installed that a device doesn’t use. For example, if you were building a phone, it doesn’t make sense to have drivers for 20 different wireless cards that the phone doesn’t contain.

However, the Jetson is also powerful enough to be a general purpose desktop computer. Desktop computer users have certain expectations, including being able to add devices and drivers, or have support for common devices available. Fortunately the Jetson community, led by user Santyago built a new Linux kernel named Grinch which includes a lot of the features to which most desktop users are accustomed.

安裝方式如下:

$ git clone https://github.com/jetsonhacks/installGrinch.git
$ cd installGrinch
$ ./installGrinch.sh

安裝ROS indigo

這一部分主要參考了以下幾篇文章:

Nvidia Jetson TK1 ROS wiki

Ubuntu ARM install of ROS Indigo

Robot Operating System (ROS) on NVIDIA Jetson TK1

$ git clone https://github.com/jetsonhacks/installROS.git
$ cd installROS

復制一份installROS.sh,并命名為installROSModified.sh。打開installROSModified.sh,將source.list改為國內源,這樣安裝的時候,速度可以快一些。比如筆者就將源改為了易科機器人實驗室(ExBot Robotics Lab)的源:

change_source_list

設置RVIZ。至于安裝腳本為什么沒有默認設置RVIZ,我們可以參考官方wiki上的說明:

It is not recommended to run rviz on most ARM-based CPUs. They're generally too slow, and the version of OpenGL that is provided by the software (mesa) libraries it not new enough to start rviz.

'IF' you have a powerful board with a GPU and vendor-supplied OpenGL libraries, it might be possible to run rviz. The IFC6410 and the NVidia Jetson TK1 are two such boards where rviz will run, although neither is fast enough for graphics-heavy tasks such as displaying pointclouds.

Note that rviz will segfault if you have the GTK_IM_MODULE environment variable set, so it's best to unset it in your~/.bashrc:

unset GTK_IM_MODULE

根據官方wiki,設置RVIZ的方式很簡單,我們只需在installROSModified.sh文件中加入如圖所示的代碼即可:

using_rviz

最后,在Terminal中運行installROSModified.sh腳本:

$ ./installROSModified.h

等待一段時間,ROS Indigo就應該安裝好了,檢查是否安裝成功也很簡單,重新打開一個Terminal,運行roscore即可,如果輸入下圖類似內容,即說明安裝成功。

roscore

安裝ros-prereq.sh(Optional)

ros-prereq.sh腳本能幫我們安裝一些常用的ROS工具包,包括navigation和mapping工具包等,在Terminal中直接運行如下代碼即可:

./ros-prereq.sh

ros-prereq.sh下載地址:鏈接: https://pan.baidu.com/s/1boYHvYn 密碼: tswv
之前忘記上傳了,感謝2樓提醒。

Hacking for OpenCV

這一部分主要參考了以下幾篇文章:

ROS, OpenCV and OpenCV4Tegra on the NVIDIA Jetson TK1

http://myzharbot.robot-home.it/blog/software/ros-nvidia-jetson-tx1-jetson-tk1-opencv-ultimate-guide/

需要修改的文件如下:

  • /opt/ros/<ros-version>/lib/pkgconfig/cv_bridge.pc
  • /opt/ros/<ros-version>/lib/pkgconfig/image_geometry.pc
  • /opt/ros/<ros-version>/share/cv_bridge/cmake/cv_bridgeConfig.cmake
  • /opt/ros/<ros-version>/share/image_geometry/cmake/image_geometryConfig.cmake

先備份:

$ sudo cp /opt/ros/indigo/lib/pkgconfig/cv_bridge.pc /opt/ros/indigo/lib/pkgconfig/cv_bridge.pc-bak
$ sudo cp /opt/ros/indigo/lib/pkgconfig/image_geometry.pc /opt/ros/indigo/lib/pkgconfig/image_geometry.pc-bak
$ sudo cp /opt/ros/indigo/share/cv_bridge/cmake/cv_bridgeConfig.cmake /opt/ros/indigo/share/cv_bridge/cmake/cv_bridgeConfig.cmake-bak
$ sudo cp /opt/ros/indigo/share/image_geometry/cmake/image_geometryConfig.cmake /opt/ros/indigo/share/image_geometry/cmake/image_geometryConfig.cmake-bak

對以上每個文件做如下修改:

  • remove each instance /usr/lib/arm-linux-gnueabihf/libopencv_ocl.so.2.4.8;
  • replace each instance of /usr/lib/arm-linux-gnueabihf/ with /usr/lib
  • replace each instance of 2.4.8 with 2.4.12 (or the current version of OpenCV in opencv4tegra package)
$ sudo gedit /opt/ros/indigo/lib/pkgconfig/cv_bridge.pc &
$ sudo gedit /opt/ros/indigo/lib/pkgconfig/image_geometry.pc &
$ sudo gedit /opt/ros/indigo/share/cv_bridge/cmake/cv_bridgeConfig.cmake &
$ sudo gedit /opt/ros/indigo/share/image_geometry/cmake/image_geometryConfig.cmake &

安裝Kinect Driver

ROS中默認沒有安裝Kinect的庫,如果我們需要使用Kinect,就需要安裝庫,安裝方法如下:

TIP: Notice that the command below that starts with “tar xvjf” mentions “x64”. If you are using a 86-bit processor change this to “x86” and do the same things for the following line starting with “cd”. View a complete list of options.

$ mkdir ~/kinectdriver 
$ cd ~/kinectdriver 
$ git clone https://github.com/avin2/SensorKinect.git
$ cd SensorKinect/Bin/
$ tar xvjf SensorKinect093-Bin-Linux-x64-v5.1.2.1.tar.bz2
$ cd Sensor-Bin-Linux-x64-v5.1.2.1/
$ sudo ./install.sh

總結

不定期更新,未完待續……

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容