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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM