前言
近期入手了一块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
命令即可:
然后以管理员身份运行此文件,注意,一定要以管理员身份运行,不然后面可能会提示权限错误。
$ sudo ./JetPack-L4T-2.1-linux-x64.run
下面是安装过程的一些截图:
首先是安装包选择界面,一般默认即可。检查下是否选择上了CUDA Toolkit和OpenCV for Tegra,这两个包一定要装。
下面是安装确认界面,确认无误后,点击“Next”即可。
根据提示,设置TK1为Force USB Recovery Mode。
打开另一个Terminal,输入lsusb
命令,检查TK1是否进入Force USB Recovery Mode。看到打印出来Nvidia Corp.
信息即可。
然后在Post Installation窗口按下Enter键即进入安装,安装过程根据网络状况不同时间不一。
手动安装(不推荐)
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 // 正常會跳出版本資訊
安装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
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
配置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
这一部分主要参考了以下几篇文章:
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)的源:
设置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文件中加入如图所示的代码即可:
最后,在Terminal中运行installROSModified.sh脚本:
$ ./installROSModified.h
等待一段时间,ROS Indigo就应该安装好了,检查是否安装成功也很简单,重新打开一个Terminal,运行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
with2.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
总结
不定期更新,未完待续……