仅仅是个人搭建记录
参考链接:
https://zhuanlan.zhihu.com/p/686439920
mkdir -p ~/tzb/catkin_ws/src
mkdir -p ~/tzb/catkin_ws/scripts
cd catkin_ws && catkin init
catkin build
cd
sudo apt-get update
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras
# 下载并设置 geographiclib 数据集
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
# 为避免下载速度慢,直接复制(假设文件在 ~/GeographicLib/)
sudo cp -r ~/GeographicLib/ /usr/share/
sudo ./install_geographiclib_datasets.sh
# 安装 Python 依赖
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse kconfiglib jsonschema future pyserial cerberus pyulog==0.7.0 pyquaternion
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
依赖不能装在base环境下,详见:
PX4 运行 make px4_sitl_default gazebo 报错-CSDN博客
git clone https://github.com/PX4/PX4-Autopilot.git PX4_Firmware
cd PX4_Firmware
git checkout -b xtdrone/dev v1.13.2
git submodule update --init --recursive
make px4_sitl_default gazebo
可成功打开gazebo
gedit ~/.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
在文档末尾添加
####用于测试是否安装成功#####
roslaunch px4 mavros_posix_sitl.launch
######Tips######
从百度网盘里下载并解压!!!!!
cp -r ~/models/ ~/.gazebo/
语雀文档里面有:
######Tips######
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 libfuse2 -y
sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor0 -y
wget https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage
chmod +x ./QGroundControl.AppImage
./QGroundControl.AppImage
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/
# 添加launch文件
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
# 修改CMakeLists.txt
cp sitl_config/CMakeLists.txt ~/PX4_Firmware/Tools/sitl_gazebo
# 修改部分模型文件
cp -r sitl_config/models/* ~/PX4_Firmware/Tools/sitl_gazebo/models/
# 替换同名文件
cd ~/.gazebo/models/
rm -r stereo_camera/ 3d_lidar/ 3d_gpu_lidar/ hokuyo_lidar/
cd ~/PX4_Autopilot
rm -r build/
make px4_sitl_default gazebo
报错:
0/4] Performing build step for 'sitl_gazebo' [1/1] Generating /home/leaf/PX4_Firmware/Tools/sitl_gazebo/models/standard_vtol/standard_vtol.sdf FAILED: /home/leaf/PX4_Firmware/Tools/sitl_gazebo/models/standard_vtol/standard_vtol.sdf cd /home/leaf/PX4_Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/python3 /home/leaf/PX4_Firmware/Tools/sitl_gazebo/scripts/jinja_gen.py /home/leaf/PX4_Firmware/Tools/sitl_gazebo/models/standard_vtol/standard_vtol.sdf.jinja /home/leaf/PX4_Firmware/Tools/sitl_gazebo --generate_ros_models true Traceback (most recent call last): File "/home/leaf/PX4_Firmware/Tools/sitl_gazebo/scripts/jinja_gen.py", line 96, in <module> raise Exception("ERROR: generation would overwrite changes to {}
. ".format(filename_out) + \ Exception: ERROR: generation would overwrite changes to /home/leaf/PX4_Firmware/Tools/sitl_gazebo/models/standard_vtol/standard_vtol.sdf
. Changes should only be made to the template file /home/leaf/PX4_Firmware/Tools/sitl_gazebo/models/standard_vtol/standard_vtol.sdf.jinja
. Remove standard_vtol.sdf
(after extracting your changes) to disable this overwrite protection. ninja: build stopped: subcommand failed. FAILED: external/Stamp/sitl_gazebo/sitl_gazebo-build cd /home/leaf/PX4_Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/cmake --build /home/leaf/PX4_Firmware/build/px4_sitl_default/build_gazebo -- -j 8 ninja: build stopped: subcommand failed. make: *** [Makefile:230:px4_sitl_default] 错误 1
解决:
cd ~/catkin_ws
cp -r ~/XTDrone/sitl_config/gazebo_ros_pkgs src/
catkin build
##########替换比赛文件########
下载赛题文件!!!!!!!!
cp -r ~/tzb/zhihang/standard_vtol/ ~/PX4_Firmware/Tools/sitl_gazebo/models/
cp -r ~/tzb/zhihang/target_blue/ ~/PX4_Firmware/Tools/sitl_gazebo/models/
cp -r ~/tzb/zhihang/target_green/ ~/PX4_Firmware/Tools/sitl_gazebo/models/
cp -r ~/tzb/zhihang/zhihang2024.launch ~/PX4_Firmware/launch
cp -r ~/tzb/zhihang/zhihang2024.world ~/PX4_Firmware/Tools/sitl_gazebo/worlds/
cp -r ~/tzb/zhihang/zhihang2024/ ~/XTDrone/
roslaunch px4 zhihang2024.launch
报错:
解决:
即可成功打开gazebo