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

ArduPilot开源代码之ROS2Humble+CartographerSLAM+SITL+Gazebo

ArduPilot开源代码之ROS2Humble+CartographerSLAM+SITL+Gazebo

  • 1. 源由
  • 2. 仿真环境
  • 3. 环境搭建
    • 3.1 仿真硬件
    • 3.2 Gazebo Harmonic安装
    • 3.3 ROS2 Humble系统安装
    • 3.4 ROS2 Ardupilot工作环境
    • 3.5 ROS2启动SITL
    • 3.6 Gazebo+ROS2启动SITL
    • 3.7 CartographerSLAM+ROS2启动SITL
  • 4. 总结
  • 5. 参考资料

1. 源由

从测试的角度分析问题,大致有以下几个逻辑过程:

  1. 【白盒】逻辑走读
  2. 【灰盒】单元测试
  3. 【黑盒】系统测试(仿真)

这个Ardupilot的代码用于无人机,更要面临程序异常导致的坠机问题。

因此,仿真环境的验证就显得尤为重要。可以避免:

  1. 设备损坏
  2. 事故发生
  3. 快速验证

当然,仿真也有一些不现实的问题,但是它是与实际飞行最接近的环境。在实际试飞前,依然需要做各种用例和方法来确保飞行安全。

2. 仿真环境

Ardupilot仿真环境的组成:

  • Ardupilot SITL / Flight Control
  • Gazebo Harmonic / Robotics Simulator
  • ROS2 Humble / Companion Computer
  • Cartographer SLAM / Non-GPS Position

3. 环境搭建

3.1 仿真硬件

基于《Linux 36.3@Jetson Orin Nano之系统安装》,在Jetson Orin Nano 8GB硬件上进行仿真测试。

3.2 Gazebo Harmonic安装

参考Gazebo Harmonic, Binary Installation on Ubuntu:

  • Step 1: 更新系统
$ sudo apt-get update
$ sudo apt-get install lsb-release gnupg
  • Step 2: 添加Gazebo秘钥
$ curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg

由于网络等问题,curl可以分步骤执行,以下是curl分布执行所需要使用到的命令集合:

$ export https_proxy=http://192.168.1.10:808
$ curl https://packages.osrfoundation.org/gazebo.gpg --output gazebo.gpg
$ sudo mv gazebo.gpg /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg

注:相关代理命令请参考apt-get通过代理更新系统。

  • Step 3: 添加Gazebo源
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
  • Step 4: 安装Gazebo Harmonic
$ sudo apt-get update
$ sudo apt-get install gz-harmonic
  • 其他(若要删除Gazebo)
$ sudo apt remove gz-harmonic && sudo apt autoremove

3.3 ROS2 Humble系统安装

参考ROS2 Humble, Debian packages for ROS 2 on Ubuntu:

  • Step 1: 设置环境
$ locale  # check for UTF-8$ sudo apt update && sudo apt install locales
$ sudo locale-gen en_US en_US.UTF-8
$ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
$ export LANG=en_US.UTF-8$ locale  # verify settings
  • Step 2: 添加ROS2秘钥
$ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

由于网络等问题,curl可以分步骤执行,以下是curl分布执行所需要使用到的命令集合:

$ export https_proxy=http://192.168.1.10:808
$ curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o ros-archive-keyring.gpg
$ sudo mv ros-archive-keyring.gpg /usr/share/keyrings/
  • Step 3: 添加ROS2源
$ sudo apt install software-properties-common
$ sudo add-apt-repository universe
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
  • Step 4: 安装ROS2 Humble
$ sudo apt update
$ sudo apt install ros-humble-desktop
  • 其他(ROS2环境设置)
$ source /opt/ros/humble/setup.bash

3.4 ROS2 Ardupilot工作环境

参考Companion Computers - ROS 2:

  • Step 1: 新建工程环境
$ cd ~
$ mkdir ros2_ws
$ cd ~/ros2_ws
$ vcs import --recursive --input  https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/ros2/ros2.repos src

由于网络等问题,vcs可以分步骤执行,以下是vcs分布执行所需要使用到的命令集合:

$ curl -O https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos
$ vcs import --input ros2_gz.repos src

部分代码库可能有雨容量较大,下载经常出现问题,采用SSH可以解决:

