# PID altitude control of quadcopter

36 views (last 30 days)
Dhruvilkumar Chavada on 25 May 2023
Answered: Sam Chak on 1 Jun 2023
Hello everyone,
I am designing a flight control algorithm for a UAV. In the first step, I am just designing control just altitude using PID.
I gave an step input of 50 m after 10 s as the reference altitude.
Problem 1: when i ran the simulink model, the UAV is going high and high.
Problem 2: The altitude starts rising after 3 s, even though the reference signal is 0 for first 10 s.
I tried tuning PID with simulink tuning app and with ZN method, but not getting required output.
I am attaching my simulink model for reference.
i have selected motor and propeller from T motors. The website link and other required information are mentioned in the model.
Currently, I am interpolating rpm data from the available throttle and rpm data from the website.
correct me if i am wrong here, the output of PID control is PWM and 50% throttle setting can be assumed to be 50% of voltage supply?
Do i need to add PWM block after PID block?
Thanks and regards,
Dhruvilkumar Chavada on 1 Jun 2023
I have attached the pdf for mathematical model containing all forces and moments and equations of motions for the same.
The actual quadcopter has 4 tilit rotor, thus i have included force and moment vectoring while calculation total force and moments.
I have a doubt regarding PWM block. Do i need to insert PWM block after PID or no?

Sam Chak on 1 Jun 2023
The following example is based on the pure math analysis on the contineous-time equations of motion given in your note. Thus, PWM is not considered in the design.
The Moment equations of motion (attitude model) are
... Eq. (1)
If assuming small angles on , then the Euler rate can be expressed as follows:
... Eq. (2)
and the Moment equations of motion become
... Eq. (3)
From Eq. (3), if the Control Moments are defined as
... Eq. (4)
where is assumed to be known, and are the PID controllers to be designed, then Eq. (3) can be 'flattened' to decoupled Double Integrator Systems
... Eq. (5)
which allows the Engineer to design some control laws based on simple knowledge of differential equations.
In the absence of external disturbances, state-feedback PD controllers are sufficient to stabilize the systems in Eq. (5) based on the knowledge of . Multiplying with the moment of inertia, it becomes
where
Iy = 5;
wy = 1; % tune this parameter to tune kp and kd simultaneously
kd = 2*Iy*wy % derivative gain
kd = 10
kp = Iy*wy^2 % proportional gain
kp = 5
Gp = tf(1, [1 0]);
Gv = tf(1, [Iy 0]);
G1 = feedback(Gv, kd);
G2 = series(kp, series(G1, Gp));
Gcl = minreal(feedback(G2, 1))
Gcl = 1 ------------- s^2 + 2 s + 1 Continuous-time transfer function.
step(Gcl, 20), grid on
If the Euler angular rate signals cannot be accurately measured, then the output-feedback PD controllers (PID controller block in Simulink) should be used. The autotuner feature can be used, if you understand how it works.
Also take note that in your note, the actuation dynamics (rotors) are not considered in the design. In practice, there will be a slight delay in the signal transmission. Anyhow, you can try this design approach assuming that the nominal model is known.

### Categories

Find more on Guidance, Navigation, and Control (GNC) in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!