Quaternion-based state-dependent diﬀerential Riccati equation for quadrotor drones: Regulation control problem in aerobatic ﬂight

The quaternion is a powerful and common tool to avoid singularity in rotational dynamics in three-dimensional (3D) space. Here it has been particularly used as an alternative to Euler angles and rotation matrix. The application of the quaternion is exercised in quadrotor modeling and control. It changes the dynamics and represents a singularity-free attitude model. Here for the ﬁrst time (for the best knowledge of authors), the state-dependent diﬀerential Riccati equation (SDDRE) control has been implemented on the quaternion-based model of a quadcopter. The proposed control structure is capable of aerobatic ﬂight, and the Pugachev’s Cobra maneuver is chosen to assess the capability of the quaternion-based SDDRE approach. The introduced control simulator is validated by comparison with conventional dynamics based on Euler angles, controlled using a proportional-derivative (PD) controller on a normal regulation ﬂight. The simulator successfully performed the Cobra maneuver and also validated the proposed structure. The more precision in regulation along with lower energy consumption demonstrated the superiority of the introduced approach.


Introduction
The Euler angles and rotation matrix in three-dimensional (3D) space are vulnerable to singularities, considering dynamics, especially in an aerobatic flight. Here we focus, particularly on multirotor drones and quadcopters. The dynamics of the multirotor drones are usually subjected to hovering assumptions to guarantee a stable flight [1]. To perform agile maneuvers with sudden changes in attitude, geometric control was introduced that avoids singularities and computes the rotation matrix in another manifold [2]. Krishna et al. used the geometric control for helicopter trajectory tracking in agile flight regarding the attitude of the system [3]. The sliding mode was employed as the controller and the error function in the geometric domain constructed the sliding condition to prove the stability. The geometric control was also applied on quadrotor drones subject to wind disturbance and sudden changes in attitude dynamics [4]. A flip is representative of a challenging maneuver that includes passing through a singularity that was addressed by the geometric approach [5]. The π (rad) flip in roll angle was considered, sudden motion between two stable roll angles. The change in the manifold and solving singularity cost the user more complicated integration methods [6]. Variational integration is an effective method [7]. Improper treatment of the integration may cause numerical drift in the results, especially in big orientation changes.
The quaternion is another representation of the complex numbers in mathematics, with a wide range of usage in theory and application. The focus of this work is to implement the alternative representation of the Euler angles and rotation matrix in 3D space. The application of quaternion in control was reported on aircraft [8,9], orientation and translation control of manipulators [10,11], control of autonomous underwater vehicles [12][13][14][15], helicopter attitude control [16], etc. Terze et al. used quaternion representation of the rotational dynamics for aircraft simulators and introduced shifting update process to ensure precise integration in long flight simulations [8]. Kinematics control of a robotic arm was presented using dual quaternion, aimed to present a robust controller without decoupling of the translational and orientation dynamics [10]. Cooke et al. presented a thorough implementation of the quaternion dynamics for flight simulation [17]. The performance of the quaternion-based control was validated by an omnidirectional intelligent navigator for an underwater platform [12]. Suzuki et al. presented the simulation and experimental studies on Lepton-Ex unmanned helicopter using quaternion feedback in control [16]. Quadrotor and multicopters were also employed quaternions [18][19][20][21][22][23]. A study compared three controllers, linear quadratic regulator (LQR), proportional-derivative (PD), and model predictive controller (MPC) for trajectory tracking that revealed the PD and the LQR gained better results in an ideal condition, and the MPC was more accurate in presence of disturbance [18]. Quaternion variables in the attitude controller provided an advantage, employment of low-cost sensors due to the high-speed capability of the singularity-free controller [20]. Palomo et al. presented an observer-based method based on positionyaw for the ellipsoid method [21]. Linear matrix inequalities were used to optimize the feedback of the observer, and experimental results showed successful tracking in high speed maneuver. Euler angles are popular in UAV modeling though they suffer from gimbal lock when two orthogonal axes align and lock together [24]. Another disadvantage of Euler angles is the computational cost by computing so many trigonometric functions [25], on the contrary, quaternion mathematics only involves algebraic computations [26]. Sanchez et al. used quaternion dynamics for quadrotor control based on receiving gesture commands [27], where it was important to cope with the unpredictability of the gesture and quaternion made it more reliable due to insensitivity to singularity.
Performing experiment on aggressive maneuvers requires more safety concerns in addition to solving singularities. Gillula et al. used the Hamilton-Jacobi differential game approach for finding a reachable set for aerobatic maneuvers to guarantee safety [28]. Considering the constraint of the actuators in the flight experiment is an important issue since, during the flip, it is highly probable to put the rotors in saturation [29]. Here in this work, the simulation of the Cobra maneuver is done and for experimentation, actuator limits and speed of the maneuver must be considered to avoid undesired saturations in the middle of trajectory that could be dangerous.
The state-dependent Riccati equation (SDRE) is a closed-loop optimal nonlinear controller introduced in the 1960s [30]. The utilization of the quaternion in SDRE was explored in several platforms such as satellite [31,32], spacecraft [33][34][35][36], spacecraft in proximity operations [37], attitude control of a rigid body [38], and remote sensing CubeSats [39]. Here we present the state-dependent differential Riccati equation (SDDRE) control based on quaternion for quadcopter dynamic systems. For the best knowledge of authors, a quaternion-based SDDRE controller has not been used for quadrotors in the literature so far which makes the first contribution of this work. The SDDRE is a finite time controller that penalizes the states (error variables) by a final boundary condition [40].
The singularity-free attitude control is the principal advantage of the quaternion. The Cobra is a challenging aerobatic flight maneuver, performed by a jet aircraft [41,42]. The motion turns the aircraft vertical (even for pitch angle θ > π/2) to perform the maneuver along with sudden deceleration; the thrust of the jet engine helps to avoid the system from falling.
A tail-sitter drone is a good choice, with a vertical thrust option, to perform the Cobra maneuver [43]. Xu et al. presented iterative learning control for a tail sitter unmanned aerial vertical-take-off-andlanding system for Pugachev's Cobra maneuver [43]. They used the acceleration model that resulted in simple dynamics without system identification. The Cobra was exercised by a quadrotor using adaptive control [44]. The quadrotor possessed 28(g), a small lightweight platform. An adaptive backstepping controller with a modified recursive least-square was employed to control the system.
Contributions: (1) presenting a quaternion-based SDDRE control peculiar to a quadrotor. (2) Implementing Cobra maneuver in pitch angle in a forward flight. The performed Cobra in ref. [44] was done in vertical ascending flight. In a forward flight, conducting a Cobra maneuver, the system will lose its thrust (θ ≈ π/2) and is subjected to fall. Here in this work, using SDDRE, the Cobra in forward flight is done.
Section 2 describes the preliminaries in quaternion mathematics. Section 3 states the system dynamics details. Section 4 presents the SDDRE control structure. Section 5 expresses the approximate closed-form solution to the SDDRE. Section 6 presents the implementation and method and cascade design. Simulations are reported in Section 7 which includes validation and aerobatic flight, and concluding remarks are summarized in Section 8.
Notations: R n denotes the n-dimensional Euclidean space, H n denotes the n-dimensional Hamilton space, and (·) * performs conjugate transpose. R n×m is the set of n × m real matrices; (·) T is the transpose of a matrix or a vector; denotes Kronecker product; diag (·) means a diagonal matrix; I n×n and 0 n×n denote n × n identity and zero matrices.

