# Improved Altitude Control Algorithm for Quadcopter Unmanned Aerial Vehicles
## 3 Controller Design  
The multi-loop PID-PID control scheme for quadcopter altitude control was introduced and verified in some existing studies [28; 33; 47]. In this section, we present our new altitude control algorithm which also consists of a multi-loop controller, i.e., outer-loop and inner-loop. We derive the outer-loop as a multi-mode (i.e., nonlinear and linear modes) control law while the inner-loop is a PID controller. Let \(z_{d}\) denote the desired attitude, and \(v_{z}\) represent the vertical velocity of the vehicle. The altitude tracking error is then given by:  
\[e_{z}=z_{d}-z \tag{3}\]  
Then the derivative of \(e_{z}\) is:  
\[\dot{e}_{z}=\dot{z}_{d}-v_{z} \tag{4}\]  
Figure 1: Quadcopter configuration. Figure 2: Full quadcopter controller scheme. The proposed algorithm is applied to the altitude control while conventional proportional–integral–derivative (PID) controllers are used for horizontal position and attitude control. A multi-mode control law is chosen for the outer-loop of the altitude controller as:  
\[v_{z}=\left\{ \begin{array}{rl}-\sqrt{2a_{\max}(-e_{z}-e_{0})}+\dot{z}_{d},&e_{z} <-d_{l}\\ k_{\varepsilon_{2}}+\dot{z}_{d},&-d_{l}\leq e_{z}\leq d_{l}\\ \sqrt{2a_{\max}(e_{z}-e_{0})}+\dot{z}_{d},&e_{z}>d_{l}\end{array} \right. \tag{5}\]  
where, \(a_{\max}\) is a positive constant which represents the desired maximum acceleration of the vehicle; \(d_{l}\) a positive constant at which the line \((\Delta):\ v_{z}=ke_{z}+\dot{z}_{d}\) to be tangential to the curve \((S):\ v_{z}=\left\{ \begin{array}{rl}-\sqrt{2a_{\max}(-e_{z}-e_{0})}+\dot{z}_ {d},&e_{z}<-d_{l}\\ \sqrt{2a_{\max}(e_{z}-e_{0})}+\dot{z}_{d},&e_{z}>d_{l}\end{array} \right. ;\)\(k,\ e_{0}\) positive constants, and \(e_{0}<d_{l}\); \(v_{z}\) the control action which will be fed into the inner-loop (see Figure 3) as a velocity reference [31]. Figure 4 shows \(v_{z}\) as a function of \(e_{z}\) from Expression (5) corresponding to \(\dot{z}_{d}=0\). For \(\dot{z}_{d}\
eq 0\), the graphs are shifted along the \(v_{z}\) axis an amount of \(\dot{z}_{d}\) without any change of the relations between \((S)\) and \((\Delta)\). In order for the line \((\Delta)\) to be tangential to the curve \((S)\) at \(e_{z}=d_{l}\), the followings must be satisfied:  
\[\left\{ \begin{array}{rl}ke_{z}=\sqrt{2a_{\max}(d_{l}-e_{0})}\\ k=\frac{\sqrt{2a_{\max}}}{2\sqrt{d_{l}-e_{0}}}\end{array} \right. \tag{6}\]  
Manipulating (6) yields:  
\[\left\{ \begin{array}{rl}d_{l}=\frac{a_{\max}}{k^{2}}\\ e_{0}=\frac{d_{l}}{2}\end{array} \right. \tag{7}\]  
Figure 4: Graphical illustration of the curve \((S)\) (blue), the line \((\Delta)\) (green), and their relations. Figure 3: The multi-loop altitude control scheme of the quadcopter. The proposed algorithm is implemented in the outer-loop while a PID controller is used in the inner-loop. **Theorem 1**. : _If the control law is designed as Expression (3) with the parameters satisfying (6) then the system (1) is asymptotically stable and the tracking error is forced to zero._  
**Proof. ** Choose a Lyapunov candidate function as:  
\[V=\left\{ \begin{array}{rl}&2\sqrt{-e_{z}-e_{0}},\ \ \ e_{z}<-d_{l}\\ &\frac{1}{2}e_{z}^{2},\ \ \ -d_{l}\leq e_{z}\leq d_{l}\\ &2\sqrt{e_{z}-e_{0}},\ \ \ \ e_{z}>d_{l}\end{array} \right. \tag{8}\]  
It is clear that \(V>0,\ \forall e_{z}\
eq 0\). We have:  
\[\dot{V}=\left\{ \begin{array}{rl}&\frac{-\dot{e}_{z}}{\sqrt{-e_{z}-e_{0}}}, \ \ \ e_{z}<-d_{l}\\ &\dot{e}_{z}e_{z},\ \ \ -d_{l}\leq e_{z}\leq d_{l}\\ &\frac{\dot{e}_{z}}{\sqrt{e_{z}-e_{0}}},\ \ \ e_{z}>d_{l}\end{array} \right. \tag{9}\]  
Substituting (4) into (9) and choosing control laws as (5), we have:  
\[\dot{V}=\left\{ \begin{array}{rl}&-\sqrt{2a_{\max}},\ \ \ e_{z}<-d_{l}\\ &-ke_{z}^{2},\ \ \ \ -d_{l}\leq e_{z}\leq d_{l}\\ &-\sqrt{2a_{\max}},\ \ \ e_{z}>d_{l}\end{array} \right. \tag{10}\]  
Clearly, we have \(\dot{V}<0,\ \forall e_{z}\
eq 0\) which means that the tracking error, \(e_{z}\), converges to zero as time \(t\rightarrow\infty\). This completes the proof. **Remark 1**.