【XTDrone Ubuntu20.04】XTDrone+ Ubuntu20.04 + PX4安装

XTDrone仿真平台配置

文章目录

  • XTDrone仿真平台配置
      • 依赖安装
    • ROS一键安装
    • Marvos安装
    • PX4 安装
    • 安装QTGroundControl
    • XTDrone下载安装

环境:

VMWare 16.0

Ubuntu 22.04 (因为没人配过)Ubuntu 20.04

参考文章:

  • 仿真平台基础配置 (yuque.com)

  • Ubuntu20.04搭建PX4仿真环境及XTDrone开发平台(最详细最明白)_ubuntu安装px4_哒哒哒,啥也不会的博客-CSDN博客

安装过程:

简单地说,XTDrone安装包括几个部分:ROS安装、Gazebo安装、marvos安装和PX4 安装,XTDrone下载和配置。

依赖安装

首先安装一个aptitude以解决出现的依赖问题

依赖问题的报错形式:

有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
包尚未被创建或是它们已被从新到(Incoming)目录移出。
下列信息可能会对解决问题有所帮助:
下列软件包有未满足的依赖关系:
fcitx : 依赖: fcitx-data 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

使用sudo apt install aptitude 安装aptitude,在一定程度上能解决依赖问题

先从语雀下载压缩包PX4_Firmware,并将该zip压缩包放置到Ubuntu主目录下,使用unzip命令解压,没用unzip命令工具,使用sudo apt install unzipsudo pip install unzip,然后解压后,将其命名为PX4_Firmware,使用cd PX4_Firmware/Tools/setup,其中有一个requements.txt文件:

argcomplete
argparse>=1.2
cerberus
coverage
empy>=3.3
future
jinja2>=2.8
jsonschema
kconfiglib
lxml
matplotlib>=3.0.*
numpy>=1.13
nunavut>=1.1.0
packaging
pandas>=0.21
pkgconfig
psutil
pygments
wheel>=0.31.1
pymavlink
pyros-genmsg
pyserial
pyulog>=0.5.0
pyyaml
requests
setuptools>=39.2.0
six>=1.12.0
toml>=0.9

这是官当给出的PX4所需依赖。

PX4_Firmware/Tools/setup目录下执行命令:

bash ubuntu.sh --no-sim-tools 
不加参数 --no-sim-tools,就会自动安装ubuntu版本对应的gazebo及gazebo-dev,和javsim等仿真依赖
sudo apt install ninja-build exiftool ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python-pip python3-pip gawk
pip2 install pandas jinja2 pyserial cerberus pyulog==0.7.0 numpy toml pyquaternion empy pyyaml 
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse

记录

语雀文档中提到的一个错误:

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 "", 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/

如果出现该错误,可以先更新setuptools 和 pip。(我没出现过)

更新setuptools命令:

pip install --upgrade setuptools
#若未报错不需要输入这两行命令
python -m pip install --upgrade pip

放置一个清华源安装地址:

https://pypi.tuna.tsinghua.edu.cn/simple

如果报错:网络连接不上,或者下载一半就不下了,然后报错的情况,就在上面的命令后面写上:

pip2 install pandas jinja2 pyserial cerberus pyulog==0.7.0 numpy toml pyquaternion empy pyyaml -i https://pypi.tuna.tsinghua.edu.cn/simple

可能的报错如下:

ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 101] Network is unreachable'))

ROS一键安装

鱼香肉丝开发的ubuntu一键安装挺不错的,避免了自己安装的很多麻烦,包括编译上的麻烦,换源等诸多问题。

wget http://fishros.com/install -O fishros && . fishros