Preliminaries: Quaternion mathematics
Here we consider the quaternion definition with real-scalar part q 0 and vector-imaginary part where r ∈ R 3 is a unit rotation vector and ϑ is the corresponding rotation angle about that ref. [20]. To solve the ambiguity of the direction of quaternions, 0 ≤ q 0 ≤ 1 is chosen. A conjugate transpose of the quaternion (1) is presented as The multiplication product of two arbitrary quaternions q and p is defined through Kronecker product A unit quaternion can build a rotation transformation by two multiplications by Kronecker product that could rotate an arbitrary vector v from the global coordinate to a moving coordinate q as in the form of q ⊗ 0, v T T ⊗ q * . So, using definitions (2) and (3), the rotation matrix is built by replacing x, y, z in turn into v: which form [25]: where that is R x (2: 4) selects three last components of R x . The angular velocity vector of the quaternion is accessible (supposedly) in local moving coordinate; it is presented by the vector ω (q,q): Then the derivative of the quaternion is found [45]:q in whichq ω (q, ω): H × R 3 → R 4 and Q(q) has been introduced in Eq. (3). The relation between the Euler angles (ϕ, θ , ψ) and quaternions is also needed for the control design [25]: and also with inverse mapping, one could find:

Dynamics of the system
Consider a "plus-shaped" quadrotor drone with two moving and fixed reference coordinates, body frame denoted by B, and global frame marked with M = {X, Y, Z}, with respect, see Fig. 1. The position of the moving coordinate is defined through the vector ξ 1 where υ 1 T m s , and R(q):H → R 3×3 is the quaternion-based rotation matrix; and {ϕ, θ , ψ} (rad) are Euler angles set in global coordinate. The local angular velocity vector set on the body frame is also named υ 2 (t) = p(t), q(t), r(t) T rad s . To find the dynamics of the system, Newton-Euler equation could be used that results in two sets of dynamic equations, the first set is translational: where R 3 (q) is the last column of R(q), g = 9.81 m s 2 is the gravity constant, m (kg) is the total mass of the drone, and e 3 = [0,0,1] T . The second set is rotational dynamic: where is the input torque vector and J = diag I xx , I yy , I zz kgm 2 is the inertia matrix assigned in the body frame.
The state-vector is which provides the state-space representation of the multi-copter using Eqs. (4)-(8) and setting ω(t) = υ 2 (t) = p, q, r T in Eq. (4): In state-space Eq. (9), D ∈ R 3×3 collects drag and aerodynamics parameters of the quadcopter model and has been added to complete the model.