$ diff -urN ros2_gz.repos.bak ros2_gz.repos
--- ros2_gz.repos.bak   2024-07-30 18:26:51.804632126 +0800
+++ ros2_gz.repos       2024-07-30 18:27:53.341738354 +0800
@@ -1,11 +1,11 @@repositories:ardupilot:type: git
-    url: https://github.com/ArduPilot/ardupilot.git
+    url: git@github.com:ArduPilot/ardupilot.gitversion: masterardupilot_gazebo:type: git
-    url: https://github.com/ArduPilot/ardupilot_gazebo.git
+    url: git@github.com:ArduPilot/ardupilot_gazebo.gitversion: ros2ardupilot_gz:type: git
@@ -13,7 +13,7 @@version: mainardupilot_sitl_models:type: git
-    url: https://github.com/ArduPilot/SITL_Models.git
+    url: git@github.com:ArduPilot/SITL_Models.gitversion: mainmicro_ros_agent:type: git

采用分布下载代码库,需要对每个模块的子模块进行代码同步:

$ cd src/<module>
$ git submodule update --init --recursive
  • Step 2: ROS2环境和依赖更新
$ sudo apt update
$ rosdep update
$ source /opt/ros/humble/setup.bash
$ rosdep install --from-paths src --ignore-src
  • Step 3: 安装microxrceddsgen
$ sudo apt install default-jre
$ cd ~/ros2_ws
$ git clone --recurse-submodules https://github.com/ardupilot/Micro-XRCE-DDS-Gen.git
$ cd Micro-XRCE-DDS-Gen
$ ./gradlew assemble
$ echo "export PATH=\$PATH:$PWD/scripts" >> ~/.bashrc

测试

$ source ~/.bashrc
$ microxrceddsgen -version
openjdk version "11.0.23" 2024-04-16
OpenJDK Runtime Environment (build 11.0.23+9-post-Ubuntu-1ubuntu122.04.1)
OpenJDK 64-Bit Server VM (build 11.0.23+9-post-Ubuntu-1ubuntu122.04.1, mixed mode)
microxrceddsgen version: null
  • Step 4: 编译ROS2 Arudpilot工作环境
$ cd ~/ros2_ws
$ colcon build --packages-up-to ardupilot_dds_tests

若编译报错,执行以下命令:

$ colcon build --packages-up-to ardupilot_dds_tests --event-handlers=console_cohesion+

测试

$ cd ~/ros2_ws
$ source ./install/setup.bash
$ colcon test --packages-select ardupilot_dds_tests
$ colcon test-result --all --verbose

3.5 ROS2启动SITL

参考:

  • ROS 2 with SITL

  • ArduPilot ROS 2 packages

  • Step 1: 编译SITL

$ source /opt/ros/humble/setup.bash
$ cd ~/ros2_ws/
$ colcon build --packages-up-to ardupilot_sitl

或者参考《Ardupilot开源飞控工程项目编译回顾》,可以直接在ardupilot工程下编译。

  • Step 2: ROS2启动SITL
$ source ~/ros2_ws/install/setup.bash
$ ros2 launch ardupilot_sitl sitl_dds_udp.launch.py transport:=udp4 refs:=$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/dds_xrce_profile.xml synthetic_clock:=True wipe:=False model:=quad speedup:=1 slave:=0 instance:=0 defaults:=$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/copter.parm,$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/dds_udp.parm sim_address:=127.0.0.1 master:=tcp:127.0.0.1:5760 sitl:=127.0.0.1:5501
  • Step 3: mavprxoy启动地图&控制台
$ mavproxy.py --console --map --aircraft test --master=:14550
  • Step 4: mavproxy操作飞机
> mode guided
> arm throttle
> takeoff 5.0
> velocity 10 0 0
> mode RTL

3.6 Gazebo+ROS2启动SITL

参考:

  • ROS 2 with Gazebo

  • 章节3.4 ROS2 Ardupilot工作环境

  • Step 1: 工作环境代码clone

$ cd ~/ros2_ws
$ vcs import --input https://raw.githubusercontent.com/ArduPilot/ardupilot_gz/main/ros2_gz.repos --recursive src
  • Step 2: 指定gazbo版本
$ export GZ_VERSION=harmonic
  • Step 3: 更新ROS2依赖库
$ cd ~/ros2_ws
$ source /opt/ros/humble/setup.bash
$ sudo apt update
$ rosdep update
$ rosdep install --from-paths src --ignore-src -r
  • Step 4: 编译Ardupilot ROS2组件
$ cd ~/ros2_ws
$ colcon build --packages-up-to ardupilot_gz_bringup

测试

$ cd ~/ros2_ws
$ source install/setup.bash
$ colcon test --packages-select ardupilot_sitl ardupilot_dds_tests ardupilot_gazebo ardupilot_gz_applications ardupilot_gz_description ardupilot_gz_gazebo ardupilot_gz_bringup
$ colcon test-result --all --verbose
  • Step 5: ROS2在Gazebo启动SITL模拟
