参考资料:
https://www.yuque.com/xtdrone/manual_cn/basic_config_1.11
本文主要是对搭建肖坤的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 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install packaging numpy empy toml pyyaml jinja2 -i https://pypi.tuna.tsinghua.edu.cn/simple
可能有个别依赖(如pyulog)安装不上,可以先不一起装后续再单独安装
注意PX4和ROS均不能使用Anaconda,如果有安装务必gedit ~/.bashrc
把相关代码注释掉
安装详见ROS官方文档http://wiki.ros.org/Installation/Ubuntu
ROS-Melodic可以选择desktop-full以完全安装,但是这里建议仅安装desktop,其余gazebo等相关库留着后续单独安装
配置Ubuntu存储库
在software&Update中将几个框都勾选了
Setup your sources. list (设置以接受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 update
sudo apt install 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 rosdep init
rosdep update
这里更新时可能一直链接不上,根据如下操作:
#打开hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133 raw.githubusercontent.com
#保存后退出再尝试
反复执行rosdep update命令即可,实在不行可以连手机热点会更有效
安装后启动ROS看到一大串输出说明安装成功:
roscore
新建工作空间,除去PX4仿真环境启动外,其余ROS相关工程在此工作空间下管理即可:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
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 xenial main说明没问题
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install gazebo9
安装完后在终端输入gazebo
打开gazebo说明安装成功
sudo apt install ros-melodic-gazebo-*
~/.gazebo
目录中(隐藏文件夹,Ctrl+H可看到)sudo apt install ros-melodic-mavros ros-melodic-mavros-extras # for ros-melodic
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配置
以下给出推荐配置,更多配置详见PX4仿真文档
git clone https://github.com/PX4/PX4-Autopilot.git
mv PX4-Autopilot PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1
git submodule update --init --recursive
make px4_sitl_default gazebo
由于国内github下载速度慢,XTDrone作者提供了gitee下载
git clone https://gitee.com/robin_shaun/PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1
从gitee下载更新submodule前,需要更新.gitmodules
(PX4_Firmware文件夹中Ctrl+h查看隐藏文件)
[submodule "mavlink/include/mavlink/v2.0"]
path = mavlink/include/mavlink/v2.0
url = https://gitee.com/robin_shaun/c_library_v2.git
branch = master
[submodule "src/drivers/uavcan/libuavcan"]
path = src/drivers/uavcan/libuavcan
url = https://gitee.com/robin_shaun/uavcan.git
branch = px4
[submodule "Tools/jMAVSim"]
path = Tools/jMAVSim
url = https://gitee.com/robin_shaun/jMAVSim.git
branch = master
[submodule "Tools/sitl_gazebo"]
path = Tools/sitl_gazebo
url = https://gitee.com/robin_shaun/sitl_gazebo.git
branch = master
[submodule "src/lib/matrix"]
path = src/lib/matrix
url = https://gitee.com/robin_shaun/Matrix.git
branch = master
[submodule "src/lib/ecl"]
path = src/lib/ecl
url = https://gitee.com/robin_shaun/ecl.git
branch = master
[submodule "boards/atlflight/cmake_hexagon"]
path = boards/atlflight/cmake_hexagon
url = https://gitee.com/robin_shaun/cmake_hexagon.git
branch = px4
[submodule "src/drivers/gps/devices"]
path = src/drivers/gps/devices
url = https://gitee.com/robin_shaun/GpsDrivers.git
branch = master
[submodule "src/modules/micrortps_bridge/micro-CDR"]
path = src/modules/micrortps_bridge/micro-CDR
url = https://gitee.com/robin_shaun/micro-CDR.git
branch = px4
[submodule "platforms/nuttx/NuttX/nuttx"]
path = platforms/nuttx/NuttX/nuttx
url = https://gitee.com/robin_shaun/NuttX.git
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/nuttx/NuttX/apps"]
path = platforms/nuttx/NuttX/apps
url = https://gitee.com/robin_shaun/NuttX-apps.git
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/qurt/dspal"]
path = platforms/qurt/dspal
url = https://gitee.com/robin_shaun/dspal.git
[submodule "Tools/flightgear_bridge"]
path = Tools/flightgear_bridge
url = https://gitee.com/robin_shaun/PX4-FlightGear-Bridge.git
branch = master
[submodule "Tools/jsbsim_bridge"]
path = Tools/jsbsim_bridge
url = https://gitee.com/robin_shaun/px4-jsbsim-bridge.git
[submodule "src/examples/gyro_fft/CMSIS_5"]
path = src/examples/gyro_fft/CMSIS_5
url = https://gitee.com/mirrors/CMSIS_5
执行:
git submodule update --init --recursive
更改子模块下的submodule:
cd ~/PX4_Firmware/src/drivers/uavcan/libuavcan
gedit .gitmodules
修改:
[submodule "dsdl"]
path = dsdl
url = https://gitee.com/robin_shaun/dsdl
branch = legacy-v0
[submodule "libuavcan/dsdl_compiler/pyuavcan"]
path = libuavcan/dsdl_compiler/pyuavcan
url = https://gitee.com/robin_shaun/pyuavcan
[submodule "libuavcan_drivers/kinetis"]
path = libuavcan_drivers/kinetis
url = https://gitee.com/robin_shaun/libuavcan_kinetis.git
git submodule update --init --recursive
cd ~/PX4_Firmware/Tools/jMAVSim
gedit .gitmodules
修改:
[submodule "jMAVlib"]
path = jMAVlib
url = https://gitee.com/robin_shaun/jMAVlib
branch = master
git submodule update --init --recursive
cd ~/PX4_Firmware/Tools/sitl_gazebo
gedit .gitmodules
修改:
[submodule "external/OpticalFlow"]
path = external/OpticalFlow
url = https://gitee.com/robin_shaun/OpticalFlow
git submodule update --init --recursive
cd ~/PX4_Firmware/platforms/qurt/dspal
gedit .gitmodules
修改:
[submodule "cmake_hexagon"]
path = cmake_hexagon
url = https://gitee.com/robin_shaun/cmake_hexagon
git submodule update --init --recursive
cd ~/PX4_Firmware/src/drivers/uavcan/libuavcan/libuavcan/dsdl_compiler/pyuavcan
gedit .gitmodules
修改:
[submodule "dsdl"]
path = dsdl
url = https://gitee.com/robin_shaun/dsdl
git submodule update --init --recursive
cd ~/PX4_Firmware/Tools/sitl_gazebo/external/OpticalFlow
gedit .gitmodules
修改:
[submodule "external/klt_feature_tracker"]
path = external/klt_feature_tracker
url = https://gitee.com/robin_shaun/klt_feature_tracker
git submodule update --init --recursive
cd ~/PX4_Firmware
make px4_sitl_default gazebo
打开一个新的终端,修改~/.bashrc
,末尾加入以下代码,注意路径匹配,前两个source顺序不能换:
source ~/catkin_ws/devel/setup.bash
source ~/PX4_Firmware/Tools/setup_gazebo.bash ~/PX4_Firmware/ ~/PX4_Firmware/build/px4_sitl_default
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
运行:
rostopic echo /mavros/state
若connected: True,则说明MAVROS与SITL通信成功。如果是false,一般是因为.bashrc里的路径写的不对,请仔细检查。
然后点击安装链接,安装地面站QGroundControl。
git clone https://gitee.com/robin_shaun/XTDrone.git
cd XTDrone
git submodule update --init --recursive
cp sensing/gimbal/gazebo_gimbal_controller_plugin.cpp ~/PX4_Firmware/Tools/sitl_gazebo/src/
cp sitl_config/init.d-posix/rcS ~/PX4_Firmware/ROMFS/px4fmu_common/init.d-posix/
cp sitl_config/worlds/* ~/PX4_Firmware/Tools/sitl_gazebo/worlds/
cp -r sitl_config/models/* ~/PX4_Firmware/Tools/sitl_gazebo/models/
rm -r ~/.gazebo/models/stereo_camera/ #删除原有的双目相机模型
cp sitl_config/launch/* ~/PX4_Firmware/launch/
因为Gazebo寻找模型的顺序,是先在.gazebo/models/下寻找,然后在其他路径寻找,所以在往PX4 SITL复制models时,要注意.gazebo/models/下有没有同名文件(比如.gazebo/models/下默认有stereo_camera),有的话要么将该同名文件删去,要么替换该同名文件。
由于修改了PX4 sitl_gazebo中的gazebo_gimbal_controller_plugin.cpp(源代码不能控制多无人机的云台),要再编译一次:
cd ~/PX4_Firmware
make px4_sitl_default gazebo
打开一个终端运行:
cd ~/PX4_Firmware
roslaunch px4 indoor1.launch
启动Gazebo后,打开另一个终端运行:
cd ~/XTDrone/communication/
python multirotor_communication.py iris 0 #建立与无人机模型iris0的链接
建立通信后,打开另一个终端运行:
cd ~/XTDrone/control/keyboard
python multirotor_keyboard_control.py iris 1 vel #iris代表机型,1代表飞机的个数,vel表示速度控制模式
此时便可通过键盘控制一架iris,至此,仿真平台基础配置完成!祝贺您完成了第一步!