Ubuntu 20.04是最后一个支持ROS1的,对应安装ROS1的Noetic,(Ubuntu 22.04只能安装ROS2,ROS2都不是很熟,我安装试了一下,不太会用,所以又用20.04了

安装时间会比较漫长:安装结束后,使用roscore命令启动ros(ROS2中不再这样启动),出现一大段信息,包括如下信息,即安装成功。

Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ubuntu:37819/
ros_comm version 1.16.0


SUMMARY
========

PARAMETERS
 * /rosdistro: noetic
 * /rosversion: 1.16.0

NODES

auto-starting new master
process[master]: started with pid [34913]
ROS_MASTER_URI=http://ubuntu:11311/

setting /run_id to 28b04b30-835b-11ee-87ca-e5b945730283
process[rosout-1]: started with pid [34924]
started core service [/rosout]

文档里有推荐安装rosdep,

rosdep是ros的依赖项管理工具,在安装完ros之后建议安装此工具,但是在rosdep init和 rosdep update时国外的网站实在令人头疼。所以使用rosdepc

所以安装一下:

sudo pip install rosdepc

rosdepc需要进行初始化和更新

sudo rosdepc init
rosdepc update

如果之前没有catkin_ws,则需要新建工作空间,之后除去PX4仿真环境启动外,其余ROS相关工程在此工作空间下管理。

文档中推荐做法,估计是为了集中管理?

mkdir -p ~/catkin_ws/src
mkdir -p ~/catkin_ws/scripts
cd catkin_ws && catkin init # 使用catkin_make话,则为cd catkin_ws/src && catkin_init_workspace
catkin build # 使用catkin_make话,则为 cd .. && catkin_make 
gedit ~/.bashrc
在下面写入:source ~/catkin_ws/devel/setup.bash #先写好source路径
关闭文件,在终端执行
source ~/.bashrc

catkin build需要先装catkin-tools(sudo apt install python3-catkin-tools),安装好Ubutu系统应该会有这个命令工具。

文档里说要卸载之前的Gazebo,CSDN博客里给出以下原因

XTDrone一般用gazebo9进行仿真,而在安装ros noetic时会自动安装gazebo11以及对应的gazebo-ros插件,这里我们需要卸载,然后安装gazebo9以及肖老师修改过的gazebo-ros插件。

感觉也可以用gazebo11来进行仿真,如果比较有时间的话,可以试一试。

感觉Gazebo 11也不是不行,文档里给出可以

  1. 选用Alternative installation: step-by-step的安装方式
  2. 如果安装有依赖问题,可以使用sudo aptitude install gazebo11,选择合理的依赖解决办法(别把ROS删了)
  3. 按步骤装完Gazebo后,升级所有的包 sudo apt upgrade,这样能保证gazebo所有依赖版本一致

卸载Gazebo

sudo apt-get remove gazebo* 
sudo apt-get remove libgazebo*
sudo apt-get remove ros-noetic-gazebo* #kinetic melodic对应修改

安装Gazebo

a、添加软件仓库 
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
b、获取密钥
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
c、更新软件源
sudo apt-get update
d、安装Gazebo 9
sudo apt-get install gazebo9
sudo apt-get install libgazebo9-dev #一定要记得这个
安装Gazebo 11 
sudo apt-get install gazebo11
sudo apt-get install libgazebo11-dev

插件修改的重新编译

安装依赖:

sudo apt-get install ros-noetic-moveit-msgs ros-noetic-object-recognition-msgs ros-noetic-octomap-msgs ros-noetic-camera-info-manager  ros-noetic-control-toolbox ros-noetic-polled-camera ros-noetic-controller-manager ros-noetic-transmission-interface ros-noetic-joint-limits-interface

然后克隆并编译Gazebo的插件gazebo_ros_pkgs,放在~/catkin_ws/src下(如果编译时还缺其他的依赖,同上方法安装)

cd ~/catkin_ws/src
git clone https://github.com/ros-simulation/gazebo_ros_pkgs.git
cd ~/catkin_ws
catkin build

上面需要使用git命令工具,如果没安装过

sudo apt install git

catkin build后的结果,成功的情况是不会有Error的,(红色的Error看得人心惊肉跳)

-----------------------------------------------------------------------
Profile:                     default
Extending:             [env] /opt/ros/noetic:/home/sunx/catkin_ws/devel
Workspace:                   /home/sunx/catkin_ws
-----------------------------------------------------------------------
Build Space:        [exists] /home/sunx/catkin_ws/build
Devel Space:        [exists] /home/sunx/catkin_ws/devel
Install Space:      [unused] /home/sunx/catkin_ws/install
Log Space:          [exists] /home/sunx/catkin_ws/logs
Source Space:       [exists] /home/sunx/catkin_ws/src
DESTDIR:            [unused] None
-----------------------------------------------------------------------
Devel Space Layout:          linked
Install Space Layout:        None
-----------------------------------------------------------------------
Additional CMake Args:       None
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
-----------------------------------------------------------------------
Buildlisted Packages:        None
Skiplisted Packages:         None
-----------------------------------------------------------------------
Workspace configuration appears valid.
-----------------------------------------------------------------------
[build] Found 6 packages in 0.0 seconds.                                       
[build] Updating package table.                                                
Starting  >>> gazebo_dev                                                       
Starting  >>> gazebo_msgs                                                      
Finished  <<< gazebo_dev                        [ 1.2 seconds ]                
Finished  <<< gazebo_msgs                       [ 9.4 seconds ]                
Starting  >>> gazebo_ros                                                       
Finished  <<< gazebo_ros                        [ 20.6 seconds ]               
Starting  >>> gazebo_plugins                                                   
Starting  >>> gazebo_ros_control                                               
Finished  <<< gazebo_ros_control                [ 25.8 seconds ]               
Finished  <<< gazebo_plugins                    [ 3 minutes and 41.5 seconds ] 
Starting  >>> gazebo_ros_pkgs                                                  
Finished  <<< gazebo_ros_pkgs                   [ 1.3 seconds ]                
[build] Summary: All 6 packages succeeded!                                     
[build]   Ignored:   None.                                                     
[build]   Warnings:  None.                                                     
[build]   Abandoned: None.                                                     
[build]   Failed:    None.                                                     
[build] Runtime: 4 minutes and 13.0 seconds total.                             
[build] Note: Workspace packages have changed, please re-source setup files to use them.

问题git clone https://github.com/ros-simulation/gazebo_ros_pkgs.git有时候无法正常克隆库,会报错。

解决方案一:

  1. 在github网站上下载适用于自己ROS版本的压缩包ros-simulation/gazebo_ros_pkgs: Wrappers, tools and additional API’s for using ROS with Gazebo (github.com)

  2. 将压缩包放到~/catkin_ws/src目录下解压缩,一般下载下来的压缩包是zip文件,需要使用unzip命令工具。使用pip install unzip命令安装

  3. 使用cd ~/catkin_wscatkin build进行编译。

编译通过后使用命令:

roscore 

开始ros服务,使用命令

source ~/catkin_ws/devel/setup.bash
rosrun gazebo_ros gazebo

开启gazebo,查看安装是否成功。

Gazebo有很多开源的模型文件,models.zip下载后将该附件解压缩后放在~/.gazebo中,此时在~/.gazebo/models/路径下可以看到很多模型。如果不做这一步,之后运行Gazebo仿真,可能会缺模型,这时会自动下载,Gazebo模型服务器在国外,自动下载会比较久。

Marvos安装

注意,mavros-extras一定别忘记装,否则视觉定位将无法完成

sudo apt install ros-noetic-mavros ros-noetic-mavros-extras  # for ros-noetic
wget https://gitee.com/robin_shaun/XTDrone/raw/master/sitl_config/mavros/install_geographiclib_datasets.sh

sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh #这步需要装一段时间

PX4 安装

安装方式:从语雀下载压缩包PX4_Firmware,使用该压缩包解压编译,从git上下载的代码可能很多方面都要修改,而且下载速度很慢。

使用该包会报错:

[0/1] Re-running CMake...
CMake Error: The source directory "/home/robin/PX4_Firmware_13" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
FAILED: build.ninja 
/usr/bin/cmake -H/home/robin/PX4_Firmware_13 -B/home/robin/PX4_Firmware_13/build/px4_sitl_default
ninja: error: rebuilding 'build.ninja': subcommand failed
make: *** [Makefile:230: px4_sitl_default] Error 1

主要是编译的CMakeCache.txt文件中的路径都是/home/robin/PX4_Firmware_13(肖老师自己电报的路径),可能编译过不了,然后自己改也是比较麻烦,我尝试改了CMakeCache.txt文件中路径问题,还是报错,还需要改build.ninja文件、cmake_install.cmake等等。这两个文件都在PX4_Firmware_13/build/px4_sitl_default目录下。~~(反正要改很多文件,你就改吧,我是把这个目录下的编译文件都改了一遍,但还是有报错

这样看用git命令也是可以,可以通过git 克隆代码

git clone -b v1.13.2 https://github.com/PX4/PX4-Autopilot.git --recursive
git clone -b v1.13.2 https://github.com.cnpmjs.org/PX4/PX4-Autopilot.git --recursive
mv PX4-Autopilot PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.13.2
git submodule update --init --recursive
make px4_sitl_default gazebo

好叭,最后还是用的VS code整体修改才可以编译

chmod +x Tools/check_submodules.sh 
chmod +x Tools/sitl_run.sh

最好发现还是不行,报错是:

Error creating PX4_Firmware/build/px4_sitl_default/etc -> /home/sunx/PX4_Fir

这个错误还显示不全,应该是软连接问题。

克隆又克隆不下来,编译又编译不过,丢。

新的可行方法

  1. 下载语雀文档中的PX4包,解压后进入PX4_Firmware然后使用命令rm -rf build,删除build文件夹,然后使用命令mkdir build

  2. 使用命令重新编译

    cd build
    cmake ..
    make
    
  3. 使用命令

    git checkout -b xtdrone/dev v1.13.2
    git submodule update --init --recursive
    make px4_sitl_default gazebo
    

终于编译成功了。花了一天和一个晚上

修改 ~/.bashrc,加入以下代码,注意路径匹配,前两个source顺序不能颠倒

#配好好路径
gedit ~/.bashrc
在里面写入:
source ~/catkin_ws/devel/setup.bash
source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default
#确保文件最底部是export,而不是source 
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4_Firmware/Tools/sitl_gazebo

关闭文件,在终端执行
source ~/.bashrc

然后运行如下命令,此时会启动Gazebo,如下图所示。

cd ~/PX4_Firmware
roslaunch px4 mavros_posix_sitl.launch

【XTDrone Ubuntu20.04】XTDrone+ Ubuntu20.04 + PX4安装_第1张图片

安装QTGroundControl

第一次安装该软件:

sudo usermod -a -G dialout $USER
sudo apt-get remove modemmanager -y
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libqt5gui5 -y
sudo apt install libfuse2 -y

XTDrone下载安装

FAILED: /home/sunx/PX4_Firmware/Tools/sitl_gazebo/models/typhoon_h480/typhoon_h480.sdf 
cd /home/sunx/PX4_Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/python3 /home/sunx/PX4_Firmware/Tools/sitl_gazebo/scripts/jinja_gen.py /home/sunx/PX4_Firmware/Tools/sitl_gazebo/models/typhoon_h480/typhoon_h480.sdf.jinja /home/sunx/PX4_Firmware/Tools/sitl_gazebo --generate_ros_models true
Traceback (most recent call last):
  File "/home/sunx/PX4_Firmware/Tools/sitl_gazebo/scripts/jinja_gen.py", line 96, in 
    raise Exception("ERROR: generation would overwrite changes to `{}`. ".format(filename_out) + \
Exception: ERROR: generation would overwrite changes to `/home/sunx/PX4_Firmware/Tools/sitl_gazebo/models/typhoon_h480/typhoon_h480.sdf`. Changes should only be made to the template file `/home/sunx/PX4_Firmware/Tools/sitl_gazebo/models/typhoon_h480/typhoon_h480.sdf.jinja`. Remove `typhoon_h480.sdf` (after extracting your changes) to disable this overwrite protection.

解决方案:

find . -name "typhoon.sdf"
然后使用rm 命令删除该文件
FAILED: external/Stamp/sitl_gazebo/sitl_gazebo-build 
cd /home/sunx/PX4_Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/cmake --build /home/sunx/PX4_Firmware/build/px4_sitl_default/build_gazebo -- -j 2

删除文件后,这个问题就可以解决了。

注意,用ctrl+c关闭仿真进程,有可能没有把Gazebo的相关进程关干净,这样再启动仿真时可能会报错。如果出现这种情况,可以用killall -9 gzclient,killall -9 gzserver 这两个命令强行关闭gazebo所有进程。

killall -9 gzclient
killall -9 gzserver 

你可能感兴趣的:(XTDrone,PX4,学习)