1 依赖安装
2 ROS安装
3 Gazebo安装
4 MAVROS安装
5 PX4配置
6 XTDrone源码下载
7 验证
目录
安装前请注意:
本教程对应与px4源码版本v1.13(查看固件版本命令git describe --always --tags)
Ubuntu20对应ros noetic版本
sudo apt install ninja-build exiftool ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python3-pip gawk
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse kconfiglib jsonschema future
参照roswiki步骤安装 roswiki链接:
Installation/Ubuntu - ROS Wiki
注意:在执行sudo rosdep init rosdep update 大概率由于网速问题不通过
解决方法:参考鱼香ros官网一键安装
sudo pip install rosdepc
sudo rosdepc init
rosdepc update
如果执行第一条命令提示没有pip可以将pip换成pip3试试,如果pip3还没有,则:
sudo apt-get install python3-pip
之后在执行上面三行命令。
Gazebo包括Gazebo本身和ROS的插件,需要分别安装。首先卸载之前的Gazebo,执行如下命令:
sudo apt-get remove gazebo*
sudo apt-get remove libgazebo*
sudo apt-get remove ros-noetic-gazebo* #kinetic melodic对应修改
重新安装gazebo:
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_relea
se -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' #导入安装源
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add - #导入密钥
sudo apt-get update #更新
sudo apt-get install gazebo11 #安装gazebo
sudo apt-get install libgazebo11-dev
验证安装时候正确
gazebo
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 #这步需要装一段时间
或者参考如下链接:
执行 install_geographiclib_datasets.sh 错误!_cannot write to ‘install_geographiclib_datasets.sh-CSDN博客
git clone https://github.com/PX4/PX4-Autopilot.git
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
通过以下命令验证:
cd PX4_Firmware
make px4_sitl_default gazebo
正常情况会出现如下界面:
接下载在.bashrc中添加如下代码(此步骤为添加环境变量,如果不添加可以一行一行敲进终端):
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)再次进行验证:
cd ~/PX4_Firmware
roslaunch px4 mavros_posix_sitl.launch
正常情况下会出现如下界面:
git clone https://gitee.com/robin_shaun/XTDrone.git
cd XTDrone
git checkout 1_13_2
git submodule update --init --recursive
cp sitl_config/init.d-posix/* ~/PX4_Firmware/ROMFS/px4fmu_common/init.d-posix/
cp -r sitl_config/launch/* ~/PX4_Firmware/launch/
cp sitl_config/worlds/* ~/PX4_Firmware/Tools/sitl_gazebo/worlds/
cp sitl_config/gazebo_plugin/gimbal_controller/gazebo_gimbal_controller_plugin.cpp ~/PX4_Firmware/Tools/sitl_gazebo/src
cp sitl_config/gazebo_plugin/gimbal_controller/gazebo_gimbal_controller_plugin.hh ~/PX4_Firmware/Tools/sitl_gazebo/include
cp sitl_config/gazebo_plugin/wind_plugin/gazebo_ros_wind_plugin_xtdrone.cpp ~/PX4_Firmware/Tools/sitl_gazebo/src
cp sitl_config/gazebo_plugin/wind_plugin/gazebo_ros_wind_plugin_xtdrone.h ~/PX4_Firmware/Tools/sitl_gazebo/include
cp sitl_config/CMakeLists.txt ~/PX4_Firmware/Tools/sitl_gazebo
cp -r sitl_config/models/* ~/PX4_Firmware/Tools/sitl_gazebo/models/
注意看在这个过程中切换了代码版本和飞控代码保持一致,之后执行:
cd ~/PX4_Firmware
rm -r build/
make px4_sitl_default gazebo
修改PX4 sitl_gazebo中的插件,需要重新编译PX4;如果不删除build目录会报错如下:
加载gazebo环境
roslaunch px4 indoor1.launch
重新打开一个终端,输入如下命令,建立与无人机的通信:
cd ~/XTDrone/communication/
python multirotor_communication.py iris 0
看到如下信息,说明通信成功
在启动一个终端打开键盘控制节点:
cd ~/XTDrone/control/keyboard
python multirotor_keyboard_control.py iris 1 vel
之后输出如下信息,说明一切正常:
一切正常可以通过键盘控制无人机飞行: