Nvidia Jetson Nano开发板Ubuntu18.04+OpenCV3.2+Ros Melodic+Turtlebot搭建教程

Nvidia Jetson Nano开发板Ubuntu18.04+OpenCV3.2+Ros Melodic+Turtlebot搭建教程_第1张图片Nvidia Jetson Nano开发板Ubuntu18.04+OpenCV3.2+Ros Melodic+Turtlebot搭建教程_第2张图片

最近在研究低成本机器人+AI能用的板子,找到了这款今年发布的板子,官方定价仅售99美金,感觉性价比超高啊。

按照官方提供的烧录教程和镜像安装默认的Ubuntu 18.04 Bionic版本,在搭建所需要的环境的时候遇到了一些坑,在这边记录一下,供各位伸手党取阅。

首先安装ROS,由于官方源在国外速度比较慢,所以第一次尝试使用了国内的源,但是发现到后面会rosdep init的时候会有坑,出现如下报错

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

各种方法都无解之后,老老实实按照官方教程,从官方源下载,步骤如下

1.Configure your Ubuntu repositories

Configure your Ubuntu repositories to allow "restricted," "universe," and "multiverse." You can follow the Ubuntu guide for instructions on doing this.

2.Setup your sources.list

Setup your computer to accept software from packages.ros.org.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

3.Set up your keys

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

4.Installation

First, make sure your Debian package index is up-to-date:

sudo apt update

5.Initialize rosdep

Before you can use ROS, you will need to initialize rosdep. rosdep enables you to easily install system dependencies for source you want to compile and is required to run some core components in ROS.

sudo rosdep init
rosdep update

6.Environment setup

It's convenient if the ROS environment variables are automatically added to your bash session every time a new shell is launched:

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

7.Dependencies for building packages

Up to now you have installed what you need to run the core ROS packages. To create and manage your own ROS workspaces, there are various tools and requirements that are distributed separately. For example, rosinstall is a frequently used command-line tool that enables you to easily download many source trees for ROS packages with one command.

To install this tool and other dependencies for building ROS packages, run:

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential

至此ROS(Melodic)安装完成,运行roscore会看到ros系统启动打印信息

接下来是安装OpenCV3.2.0,需要将GPU加速支持加入编译opencv

1.安装依赖

sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl

另外需要安装libjasper-dev,这又是一大坑,由于我们是ARM架构的18.04,网上一般的方法都会报错

E: Unable to locate package libjasper-dev

此时需要把/etc/apt/sources.lists的源(提前备份一下)换成如下

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe

sudo apt-get  update

sudo apt-get install libjasper1 libjasper-dev安装成功

2.下载opencv源码

mkdir -p ~/tools/
cd ~/tools/
curl -L https://github.com/opencv/opencv/archive/3.2.0.zip -o opencv-3.2.0.zip
unzip opencv-3.2.0.zip 

下载opencv_contrib

git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout -b v3.2.0 3.2.0

在opencv-3.2.0/cmake路径下找到FindCUDA.cmake

找到 find_cuda_helper_libs(nppi) 替换为

  find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)
  • 找到行,
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
  • 替换为:
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
  • 找到行
unset(CUDA_nppi_LIBRARY CACHE)
  • 替换为
unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)

同路径下找到OpenCVDetectCUDA.cmake

  • 找到
 ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  ...
  • 修改为
  ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  ...

opencv-3.2.0/modules/cudev/include/opencv2/cudev路径下找到common.hpp,打开加入

#include 

然后把路径切换回 opencv-3.2.0下

3.编译源码

mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="7.2" -D ENABLE_PRECOMPILED_HEADERS=OFF  -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/tools/opencv_contrib/modules ..

make -j8
sudo make install 

等待结束。

然后安装Turtlebot

  • 复制所需要的库到对应的目录

