This repository provides a workspace for simulating and controlling an Iris drone using PX4, ROS 2, and Gazebo Classic. It includes packages for low-level motor control, motor failure detection, trajectory publishing, and real-time visualization. The workspace is designed to streamline drone simulation and testing, offering tools for motor control, parameter configuration, and motor failure analysis.
ROS_PX4/
├── src/
│ ├── px4_detector/ # Package for motor failure detection and trajectory control
│ │ └── px4_detector/
│ │ ├── trajectory_publisher.py # Publishes trajectories for the drone ✈️
│ │ └── detector.py # Motor failure detection logic ⚙️
│ ├── px4_motor_control/ # Low-level motor control package 🔧
│ │ ├── config/
│ │ │ ├── initial_gains_iris.yaml # Initial PID gain values
│ │ │ ├── iris_param.yaml # Iris drone parameters
│ │ │ └── sitl_params.yaml # Simulation parameters
│ │ ├── include/
│ │ │ └── px4_offboard_lowlevel/
│ │ │ ├── controller_node.h # Node header for motor control 🛠️
│ │ │ └── controller.h # Main motor control logic
│ │ ├── launch/
│ │ │ └── setup.launch.py # ROS 2 launch file for simulation 🚀
│ │ ├── src/
│ │ │ ├── controller_node.cpp # ROS 2 node for motor control
│ │ │ └── controller.cpp # Motor control implementation
│ │ ├── CMakeLists.txt
│ │ └── package.xml
│ ├── px4_msgs/ # ROS 2 custom messages for PX4 📬
│ │ └── msgs/
│ │ ├── ActionRequest.msg # Custom message definitions
│ │ ...
│ └── px4_ros_com/ # Interface for ROS 2 and PX4 communication
├── .gitignore
├── .gitmodules
└── README.md
-
Drone Simulation 🛸:
Simulate the Iris drone in Gazebo Classic using PX4's SITL (Software in the Loop) environment. -
Low-Level Motor Control 🔧:
Implement precise motor control using a ROS 2 node with configurable PID gains. -
Motor Failure Detection
⚠️ :
Simulate motor failures for testing robust flight control and fault tolerance. -
Trajectory Control 📈:
Publish desired drone trajectories using Python scripts. -
Real-Time Visualization 📊:
Visualize drone parameters like thrust, torque, and position tracking using PlotJuggler. -
Configurable Parameters 🛠️:
Customize drone parameters, PID gains, and SITL settings via YAML files.
- Operating System: Ubuntu 22.04 🐧
- ROS 2: Humble 🤖
- PX4-Autopilot: Follow the PX4 installation guide.
- Gazebo Classic: Install for realistic drone simulation.
- PlotJuggler (optional): For real-time data visualization.
git clone https://github.com/Hit2737/ROS_PX4.git
-
Navigate to the workspace directory:
cd ROS_PX4
-
Build the workspace using
colcon
:colcon build --symlink-install
Start the PX4 SITL simulation for the Iris drone:
cd PX4-Autopilot
make px4_sitl gazebo-classic_iris
Before running any ROS 2 commands, source the workspace:
source install/setup.bash
Run the main launch file for motor control and trajectory configuration:
ros2 launch px4_motor_control setup.launch.py
In a new terminal, source the workspace and run the trajectory publisher:
ros2 run px4_detector trajectory_publisher
To fail a specific motor during the simulation, use the following command:
gz topic -p /gazebo/motor_failure_num -m "data: <motor_number>"
Replace <motor_number>
with the motor index you want to fail (e.g., 2
).
For real-time data visualization, launch PlotJuggler:
ros2 run plotjuggler plotjuggler
The px4_motor_control/config/
directory contains key configuration files:
-
initial_gains_iris.yaml
:
Configures initial PID gains for motor control. -
iris_param.yaml
:
Drone-specific parameters such as mass, inertia, and motor coefficients. -
sitl_params.yaml
:
SITL-specific parameters for tuning the simulation environment.
This repository is inspired by:
- SMART Research Group's Repository.
- The PX4 open-source community for providing tools and documentation.
For detailed documentation and updates, visit the PX4 website.
Explore the possibilities of PX4, ROS 2, and Gazebo Classic for building robust drone systems. 🛸🎉