环境配置
我们使用阿木实验室的板载电脑allspark2(arm Orin-NX架构)+Pixhawk6C实机飞行测试ego-planner,文章尾部附arm QGC安装教程 && arm机载电脑与Pixhawk6c组合下提高飞控imu频率的方法。
【鸣谢】感谢阿木实验室支持
配置cuda 11.4(根据自己板载电脑的算力去选择cuda版本)
- jetop安装
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install -U jetson-stats
- 查看机载电脑当前环境(是否已经配置cuda或者本身含opencv)
jetson_release
如果CUDA已经安装,检查一下版本是否对应。
- 安装CUDA11.4
sudo apt-get install cuda-11-4
- 安装cudnn(这个可能用不上,如果部署深度学习模型,还可以再配置TensorRT)装一个也没啥
sudo apt-get install libcudnn8
- 下载功能包,设置cuda
sudo apt-get install -y cmake libavcodec-dev libavformat-dev libavutil-dev \
libglew-dev libgtk2.0-dev libgtk-3-dev libjpeg-dev libpng-dev libpostproc-dev \
libswscale-dev libtbb-dev libtiff5-dev libv4l-dev libxvidcore-dev \
libx264-dev qt5-default zlib1g-dev libgl1 libglvnd-dev pkg-config \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev mesa-utils
sudo apt-get install python2.7-dev python3-dev python-numpy python3-numpy
# To fix OpenGL related compilation problems
cd /usr/lib/aarch64-linux-gnu/
sudo ln -sf libGL.so.1.0.0 libGL.so //这一行代码存疑,我感觉运行这行反而会导致后面的libGL.so在编译的时候找不到!!!可以先不运行这一行,先编译
sudo vim /usr/local/cuda/include/cuda_gl_interop.h
注释cuda_gl_interop.h 62~68行的下列部分,保留有颜色部分
//#if defined(__arm__) || defined(__aarch64__)
//#ifndef GL_VERSION
//#error Please include the appropriate gl headers before including cuda_gl_interop.h
//#endif
//#else
#include <GL/gl.h>
//#endif
下载Fast-Drone-250程序包
可以安装在Home文件夹下
cd ~/Home
git clone http://github.com/ZJU-FAST-Lab/Fast-Drone-250
如果git很慢,可以自行科学下载该程序包
配置OpenCV with CUDA
以下步骤在~/Download文件夹下执行即可,如果Opencv遇到编译问题,提示在该文件夹下无法编译,可以将其整体移动至Home文件夹即可解决。
- 暴力卸载原有的opencv 4.2.0 (感觉 nx更支持3.x,之前编译4.x bug较多)
cd ~/Download
sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update
【此方法可能会误删一些ROS rqt之类的文件,建议后面鱼香ROS重新补充安装一下】
- 安装opencv3.4.18和opencv_contrib3.4.18,并且进行带cuda的的编译
如果编译遇到问题,对症在网上寻求解答。
github官网下载opencv3.x的版本和对应的 opencv_contrib3.x
opencv下载链接:https://hub.nuaa.cf/opencv/opencv/tree/3.4.18
opencv_contrib下载链接:https://hub.nuaa.cf/opencv/opencv_contrib/tree/3.4.18
下载后将opencv_contrib3.4.18解压放入opencv3.4.18文件夹下,
然后可以在Download文件夹下执行编译。【切记下面的CUDA_ARCH_BIN尽量选择7.2,网上其他博客都说7.2适合NX,8.7也许部分也可以,等大家测一测】
cd ~/Download/opencv-3.4.18
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=7.2 \
-D CUDA_ARCH_PTX="" \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D WITH_CUBLAS=ON \
-D WITH_LIBV4L=ON \
-D WITH_GSTREAMER=ON \
-D WITH_GSTREAMER_0_10=OFF \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D CUDA_NVCC_FLAGS="--expt-relaxed-constexpr" \
-D WITH_TBB=ON \
../
make -j8
sudo make install
到此编译成功,然后如果不出意外,可以查到OpenCV with CUDA
jetson_release
- 安装eigen3
sudo apt-get remove libeigen3-dev
cd ~/Downloads/
wget -O eigen.zip https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip #check version
unzip eigen.zip
mkdir eigen-build && cd eigen-build
cmake ../eigen-3.3.7/ && sudo make install
pkg-config --modversion eigen3 # 检查 Eigen 版本,判断是否安装成功
- 下载ceres1.14到Fast-Drone-250文件夹,替换掉里面的ceres 2.0.0rc1版本,保留压缩包里面的glog文件
cd ~/Fast-Drone-250
sudo apt-get install -y cmake libgoogle-glog-dev libatlas-base-dev libsuitesparse-dev
wget http://ceres-solver.org/ceres-solver-1.14.0.tar.gz
tar zxf ceres-solver-1.14.0.tar.gz
- 修改cv bridge
进入opt/ros/melodic/share/cv_brige_cmake,更改cv_brigeConfige.cmake
cd /opt/ros/noetic/share/cv_bridge/cmake
sudo gedit cv_bridgeConfig.cmake
修改line 94-118,直接复制覆盖!
#if(NOT "include;/usr/include/opencv4 " STREQUAL " ")
# set(cv_bridge_INCLUDE_DIRS "")
# set(_include_dirs "include;/usr/include/opencv4")
set(libraries "cv_bridge;/usr/local/lib/libopencv_core.so.3.4.18;/usr/local/lib/libopencv_imgproc.so.3.4.18;/usr/local/lib/libopencv_imgcodecs.so.3.4.18")
if(NOT "https://github.com/ros-perception/vision_opencv/issues " STREQUAL " ")
set(_report "Check the issue tracker 'https://github.com/ros-perception/vision_opencv/issues' and consider creating a ticket if the problem has not been reported yet.")
elseif(NOT "http://www.ros.org/wiki/cv_bridge " STREQUAL " ")
set(_report "Check the website 'http://www.ros.org/wiki/cv_bridge' for information and consider reporting the problem.")
else()
set(_report "Report the problem to the maintainer 'Vincent Rabaud <vincent.rabaud@gmail.com>' and request to fix the problem.")
endif()
foreach(idir ${_include_dirs})
if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir})
set(include ${idir})
elseif("${idir} " STREQUAL "include ")
get_filename_component(include "${cv_bridge_DIR}/../../../include" ABSOLUTE)
if(NOT IS_DIRECTORY ${include})
message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found. It does not exist in '${include}'. ${_report}")
endif()
else()
message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found. It does neither exist as an absolute directory nor in '\${prefix}/${idir}'. ${_report}")
endif()
_list_append_unique(cv_bridge_INCLUDE_DIRS ${include})
endforeach()
#endif()
- 补充ROS完整,因为有可能前面暴力删opencv把ROS一些比如rqt等包删除
wget http://fishros.com/install -O fishros && . fishros
系统资源:安装中需要更换系统资源就换,不需要就不换
根据自己需求选择具体的版本,记得一定是(ROS1)桌面版,选择安装完整的ROS
- Mavros安装
sudo apt-get install ros-noetic-mavros
cd /opt/ros/noetic/lib/mavros
sudo ./install_geographiclib_datasets.sh
下载 VINS-GPU
cd ~/Fast-Drone-250/src/realflight_modules
mkdir -p vins_gpu/src
cd vins_gpu/src
git clone https://github.com/pjrambo/VINS-Fusion-gpu.git
//如果git很慢,建议自行下载安装包解压到vins_gpu/src目录
需要更改vins_estimator/CMakeLists.txt和 loop_fusion/CMakeLists.txt文件,大概20行左右。需要把OpenCV路径改成你自己的路径
#include(/home/amov/opencv-3.4.18/build/OpenCVConfig.cmake)
include(/usr/local/share/OpenCV/OpenCVConfig.cmake)
#message(WARNING "OpenCV_VERSION: ${OpenCV_VERSION}")
改成下面这样:
还需要将四个功能包camera_models、global_fusion、loop_fusion、vins_estimator中catkin_include ros自带的opencv链接去掉,即在四个cmakelist中的catkin_package( )后面加入去除你的系统之前本身含有的旧的 OpenCV库的参数
,我的系统之前安装的是OpenCV4.2.0
list(REMOVE_ITEM catkin_LIBRARIES "/usr/lib/aarch64-linux-gnu/libopencv_core.so.4.2.0")
list(REMOVE_ITEM catkin_LIBRARIES "/usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.4.2.0")
list(REMOVE_ITEM catkin_LIBRARIES "/usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so.4.2.0")
如下图:
编译Fast-Drone-250
- 将realflight_modules文件夹下原本VINS-Fusion里面的config文件夹里面的全部文件复制到vins_gpu里面的config文件夹里面,遇到替换就替换。
然后将VINS-Fusion/vins_estimator/launch/fast_drone_250.launch文件复制到vins_gpu对应的目录里面
- 修改local_senseing/cmake.list为支持GPU还有改变 arch 和 code 的flags
line 8-9
set(ENABLE_CUDA false)
修改为
set(ENABLE_CUDA true)
下面这个似乎改不改影响不大,不确定,留个坑。
set(CUDA_NVCC_FLAGS
# -gencode arch=compute_xx,code=sm_xx;
-gencode arch=compute_61,code=sm_61;
)
如下图所示
然后开始编译
cd ~/Fast-Drone-250
catkin_make
编译时候请释放所有性能,可以在系统右上角选择0:MAXN,如下图所示,编译的适合拉满了,8个核都拉满了。
【重要】请检查自己的~/.bashrc文件,关闭其他的连接方式,比如我这边无人机需要注释之前做动捕实验的参数。
sudo gedit ~/.bashrc
一切没问题后,source一下,然后就可以愉快的进行仿真实验
source devel/setup.bash
roslaunch ego_planner single_run_in_sim.launch
在Rviz内按下键盘G键,再单击鼠标左键以点选无人机目标点
实机实验
- 自行补充安装
Terminator,VScode,net-tools,ssh
sudo apt install terminator
sudo apt install openssh-server
sudo apt install ros-noetic-plotjuggler
sudo apt install ros-noetic-plotjuggler-ros
sudo apt install net-tools
ifconfig
- 检查飞控mavros连接正常
ls /dev/tty*
,确认飞控的串口连接正常。一般是/dev/ttyACM0
sudo chmod 777 /dev/ttyACM0
,为串口附加权限
roslaunch mavros px4.launch
rostopic hz /mavros/imu/data_raw
确认飞控传输的imu频率在200hz左右
- VINS外参精确自标定
sh shfiles/rspx4.sh
rostopic echo /vins_fusion/imu_propagate
拿起飞机沿着场地尽量缓慢地行走,场地内光照变化不要太大,灯光不要太暗,不要使用会频闪的光源,尽量多放些杂物来增加VINS用于匹配的特征点,把 vins_output/extrinsic_parameter.txt 里的内容替换到 fast-drone-250.yaml 的
body_T_cam0 和 body_T_cam1
重复上述操作直到走几圈后VINS的里程计数据偏差收敛到满意值(一般在0.3米内)
- 建图模块验证
sh shfiles/rspx4.sh
roslaunch ego_planner single_run_in_exp.launch
roslaunch ego_planner rviz.launch
- Ego-Planner实验
自动起飞
roslaunch ego-planner single_run_in_exp.launch
sh shfiles/record.sh
roslaunch ego_planner rviz.launch
按下G键加鼠标左键点选目标点使无人机飞行文章来源:https://www.toymoban.com/news/detail-842186.html
【未完待续,图片没加完】文章来源地址https://www.toymoban.com/news/detail-842186.html
到了这里,关于【ARM NX环境下】最优雅的配置ego-planner到arm架构的nx机载电脑上(opencv3.4.18-cuda11.4+VINS-Fusion-GPU),并且实机试飞成功实验记录的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!