# Passivity-Based Control for a Micro Air Vehicle Using Unit Quaternions
## 4 PBC Methodology for a Quad-Rotor Using Quaternions  
The development of the mathematical model using quaternions simplifies the control law design. In the sense that the proposed control law is such that the quad-rotor system can be analyzed and controlled as a fully-actuated system. Also, the proposed control law avoids the issues with singularities. The idea is to apply the PBC approach to (15). Thus, the total energy is  
\[H(\dot{\varepsilon},\dot{\varepsilon})=\frac{1}{2}\dot{\varepsilon}^{T}M\dot{ \dot{\varepsilon}}+V(\dot{\varepsilon}) \tag{24}\]  
In PBC methodology, the control input is naturally decomposed into two terms  
\[u_{u}=u_{\text{es}}(\dot{\varepsilon})+u_{\text{di}}(\dot{\varepsilon}) \tag{25}\]  
where the first term is designed to achieve the energy-shaping and the second one injects the damping. From (4) notice that if we can find \(u_{\text{es}}\) such that  
\[-\int_{0}^{t}u_{\text{es}}^{T}\left[\dot{\varepsilon}(t)\right]\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\  
The passive outputs for this system are the generalized velocities, that is \(\tilde{y}=\dot{\xi}\). The easiest way to shape the energy is by [29]  
\[u_{\text{es}}=\
abla_{\xi}H(\xi,\dot{\xi})-K_{p}(\xi-\xi_{*}) \tag{29}\]  
where \(u_{\text{es}}\) stabilizes \(\xi_{*}\) with Lyapunov function the difference between the stored and supplied energies. Then, introducing (29) and \(\tilde{y}=\dot{\xi}\), into (26) we can obtain  
\[H_{d}(\xi)=-V(\xi)+\frac{1}{2}\left(\xi-\xi_{*}\right)K_{p}\left(\xi-\xi_{*} \right)+k \tag{30}\]  
where \(K_{p}=K_{p}^{T}>0\) contains design parameters. Substituting (24) and (30) into (27), it follows that  
\[H_{d}(\xi,\dot{\xi})=\frac{1}{2}\dot{\xi}^{T}M\dot{\xi}+\frac{1}{2}\left(\xi- \xi_{*}\right)K_{p}\left(\xi-\xi_{*}\right) \tag{31}\]  
The controller (29) can be rewritten as  
\[u_{\text{es}}(\xi)=\
abla_{\xi}H(\xi,\dot{\xi})-\
abla_{\xi}H_{d}(\xi,\dot{ \xi}) \tag{32}\]  
From (32), we can ensure that the map \(u_{\text{es}}\rightarrow\tilde{y}\) is passive with (31) as the desired energy function. The damping injection term is given by  
\[u_{\text{di}}(\dot{\xi})=-K_{p}\dot{\xi} \tag{33}\]  
where \(K_{p}=K_{p}^{T}>0\) contains design parameters. To compute the final control law, consider that \(K_{p}=\left[ \begin{array}{cc}K_{pt}&0_{3\times 3}\\ 0_{3\times 3}&K_{pr}\end{array} \right]\) and \(K_{p}=\left[ \begin{array}{cc}K_{pt}&0_{3\times 3}\\ 0_{3\times 3}&K_{pr}\end{array} \right]\). Now, we first determine the energy-shaping term \(u_{\text{es}}\) from (32), which, in this case, takes the form  
\[u_{\text{es}}=\left[ \begin{array}{c}-m\tilde{y}-K_{pt}\left(p-p_{d}\right) \\ -2K_{pr}\ln\left(\boldsymbol{q}_{e}\right)\end{array} \right]\]  
Note that the term \(\boldsymbol{q}_{e}=\boldsymbol{q}\otimes\boldsymbol{q}_{d}^{*}\) is the quaternion error between the actual orientation \(\boldsymbol{q}\) and the desired reference \(\boldsymbol{q}_{d}^{*}\). If the control law is such that \(\ln\left(\boldsymbol{q}_{e}\right)\rightarrow[0\quad 0\quad 0]^{T}\), then \(\boldsymbol{q}_{e}\to 1+[0\quad 0\quad 0]^{T}\), which implies that the orientation of the UAV converges to the desired reference \(\boldsymbol{q}\rightarrow\boldsymbol{q}_{d}^{*}\). Here \(p_{d}\) denotes the desired position. Hence, we determine the damping injection term \(u_{\text{di}}\) from (33)  
\[u_{\text{di}}=\left[ \begin{array}{c}-K_{pt}\left(\dot{p}-\dot{p}_{d}\right) \\ -K_{pr}\left(\dot{\theta}-\dot{\theta}_{d}\right)\end{array} \right]\]  
where \(\theta_{d}=2\ln\boldsymbol{q}_{d}\), and the matrices \(K_{i}>0\), \(i:pt,pr,vt,vr\) are composed by the tuning parameters. From (25) the control law is applied to the model (15) according to the following equivalence:  
\[ \begin{bmatrix}F_{u}\\ \tau_{u}\end{bmatrix} =\left[ \begin{array}{c}-m\tilde{y}-K_{pt}\left(p-p_{d} \right)-K_{pt}\left(\dot{p}-\dot{p}_{d}\right)\\ -2K_{pr}\ln\left(\boldsymbol{q}_{e}\right)-K_{pr}\left(\dot{\theta}-\dot{ \theta}_{d}\right)\end{array}