文章目录
开篇警示!
- 安装Ubuntu需要的环境可为Ubuntu16.04与Ubuntu18.04(此环境检验可用,其他未知),推荐Ubuntu18.04
- 要保证磁盘空间足够大或是后续磁盘空间可扩容,因为配置完成后,20G的磁盘只会剩余1.3G左右的可用空间,后续编译运行直接挂
- 本文教程配置如下:
项目 | 内容 |
---|---|
环境 | VMWare16虚拟环境 |
系统 | Ubuntu18.04 |
ROS版本 | ros-melodic |
控制 | PX4 |
仿真平台 | Gazebo |
一、安装依赖
- 使用apt安装安装Python2、pip、Python3、pip3
sudo apt update
# 安装Python2.7
sudo apt install python
sudo apt install python-pip
#Ubuntu18.04默认安装Python3.6.9,如果没有则下载
sudo apt install python3.6
sudo apt install python3-pip
- 其他依赖安装
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
- 有时候apt报错,提示“有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?”,这时按照提示的要求进行操作即可。
(扩展)如果出现如下报错情况,可先更新 setuptools 和 pip,否则跳过
Collecting pandas
Using cached https://files.pythonhosted.org/packages/64/f1/8fdbd74edfc31625d597717be8c155c6226fc72a7c954c52583ab81a8614/pandas-1.1.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-qtvsjq8t/pandas/setup.py", line 349
f"{extension}-source file '{sourcefile}' not found.\n"
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qtvsjq8t/pandas/
执行:
pip install --upgrade setuptools
#若未报错不需要输入这两行命令
python -m pip install --upgrade pip
• 特别提醒,在整个环境配置中,不要轻易使用 apt-get autoremove,详见
慎用apt-get autoremove
• 特别提醒,PX4和ROS不能使用Anaconda,如果之前已经安装,在.bashrc里一定要把相关代码注释掉
二、ROS安装
安装步骤ROS官网,需注意:
-
Ubuntu 16.04对应Kinetic,18.04对应Melodic,XTDrone平台目前支持这两个发行版,本教程以Ubuntu18.04为基准,对应Melodic。
-
如果您的网络环境不佳,Setup your sources.list 时中可选择中科大镜像或清华镜像。
下面开始安装ROS-Melodic教程(也可自行查看官网教程):
配置国内镜像源(Ubuntu的Desktop版本可用设置选项配置 或 命名行配置):
手动配置:在软件列表中找到 software & updates,点击后Download from
选择other
更改:
建议自己点击Select Best Server
自行定位到最佳下载速度的源,我定位到的是China下的清华源:
保存退出。
执行:sudo apt undate
,此步骤实际上可不用,在配置后关闭时,系统已经更新了,但为了避免个别朋友没有注意关闭保存,可以执行一次确保更新。
安装ROS
- 配置ROS软件源以接受来自package.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 apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
执行结果如下即可:
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Executing: /tmp/apt-key-gpghome.0oSwXKzemT/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
gpg: key F42ED6FBAB17C654: public key "Open Robotics <info@osrfoundation.org>" imported
gpg: Total number processed: 1
gpg: imported: 1
- 再次更新系统软件源
sudo apt update
- Desktop版本桌面安装:ROS、rqt、rviz和机器人通用库
sudo apt install ros-melodic-desktop
可以选择安装Melodic不同的版本,不同版本之间,包含的软件包不同,其他版本官方的指令如下,可自行选择:
- 初始化rosdep(问题常出)
sudo rosdep init
sudo rosdep fix-permissions
rosdep update
5.1 如报错找不到 rosdep 命令:
ganahe@ganahe-virtual-machine:~$ sudo rosdep init
sudo: rosdep: command not found
则执行再继续上面的操作:
sudo apt-get install python-rosdep
5.2 如报错网络连接失败,是网络问题导致,而不是软件源的问题,解决办法:
#备份hosts文件,以防瞎改
sudo cd /etc/hosts /etc/hosts_backup
#打开hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133 raw.githubusercontent.com
保存后退出再执行以上操作。
处理完成后,出现如下则正常:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-45fgXkUP-1610537951715)(https://i.loli.net/2021/01/13/xgHTDMacyRF4uIl.png)]
- 配置用户环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
这两条指令相当于Windows系统中设置环境变量path,实现在terminal中执行ROS系统指令,这里强调是系统指令,而不是自己创建的包或者节点,后者是需要使能相应的工作空间,具体可以参考:ROS工作空间。
查看环境变量是否设置正确,命令如下:
env | grep ROS
- 构建包的依赖关系
到目前为止,已经安装了运行核心ROS软件包所需的软件。 为了创建和管理自己的ROS工作区,有各种工具和要求分别分发。 例如,rosinstall是一个常用的命令行工具,使您可以通过一个命令轻松下载ROS软件包的许多源代码树。
要安装此工具和其他依赖项以构建ROS软件包,请运行:
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
- 验证安装
执行rosversion -d
出现:
ganahe@ganahe-virtual-machine:~$ rosversion -d
melodic
安装完成后,启动roscore:
roscore
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Tdfdrzjj-1610537951716)(https://i.loli.net/2021/01/13/5riNZy3agQfbAT2.png)]
成功安装ROS melodic。
- 工作空间管理
如果之前没有catkin_ws,则需要新建工作空间,之后除去PX4仿真环境启动外,其余ROS相关工程在此工作空间下管理。
mkdir -p ~/catkin_ws/src
mkdir -p ~/catkin_ws/scripts
# 移动到工作空间,如果使用catkin-tools话,则为cd catkin_ws && catkin init
cd catkin_ws/src && catkin_init_workspace
cd .. && catkin_make # 使用catkin-tools话,则为catkin build
catkin-tools与catkin_make的区别参见Migrating from catkin_make,自行选择合适的管理工具。
执行效果如下:
ganahe@ganahe-virtual-machine:~$ mkdir -p ~/catkin_ws/src
ganahe@ganahe-virtual-machine:~$ mkdir -p ~/catkin_ws/scripts
ganahe@ganahe-virtual-machine:~$ cd catkin_ws/src && catkin_init_workspace
Creating symlink "/home/ganahe/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/melodic/share/catkin/cmake/toplevel.cmake"
ganahe@ganahe-virtual-machine:~/catkin_ws/src$ ls
CMakeLists.txt
ganahe@ganahe-virtual-machine:~/catkin_ws/src$ cd .. && catkin_make
Base path: /home/ganahe/catkin_ws
Source space: /home/ganahe/catkin_ws/src
Build space: /home/ganahe/catkin_ws/build
Devel space: /home/ganahe/catkin_ws/devel
Install space: /home/ganahe/catkin_ws/install
####
#### Running command: "cmake /home/ganahe/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/ganahe/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/ganahe/catkin_ws/install -G Unix Makefiles" in "/home/ganahe/catkin_ws/build"
####
l
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CATKIN_DEVEL_PREFIX: /home/ganahe/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2")
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/ganahe/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ganahe/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/ganahe/catkin_ws/build"
####
ganahe@ganahe-virtual-machine:~/catkin_ws$ l
build/ devel/ scripts/ src/
三、安装Gazebo
(一)注意事项
• 注意:Melodic自带的gazebo9版本过低,建议升级
-
选用
Alternative installation: step-by-step
的安装方式,安装最新的gazebo9
,不要安装gazebo11 -
如果安装有依赖问题,可以使用
sudo aptitude install gazebo9
,选择合理的依赖解决办法(别把ROS删了)
(二)开始安装
有两种安装方式,一种从官方获取脚本一行代码实现安装,但是此方式虽然简单,但安装时缺斤少两,不好处理;
选择”循序渐进“方式:
- 配置源以接受来自packes.osrfoundation.org的软件
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
:
ganahe@ganahe-virtual-machine:~/catkin_ws$ 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 -
- 安装Gazebo9
首先更新debian数据库:sudo apt-get update
下载版本9:sudo apt-get install gazebo9
安装完成后执行gazebo
运行如下:
如果报错:
ganahe@ganahe-virtual-machine:~$ gazebo
VMware: vmw_ioctl_command error Invalid argument.
执行export SVGA_VGPU10=0
再运行。
- 安装ROS的Gazebo插件
Gazebo本身是独立于ROS的,因此还需要安装ROS的Gazebo插件:
sudo apt install ros-melodic-gazebo-*
如果是kinetic版本,执行sudo apt install ros-kinetic-gazebo9-*
。
- 获取gazebo模型
Gazebo有很多开源的模型文件,整个模型文件大致有1G,官方下载的速度极慢,可从合作平台微信公众号:星辰换日
,获取下载提取码:
链接:https://pan.baidu.com/s/16LWBEBkxDLjRdgKfDm-mXA
回复**Gazebo仿真模型
**即可。
将该压缩包解压缩后放在~/.gazebo
中(一般在home目录),此时在~/.gazebo/models/
路径下可以看到很多模型。如果不做这一步,之后运行Gazebo仿真,可能会缺模型,这时会自动下载,国内的网比较慢,自动下载会下载比较久。
四、MAVROS安装
注意,mavros-extras一定别忘记装,否则视觉定位将无法完成
# ros-melodic版本,ros-kinetic的需要看后面标注。
sudo apt install ros-melodic-mavros ros-melodic-mavros-extras
wget 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 #这步需要装一段时间,请耐心等待PX4配置
ros-kinetic第一句执行版本:sudo apt install ros-kinetic-mavros ros-kinetic-mavros-extras
五、PX4配置等
阅读完整原文:传送
参考文献
[1]XTDrone无人机仿真平台基础配置
[2]ROS Melodic安装官方教程
[3]Gazebo安装官方教程
[4]Px4仿真文档
https://dgzc.ganahe.top/ganahe/2021/uavgazebomoni.html