赞
踩
SITL(Software in the Loop)软件在环仿真平台,与之对应的有(HITL)硬件在环仿真。本文目的是搭建一个无人机软件仿真环境,使用PX4开源飞控,gazebo作为仿真器,结合ROS编写机器人软件程序,mavros是ROS的工具包,使各软件进行信息交互。
主要有PX4和Ardupilot(APM)
PX4相关地址:
Ardupilot相关地址:
本文主要参考XTDrone的使用文档,为其内容的补充
sudo apt install -y ninja-build exiftool python-argparse python-empy python-toml python-numpy python-yaml python-dev python-pip ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
pip2 install pandas jinja2 pyserial cerberus pyulog numpy toml pyquaternion
pip3 install packaging numpy empy toml pyyaml jinja2
选用清华镜像,参考官网教程
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
关于https://raw.githubusercontent.com的网络问题,可以在网址前加上"https://ghproxy.com/"代理加速。
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
或者加上代理
curl -s https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
可选ros-melodic-desktop-full、ros-melodic-desktop和ros-melodic-ros-base。
ros-melodic-desktop-full自带Gazebo,此处选择ros-melodic-desktop,后面再自己安装Gazebo。
~~ ~~
更新
gitee的一个issues提到能够直接下载ros-melodic-desktop-full,再执行
sudo apt upgrade libignition-math2
后,gazebo会从9.0.0升级到9.16,待验证
~~ ~~
先更新源
sudo apt-get update
再下载安装
sudo apt install ros-melodic-desktop
未更新源会出现问题
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ros-melodic-desktop
环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
依赖
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
网络问题,无法连接到raw.githubusercontent.com,可以通过改host等方式,但ip地址会变动,不一定有效。
建议直接在目标位置手动创建文件:
sudo vim /etc/ros/rosdep/sources.list.d/20-default.list
然后输入下面内容,再保存退出即可。
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
创建完文件后就能直接运行下一步了。
更新
rosdep update
大概率出现timed out超时,需要手动改地址,加上代理,在打开文件系统,进入/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py或命令
图形化操作
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
命令行操作
sudo vim /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
然后找到大概第310行(通过图中Go to Line)添加
vim中 通过 :310
跳到310行
url="https://ghproxy.com/"+url
同样,下方列出的地方修改或添加 https://ghproxy.com/
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 204行添加
gbpdistro_url = "https://ghproxy.com/" + gbpdistro_url
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py 68行
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 36行
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py 72行
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py 39行
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py 68行和119行
然后重新运行更新命令,成功后就能启动了。
roscore
显示
Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://ubuntu:34149/ ros_comm version 1.14.11 SUMMARY ======== PARAMETERS * /rosdistro: melodic * /rosversion: 1.14.11 NODES auto-starting new master process[master]: started with pid [28148] ROS_MASTER_URI=http://ubuntu:11311/ setting /run_id to 7acb3a28-daf8-11eb-a451-000c292038f9 process[rosout-1]: started with pid [28159] started core service [/rosout]
创建catkin_ws工作空间
mkdir -p ~/catkin_ws/src
mkdir -p ~/catkin_ws/scripts
cd catkin_ws/src && catkin_init_workspace # 使用catkin-tools话,则为cd catkin_ws && catkin init
cd .. && catkin_make # 使用catkin-tools话,则为catkin build
依旧有官网教程
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
cat /etc/apt/sources.list.d/gazebo-stable.list
#显示deb http://packages.osrfoundation.org/gazebo/ubuntu-stable bionic main
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
更新源
sudo apt-get update
安装gazebo9.1
sudo apt-get install gazebo9=9.1*
启动
gazebo
虚拟机可能报错
VMware: vmw_ioctl_command error Invalid argument.
输入
echo "export SVGA_VGPU10=0" >> ~/.bashrc
source ~/.bashrc
之后才成功启动
安装ROS的Gazebo插件
sudo apt install ros-melodic-gazebo-* #melodic
开两个终端分别运行
roscore #终端1 启动ROS
rosrun gazebo_ros gazebo #终端2 启动Gazebo
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
roscd mavros
sudo wget https://ghproxy.com/https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh
最后安装时间较长
Installing GeographicLib geoids egm96-5
Installing GeographicLib gravity egm96
Installing GeographicLib magnetic emm2015
我安装时出现错误
Error while installing GeographicLib geoids egm96-5
尝试在上述的 wget步骤中,地址加上https://ghproxy.com/,重新下载install_geographiclib_datasets.sh(先删除原先的),失败就ctrl+c,多次重新执行最后一步才成功。
使用github库,若存在网络问题,可以在github.com后面加上.cnpmjs.org。
cd ~
git clone https://github.com.cnpmjs.org/PX4/PX4-Autopilot.git
也可以使用gitee的库。详见XTDrone教程
在.gitmodules中的所有github.com地址加上.cnpmjs.org后缀。
cd PX4-Autopilot/
git submodule update --init --recursive
bash ./Tools/setup/ubuntu.sh --no-nuttx --no-sim-tools #安装python依赖
#安装依赖我这里报了错,但好像不影响
编译
make px4_sitl_default gazebo
XTDrone教程
source ~/catkin_ws/devel/setup.bash
source ~/PX4-Autopilot/Tools/setup_gazebo.bash ~/PX4-Autopilot/ ~/PX4-Autopilot/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/sitl_gazebo
我照上面输入后,启动报错,参考此处找了下面两个命令后才成功。
cd ~/PX4-Autopilot
source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd):$(pwd)/Tools/sitl_gazebo
启动前,建议先到网上下载Model包(XTDrone教程有)到.gazebo文件夹下。
cd ~/PX4-Autopilot
roslaunch px4 mavros_posix_sitl.launch
参考较多,若有侵权,联系删除。
[入门教程] PX4-Gazebo仿真
无人机仿真之搭建仿真平台-SITL、gazebo、ROS
XTDrone使用文档
ROS的安装-> rosdep init /update报错2021.5.6实测有效
Ubuntu18.04下基于ROS和PX4的无人机仿真平台的基础配置搭建
gazebo学习时遇到的问题(PX4篇)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。