How to Design a Simple PID Controller for Quadcopter Trajectory Tracking

45 views (last 30 days)
Hello everyone,
I am new to quadcopter control and am trying to design a simple PID controller for trajectory tracking in Simulink.
I am using the UAV Toolbox and started with the example "Simulate UAV Scenario Using UAV Scenario Blocks". My main questions are:
  1. Plotting a Trajectory: In the provided UAV Scenario scope, how can I plot a desired trajectory (e.g., a reference path) to visualize it against the quadcopter's actual path?
  2. Controller Design Logic: For the core controller, I need help with the logic. Let's say my desired trajectory point is [x, y, z] and the quadcopter's current position is [xp, yp, zp].
  • How do I convert the resulting position error into the correct commands for Roll, Pitch, Yaw Rate, and Thrust?
  • I understand this likely requires a cascaded PID structure. Could you please explain the high-level logic or provide a basic example of how the outputs should be calculated from the errors in X, Y, and Z?
Any guidance, code snippets, or pointers to relevant documentation would be greatly appreciated.
Thank you!
  2 Comments
Sam Chak
Sam Chak on 4 Oct 2025 at 3:26
If you have obtained the linear state-space matrices (A, B, C, D) of the UAV in your previous post, and you have learned how to properly design a PID controller for a SISO system without blindly auto-tuning the control parameters, then you can extend the mathematical design concepts to UAV control. In this context, "blindly auto-tuning" refers to allowing the machine to auto-tune the control parameters without considering the desired performance requirements, provided that the system is asymptotically stable.
For example, the demo below allows pidtune() to auto-tune the system. However, an overshoot exceeding 20% and a settling time longer than 5 seconds do not satisfy the desired performance criteria.
sys = ss([0 1; 0 0], [0; 1], [1, 0], 0)
sys = A = x1 x2 x1 0 1 x2 0 0 B = u1 x1 0 x2 1 C = x1 x2 y1 1 0 D = u1 y1 0 Continuous-time state-space model.
C = pidtune(sys, 'PD')
C = Kp + Kd * s with Kp = 0.5, Kd = 0.866 Continuous-time PD controller in parallel form.
cL = feedback(C*sys, 1);
step(cL), grid on
stepinfo(cL)
ans = struct with fields:
RiseTime: 1.2563 TransientTime: 9.4293 SettlingTime: 9.4293 SettlingMin: 0.9038 SettlingMax: 1.2435 Overshoot: 24.3470 Undershoot: 0 Peak: 1.2435 PeakTime: 3.2969

Sign in to comment.

Answers (1)

Jianxin Sun
Jianxin Sun on 20 Oct 2025 at 13:02
Hi,
  1. Plot reference trajectory in scenario scope: one way to do this is to create a "reference vehicle" and move it using UAV Scenario Motion Write block to exact location you want the vehicle to be at each simulation time if your trajectory is a function of time. If your trajectory is instead a 3D path that you would like to visualize, you can add it as a mesh object to the scenario first. Then use it in the UAV Scenario Configuation block. Here is a code example on how to construct such scenario object:
x = uavScenario;
% Example trajectory : 3xN matrix of points
points = [1 2 3 4 5;
2 4 4 5 6;
3 4 6 6 7]; % Each column is a point [x;y;z]
% Transpose for patch (N x 3)
verts = points';
% Create edges as pairs of consecutive indices
N = size(verts,1);
faces = [(1:N-1)' (2:N)' (2:N)'];
x.addMesh('custom', {verts, faces}, [1 1 1]);
ax = show3D(x);
hold(ax, 'on')
plot3(ax, points(1,:), points(2,:), points(3,:), 'o')
2. Controller Design Logic: For the core controller, I need help with the logic. Let's say my desired trajectory point is [x, y, z] and the quadcopter's current position is [xp, yp, zp].
For the controller structure: following paper provides a good starting point on quadrotor trajectory tracking controller architecture. Mellinger, D., Michael, N., Kumar, V. (2014). Trajectory Generation and Control for Precise Aggressive Maneuvers with Quadrotors. In: Khatib, O., Kumar, V., Sukhatme, G. (eds) Experimental Robotics. Springer Tracts in Advanced Robotics, vol 79. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-28572-1_25
You would still need to apply the controller tuning techniques provided by others though.

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!