This is a ROS package containing the px4 SITL (Software In The Loop) targets and gazebo simulation plugins. All these targets and plugins are compiled from the PX4 source code. The aim of this package is to simpilify the process of PX4 SITL simulation with gazebo as all the targets are prebuilt. No need for downloading PX4 source code anymore!
Environment: Ubuntu20.04 wih ROS1 installed.
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras -y
wget https://gitee.com/shu-peixuan/ros-install-command/raw/c9865c748045a0cce0173fcfcb95729784bd31e5/install_geographiclib_datasets.sh
sudo chmod a+x ./install_geographiclib_datasets.sh
sudo ./install_geographiclib_datasets.sh # this step takes some time
rm install_geographiclib_datasets.sh
sudo apt install --no-upgrade gazebo11 -y
sudo apt install --no-upgrade ros-noetic-gazebo-ros -y
sudo apt install xmlstarlet
IMPORTANT : gazebo11 version has to be newer than 1.15.1. (v1.15.0 has been proven to be incompatible).
gazebo -v # check your gazebo version (should be newer than v1.15.1)
The default version of gazebo11 in the ubuntu apt source is v1.11.0. You have to add the following Gazebo binary repository:
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > '
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
# Update list, since new gazebo-stable.list has been added
sudo apt-get update -y --quiet
sudo apt-get install gazebo11 libgazebo11-dev -y
or simply use the scripts:
./upgrade_gazebo.sh
PX4 SITL build version:
v1.14.3
with the following modification (see also https://gitee.com/bhswift/fixed-wing-px4-modify.git):
- Changed fixed-wing offboard mode in which PX4 can receives roll/height/airspeed setpoints. (no influence on the original PX4 offboard commands).
- Fix the gazebo_mavlink_interface.cpp plugin to allow multiple vehicle simulation acceleration (PX4_SIM_SPEED_FACTOR != 1).
mkdir -p px4_sitl_ws/src
cd px4_sitl_ws/src
git clone https://gitee.com/bhswift/px4_sitl.git
cd ../
catkin_make install
Source the bash script in install/
(DO NOT source devel/setup.bash
).
source install/setup.bash
You will launch PX4 software simulation
+ gazebo gzserver
+ gazebo_ros vehicle spawn
+ mavros node
:
export PX4_SIM_SPEED_FACTOR=1 # optional
roslaunch px4_sitl single_mavros_px4_gazebo_sitl.launch vehicle:=iris gazebo_gui:=true
-
vehicle
options:iris
(quadrotor),plane
,standard_vtol
-
gazebo_gui
determines whether to open gazebo UI. -
PX4_SIM_SPEED_FACTOR
: max simulation speed (less than 10 is appropriate).
export PX4_SIM_SPEED_FACTOR=1 # optional
roslaunch px4_sitl multi_mavros_px4_gazebo_sitl.launch vehicle:=standard_vtol gazebo_gui:=true
For a modified PX4 source code, compile the PX4 SITL in the source repo :
cd ~/PX4-Autopilot
make px4_sitl gazebo-classic
and substitute the build/px4_sitl_default/bin
folder:
cp -r ~/PX4-Autopilot/build/px4_sitl_default/bin ~/px4_sitl_ws/src/px4_sitl/build/px4_sitl_default/bin
The modified gazebo plugins in PX4-Autopilot/build/px4_sitl_default/build_gazebo-classic
should be moved to build/px4_sitl_default/build_gazebo-classic
as well.
The folder build/
is copied from PX4-Autopilot/build
with deletion of useless files:
bin/
: The PX4 software exectuables. (All copied)build_gazebo-classic/
: The libgazebo plugins. (Some reserved)etc/
: launch PX4 SITL related. (All copied)- other files: useless and deleted.
The foldersmodels/
and /worlds
are copied from PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic
.
The file launch/empty_world.launch
is copied from gazebo_ros/launch
.