• ros与px4无人机仿真环境


    前言

    环境准备

    虚拟机 VMWare Workstation Pro 15.5
    系统镜像 ubuntu-18.04.6-desktop-amd64.iso
    如果有需要,可以私信我发送。

    安装系统

    虚拟机创建与系统安装

    1. 在VMWare中,新建虚拟机
      选择自定义
    2. 设置光盘映像文件
    3. 设置 Linux名称 和 用户名
    4. 设置虚拟机名称以及存放位置
      简易将虚拟机保存在C盘以外的盘符。
    5. 处理器配置
      这个配置按需要配置就好。这些处理器和 本机的参数不一定一致,虚拟机会虚拟出这些处理器。
    6. 虚拟机内存
      按自己电脑配置配置,尽量大一些。
    7. 磁盘容量
      尽量大一些,最好不要小于40GB
    8. 完成,等待开机即可

    Ububtu设置

    设置中文

    settings --> Region & Language
    点击 Manage Installed Languages,安装中文

    更换镜像源

    打开软件与更新的文件,在Ubuntu Software栏里我们可以看到Ubuntu下载和更新源的网址,在这里更换网址为国内镜像源的网址即可,然后点击Revert并更新一下软件包。

    开启终端(Ctrl + Alt + T)
    首先将ubuntu下的source.list进行备份,以免后期出现问题无法恢复。

    $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bcakup
    

    编辑sources.list

    $ sudo gedit /et/apt/sources.list
    

    将所有http://cn.archive.ubuntu.com替换为http://mirrors.tuna.tsinghua.edu.cn

    # deb cdrom:[Ubuntu 18.04.6 LTS _Bionic Beaver_ - Release amd64 (20210915)]/ bionic main restricted
    
    # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
    # newer versions of the distribution.
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
    
    ## Major bug fix updates produced after the final release of the
    ## distribution.
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
    ## team. Also, please note that software in universe WILL NOT receive any
    ## review or updates from the Ubuntu security team.
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic universe
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic universe
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates universe
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates universe
    
    ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
    ## team, and may not be under a free licence. Please satisfy yourself as to 
    ## your rights to use the software. Also, please note that software in 
    ## multiverse WILL NOT receive any review or updates from the Ubuntu
    ## security team.
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic multiverse
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic multiverse
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates multiverse
    # deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
    
    ## N.B. software from this repository may not have been tested as
    ## extensively as that contained in the main release, although it includes
    ## newer versions of some applications which may provide useful features.
    ## Also, please note that software in backports WILL NOT receive any review
    ## or updates from the Ubuntu security team.
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    
    ## Uncomment the following two lines to add software from Canonical's
    ## 'partner' repository.
    ## This software is not part of Ubuntu, but is offered by Canonical and the
    ## respective vendors as a service to Ubuntu users.
    # deb http://archive.canonical.com/ubuntu bionic partner
    # deb-src http://archive.canonical.com/ubuntu bionic partner
    
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted
    # deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security universe
    # deb-src http://security.ubuntu.com/ubuntu bionic-security universe
    deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security multiverse
    # deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
    

    更新软件列表并升级

    $ sudo apt-get update
    $ sudo apt-get upgrade
    

    安装ROS

    ROS的版本也有很多种,它主要和Ubuntu系统的版本一一对应,因此你的系统版本决定了你需要下载的ROS版本,比如我们使用的是Ubuntu 18.04,因此,将选择Melodic版本。
    可以参考官网的安装步骤

    设置sources.list

    Setup your computer to accept software from packages.ros.org.
    让你的电脑可以接受来自 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'
    

    也可以设置为清华的源

    $ sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
    

    设置keys

    设置下载密钥

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

    安装ROS

    首先确保你的软件包及依赖都是最新的,以免发生致命(Fatal error)的错误。

    $ sudo apt update
    

    官网提供了三种安装方式,但是考虑到大家后续的用途都是比较广泛的(且为了避免麻烦),因此推荐大家都安装完整的桌面版本。

    $ sudo apt install ros-melodic-desktop-full
    

    漫长的等待下载和安装过程。

    添加环境变量

    执行如下的命令将环境变量直接手动添加至.bashrc文件里,这样就能保证每次在打开终端的时候都能自动的为终端添加ROS的环境变量。

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

    让环境变量生效:

    $ source ~/.bashrc
    

    安装一些功能包的依赖项

    到目前为止,您已经安装了运行核心ROS包所需的软件。为了创建和管理自己的ROS工作区,有各种工具和需求分别分发。
    例如,rosinstall是一个常用的命令行工具,它使您可以通过一个命令轻松下载ROS包的多个源代码树。
    要安装此工具和其他用于构建ROS包的依赖项,请运行:

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

    初始化rosdep

    在使用许多ROS工具之前,需要初始化rosdep。rosdep使您能够轻松地为要编译的源代码安装系统依赖项,并且是在ROS中运行一些核心组件所必需的。如果您尚未安装rosdep,请按以下步骤进行安装。

    $ sudo apt install python-rosdep
    

    之后,执行下面的命令,来初始化rosdep

    $ sudo rosdep init
    $ rosdep update
    

    如果顺利的话,这样已经成功安装了ros。
    但是,世界总是这么不仅人意。大多数情况下,会报如下的错误:
    ros初始化错误

    打开host文件

    $ sudo gedit /etc/hosts
    

    在末尾添加语句:

    151.101.84.133 raw.githubusercontent.com
    

    重新执行初始化的两条命令

    正确初始化

    测试

    在三个终端中分别键入以下命令:

    $ roscore
    $ rosrun turtlesim turtlesim_node
    $ rosrun turtlesim turtle_teleop_key
    

    PX4固件下载

    同样可以参考官网教程

    克隆源代码

    新建一个文件夹,这个文件夹可以随便取名

    $ sudo mkdir -p workspace/px4_src
    $ cd ~/workspace/px4_src
    

    克隆源代码.
    这一步非常非常需要网络,如有必要也可以在终端使用其它的一种上网方式,懂得都懂。

    $ sudo git clone https://github.com/PX4/PX4-Autopilot.git --recursive
    

    安装相关依赖和仿真环境

    进入克隆好的文件夹目录下,运行脚本文件,安装相关依赖和仿真环境

    由于我们并不直接使用Nuttx系统,因此并不需要安装关于nuttx的相关依赖和环境, 同时由于我们在前面安装ROS的时候已经自带了Gazebo仿真环境,因此,这里切记一定不要勾选仿真工具,选择no-sim-tools,否则会出现仿真环境版本冲突的情况。

    $ cd PX4-Autopilot/Tools/setup
    $ bash ubuntu.sh --no-nuttx --no-sim-tools
    

    编译测试

    由于我们后期仿真都是建立在gazebo上,因此可以直接执行如下代码

    $ cd ~/px4_src/PX4-Autopilot
    $ make px4_sitl gazebo
    

    注:由于前面我们没有选择仿真工具,因此在这里大多数人会报错,缺少一个依赖,如下图所示。

    地面站下载

    地面站的下载较为方便,进入下面的网站,找到和你操作系统相匹配的可执行文件进行下载即可。
    Dronecode
    在运行前我们还需要对其进行加权,然后双击即可打开,打开界面如下图所示。

    $ chmod +x ./QGroundControl.AppImage
    

    MAVROS下载

    $ sudo apt install ros-melodic-mavros*
    $ sudo /opt/ros/melodic/lib/mavros/install_geographiclib_datasets.sh
    
  • 相关阅读:
    转 PHP in_array() 函数
    转 PHP Cookies
    华硕笔记本怎样调整屏幕亮度
    转 Oracle 12c: Managing Resources
    转 SQLPLUS中SQL换行执行
    转 php中$_request与$_post、$_get的区别
    TDB 12c : Transportable Database
    oracle (DBaaS) 服务介绍
    domain admin域管理员
    转 【TTS】AIX平台数据库迁移到Linux--基于RMAN(真实环境)
  • 原文地址:https://www.cnblogs.com/Gazikel/p/15911376.html
Copyright © 2020-2023  润新知