# Building a Realistic Virtual Simulator for Unmanned Aerial Vehicle Teleoperation
## 2 Building a Realistic UAV Simulator
### Modeling
#### 2.2.3 Quadrotor Dynamics  
Dynamics studies the physical phenomena involved in the movement of the quadrotor. For this, the Lagrangian approach obtains the quadrotor dynamics. This approach requires the analysis of the energies in the system and involves the formulation of a mechanical Lagrangian \(\mathcal{L}\). The Lagrangian is given by the difference between the total kinetic energy and the total potential energy of the quadrotor, as observed in (7). \[\mathcal{L}=\mathcal{K}-\mathcal{U} \tag{7}\]  
Potential energy is the ability of a body to carry out work depending on its configuration. In the case of the quadrotor, the potential energy depends on its vertical position and is given by:  
\[\mathcal{U}=mgz \tag{8}\]  
where \(m\) is the mass, and \(g\) is the acceleration of gravity. On the other hand, kinetic energy is related to the motion of a body of a given mass. In this way, the kinetic energy of the quadrotor is due to two independent movements: the translation and the rotation. So, the total kinetic energy is the sum of the translational and rotational kinetic energies, respectively \(\mathcal{K}_{T}\) and \(\mathcal{K}_{R}\), as indicated in (9). \[\mathcal{K}=\mathcal{K}_{T}+\mathcal{K}_{R} \tag{9}\]  
The translational kinetic energy of a mechanical system is given by [43]:  
Figure 3: Angular velocity of the quadrotor concerning the three main axes in the frame \(\{l\}\). \[\mathcal{K}_{T}=\frac{1}{2}m\mathbf{v}^{T}\mathbf{v} \tag{10}\]  
where \(m\) is the body's mass and \(\mathbf{v}\) is its linear velocity vector. In the quadrotor, the above linear velocity is \(\mathbf{v}=\mathbf{\dot{\xi}}\). Analogously, the rotational kinetic energy of a mechanical system is given by [43]:  
\[\mathcal{K}_{R}=\frac{1}{2}\mathbf{\omega}^{T}l\mathbf{\omega} \tag{11}\]  
with \(\mathbf{\omega}\) as the angular velocity vector of the system and \(I\) as its moment of inertia. Since symmetric mass distribution is assumed in the quadrotor, the moment of inertia \(I\) of this system has the following form:  
\[I=\left[ \begin{array}{ccc}I_{xx}&0&0\\ 0&I_{yy}&0\\ 0&0&I_{zz}\end{array} \right] \tag{12}\]  
where \(I_{xx}\), \(I_{yy}\), and \(I_{zz}\) are the moments of inertia about the three coordinate axes. Based on the Lagrangian \(\mathcal{L}\) calculated before, the quadrotor can be modeled through the Lagrange equation of motion in (13) [44]. \[\frac{d}{dt}\left(\frac{\partial}{\partial\mathbf{\dot{q}}}\mathcal{L}(\mathbf{q},\bm {\dot{q}})\right)-\frac{\partial}{\partial\mathbf{q}}\mathcal{L}(\mathbf{q},\mathbf{\dot{ q}})=0 \tag{13}\]  
where \(\mathbf{q}\) is the vector of generalized coordinates of the system, \(\mathbf{\dot{q}}\) is the vector with the first time derivative of these coordinates, and \(t\) is time. Considering that the motion of the quadrotor is made up of rotation and translation independently, the equations of its motion can be obtained through two separate analyzes as denoted by (14). \[\left\{ \begin{array}{l}\frac{d}{dt}\left(\frac{\partial}{\partial\mathbf{\dot{q} }}\mathcal{L}(\mathbf{\dot{\xi}},\mathbf{\dot{\xi}})\right)-\frac{\partial}{\partial \mathbf{\dot{q}}}\mathcal{L}(\mathbf{\dot{\xi}},\mathbf{\dot{\xi}})=0\\ \frac{d}{dt}\left(\frac{\partial}{\partial\mathbf{\dot{q}}}\mathcal{L}(\mathbf{\eta}, \mathbf{\dot{\eta}})\right)-\frac{\partial}{\partial\mathbf{q}}\mathcal{L}(\mathbf{\eta}, \mathbf{\dot{\eta}})=0\end{array} \right. \tag{14}\]  
with \(\mathcal{L}(\mathbf{\dot{\xi}},\mathbf{\dot{\xi}})=\mathcal{K}_{T}-\mathcal{U}\) and \(\mathcal{L}(\mathbf{\eta},\mathbf{\dot{\eta}})=\mathcal{K}_{R}\). By calculating the derivatives in (14) and rearranging the terms obtained, the motion equation of the quadrotor can be expressed in the matrix closed-form as:  
\[\left\{ \begin{array}{l}M_{T}(\mathbf{\dot{\xi}})\ddot{\mathbf{\xi}}+g_{T}(\mathbf{\dot{ \xi}})=0\\ M_{R}(\mathbf{\eta})\ddot{\mathbf{\eta}}+C_{R}(\mathbf{\eta},\mathbf{\dot{\eta}})\dot{\mathbf{\eta} }=0\end{array} \right.