cd /usr/lib/aarch64-linux-gnu
sudo ln -s /usr/local/lib/libopencv_aruco.so.3.2.0  libopencv_aruco.so.3.2.0            
sudo ln -s /usr/local/lib/libopencv_cudaimgproc.so.3.2.0   libopencv_cudaimgproc.so.3.2.0 
sudo ln -s /usr/local/lib/libopencv_flann.so.3.2.0    libopencv_flann.so.3.2.0         
sudo ln -s /usr/local/lib/libopencv_phase_unwrapping.so.3.2.0  libopencv_phase_unwrapping.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_surface_matching.so.3.2.0 libopencv_surface_matching.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_bgsegm.so.3.2.0  libopencv_bgsegm.so.3.2.0         
sudo ln -s /usr/local/lib/libopencv_cudalegacy.so.3.2.0  libopencv_cudalegacy.so.3.2.0    
sudo ln -s /usr/local/lib/libopencv_freetype.so.3.2.0  libopencv_freetype.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_photo.so.3.2.0  libopencv_photo.so.3.2.0           
sudo ln -s /usr/local/lib/libopencv_text.so.3.2.0 libopencv_text.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_bioinspired.so.3.2.0  libopencv_bioinspired.so.3.2.0    
sudo ln -s /usr/local/lib/libopencv_cudaobjdetect.so.3.2.0  libopencv_cudaobjdetect.so.3.2.0  
sudo ln -s /usr/local/lib/libopencv_fuzzy.so.3.2.0      libopencv_fuzzy.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_plot.so.3.2.0     libopencv_plot.so.3.2.0         
sudo ln -s /usr/local/lib/libopencv_videoio.so.3.2.0 libopencv_videoio.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_calib3d.so.3.2.0   libopencv_calib3d.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_cudaoptflow.so.3.2.0    libopencv_cudaoptflow.so.3.2.0 
sudo ln -s /usr/local/lib/libopencv_hdf.so.3.2.0     libopencv_hdf.so.3.2.0          
sudo ln -s /usr/local/lib/libopencv_reg.so.3.2.0    libopencv_reg.so.3.2.0            
sudo ln -s /usr/local/lib/libopencv_video.so.3.2.0  libopencv_video.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_ccalib.so.3.2.0   libopencv_ccalib.so.3.2.0        
sudo ln -s /usr/local/lib/libopencv_cudastereo.so.3.2.0   libopencv_cudastereo.so.3.2.0   
sudo ln -s /usr/local/lib/libopencv_highgui.so.3.2.0      libopencv_highgui.so.3.2.0     
sudo ln -s /usr/local/lib/libopencv_rgbd.so.3.2.0      libopencv_rgbd.so.3.2.0        
sudo ln -s /usr/local/lib/libopencv_videostab.so.3.2.0   libopencv_videostab.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_core.so.3.2.0    libopencv_core.so.3.2.0         
sudo ln -s /usr/local/lib/libopencv_cudawarping.so.3.2.0  libopencv_cudawarping.so.3.2.0   
sudo ln -s /usr/local/lib/libopencv_imgcodecs.so.3.2.0   libopencv_imgcodecs.so.3.2.0      
sudo ln -s /usr/local/lib/libopencv_saliency.so.3.2.0    libopencv_saliency.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_viz.so.3.2.0   libopencv_viz.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_cudaarithm.so.3.2.0   libopencv_cudaarithm.so.3.2.0    
sudo ln -s /usr/local/lib/libopencv_cudev.so.3.2.0    libopencv_cudev.so.3.2.0        
sudo ln -s /usr/local/lib/libopencv_imgproc.so.3.2.0   libopencv_imgproc.so.3.2.0        
sudo ln -s /usr/local/lib/libopencv_shape.so.3.2.0    libopencv_shape.so.3.2.0          
sudo ln -s /usr/local/lib/libopencv_xfeatures2d.so.3.2.0  libopencv_xfeatures2d.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_cudabgsegm.so.3.2.0   libopencv_cudabgsegm.so.3.2.0    
sudo ln -s /usr/local/lib/libopencv_datasets.so.3.2.0     libopencv_datasets.so.3.2.0   
sudo ln -s /usr/local/lib/libopencv_line_descriptor.so.3.2.0   libopencv_line_descriptor.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_stereo.so.3.2.0      libopencv_stereo.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_ximgproc.so.3.2.0    libopencv_ximgproc.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_cudacodec.so.3.2.0    libopencv_cudacodec.so.3.2.0     
sudo ln -s /usr/local/lib/libopencv_dpm.so.3.2.0      libopencv_dpm.so.3.2.0        
sudo ln -s /usr/local/lib/libopencv_ml.so.3.2.0     libopencv_ml.so.3.2.0            
sudo ln -s /usr/local/lib/libopencv_stitching.so.3.2.0  libopencv_stitching.so.3.2.0         
sudo ln -s /usr/local/lib/libopencv_xobjdetect.so.3.2.0 libopencv_xobjdetect.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_cudafeatures2d.so.3.2.0  libopencv_cudafeatures2d.so.3.2.0 
sudo ln -s /usr/local/lib/libopencv_face.so.3.2.0   libopencv_face.so.3.2.0          
sudo ln -s /usr/local/lib/libopencv_objdetect.so.3.2.0    libopencv_objdetect.so.3.2.0     
sudo ln -s /usr/local/lib/libopencv_structured_light.so.3.2.0  libopencv_structured_light.so.3.2.0  
sudo ln -s /usr/local/lib/libopencv_xphoto.so.3.2.0 libopencv_xphoto.so.3.2.0
sudo ln -s /usr/local/lib/libopencv_cudafilters.so.3.2.0    libopencv_cudafilters.so.3.2.0   
sudo ln -s /usr/local/lib/libopencv_features2d.so.3.2.0    libopencv_features2d.so.3.2.0 
sudo ln -s /usr/local/lib/libopencv_optflow.so.3.2.0    libopencv_optflow.so.3.2.0       
sudo ln -s /usr/local/lib/libopencv_superres.so.3.2.0     libopencv_superres.so.3.2.0 
  • 安装依赖:
