# Building a Realistic Virtual Simulator for Unmanned Aerial Vehicle Teleoperation
## 2 Building a Realistic UAV Simulator
### Virtual Teleoperation  
Teleoperation can be defined as the continuous control of a remote slave robot by a human [51]. This definition fits naturally with the piloting of UAVs. In virtual teleoperation, the slave robot is virtual, and its remoteness is perceived through a virtual simulation, i.e., the human manipulates a virtual environment [51]. This kind of interaction is helpful in education, evaluation, and training [52]. The teleoperation algorithm proposed in this framework takes as inputs the commands triggered by the human user. They indicate how the quadrotor should move in terms of its generalized torques and forces. It is necessary to define which operations the user can perform through a master device. Even when there are very specialized master devices, gamepads are used more and more frequently to control UAVs. The above is because these game devices meet several usability criteria such as reduced size, portability, adaptability, universality, and ergonomics and can be acquired at affordable costs [53]. So, the Xbox Series gamepad is adopted as the master device, and its enabled commands are depicted in Figure 7. The commands established for this device develop the elevation, yaw, pitch, and roll movements in the quadrotor. It is important to highlight that although a gamepad is adopted to develop this framework, it is possible to carry out a mapping similar to the one carried out below between the input mechanisms of a more specialized device and the actions in the UAV. Figure 6: The 3D virtual environment. The teleoperation algorithm in Algorithm 1 is proposed in this framework based on the above interactions. At every instant \(dt\) in the virtual dynamic simulation, this algorithm handles the commands of the master device as follows:  
1. Elevation (lines 1-5 in Algorithm 1): Allows takeoff, landing, and keeping the quadrotor in the air. For this, the reference height \(z_{d}\) varies proportionally to the positional value of the left stick for the vertical axis \(u_{LSV}\in[-1,1]\) using the constant \(k_{z}\). This reference value is set to \(z_{d}=0\) when \(z_{d}<0\) to avoid trespassing the floor. Then, \(z_{d}\) is utilized to calculate the vertical thrust \(f_{B,z}\) by a Proportional Integral Derivative (PID) controller with the gravity compensation term \(m_{\beta}\), where \(k_{p,z}\), \(k_{i,z}\), and \(k_{d,z}\) are the proportional, integral, and derivative gains, respectively. 2. Yaw (lines 6-8 in Algorithm 1): Changes the direction the front of the quadrotor is pointing, to the left or to the right (it is assumed that the front of the quadrotor coincides with the positive direction of the axis \(x_{B}\)). In this case, the desired yaw angle \(\psi_{d}\) takes a value proportional to the positional value of the left stick for the horizontal axis \(u_{LSH}\in[-1,1]\) with the constant \(k_{\phi}\). A PID controller is also adopted to develop the torque \(\tau_{\phi}\) with \(k_{p,\phi}\), \(k_{i,\phi}\), and \(k_{d,\phi}\) as the proportional, integral, and derivative gains, respectively. 3. Pitch (lines 9-16 in Algorithm 1): Produces a forward and backward movement of the quadrotor in the direction the front of the quadrotor is pointing. Here, the desired pitch angle \(\theta\) is proportionally modified by the positional value of the right stick for the vertical axis \(u_{RSV}\in[-1,1]\) based on the constant \(k_{\theta}\). Additionally, the reference is set as \(\theta_{d}=0\) to stop the vehicle when \(u_{RSV}=0\). Moreover, the value of \(\theta_{d}\) is bounded in the interval \([-\pi/4,\pi/4]\) to avoid singularities. As in the above case, a PID controller is included to develop the torque \(\tau_{\theta}\), where \(k_{p,\theta}\), \(k_{i,\theta}\), and \(k_{d,\theta}\) are the proportional, integral, and derivative parameters, respectively. 4. Roll (lines 17-24 in Algorithm 1): Generates movement towards the sides of the quadrotor, i.e., in the direction of the axis \(y_{B}\).