This repository contains a complete MATLAB/Simulink project for simulating the flight dynamics and control of a 6-DOF Quadcopter Unmanned Aerial Vehicle (UAV). The project implements a cascade control strategy to track complex 3D trajectories (such as a spiral ascent).
The simulation models the physics of a quadrotor, including rigid body dynamics, motor mixing, and environmental feedback. It utilizes a feedback control loop to adjust the rotor speeds (
- Full Dynamics Model: Includes specific blocks for Attitude and Position integration.
- Cascade Control: Separated loops for position tracking and attitude stabilization.
- 3D Visualization: A post-processing script animates the drone's orientation and path.
- Data Logging: Real-time plotting of Euler angles and XYZ coordinates.
The system is built in Simulink (demo.slx). Below are the details of the internal subsystems.
This is the main simulation loop. It connects the Control Algorithm, the Quadcopter Plant (Dynamics), and the Reference Trajectory generation.

The controller takes the reference position (
This subsystem calculates the Euler angles (
This block is responsible for integrating the linear accelerations and velocities to determine the drone's absolute position (
After running the simulation, the run.m script generates the following visualizations to validate performance.
The drone (represented by the red/blue cross) successfully tracks a spiral climbing path. The green dot indicates the reference target.

Comparison between Reference Position (Red Dashed) and Actual Position (Blue Solid).
The plots below show the Roll (
- Clone the Repository:
git clone https://github.com/swzhangf/Quadcopter-UAV-Control-Simulation.git
- Open MATLAB: Ensure you have MATLAB and Simulink installed.
- Run Simulation:
- Open
demo.slx. - Click the Run button in Simulink.
- Wait for the simulation to finish (workspace variables like
tout,x,ywill be created).
- Open
- Visualize:
- Open
run.m. - Run the script to see the 3D animation and generate the plots.
- Open
-
demo.slx: Main Simulink model file. -
run.m: Visualization and plotting script. -
drone.m: Helper function for calculating the rotation matrix ($C_{bn}$ ) for 3D plotting. -
*.jpg: Project documentation images.
This project is open-source and available under the MIT License.
