当前位置: 首页 > news >正文

无人机避障——XTDrone中运行VINS-Fusion+Ego-planner进行路径规划

本文聚焦于无人机避障技术领域的经典方案,重点探讨视觉双目VINS-Fusion建图与Ego-planner路径规划的组合应用。通过视觉双目VINS-Fusion实现精准的环境建图与自身定位,结合Ego-planner的高效路径规划能力,使无人机在复杂环境中实现自主避障飞行。基于XTDrone平台,采用PX4固件和Mavros协议进行仿真测试,验证了该技术方案的可行性和有效性,展示了其在实际应用中的潜力和优势。

参考链接:

视觉惯性里程计(VIO) · 语雀VINS-Mono编译首先参考这里配置依赖,然后编译c...https://www.yuque.com/xtdrone/manual_cn/vio#luwyy

VINS-Fusion仿真

遇到报错问题:

基本报错参考链接:

Ubuntu20.04运行Vins-fusion_ubuntu20.04 vins-fussion-CSDN博客

原文中:

在报错的项目的CMakeList里的
set(CMAKE_CXX_FLAGS “-std=c++11”)
改成
set(CMAKE_CXX_STANDARD 14)

实际上:

Vins-fusion中的文件夹下的功能包的CMake.list都需要进行以上修改。

原文中:

但在Opencv4中,CV_LOAD_IMAGE_GRAYSCALE找不到,经过查看Opencv的API可知,CV_LOAD_IMAGE_GRAYSCALE已改为 IMREAD_GRAYSCALE,修改即可。

实际上:

