Ubuntu20.04从零开搭PX4&Mavros&Gazebo环境并测试

仅仅是个人搭建记录


参考链接:

https://zhuanlan.zhihu.com/p/686439920

仿真平台基础配置(对应PX4 1.13版) · 语雀

 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/

语雀文档里面有:

仿真平台基础配置(对应PX4 1.13版) · 语雀

######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

相关推荐
Mr.Winter`3 小时前
优化求解 | 非线性最小二乘优化器Ceres安装教程与应用案例
人工智能·机器人·自动驾驶·ros·数值优化
&黄昏的乐师1 天前
Opencv+ROS实现摄像头读取处理画面信息
linux·人工智能·opencv·计算机视觉·ros
Robot2511 天前
人形机器人赛道资本之争:“南”[智元机器人],“北”[银河通用]
人工智能·机器人
Matlab程序猿小助手1 天前
【MATLAB源码-第222期】基于matlab的改进蚁群算法三维栅格地图路径规划,加入精英蚁群策略。包括起点终点,障碍物,着火点,楼梯。
开发语言·人工智能·算法·matlab·机器人·无人机
儒雅芝士1 天前
Ros2 操作指令记录
c++·python·机器人
GAOJ_K1 天前
产业用机器人中的旋转花键若损伤有何影响?
科技·机器人·自动化·制造
视言1 天前
大模型时代的具身智能系列专题(十二)
人工智能·深度学习·计算机视觉·机器人·具身智能
FreeIPCC1 天前
部署一套开源客服系统,用户需要准备什么设备?
大数据·人工智能·语言模型·机器人·开源·信息与通信
C7211BA1 天前
基于网页的大语言模型聊天机器人
人工智能·语言模型·机器人
Simulink_1 天前
ROS学习笔记15——Xacro
linux·笔记·学习·机器人·ros