The state-dependent differential Riccati equation controller design
Consider the time-invariant affine-in-control nonlinear systeṁ where x(t) ∈ R n is the state vector, u(t) ∈ R m is the input vector, f(x(t)): R n → R n and g(x(t), u(t)): R n × R m → R n represents the dynamics and they satisfy local Lipschitz condition. n is the dimension of the state vector and m is the total number of actuators. The system Eq. (10) is transformed into state-dependent coefficient (SDC) parameterization [46]: g(x(t), u(t)) = B(x(t))u(t), (12) in which B(x(t)): R n → R n×m and A(x(t)): R n → R n×n are held. The pair of {A(x(t)), B(x(t))} is a controllable parameterization of system (10) [47]. The cost function of the SDDRE is structured as where t f ∈ R + is the final time of the control task, Q(x(t)): R n → R n×n , R(x(t))R n → R m×m , and F ∈ R n×n are weighting matrices, for states and inputs in t ∈ [0, t f ) and states at the final time t f with respect.
The pair of A(x(t)), Q 1 2 (x(t)) is an observable parameterization of system (10) where Q 1 2 (x(t)) is the Cholesky decomposition of weighting matrix in (13).
Using the necessary condition for optimality, ∂H(x(t),u(t),λ(t)) ∂x(t) = −λ(t) and the derivative of the co-state vectorλ =Kx + Kẋ, one could find: where (x) collects the derivative terms (see the complete equation in ref. [46]), then the SDDRE is represented as [48]: with K (x (t f )) = F, a final boundary condition.

