## 6 The Controller Design
### The Outer-Loop Design  
The inputs of the outer loops are the current position of the vehicle and the desired trajectory, which is typically decoupled in longitudinal and lateral characteristics. The outer loop uses the position information to calculate the desired angular rate and translate them to the inner loop for stability control. At stage I, the longitudinal and lateral navigation mechanisms are activated for path tracking. The lateral controller uses the cross-track error, \(\Delta y\), and path azimuth angle, \(\psi_{d}\), as the control inputs to calculate the azimuth angle command, \(\dot{\psi}_{c}\). First, the desired lateral speed is calculated by a simple proportional relation. \[\dot{y}_{d}=k_{py}\Delta y \tag{16}\]  
Here, \(k_{py}\) is the proportional gain. Equation (16) aims to let the cross-track error converge with a time level of \(1/k_{Py}\). The desired azimuth angle, \(\Delta\psi_{c}\), can be calculated by the desired lateral speed:  
\[\Delta\psi_{c}=\sin^{-1}(\dot{y}_{d}/V_{g}) \tag{17}\]  
where the \(V_{xg}\) is the ground speed of the aircraft. Since \(\Delta\psi_{c}\) is usually a small number, approximately, \(\Delta\psi_{c}=\dot{y}_{d}/V_{xg}\). The range of \(\Delta\psi_{c}\) is limited to \([-\pi/2,\pi/2]\). Then, the azimuth angle command is obtained by \(\Delta\psi_{c}\) and \(\psi_{d}\) as:  
\[\psi_{c}=\psi_{d}+\Delta\psi_{c}\approx\psi_{d}+\dot{y}_{d}/V_{xg} \tag{18}\]  
Using the direction conversion matrix, the angular speed in the ground frame is converted to the body frame:  
\[\left\{ \begin{array}{l}\dot{\phi}=p+\tan\theta(q\sin\phi+r\cos\phi)\\ \dot{\theta}=q\cos\phi-r\sin\phi\\ \dot{\psi}=(q\sin\phi+r\cos\phi)/\cos\theta\end{array} \right. \tag{19}\]  
According to Equation (19), the yaw angular rate command is given as:  
\[r_{c}=\frac{\dot{\psi}_{c}\cos\theta-q\sin\phi}{\cos\phi} \tag{20}\]  
The longitudinal controller uses the desired altitude, \(h_{d}\), the desired descending or climbing rate, \(\dot{h}_{d}\), and the real altitude, \(h\), as the inputs to calculate the descending rate command:  
\[\dot{h}_{c}=k_{Ph}(h_{d}-h)+\dot{h}_{d} \tag{21}\]  
where \(k_{ph}\) is the proportional gain. Then, the descending rate command is converted to the gliding angle command:  
\[\gamma_{c}=\tan^{-1}\theta\left(\dot{h}_{c}/V_{g}\right) \tag{22}\]  
With the proportional-integral control, the pitch angle command is given as:  
\[\theta_{c}=k_{P\gamma}(\gamma_{c}-\gamma)+k_{I\gamma}\int(\gamma_{c}-\gamma)dt \tag{23}\]  
where \(k_{P\gamma}\) is the proportional gain and \(k_{I\gamma}\) is the integral gain. Then, \(\theta\) can be controlled by a proportional controller:  
\[\dot{\theta}_{c}=k_{p\theta}(\theta_{c}-\theta) \tag{24}\]  
where \(k_{p\theta}\) is the proportional gain and \(\dot{\theta}_{c}\) is the pitch angular rate command. According to Equation (19), the pitch angular rate can be expressed as:  
\[q_{c}=\frac{\dot{\theta}_{c}}{\cos\phi}+r\tan\phi \tag{25}\]  
In the roll channel, the roll angle is controlled by a proportional controller:  
\[\dot{\phi}_{c}=k_{P\phi}(\phi_{c}-\phi) \tag{26}\]  
where \(k_{P\phi}\) is the proportional gain. According to Equation (19), the roll angular rate can be expressed as:  
\[p_{c}=\dot{\phi}_{c}-\tan\theta(q\sin\phi+r\cos\phi) \tag{27}\]  
In the speed channel, the desired ground velocity, \(V_{gd}\), is controlled by a proportional and integral controller. The input is the real ground velocity of the aircraft, \(V_{g}\), and the output is the throttle command, \(\delta_{TN}\). \[\delta_{TN}=k_{P\psi}\Big{(}V_{gd}-V_{g}\Big{)}+k_{I\psi}\int\Big{(}V_{gd}-V_{ g}\Big{)}dt \tag{28}\]  
where \(k_{P\psi}\) is the proportional gain and \(k_{I\psi}\) is the integral gain. Besides, the deflection angle of the thrust vector is negatively correlated with the ground speed. All the aforementioned commands construct the inner-loop inputs for stage I, written as \(U=[p_{c},q_{c},r_{c},\delta_{TN},\delta_{N}]\).