# Quadrotor Stabilization and Tracking Using Nonlinear Surface Sliding Mode Control and Observer
## 5 Sliding Mode Control-Based Tracking System  
### Attitude and Altitude Control  
The purpose of SMC is to make the measurement angle and tracking error converge to the desired value in finite time using a proper control input \(u_{i}\). In this section, we use SMC to stabilize the quadrotor attitude and to control the altitude tracking with the SMO-based quadrotor attitude dynamics of Section 3. We use the Lyapunov function to satisfy the stability condition [36]. The Lyapunov stability function for attitude is confirmed as follows:  
\[V(\hat{\sigma})=\frac{1}{2}\hat{\sigma}^{2}\,\ \dot{V}(\hat{\sigma})=\hat{\sigma} \hat{\sigma}<0. \tag{13}\]  
We derive the time derivative of the sliding surface as  
\[ \begin{split}\dot{\hat{\sigma}}_{1}(\mathbf{x},t)& =\dot{\hat{x}}_{2}-\dot{x}_{2d}-\frac{1}{\lambda_{1}}(\hat{x}_{2}- x_{2d}+z_{1})+\dot{h}(\sigma_{1}(\mathbf{x},t))\\ &=c_{1}\dot{\hat{x}}_{4}\dot{x}_{6}+c_{2}\dot{\hat{x}}_{4}\Omega+ c_{6}\mu_{1}+\omega_{1}+z_{2}-\dot{x}_{2d}-\frac{1}{\lambda_{1}}(\hat{x}_{2}-x_{2d}+z _{1})\\ &-\alpha_{1}q_{1}\big{(}\ddot{\hat{x}}+\lambda_{1}\dot{\hat{e}} \big{)}\left[\frac{1}{1+e^{-\alpha_{1}\sigma_{1}(\mathbf{x})}}-\frac{1}{\left(1 +e^{-\alpha_{1}\sigma_{1}(\mathbf{x})}\right)^{2}}\right]\\ &=-\mu_{1}sat(\hat{\sigma}_{1})-\mu_{2}\hat{\sigma}_{1},\end{split}  \tag{14}\]  
where \(\dot{\hat{x}}_{2}\) is designed in Equation (8) and \(\mu_{1}\), \(\mu_{2}\) are positive constants. \(\alpha_{1}\) means \(a_{1}\sin\theta_{1}\) in Equation (12). In Equation (14), \(\dot{\hat{\sigma}}_{1}(\mathbf{x},t)\) is defined as \(-\mu_{1}sat(\hat{\sigma}_{1})-\mu_{2}\hat{\sigma}_{1}\) to make \(\hat{\sigma}_{1}(\mathbf{x},t)\) and \(\dot{\hat{\sigma}}_{1}(\mathbf{x},t)\) have the opposite sign for the satisfaction of Lyapunov stability condition. We can obtain the control input \(u_{1}\) from Equation (14) as  
\[ \begin{split} u_{1}&=-\frac{1}{\epsilon_{6}}\Big{[} c_{1}\hat{x}_{4}\hat{x}_{6}+c_{2}\hat{x}_{4}\Omega+\omega_{1}+z_{2}-\dot{x}_{2d}- \frac{1}{\lambda_{1}}(\hat{x}_{2}-x_{2d}+z_{1})\\ &\quad\quad-\alpha_{1}q_{1}\big{(}\ddot{\hat{e}}_{1}+\lambda_{1} \dot{\hat{e}}_{1}\big{)}\times\big{\{}\gamma_{1}(\sigma_{1})-\gamma_{1}^{2}( \sigma_{1})\big{\}}+\mu_{1}sat(\hat{\sigma}_{1})+\mu_{2}\hat{\sigma}_{1}\big{]} \,,\end{split}  \tag{15}\]  
where \(\gamma_{1}(\sigma_{1})\) is the sigmoid function \(\left[1+\exp(-\alpha_{1}\sigma_{1}(\mathbf{x},t))\right]^{-1}\). In Equations (14) and (15), we use the saturation function to replace the discontinuous signum function. \[sat(\hat{\sigma}_{1},\beta)=\left\{ \begin{array}{l}\operatorname{sgn}( \hat{\sigma}_{1}),|\hat{\sigma}_{1}|>\beta,\\ \frac{\partial}{\beta},\ |\hat{\sigma}_{1}|\leq\beta.\end{array} \right. \tag{16}\]  
In the saturation function, \(\beta\) is a width of the sliding surface's boundary. Following the same design procedures for \(u_{1}\), we can obtain inputs \(u_{2}\) and \(u_{3}\) as follows:  
\[ \begin{split} u_{2}&=-\frac{1}{\zeta_{7}}\big{[}c_{3}\hat{x}_ {2}\hat{x}_{6}+c_{4}\hat{x}_{2}\Omega+\omega_{2}+z_{5}-\dot{x}_{4d}-\frac{1}{ \lambda_{2}}(\hat{x}_{4}-x_{4d}+z_{4})\\ &\quad-\alpha_{2}q_{2}\big{(}\ddot{\hat{e}}_{2}+\lambda_{2}\dot{\hat{e}}_{ 2}\big{)}\times\big{\{}\gamma_{2}(\sigma_{2})-\gamma_{2}^{2}(\sigma_{2}) \big{\}}+\mu_{3}sat(\hat{\sigma}_{2})+\mu_{4}\hat{\sigma}_{2}\big{]},\\ u_{3}&=-\frac{1}{\zeta_{8}}\big{[}c_{5}\hat{x}_{2}\hat{x}_{4}+\omega_{3}+ z_{8}-\dot{x}_{6d}-\frac{1}{\lambda_{3}}(\hat{x}_{6}-x_{6d}+z_{7})\\ &\quad-\alpha_{3}q_{3}\big{(}\ddot{\hat{e}}_{3}+\lambda_{3}\dot{\hat{e}}_{ 3}\big{)}\times\big{\{}\gamma_{3}(\sigma_{3})-\gamma_{3}^{2}(\sigma_{3})\big{\}} +\mu_{5}sat(\hat{\sigma}_{3})+\mu_{6}\hat{\sigma}_{3}].\end{split}  \tag{17}\]  
As the system satisfies the Lyapunov stability condition, the sliding variable \(x_{i}-x_{id}\) converges to zero. Therefore, the control inputs \(u_{1},\ u_{2}\), and \(u_{3}\) make the errors of quadrotor angles \((\phi,\ \theta,\ \psi)\) converge to zero.