将CV_LOAD_IMAGE_GRAYSCALE改为cv::IMREAD_GRAYSCALE

 其他报错:

 /usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3fLS20StringFlagDestructorD1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a(gflags.cc.o): in function `_GLOBAL__sub_I__ZN3fLS14FLAGS_flagfileB5cxx11E':
gflags.cc:(.text.startup+0x60): 危险的重寻址: unsupported relocation
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN22gflags_mutex_namespace5MutexD1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
gflags.cc:(.text.startup+0x280): 危险的重寻址: unsupported relocation
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EED1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
gflags.cc:(.text.startup+0x2fc): 危险的重寻址: unsupported relocation
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_reporting.cc.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3fLS20StringFlagDestructorD1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a(gflags_reporting.cc.o): in function `_GLOBAL__sub_I__ZN3fLB10FLAGS_helpE':
gflags_reporting.cc:(.text.startup+0x60): 危险的重寻址: unsupported relocation
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags_completions.cc.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3fLS20StringFlagDestructorD1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a(gflags_completions.cc.o): in function `_GLOBAL__sub_I__ZN3fLS25FLAGS_tab_completion_wordB5cxx11E':
gflags_completions.cc:(.text.startup+0xa0): 危险的重寻址: unsupported relocation
collect2: error: ld returned 1 exit status
[ 43%] Generating EusLisp code from gazebo_msgs/SetLinkProperties.srv
make[2]: *** [VINS-Fusion/camera_models/CMakeFiles/camera_models.dir/build.make:352:/home/nvidia/catkin_ws/devel/lib/libcamera_models.so] 错误 1
make[1]: *** [CMakeFiles/Makefile2:916:VINS-Fusion/camera_models/CMakeFiles/camera_models.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....

解决:

根本原因:

错误信息中的 relocation R_AARCH64_ADR_PREL_PG_HI21 表明在生成动态库(.so)时,链接了未启用 -fPIC 的静态库 libgflags.a

ARM架构(如AArch64)要求动态库的所有依赖库必须编译为位置无关代码(PIC),否则无法正确处理地址重定位

libgflags.a 是静态库且未启用 -fPIC,导致其代码段包含绝对地址,无法被动态库共享使用


解决方案
1. ​重新编译gflags并强制启用-fPIC

步骤:​

# 卸载旧版本gflags
sudo rm -rf /usr/local/lib/libgflags* /usr/local/include/gflags

# 下载源码并编译
git clone https://github.com/gflags/gflags.git
cd gflags
mkdir build && cd build

# 通过CMake启用位置无关代码并生成动态库
cmake .. -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install
2. ​验证gflags安装

检查新生成的库文件是否为动态库:

ls /usr/local/lib | grep libgflags
# 正确输出应包含 libgflags.so,而非 libgflags.a
3. ​更新动态库缓存
sudo ldconfig  # 刷新动态库路径
4. ​修改项目CMake配置

camera_modelsCMakeLists.txt 中,确保链接到动态库:

# 添加以下内容以强制链接动态库
find_package(gflags REQUIRED)
target_link_libraries(camera_models PRIVATE gflags_shared)  # 使用动态库目标名
 5. 以下是更改的CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.8.3)
project(camera_models)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fPIC")

find_package(catkin REQUIRED COMPONENTS
    roscpp
    std_msgs
    )

find_package(Boost REQUIRED COMPONENTS filesystem program_options system)
include_directories(${Boost_INCLUDE_DIRS})

find_package(OpenCV REQUIRED)

# set(EIGEN_INCLUDE_DIR "/usr/local/include/eigen3")
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
find_package(gflags REQUIRED) # 第一条加在这里

catkin_package(
    INCLUDE_DIRS include
    LIBRARIES camera_models
    CATKIN_DEPENDS roscpp std_msgs
#    DEPENDS system_lib
    )

include_directories(
    ${catkin_INCLUDE_DIRS}
    )

include_directories("include")

add_executable(Calibrations 
    src/intrinsic_calib.cc
    src/chessboard/Chessboard.cc
    src/calib/CameraCalibration.cc
    src/camera_models/Camera.cc
    src/camera_models/CameraFactory.cc
    src/camera_models/CostFunctionFactory.cc
    src/camera_models/PinholeCamera.cc
    src/camera_models/PinholeFullCamera.cc
    src/camera_models/CataCamera.cc
    src/camera_models/EquidistantCamera.cc
    src/camera_models/ScaramuzzaCamera.cc
    src/sparse_graph/Transform.cc
    src/gpl/gpl.cc
    src/gpl/EigenQuaternionParameterization.cc)

add_library(camera_models
    src/chessboard/Chessboard.cc
    src/calib/CameraCalibration.cc
    src/camera_models/Camera.cc
    src/camera_models/CameraFactory.cc
    src/camera_models/CostFunctionFactory.cc
    src/camera_models/PinholeCamera.cc
    src/camera_models/PinholeFullCamera.cc
    src/camera_models/CataCamera.cc
    src/camera_models/EquidistantCamera.cc
    src/camera_models/ScaramuzzaCamera.cc
    src/sparse_graph/Transform.cc
    src/gpl/gpl.cc
    src/gpl/EigenQuaternionParameterization.cc)

target_link_libraries(Calibrations ${Boost_LIBRARIES} ${OpenCV_LIBS} ${CERES_LIBRARIES})
target_link_libraries(camera_models ${Boost_LIBRARIES} ${OpenCV_LIBS} ${CERES_LIBRARIES})
target_link_libraries(camera_models PRIVATE gflags_shared)# 第二条加在这里

 编译成功:

PX4飞控EKF配置:

修改定位方式:

打开文件:

gedit ~/PX4_Firmware/ROMFS/px4fmu_common/init.d-posix/rcS

找到GPS、气压计、视觉选择的部分,我们用的是VINS-Fusion双目视觉所以需要修改

修改前:

# GPS used
param set EKF2_AID_MASK 1
# Vision used and GPS denied
#param set EKF2_AID_MASK 24

# Barometer used for hight measurement
param set EKF2_HGT_MODE 0
# Barometer denied and vision used for hight measurement
#param set EKF2_HGT_MODE 3

 修改后:

# GPS used
#param set EKF2_AID_MASK 1
# Vision used and GPS denied
param set EKF2_AID_MASK 24
# Barometer used for hight measurement
#param set EKF2_HGT_MODE 0
# Barometer denied and vision used for hight measurement
param set EKF2_HGT_MODE 3

使修改生效:

rm ~/.ros/eeprom/parameters*
rm -rf ~/.ros/sitl*

 运行Vins-Fusion:

roslaunch px4 indoor1.launch

cd ~/catkin_ws
bash scripts/xtdrone_run_vio.sh

cd ~/XTDrone/sensing/slam/vio
python vins_transfer.py iris 0

cd ~/XTDrone/communication
python multirotor_communication.py iris 0 

cd ~/XTDrone/control/keyboard
python multirotor_keyboard_control.py iris 1 vel

运行视频:

Vins_Fusion

Ego-planner三维路径规划仿真

编译Ego-planner报错:

报错1:

解决1:

问题核心是 ​CMake无法找到PCL(Point Cloud Library)的配置文件。

安装PCL核心开发组件:

sudo apt-get install libpcl-dev pcl-tools

报错2:

解决2:

pcl_conversions.h 属于ROS的 pcl_conversions 包,需单独安装:

# 安装ROS版本的PCL转换工具包
sudo apt-get install ros-noetic-pcl-conversions ros-noetic-pcl-ros

编译成功

 代码运行整合:

#整理的运行代码
#启动仿真程序
roslaunch px4 indoor1.launch

#启动Vins-Fusion
cd ~/catkin_ws
bash scripts/xtdrone_run_vio.sh

#由于VINS-Fusion发布的是Odometry类型的话题,要将其对应转为PX4所需的话题
cd ~/XTDrone/sensing/slam/vio
python vins_transfer.py iris 0

#然后建立通信,键盘控制起飞即可
cd ~/XTDrone/communication
python multirotor_communication.py iris 0 

cd ~/XTDrone/control/keyboard
python multirotor_keyboard_control.py iris 1 vel

#转换相机位姿的坐标系方向
cd ~/XTDrone/motion_planning/3d
python ego_transfer.py iris 0

#启动rviz
cd ~/XTDrone/motion_planning/3d
rviz -d ego_rviz.rviz

#启动ego_planner
roslaunch ego_planner single_uav.launch 

按顺序运行代码:

 运行结果:

VINS-fusion+Ego-planner

 

相关文章:

  • iOS插件,Theos环境搭建与XM文件开发指南(完善版本)
  • 【论文阅读】多模态——CLIPasso
  • 从0到1,带你开启TypeScript的奇妙之旅
  • 【VUE2】第二期——生命周期及工程化
  • STM32 ——系统架构
  • 力扣热题 100:二叉树专题进阶题解析(后7道)
  • Kubernetes(K8s)集群中使用 GPU
  • MySQL中的脏读与幻读
  • html网页模板免费免费html网页模板源代码
  • 【Java---数据结构】栈和队列【Stack Queue】
  • Python数据分析之数据处理与分析
  • 重生之我在学Vue--第5天 Vue 3 路由管理(Vue Router)
  • AI 帮我精准定位解决 ReferenceError: process is not defined (文末附AI名称)
  • mobaxterm,闪退处理方法
  • 一学就会的深度学习基础指令及操作步骤(3)模型训练验证
  • FPGA|Verilog-自己写的SPI驱动
  • 【测试框架篇】单元测试框架pytest(4):assert断言详解
  • SpringBoot(1)——创建SpringBoot项目的方式
  • 【Vue3】详细探究 watch ref 数组不生效的问题
  • LeetCode 2380 二进制字符串重新安排顺序需要的时间
  • 沧州盐碱地“逆天改命”:无用之地变良田,候鸟翔集水草丰美
  • 无人机企业从科技园区搬到乡村后,村子里变得不一样了
  • 菲律宾中期选举结果揭晓,马科斯与杜特尔特家族重回“权力的游戏”
  • 南宁一学校发生伤害案件,警方通报:嫌疑人死亡,2人受伤
  • 美国务卿会见叙利亚外长,沙特等国表示将支持叙利亚重建
  • 租车订单时隔7年从花呗免密扣费?“GoFun出行”引质疑