PX4 Development

Ubuntu Development Environment

On a clean Ubuntu environment (e.g., 18.04 LTS), we need to

  • Run the script ubuntu.sh to install PX4 related dependencies (both hardware and simulation)

    • use arg --no-nuttx to omit NuttX/Pixhawk tools

    • use arg --no-sim-tools to omit jMAVSim and Gazebo9 simulator

  • Install ROS Melodic by following the official ROS Wiki.

  • Run the script ubuntu_sim_common_deps.sh to install common dependencies for simulation.

  • Install MAVROS by following the instructions in its official repository.

    • we use source installation for development

    • use sudo for install_geographiclib_datasets.sh

    • echo "source ~/catkin_ws/devel/setup.bash --extend" >> ~/.bashrc


  • ubuntu.sh is needed for both hardware and simulation

  • ubuntu_sim_ros_melodic.sh is not used/recommended

    • To have more flexibility, we install three parts separately: ROS, sim dependencies, and MAVROS

Gazebo SITL Simulation

In order to run PX4 in Gazebo simulation, we have three more steps.

  • build PX4 source code to generate a Iris quadrotor model in Gazebo (i.e. the target)

  • set up environment variables

  • roslaunch Gazebo simulation and run offboard control program

Build Iris quadrotor model in Gazebo

git clone git@github.com:UCR-Robotics/PX4-Autopilot.git --recursive
cd PX4-Autopilot
DONT_RUN=1 make px4_sitl_default gazebo
# iris.sdf will be generated in PX4-Autopilot/Tools/sitl_gazebo/models/iris

Ser up environment variables

# may add the following to ~/.bashrc 
export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:${PX4_SRC_DIR}/build/px4_sitl_default/build_gazebo
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:${PX4_SRC_DIR}/Tools/sitl_gazebo/models
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PX4_SRC_DIR}/build/px4_sitl_default/build_gazebo
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:${PX4_SRC_DIR}/Tools/sitl_gazebo

Run Offboard Control

  • launch SITL and MAVROS by mavros_posix_sitl.launch

    • similar to px4.launch or posix_sitl.launch

  • run offboard control C++ program by rosrun <package_name> offboard_node


Last updated