赞
踩
一.创建工作空间
1、创建文件夹,初始化工作空间
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
2、编译工作空间
cd ~/catkin_ws/
catkin_make
3、设置环境变量
source devel/setup.bash
(也可以在.bashrc里创建快捷键)
4、检查环境变量
echo $ROS_PACKAGE_PATH
5、创建功能包
cd ~/catkin_ws/src
catkin_create_pkg xuex std_msgs rospy roscpp(xuex是功能包的名字,后面的是依赖)
6、编译功能包
cd ~/catkin_ws
catkin_make
二.PX4仿真平台搭建
1.依赖安装(新版本支持python3,命令行做出了改动)
sudo apt install ninja-build exiftool ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python3-pip python3-pip gawk
pip3 install packaging numpy empy toml pyyaml jinja2 pyargparse
2.Gazebo安装
①卸载之前gazebo(注意noetic对应修改)
sudo apt-get remove gazebo*
sudo apt-get remove libgazebo*
sudo apt-get remove ros-noetic-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)setup keys
wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
(c)更新
sudo apt-get update
(d)下载gazebo9
sudo apt-get install gazebo9
sudo apt-get install libgazebo9-dev
(e)试运行
gazebo
3.gazebo源码编译
(a)安装依赖
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
(b)XTD源码下载
sudo apt install git
git clone https://gitee.com/robin_shaun/XTDrone.git
(c)编译
cd ~/catkin_ws
cp -r ~/XTDrone/sitl_config/gazebo_ros_pkgs src/
(该步骤显示没有该文件或目录)
catkin_make
(d)试运行
roscore
source ~/catkin_ws/devel/setup.bash
rosrun gazebo_ros gazebo(该命令报错,用“gazebo”代替)
4.MAVROS安装
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras (20.04版本改为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 #这步需要装一段时间
5.PX4配置
①直接去语雀平台下载固件
②编译
cd PX4_Firmware
make px4_sitl_default gazebo
(编译完成弹出Gazebo,关闭即可)
③修改.bashrc文件
指令sudo 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
试运行
cd ~/PX4_Firmware
roslaunch px4 mavros_posix_sitl.launch
(此步骤报错,缺少gazebo包所导致,输入sudo apt install ros-noetic-gazebo-ros-pkgs)
rostopic echo /mavros/state
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。