An approximate closed-form solution to the SDDRE
The quadrotor dynamics in Eq. (9) must be controlled by the SDDRE approach. The extended linearization model of (9) is so-called state-dependent coefficient parameterization (or apparent linearization) [49]. To solve the SDDRE (15) and to find the control gain, several methods could be used such as backward integration (BI) [50], state-transition matrix [51], and Lyapunov-based approach [52]. The BI imposes a two-round solution that might not be proper for systems that need frequent changes in initial and final conditions, nonrepetitive systems. The STM approach is not computationally robust when the final time is long [53], then the Lyapunov-based approach has been selected for this work. It works with both positive and negative solutions to the Riccati equation and delivers an approximate closedform answer, in just one round. This work uses Lyapunov-based method via negative root to the related SDRE, K − ss (x) to find the symmetric positive-definite solution to the SDDRE, K(x(t)) [50]. Subtracting (15) from generates Adding and subtracting KBR −1 B T K ss , K ss BR −1 B T K and K ss BR −1 B T K ss to (17) result in: Rewriting (18): and introducing a new variable and expressing the closed-loop matrix of the system Regarding that d dt P −1 (x) = −P −1 (x)Ṗ(x)P −1 (x), Eq. (19) should be changed to and consequently, results in a state-dependent differential Lyapunov Eq. [50]: with a final boundary condition (20) is in which E(x(t)) is an answer to a state-dependent algebraic Lyapunov equation: Proof of (21) could be checked by the substitution of Eq. (21) into (20): From (22) we have The algebraic Lyapunov Eq. (22) results inĖ(x) = 0. Regarding frozen computation at each simulation time-step, we neglect the time derivative of A cl (x) and as a result, d( . Substituting (24) into (23), mathematical manipulation cancels all terms and shows that the solution (21) holds for Eq. (20). Since we neglectedȦ cl (x) (t − t f ) ≈ 0 in the derivative d(A cl (x)(t−t f )) dt and consideredĖ(x) = 0, this approach is so-called a closed-form approximate solution.
The positive gain of the SDDRE (15) is regarded as K (x(t)) = K ss (x(t)) + P −1 (x(t)) , in which K ss (x(t)) could be a negative definite K − ss (x(t)) or positive definite K + ss (x(t)) solution to the SDRE (16). It works with both of them.
The details of the positive and negative roots of the SDRE are reported in Sections 3.1.1 and 3.3.2 of Ref. [50]. The negative root is computationally more robust than the positive one, and it has been used here in this work. Finally, notice that the negative definite solution to the SDRE (16) is the positive definite answer to ss (x(t)) = −K + n (x(t)).

Implementation of the SDDRE on quaternion-based dynamics
The state-space equation of the system (9) must be represented by SDC forms (11) and (12). On the one hand, the dimension of the state vector (13 states) is not compatible with the cascade approach, commonly used in quadrotor control (12 states) [5]. On the other hand, the separation of rotational and translational dynamics was reported helpful in the control design due to different speeds of them, slow and fast dynamic [54]. So, here we propose two subcontrollers for the translation and rotational dynamics, connected through cascade design. For the translation dynamic, the set of SDC parameterization is in which hovering condition has been assumed to findξ 1 = R(q) I υ 1 ≈ υ 1 , to make the factorization possible, and "t" stands for translation. For the orientation section, we neglect the scalar part of the quaternion, the first column, and the row of Q(q(t)) in (9), then the SDC parameterization is where Q (2: 4, 2: 4) collects the second to fourth components of Q(q(t)) in columns and rows, and "o" stands for orientation. Based on (14), the translation control law for regulation to the desired condition rather than zero is where R, Q t , F t , and K t are the corresponding matrices (with proper dimension) for the translation and Riccati equation and "des" defines the desired condition. The computation of input law (25) is based on a fully actuated system, which is not possible in reality. So, to transform the [u t (t)] 3×1 to the scalar thrust input considering the gravity as well, we use cascade design [55]: where that is R 3 (q(t)) 1 is the first component of R 3 (q(t)). The cascade design delivers the necessary desired Euler angles θ des (t) = tan −1 u t,1 cosψ des + u t,2 sinψ des u t,3 + g , φ des (t) = sin −1 ⎛ ⎝ u t,1 sinψ des − u t,2 cosψ des in which ψ des could possess an arbitrary value.
The orientation control law is also presented as Fe q (t) where e q (t) is quaternion error and The quaternion error in (28) is defined as where q des (t) is defined by substituting (26), (27), and ψ des into Eq. (5).

Validation
To validate the proposed controller design and the simulator, a comparison has been done with the PD controller and a conventional sliding mode control (SMC). We consider a system based on the Euler angles in rotational dynamics, controlled by a simple PD to have it as a reference. Then the SDDRE controller is implemented on the quaternion-based dynamics to check the performance and also to validate the correctness of the implementation. The SMC has been frequently used in UAV control [56], in the context of robustness or combined with other techniques [57]. Based on that, the SMC is selected for comparison to add the more detailed result. The mass of the system is m = 0.468 (kg), the drag coefficient matrix is D = diag (0.25, 0.25, 0.25) kg s , the components of the inertia matrix are I xx = 4.856 × 10 −3 kgm 2 , I yy = 4.856 × 10 −3 kgm 2 , and I zz = 8.801 × 10 −3 kgm 2 . The time of the simulation has been set t f = 10 (s), and the drone flies from zero coordinate to the desired position in Cartesian coordinate (−2, 3, 1.5) (m). All of the initial conditions are set zero including position, velocity, Euler angles, and angular velocity. The initial condition of the quaternions is found by substituting (φ (0) , θ (0) , ψ (0)) into (5) to reach q (0) = [1, 0, 0, 0] T .
The PD control gains are set as K P,t = I 3×3 , K D,t = 2 × I 3×3 , K P,o = I 3×3 , and K D,o = 0.5 × I 3×3 . The SDDRE controller gains are selected as follows: Two separate SMC controllers are considered for translation and orientation parts, consistent with Section 6. The sliding surface is s i (X) =Ẋ i + iXi for i = {t,o} (translation and orientation) wherẽ X i = ξ i − ξ i,des and i is a strictly positive constant matrix. The control law is also in the form of 2 ,ξ 2 ξ 2 , and K i,SMC is the correction gain of the SMC. More details on conventional dynamics, such as J c ξ 2 = W T ξ 2 IW ξ 2 , can be found in ref. [54]. To avoid chattering in SMC, tanh s i (x) σ is used where σ = 0.2 in this simulation. The SMC control parameters are selected as t = diag (0.5, 0.5, 1), o = 1.5 × I 3×3 , K t,SMC = diag (5, 5, 1), K o,SMC = 2.5 × I 3×3 , and desired accelerations are set zero,ξ i,des = 0.
Simulating the system, the results are found in the following. The position variables of the drone are illustrated in Fig. 2 to Fig. 4 with respect. The roll and pitch angles of the multi-copter are plotted in Fig. 5 and Fig. 6 with respect. The input norm of the quadrotor is illustrated in Fig. 7 and the configuration and trajectories of the drones are shown in Fig. 8.  Fig. 2. x-axis regulation of the system, comparison with PD and SMC.   The error of the regulation with PD controller was gained higher than the other two and the error of the SDDRE was obtained the least, see Table I. Since the norm of the inputs (representative of the energy consumption) of the SDDRE is less than the PD and SMC, the performance of the proposed system is satisfactory. The results also confirm the validity of the quaternion-based dynamics and also the control implementation.
Validation with previous work: To confirm the correctness of the quaternion-based dynamics and the SDDRE controller, an existing model will be employed for comparison. Xiong and Zhang used a global fast terminal sliding mode controller (TSMC) for quadrotor regulation and also compared the results    with conventional SMC [58]. Here the parameters of the system are substituted into the quaternion model and the SDDRE controls the model. The results are similar to the ones in Fig. 2 of ref. [58] presented in this section, in Fig. 9. The regulation of translation control is quite like the TSMC and regulated to desired values around 2s, without overshoot. The controller parameters are similar to Sections 7.2. (c) Fig. 9. The validation results of the quaternion-based SDDRE with previous work in ref. [58].   It should be noted that since the loop is closed, it cannot be said that the dynamics are validated; however, observing the behavior of the system in comparison with the SMC, the closed-loop system is validated.

Cobra maneuver
The motivation of using quaternions and avoiding Euler angles in rotational dynamics are to gain a singularity-free controller, and as a result, obtain agile flight and aerobatic maneuvers. One of the hardest positions in quadrotor control in π/2 (rad) rotation either in roll or pitch angles. The Cobra maneuver is famous for a jet aircraft to perform aerobatic shows or in combat for sudden brake, etc. For the quadrotors, it is the first time that this motion is simulated in a forward flight; the Cobra in ascending motion was reported [44]. That is a challenge since, in φ = π/2 or θ = π/2, there is no thrust to compensate the gravity; for an aircraft, a jet engine supports the gravity. This might cause a crash or fall for the multirotor. To perform the Cobra maneuver, θ des = π/2 is imposed in t ∈ [1, 1.35] (s) instead of Eq. (26). After that, the multirotor drone tries to recover the stability and regulate to final condition. The simulation time is t f = 10 (s) , and the parameters of the control are R t = I 3×3 , Q t = diag (1, 1, 1, 0.5, 0.5, 0.5), F t = 10 × Q, R o = I 3×3 , Q o = diag (2, 2, 2, 0, 0, 0), F o = 10 × Q o . The start point of the regulation is set at zero along with other initial conditions; the endpoint is chosen (5, 1, 1.25) (m). Simulating the drone, the error is found 7.75 (mm) and the system successfully performed the maneuver. The position variables and attitude ones are shown in Fig. 10 and Fig. 11 with respect. The trajectory and configuration of the system are demonstrated in Fig. 12. The quaternions are plotted in Fig. 13. The input thrust and input torque signals are presented in Fig. 14 and Fig. 15 with respect.

Conclusions
This work investigated the quaternion-based control design using the SDDRE to control a quadrotor in aerobatic flight. The Euler angles are vulnerable to big changes in attitude and rotational dynamics, specifically, the rotation matrix. The diagonal components of R (φ, θ , ψ) become zero for either of φ, θ , ψ at π/2. This means the omission of thrust in flight and unstable conditions. Specifically, the controllability pair will be unsatisfied. To solve this problem, quaternion representation has been used to have a singular-free attitude control and rotation matrix. The introduced model has been validated through a comparison with the conventional Euler dynamics controlled by a PD input law. To show the application of the proposed method, a challenging maneuver, Cobra, has been simulated in the forward flight, successfully controlled. The Cobra maneuver has put the drone in a position without thrust to compensate for the gravity; however, this approach generated a stable motion to reduce the fall in that condition.