This repository contains code and configuration files to work with the PX4 Autopilot for UAVs in simulation using Gazebo. The following instructions will guide you through the requirements, setup, and basic usage, including simulating motor failure.
Before setting up the project, ensure that you have the following tools and dependencies installed:
- PX4 Autopilot: Follow the official PX4 installation guide to set up the PX4 environment.
- Gazebo: For simulation. Install it using:
sudo apt install gazebo
- ROS 2 Humble (optional, if you need ROS integration with PX4)
- MAVSDK or MAVROS (optional, for interfacing with PX4)
-
Download and unzip:
cd PX4-Autopilot
-
Install PX4 dependencies:
./Tools/setup/ubuntu.sh
-
Build the PX4 firmware with Gazebo support:
make px4_sitl gazebo
This will compile PX4 and open the Gazebo simulation environment.
To launch the simulation in Gazebo:
make px4_sitl gazebo
This command initializes PX4 and starts the Gazebo simulation.
To simulate a motor failure, use the following gz topic
command in a new terminal:
gz topic -p /gazebo/motor_failure_num --msg "data: 1"
This command sets motor 1 to fail. You can change the data
field to specify different motor numbers.
Here are some additional tools that might be useful for working with PX4 and Gazebo:
- QGroundControl: For real-time monitoring and controlling UAVs in PX4. Download from the QGroundControl website.
- jMAVSim (optional): If you prefer a lightweight simulator over Gazebo.
- MAVLink Inspector: For viewing MAVLink messages in real-time.