# Real-Time Terrain-Following of an Autonomous Quadrotor by Multi-Sensor Fusion and Control
## 4 Simulation and Experiment Evaluations  
### Simulink Parameter Tuning by Attenuation Curve  
In order to obtain the optimal control effect, the parameters of the PID regulator need to be tuned. There are three common methods for PID parameter tuning in engineering: the Ziegler-Nichols tuning method, the critical proportionality method and the attenuation curve method. These three methods have their own characteristics: the Ziegler-Nichols tuning method is suitable for systems with a delay link in their open loop transfer function while the critical proportionality method requires the order of the system to be third-order or above and the attenuation curve method adjusts controller parameters by attenuation frequency characteristics [28]. If we suppose that the initial state of the quadrotor is \(\mathbf{x}=\left[ \begin{array}{cccccccccccc}0&0&0&0&0&0&0&0&0&0&1&0\end{array}  \right]^{T}\) and \(\Omega_{i}=\left[ \begin{array}{cccccccccccc}4100&4100&4100&4100&\end{array}  \right]^{T}\), this means that the drone hovers at a height of 10 m and the simulation duration is set to 15 s. After 2 s, a position control command is given to make the aircraft rise to a height of 20 m and remain hovering. The simulation results are shown in Figure 8.  
Figure 6: Structure of the cascade PID for the height and velocity control. Figure 7: Simulink structure of the cascade PID for the height and velocity control. The rising speed shown in the left picture (a) first increases and then decreases after 2 s and then oscillates and stabilizes at about 0 m/s. The right picture shows that the height overshoots after reaching 20 m and finally stabilizes at 20 m.  
According to the previously derived open loop transfer function Equation (31) of the height control system, the attenuation curve method is selected to tune the PID controller parameters and build the single-stage/cascade PID controller simulation block in Figure 8.  
After setting up the control system structure in Simulink, first set the regulator parameters in the control system to a pure proportional action (\(\overline{Ti}=\infty\), \(\tau=0\)) put the system into operation and then gradually adjust the proportionality \(\delta\) from large to small until the ratio of the amplitude of the two adjacent periodic curves is 4:1 attenuation. At this time, the ratio is 4:1, the attenuation ratio is \(\delta s\), the rise time is \(tr\) and the time interval between two adjacent peaks is \(T\)s. According to \(\delta s\), \(tr\) or \(T\)s, use the empirical formula in Table 2 to calculate each parameter value of the regulator [28]. The sequence of the PID controller parameter tuning is a proportional link first, then an integral link and then a derivative link. The parameters after tuning are:  
\[K_{p}=0.009267,T_{i}=12.5,\tau=2.7398. \tag{33}\]  
In addition to the former requirements, the cascade PID controller must follow the inner first and then the outer setting rule. The parameters after tuning are:  
Inner loop:  
\[K_{p1}=0.037975,T_{i1}=0.117,\tau_{1}=0.039. \tag{34}\]  
Outer loop:  
\[K_{p2}=3.8235,T_{i2}=5.1282,\tau_{2}=0.04875. \tag{35}\]  
Set the expected value of the height to 3 m and then input the tuned parameters into the simulation system. After the system has run, the response curves of the single-stage PID controller and the cascade PID controller are shown in Figure 9. \begin{table}
\begin{tabular}{c c c c} \hline \hline \multirow{2}{*}{**Controller**} & **Proportional Band** & **Integration Time** & **Derivative Time** \\  & \(\delta\) & \(\overline{Ti}\) & \(\overline{\tau}\) \\ \hline P & \(\delta_{s}\) & \(\infty\) & 0 \\ PI & \(1.2\ \delta_{s}\) & \(2t_{r}/0.5T_{s}\) & 0 \\ PID & \(0.8\ \delta_{s}\) & \(1.2t_{r}/0.3T_{s}\) & \(0.4t_{r}/0.1T_{s}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: PID regulator parameter tuning based on the attenuation curve method. Figure 8: Response curve of ascent velocity and height control.