$ sudo apt-get install ros-melodic-kobuki-*
$ sudo apt-get install ros-melodic-ecl-streams
$ sudo apt-get install libusb-dev
$ sudo apt-get install libspnav-dev
$ sudo apt-get install ros-melodic-joystick-drivers
$ sudo apt-get install bluetooth
$ sudo apt-get install libbluetooth-dev
$ sudo apt-get install libcwiid-dev
  • 新建工作空间,准备相关包
$ mkdir -p ~/turtlebot/src 
$ cd ~/turtlebot/src 

$ git clone https://github.com/turtlebot/turtlebot_simulator
$ git clone https://github.com/turtlebot/turtlebot.git
$ git clone https://github.com/turtlebot/turtlebot_apps.git
$ git clone https://github.com/udacity/robot_pose_ekf
$ git clone https://github.com/ros-perception/depthimage_to_laserscan.git #需要依赖opencv3.2
$ git clone https://github.com/yujinrobot/kobuki_msgs.git
$ git clone https://github.com/yujinrobot/kobuki_desktop.git
$ cd kobuki_desktop/
$ rm -r kobuki_qtestsuite
$ git clone https://github.com/toeklk/orocos-bayesian-filtering.git
$ git clone https://github.com/turtlebot/turtlebot_msgs.git
$ git clone https://github.com/ros-drivers/joystick_drivers.git
  • 复制kobuki和yujin_ocs依赖库到turtlebot/src工作空间下
$ mkdir -p ~/repos/
$ cd ~/repos/
$ git clone https://github.com/yujinrobot/kobuki.git
$ cp -r kobuki/* ~/turtlebot/src/
$ git clone https://github.com/yujinrobot/yujin_ocs.git
$ cp -r yujin_ocs/yocs_cmd_vel_mux/ yujin_ocs/yocs_controllers ~/turtlebot/src/
  • 编译工作空间
$ cd ~/turtlebot
$ rosdep install --from-paths src --ignore-src -r -y
$ catkin_make
  • 添加工作空间到bashrc文件
echo "source ~/turtlebot/devel/setup.bash" >> ~/.bashrc
  • 启用环境变量
source ~/.bashrc 

大功告成

你可能感兴趣的:(Turtlebot,opencv,Nano)