$ source install/setup.bash$ ros2 launch ardupilot_gz_bringup iris_runway.launch.py  //Iris Runway (Copter)
or
$ ros2 launch ardupilot_gz_bringup iris_maze.launch.py  //Iris Maze (Copter)
or
$ ros2 launch ardupilot_gz_bringup wildthumper.launch.py  //WildThumper (Rover)

3.7 CartographerSLAM+ROS2启动SITL

参考:Cartographer SLAM with ROS 2 in SITL

  • Step 1: ardupilot_ros组件clone
$ cd ~/ros2_ws/src
$ git clone git@github.com:ArduPilot/ardupilot_ros.git
  • Step 2: 依赖库安装
$ cd ~/ros2_ws
$ rosdep install --from-paths src --ignore-src -r --skip-keys gazebo-ros-pkgs
  • Step 3: 编译ardupilot_ros/ardupilot_gz_bringup
$ cd ~/ros2_ws
$ source ./install/setup.bash
$ colcon build --packages-up-to ardupilot_ros ardupilot_gz_bringup
  • Step 4: 360度2D激光雷达无人机迷宫仿真

启动 RViz 和 Gazebo

$ source ~/ros2_ws/install/setup.sh
$ ros2 launch ardupilot_gz_bringup iris_maze.launch.py

启动 Google Cartographer 生成 SLAM,检查在 RVIZ 中是否正确生成了地图。

在另一个终端中运行:

$ source ~/ros2_ws/install/setup.sh
$ ros2 launch ardupilot_ros cartographer.launch.py

4. 总结

本章在Jetson Orin Nano 8GB板子上,整理了Ardupilot当前在ROS2Humble+CartographerSLAM+SITL+Gazebo下的仿真运行步骤。

后续,希望能够在此基础上,进一步整理仿真环境的必要资料,比如,地图、云层、三维FPV视频等等:

  • GSoC24: Visual Follow-me using AI
  • GSoC 2024: High Altitude Non-GPS Navigation

5. 参考资料

【1】ArduPilot开源飞控系统之简单介绍
【2】ArduPilot之开源代码Task介绍
【3】ArduPilot飞控启动&运行过程简介
【4】ArduPilot之开源代码Library&Sketches设计
【5】ArduPilot之开源代码Sensor Drivers设计
【6】ArduPilot开源代码之EKF系列研读
【7】ArduPilot开源代码之AP_DAL研读系列

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • reshape函数及MATLAB应用
  • sql查询优化小知识-01,非等值条件查询影响
  • Vue3基础语法
  • C#-了解ORM框架SqlSugar并快速使用(附工具)
  • c# 对接第三方接口实现签名
  • 记一次因敏感信息泄露而导致的越权+存储型XSS
  • 谷粒商城实战笔记-75-商品服务-API-品牌管理-品牌分类关联与级联更新
  • 微信小程序云开发订单微信支付与小票和标签打印的完整高效流程
  • 【C# 】Pipe管道通信使用
  • Java实现数据库图片上传(包含从数据库拿图片传递前端渲染)-图文详解
  • SSRF-labs-master靶场
  • FFmpeg研究
  • ai智能写作软件哪个好?高效写作少不了这5个
  • 大数据——Hive原理
  • mysql 数据库空间统计sql
  • (三)从jvm层面了解线程的启动和停止
  • 【347天】每日项目总结系列085(2018.01.18)
  • 2019.2.20 c++ 知识梳理
  • flask接收请求并推入栈
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • JS进阶 - JS 、JS-Web-API与DOM、BOM
  • LeetCode刷题——29. Divide Two Integers(Part 1靠自己)
  • node学习系列之简单文件上传
  • React组件设计模式(一)
  • 从setTimeout-setInterval看JS线程
  • 跨域
  • 聊聊flink的BlobWriter
  • 聊聊spring cloud的LoadBalancerAutoConfiguration
  • 免费小说阅读小程序
  • 目录与文件属性:编写ls
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • [地铁译]使用SSD缓存应用数据——Moneta项目: 低成本优化的下一代EVCache ...
  • 《TCP IP 详解卷1:协议》阅读笔记 - 第六章
  • # MySQL server 层和存储引擎层是怎么交互数据的?
  • #NOIP 2014# day.1 生活大爆炸版 石头剪刀布
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (1)bark-ml
  • (Forward) Music Player: From UI Proposal to Code
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (MATLAB)第五章-矩阵运算
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (回溯) LeetCode 77. 组合
  • (文章复现)基于主从博弈的售电商多元零售套餐设计与多级市场购电策略
  • (学习日记)2024.03.12:UCOSIII第十四节:时基列表
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (原創) 未来三学期想要修的课 (日記)
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (转)shell中括号的特殊用法 linux if多条件判断
  • (转)Sql Server 保留几位小数的两种做法
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET 直连SAP HANA数据库