A Comparative Study Between a Classical and Optimal Controller for a Quadrotor
A Comparative Study Between a Classical and Optimal Controller for a Quadrotor
Prathamesh Saraf Department of Electrical & Electronics Engineering Birla Institute of Technology and Science – Pilani
Hyderabad, India [email protected] Manan Gupta Department of Electrical & Electronics Engineering Birla Institute of Technology and Science – Pilani
Hyderabad, India [email protected]
Dr.
Alivelu Manga Parimi Department of Electrical & Electronics Engineering Birla Institute of Technology and Science – Pilani
Hyderabad, India [email protected]
Abstract — This paper presents a simulation-based comparison between the two controllers, Proportional Integral Derivative (PID), a classical controller and Linear Quadratic Regulator (LQR), an optimal controller, for a linearized quadrotor model. To simplify an otherwise complicated dynamic model of a quadrotor, we derive a linear mathematical model using Newtonian and Euler's laws and applying basic principles of physics. This derivation gives the equations that govern the motion of a quadrotor, both concerning the body frame and the inertial frame. A state-space model is developed, which is then used to simulate the control algorithms for the quadrotor. Apart from the classic PID control algorithm, LQR is an optimal control regulator, and it is more robust for a quadrotor. Both the controllers are simulated in Simulink under the same initial conditions and show a satisfactory response.
Keywords — Proportional Integral Derivative, Linear Quadratic Regulator, Quadrotor, Simulink I. I NTRODUCTION
Quadcopters (unmanned aerial vehicles powered by four rotors) are finding increasing applications in fields ranging from video surveillance to emergency response. They are required to fly in unknown environments and must do so with accurate control. Controllers for quadcopters have been studied for quite some time now. Most controllers used on quadcopters utilize classical control, such as PID control. A proportional-integral-derivative (PID) controller is a control mechanism very commonly used in most quadcopter systems. Classical control theory encompasses linear time-invariant single-input single-output systems. The basis of control for these systems depends on how their behavior is modified using a feedback loop. On the other hand, another commonly used controller is the LQR, a type of optimal control. Optimal control theory focuses on mathematical optimization of an objective cost function for a dynamic system. Shahida et al. [1] have explored how PID controllers give better stability by bringing the closed-loop poles to the more negative side of the s-plane as compared to LQR controllers. Hayrettin et al. [2] tackle quadcopter control's problem by proposing an adaptive controller that is a hybrid of both PID and LQR controllers. Meera et al. [3] present results on a PID controller coupled with a Kalman filter being applied to UAVs. Lucas et al. [4] work on using LQR control to tune a PID controller, combining the control techniques to control the quadcopter. Existing research in the field has stated how PID has successfully been implemented for control in simulations and even real-world scenarios. However, when we extend the use cases to scenarios where external factors can cause considerable disturbances to a quadcopter's flight, we are motivated to study optimal control to see how it can factor in such uncertain circumstances. LQR is an optimal control regulator and is expected to be more robust for a quadcopter. LQR focuses on non-linear models rather than the classical linear equation approach of PID. The main drawback of PID controllers is that every test on the actual system requires its linearization. For LQR control, this step is not needed, and one can directly feed in the system equations to the controller and get the desired response. This study aims to simulate both classical and optimal controllers and obtain results for a comparison of their performances. The feasibility of implementing an LQR controller for a quadcopter is studied. We also believe this work can soon be extended to other unmanned aerial vehicles such as fixed-wing aircraft and vertical take-off and landing (VTOL) vehicles, which open up a wide avenue of applications. The following sections present the modeling and simulation, followed by the results. In section II on the Quadcopter Model, we first detail the quadcopter's physical model and layout the equations governing its motion. These equations are linearized, and a state-space model is developed in the third section. The fourth and fifth sections follow up with a comprehensive study and observations of the PID and LQR controllers. The Results section contains various cases for flight simulation using the two controllers. These are compared, and the conclusion is presented.
II. Q UADROTOR M ODEL
The position of a quadrotor in space can be specified using two reference frames: fixed and mobile. The fixed (inertial) coordinate system is one where Newton’s laws are valid and it is with respect to the Earth. The second frame is with respect to the center of the quadrotor frame, where the flight controller is positioned. The Quadrotor has four Degrees of Freedom, namely Thrust, Roll, Pitch, and Yaw. The position and movement of the quadrotor are controlled by varying the speeds and rotation direction of the four motors (two diametrically opposite motors spin clockwise and the other two motors spin anti-clockwise). However, the quadrotor has four inputs (4 motors) and 6 outputs (three translational and three rotational motions along the three axes), and hence, it is an underactuated nonlinear complex system. The Euler angles φ ∈ [−π, π], θ ∈ [π/2, π/2], 𝜓 ∈ [−π, π] are used to give the orientation of the mobile reference frame with respect to the inertial frame. These angles help form a rotation matrix that is used to represent rotation/orientation in the same way position is used to represent displacement vectors. The non-linear equations of the quadrotor system are given as [5]: 𝑥̈ = (𝑐𝑜𝑠𝜑𝑠𝑖𝑛𝜃𝑐𝑜𝑠𝜓 + 𝑠𝑖𝑛𝜑𝑠𝑖𝑛𝜓) 𝐹𝑚 (1) 𝑦̈ = (𝑐𝑜𝑠𝜑𝑠𝑖𝑛𝜃𝑠𝑖𝑛𝜓 − 𝑠𝑖𝑛𝜑𝑐𝑜𝑠𝜓) 𝐹𝑚 (2) 𝑧̈ = −𝑔 + (𝑐𝑜𝑠𝜑𝑐𝑜𝑠𝜃) 𝐹𝑚 (3) 𝑝̇ = 𝐼 𝑦𝑦 − 𝐼 𝑧𝑧 𝐼 𝑥𝑥 𝑞𝑟 − 𝐽𝑟𝐼 𝑥𝑥 𝑞𝜔 + 𝑢 𝐼 𝑥𝑥 (4) 𝑞̇ = 𝐼 𝑧𝑧 − 𝐼 𝑥𝑥 𝐼 𝑦𝑦 𝑝𝑟 − 𝐽𝑟𝐼 𝑦𝑦 𝑝𝜔 + 𝑢 𝐼 𝑦𝑦 (5) 𝑟̇ = 𝐼 𝑥𝑥 − 𝐼 𝑦𝑦 𝐼 𝑧𝑧 𝑝𝑞 + 𝑢 𝐼 𝑧𝑧 (6) where Jr is the rotor inertia and p, q, and, r represents the angular velocities with respect to roll, pitch and yaw motions respectively. The input forces are given as: 𝑢 = 𝐾 𝑓 ∗ (𝜔 + 𝜔 + 𝜔 + 𝜔 ) (7) 𝑢 = 𝐾 𝑓 ∗ (𝜔 − 𝜔 ) (8) 𝑢 = 𝐾 𝑓 ∗ (𝜔 − 𝜔 ) (9) 𝑢 = 𝐾 𝑚 ∗ (𝜔 − 𝜔 + 𝜔 − 𝜔 ) (10) where 𝐾 𝑓 is the thrust factor and 𝐾 𝑚 is the drag factor whose value depends on propeller size and air conditions in which the quadrotor is flying, 𝜔 𝑖 is the angular speed of the i th rotor. The quadrotor parameters considered for simulation are given in table 1. TABLE I.
Sr. No. Parameter Value 1. Quadrotor mass ( m ) 1 Kg 2. Arm length ( l ) 22.5cm 3. Thrust Factor ( 𝐾 𝑓 ) 9.8×10 -6
4. Drag Factor ( 𝐾 𝑚 ) 1.6×10 -7 𝐼 𝑥𝑥 𝐼 𝑦𝑦 𝐼 𝑧𝑧 The LQR optimization problem requires a linear state-space system as the A and B matrices along with the Q and R optimal control matrices are necessary for computing the full state feedback K matrix. The following section focusses on modelling the non-linear quadrotor equations as a linear state-space system. III. S TATE -S PACE M ODELING
The quadrotor state-space system consists of 12 state variables, four input variables, and four output variables. The state variables represent the absolute quadrotor orientation in space consisting of linear and rotational coordinates and their respective velocities. The input variables consist of the four quadrotor motions, namely thrust, roll, pitch, and yaw motion. The output consists of the required state variables for stability analysis of the quadrotor, which are the vertical displacement (z), roll ( 𝜑) , pitch ( 𝜃 ), and yaw ( 𝜓 ) angle displacements. 𝑋̇ = 𝐴𝑋 + 𝐵𝑈 (11)
𝑌 = 𝐶𝑋 + 𝐷𝑈 (12) 𝑋 𝑇 = [𝑥 𝑦 𝑧 𝜑 𝜃 𝜓 𝑥̇ 𝑦̇ 𝑧̇ 𝑝 𝑞 𝑟] (13) 𝑈 𝑇 = [𝑢 𝑢 𝑢 𝑢 ] (14) 𝑌 𝑇 = [𝑧 𝜑 𝜃 𝜓] (15) where A is a 12 ×
12 state matrix and B is a 12 × 𝐴 = [ 0 0 0 1 0 0 0 0 0 0 0 00 0 0 0 1 0 0 0 0 0 0 00 0 0 0 0 1 0 0 0 0 0 00 0 0 0 0 0 0 𝑢 𝑚 0 0 0 00 0 0 0 0 0 − 𝑢 𝑚 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 1 0 00 0 0 0 0 0 0 0 0 0 1 00 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0] 𝐵 = [ 0 0 0 00 0 0 00 0 0 00 0 0 00 0 0 01𝑚 0 0 00 0 0 00 0 0 00 0 0 00 1𝐼 𝑥𝑥 𝑦𝑦
00 0 0 1𝐼 𝑧𝑧 ] (16) (17) C matrix is a 4 ×
12 matrix with each column having a unity multiplier to scrape out the 4 state parameters from X, as mentioned above. D is a 4 ×
4 null matrix. Once the state-space equations are obtained, the controller is designed for the quadrotor system. The following section describes the action of a PID controller on the quadrotor system.
Fig. 1: Quadrotor illustration with inertial frames and 6 DOF coordinates. 𝜔 𝑖 is the angular speed and F i is the propeller force of the i th rotor. IV. P ROPORTIONAL I NTEGRAL D ERIVATIVE C ONTROL A. Overview
The PID controller is one of the standard classic models in control theory. The aim is to minimize the error by tuning the proportional, integral, and the derivative coefficients used in the controller equation. Error is defined as the difference between the setpoint value and the actual controller output at any particular instance. The proportional term increases/decreases the error by multiplying with a proportionality constant. The derivative term is used to estimate the controller's future response based on the error with respect to time. The derivative constant also accounts for the damping factor and needs to be tuned to minimize damping and obtain a smooth response. The integral term in the controller sums up all the past values, and the integral coefficient is used for assigning the weight to the integral term to obtain the desired output response in the shortest possible time. Thus, all three coefficients need to be tuned to obtain the setpoint value of the control system. B. Equations
The PID control equation uses the 𝐾 𝑝 , 𝐾 𝑖 , and, 𝐾 𝑑 parameters and the error value to compute the controller response. The control equation is given below: 𝑈(𝑡) = 𝐾 𝑝 𝑒(𝑡) + 𝐾 𝑖 ∫ 𝑒(𝑡)𝑑𝑡 𝑡0 + 𝐾 𝑑 𝑑𝑒(𝑡)𝑑𝑡 (18) 𝐾 𝑑 and 𝐾 𝑖 are defined as: 𝐾 𝑑 = 𝐾 𝑝 𝑇 𝑑 & 𝐾 𝑖 = 𝐾 𝑝 /𝑇 𝑖 (19) where 𝑇 𝑑 and 𝑇 𝑖 are the time periods for integral and derivative actions. The error value is defined as: 𝑒(𝑡) = 𝑠𝑒𝑡𝑝𝑜𝑖𝑛𝑡 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑐𝑡𝑢𝑎𝑙 𝑣𝑎𝑙𝑢𝑒 (20) C. Controller Design
In the Quadrotor system, the state parameters need to be controlled so that it remains stable during the flight period. A small deviation in the setpoint values of the quadrotor would create large variations in motion, which would lead to deviation from its desired trajectory and making it difficult for the user to control. Even if the main control lies in the hand of the user flying the quadrotor, unavoidable disturbances during the time of flight will create instability and malfunction of the system. Thus, there is a need for an internal flight controller, which would autonomously adjust the rotor to a stable position. The four inputs thrust, roll, pitch, and yaw motion control the six-state parameters depending on the action. Thrust controls the 𝑧 parameter, roll controls the 𝑥 and the 𝜃 parameters, pitch controls 𝑦 and 𝜑 parameter and yaw controls the 𝜓 angle [6]. Thus, the six-state parameters require 6 PID controllers with 1-2-2-1 controllers for thrust, roll, pitch, and yaw motion control, respectively. For roll and pitch motion, a cascaded PID loop is designed to have an inner and an outer feedback loop. The inner loop needs to be faster than the outer loop for an efficient response of the controller. Slowing the outer loop increases the overshoot but reduces the setting time for the rotational coordinates and their velocity and increases the time for the corresponding translational coordinate to attain the set point. The tuned PID controller parameters for optimal control are given in table 2 below. TABLE II.
After the successful implementation of the PID controller, the optimal LQR controller is designed for the linearized quadrotor model. V. L INEAR Q UADRATIC R EGULATOR A. Overview
As compared to the classic PID controller, the LQR controller involves a lot of mathematical computations to calculate the full state feedback matrix K. LQR controller uses an optimal control algorithm to minimize the cost function defined by the system equations. The cost function involves the state parameters and the input parameters to the system along with the Q and R matrices. The overall cost function needs to be minimum for optimal LQR solution. The Q and R matrices represent the weights assigned to the state parameters and the input parameters. By varying the values of the two matrices, the total value of the cost function can be adjusted according to the desired output. The two main quantities that need to be optimized for the quadrotor model are the power consumption and response speed. For a faster response of the controller, the Q matrix values need to be changed, whereas for minimizing the power consumption while achieving the desired setpoint without focusing on the time of response, the R matrix values need to be adjusted [8].
Sr. No Input Action Parameter Inner Loop Outer Loop P 9.09 1. Thrust I 1.94 NA. D 10.41 P 4.04 -2.92 2. Roll I 10.03 -0.032 D 0.33 -4.68 P 4.04 -2.92 3. Pitch I 10.03 -0.032 D 0.33 -4.68 P 1.3×10 -2
4. Yaw I 7.6×10 -4 NA. D 4.9×10 -2 Fig.2: The closed loop quadrotor system with PID controller for stabilization
Fig.3: The closed loop quadrotor system with LQR controller for stabilization B. Equations
The LQR optimization problem requires a linearized state-space model of the system. The cost function which needs to be optimized is given by:
𝐽 = ∫ (𝑋 𝑇 𝑄𝑋 + 𝑈 𝑇 𝑅𝑈)𝑑𝑡 (21)
After tuning the matrices according to the desired output matrix, the Q and R matrices are used to solve the Algebraic Riccati Equation (ARE) to compute the full state feedback matrix, which is essentially the LQR controller. 𝐴 𝑇 𝑆 + 𝑆𝐴 − 𝑆𝐵𝑅 −1 𝐵 𝑇 𝑆 + 𝑄 = 0 (22)
The S matrix obtained from the ARE is used to calculate the Full state feedback gain matrix K using the equation:
𝐾 = 𝑅 −1 𝐵 𝑇 𝑆 (23) The final feedback control relation is then calculated as:
𝑈 = −𝐾 ∗ 𝑋 (24)
The tuned Q and R matrices which give the optimal response for the Quadrotor system parameters as defined before are:
𝑄 = [ 500 0 0 0 0 0 0 0 0 0 0 00 200 0 0 0 0 0 0 0 0 0 00 0 1.71 0 0 0 0 0 0 0 0 00 0 0 500 0 0 0 0 0 0 0 00 0 0 0 200 0 0 0 0 0 0 00 0 0 0 0 3 0 0 0 0 0 00 0 0 0 0 0 10 0 0 0 0 00 0 0 0 0 0 0 10 0 0 0 00 0 0 0 0 0 0 0 10 0 0 00 0 0 0 0 0 0 0 0 0.25 0 00 0 0 0 0 0 0 0 0 0 10 00 0 0 0 0 0 0 0 0 0 0 1] (25)
𝑅 = [1 0 0 00 0.001 0 00 0 0.001 00 0 0 0.001] (26)
And the Feedback gain matrix K is computed as:
𝐾 = 10 ∗ [ 0 0 0.13 0 0 0.29 0 0 0 0 0 00 −44.7 0 0 −84.8 0 12.6 0 0 1.6 0 070.7 0 0 151.6 0 0 0 27.5 0 0 10 00 0 0 0 0 0 0 0 10 0 0 3.2] (27)
The next section presents the detailed comparative analysis of the two controllers tested for different input conditions. VI. R ESULTS A ND D ISCUSSION
The PID and the LQR controller is designed for the quadrotor system in MATLAB as shown in Fig.2 and Fig.3. The simulation tests are divided into 3 cases that help verify the controller functionality in detail. Each case either uses different initial conditions or defines another set-point for a particular parameter of the system. The cases are defined as: 1.
Pure thrust input with zero initial conditions 2.
Pure thrust input with non-zero initial conditions 3.
Thrust and Yaw input with zero initial conditions Initial conditions define the Quadrotor state just before the controller action, and the set-point defines the desired final steady-state of the system. The detailed analysis of each case along with controlller response is given below: A. Case 1
The initial conditions of the Quadrotor are set as zero for all the state parameters and pure thrust action is fed as the system input. In this case, only the vertical displacement ( 𝑧 ) is expected and should reach a steady state position once the thrust force balances the gravitational force. The vertical velocity ( 𝑧̇ ) increases rapidly in the beginning and slows down to zero as the rotor achieves steady position midair. (a) (a) (a) (b) Fig.4: The translational and rotational response of the quadrotor for a PID controller for case 1. Fig.4 and Fig.5 shows the simulated response for PID and LQR controllers respectively. It can be seen that z response for PID controller gives an overshoot of 0.5units and settles at 0.45units with a settling time of 0.8secs whereas there is no overshoot in case of LQR controller and the value settles at 0.7secs at 0.34 units. No fluctuations about the setpoint describes shows that LQR provides a stable output compared to PID controller. B. Case 2
The initial conditions for the system are set as: [1 1 0.2 1 1 0 1 1 1 1 1 1]
Where each value defines the position of each of the state parameter. The input is again given as a pure thrust force. For this case, all the state parameters except z should achieve the set point which is zero as no other input rotor action is desired. The initial conditions mentioned, show that the rotor is deviated from its set-point and thus the controller will act upon to bring the rotor back to its set-point-zero. The PID and LQR controller responses are shown in Fig. 6 and Fig. 7 (a) (b) Fig.7: The translational and rotational response of the quadrotor for an LQR controller for case 2. (a) (b) Fig.6: The rotational response of the quadrotor for a PID controller for case 2. (b) Fig.5: The translational and rotational response of the quadrotor for an LQR controller for case 1.
Both the controllers show similar settling time of 7 secs for all the state parameters. Although, the 1 st overshoot of PID controller (1.2 units) is lesser than LQR controller (1.6 units) for x and y parameters, the PID controllers gives 2 nd overshoot in its response in most of the state parameters as opposed to a single overshoot peak in case of an LQR controller. More the number of overshoot peaks, lesser is the stability. Thus, LQR response is more stable and robust as compared to the PID controller. C. Case 3
The initial conditions are set to zero and a thrust force along with a yaw motion is given as an input to both the controllers. A desired yaw angle value is given as a set point to the controller. In this case, along with achieving the yaw angle, only the vertical motion of the rotor is expected. The simulated response for PID and LQR controller is shown in Fig.8 and Fig.9 respectively. The settling time for yaw angle for the PID controller is 0.9 sec and that of LQR is 1.8sec making PID response faster. However, PID controller shows an undesired spike in the velocity curve whereas the LQR response is a gradually decreasing curve settling around 1.8sec. This drastic behavior would create instability which is undesired. Lesser the overshoot, lesser the fluctuation and more the stability. VII. C ONCLUSION
The two controllers show similar response with respect to settling time to achieve the desired response. Although, there are some points which give the optimal controller an advantage over the classical control method. In all the cases, 2 overshoot peaks can be seen in the PID controller output whereas only a single overshoot peak is obtained in LQR response. This means that the PID controller shows aggressive behavior as compared to the LQR controller response. Secondly, all the 6 PID controllers need to be tuned to obtain an efficient response which makes it a tedious work whereas only 2 matrices need to be tuned in case of the LQR controller. PID controller requires 6 feedback loops making the computation complex than the single control loop in case of an LQR controller. Thus, it can be concluded that LQR controller is better suited for Quadrotor control mechanism than the classical PID controller in terms of output, complexity, and, computation time. A
CKNOWLEDGMENT
We would like to express our gratitude towards the staff of the Control Systems Laboratory at BITS Pilani, Hyderabad Campus for their assistance in making this project a reality. R
EFERENCES [1]
S. Khatoon, D. Gupta and L. K. Das, "PID & LQR control for a quadrotor: Modeling and simulation," 2014 International Conference on Advances in Computing, Communications and Informatics (ICACCI), New Delhi, 2014, pp. 796-802, doi: 10.1109/ICACCI.2014.6968232. [2]
H. Yavuz and S. İkizoğlu , "Hyperbolic Tangent Adaptive LQR+PID Control of a Quadrotor," 2018 6th International Conference on Control Engineering & Information Technology (CEIT), Istanbul, Turkey, 2018, pp. 1-6, doi: 10.1109/CEIT.2018.8751878. [3]
M. P. Nair and R. Harikumar, "Longitudinal dynamics control of UAV," 2015 International Conference on Control Communication & Computing India (ICCC), Trivandrum, 2015, pp. 30-35, doi: 10.1109/ICCC.2015.7432865. [4]
L. M. Argentim, W. C. Rezende, P. E. Santos and R. A. Aguiar, "PID, LQR and LQR-PID on a quadcopter platform," 2013 International Conference on Informatics, Electronics and Vision (ICIEV), Dhaka, 2013, pp. 1-6, doi: 10.1109/ICIEV.2013.6572698. [5]
Dhewa, Oktaf & Dharmawan, Andi & Priyambodo, Tri. (2017). Model of Linear Quadratic Regulator (LQR) Control Method in Hovering State of Quadrotor. Journal of Telecommunication, Electronic and Computer Engineering (JTEC). 9. 135-143. [6]
Q. Jiao, J. Liu, Y. Zhang and W. Lian, "Analysis and design the controller for quadrotors based on PID control method," 2018 33rd Youth Academic Annual Conference of Chinese Association of Automation (YAC), Nanjing, 2018, pp. 88-92, doi: 10.1109/YAC.2018.8406352. [7]
D. Kucherov, A. Kozub and A. Rasstrygin, "Setting the PID Controller for Controlling Quadrotor Flight: a Gradient Approach," 2018 IEEE 5th International Conference on Methods and Systems of Navigation and Motion Control (MSNMC), Kiev, 2018, pp. 90-93, doi: 10.1109/MSNMC.2018.8576294. [8]
Islam, Maidul & Okasha, Mohamed & Sulaeman, E. & Fatai, S. & Legowo, Ari. (2019). Performance evaluation of linear quadratic regulator and linear quadratic gaussian controllers on quadrotor platform. International Journal of Recent Technology and Engineering. 7. 191-195.