## 3 The Proposed Cascade Control Scheme
### Hybrid Neuro-Fuzzy PID Controller  
The adaptive neuro-fuzzy inference system (ANFIS) combines the benefits of neural networks and fuzzy logic systems. The ANFIS was first designed by [PERSON] in 1995 [24; 25; 26]. A fuzzy logic system offers a structural framework for neural networks based on membership functions and fuzzy rules (if-then). A connection structure and learning capabilities are provided by neural networks to the fuzzy logic system [26]. To improve the system efficiency, the role of artificial neural networks is to train and optimize the fuzzy parameters in membership functions [26]. The structure of an ANFIS with two inputs and one output is depicted in Figure 4. The ANFIS consists of five layers, and each layer is composed of several nodes. To fuzzify the inputs, several computing nodes with activation functions based on fuzzy logic membership functions are used to make up Layer 1. The role of Layer 2 is to select the minimum value of the inputs. In Layer 3, the normalization of each input is carried out. Then, the outputs of Layer 3 are applied to the defuzzifiers in Layer 4. In the last layer, the output signals are generated by accumulating all of the fuzzifiers' outputs. In this study, the ANFIS was integrated with a conventional PID controller to design two hybrid neuro-fuzzy PID controllers (H-NFPID) for the first and the second control loops. The structures of H-NFPID1 and H-NFPID2 are shown in Figure 5. In Figure 5, the error tracking and its derivative obtained from the values of the drill bit and reference velocities are considered as the inputs of the H-NFPID1 controller:  
\[e_{1}=k_{e1}(\Omega^{*}-x_{7}) \tag{15}\]  
\[C_{e1}=k_{ce1}\frac{d(\Omega^{*}-x_{7})}{dt} \tag{16}\]  
Figure 3: The proposed cascade control scheme.  
where \(k_{e1}\) and \(k_{ce1}\) represent the normalizing coefficients for the inputs of H-NFPID1, while \(\Omega^{*}\) is the desired velocity.  
The output of H-NFFPID1 can written as follows:  
\[\Delta x_{1}^{*}=k_{p1}X+k_{i1}\int Xdt+k_{d1}\frac{de_{1}}{dt} \tag{17}\]  
where \(k_{p1}\) and \(k_{i1}\) are the denormalizing proportional coefficient and integral coefficient, respectively, \(k_{d1}\) is the derivative coefficient, and \(X\) is the output of ANFIS1.  
As shown in Figure 5b, the inputs of the H-NFPID2 controller are the error tracking and its derivative for the angular velocities of the rotary table velocity:  
\[e_{2}=k_{e2}(x_{1}^{*}-x_{1}) \tag{18}\]  
\[C_{e2}=k_{ce2}\frac{d(x_{1}^{*}-x_{1})}{dt} \tag{19}\]  
where \(k_{e2}\) and \(k_{ce2}\) represent the normalizing coefficients for the inputs of H-NFPID2, while \(x_{1}^{*}\) is the desired angular velocity for the rotary table. The output of H-NFFPID1 can written as follows:  
\[\Delta u=k_{p2}U+k_{i2}\int Udt+k_{d2}\frac{de_{2}}{dt} \tag{20}\]  
where \(k_{p1}\), \(k_{i1}\), \(k_{d1}\), and \(U\) are the denormalizing proportional coefficient, the denormalizing integral coefficient, the derivative coefficient, and the output of ANFIS2, respectively. The objective of the derivative term used in the proposed H-NFPID1 and H-NFPID2 controllers is to decrease the settling time and enhance the stability of the drill string. On the other hand, ANFIS1 and ANFIS2 were designed with minimum fuzzy rules for the first and second control loops, respectively, in order to decrease the computational burden. Here, three Gaussian functions were employed as input membership functions for the two ANFIS controllers, in addition to only nine fuzzy rules.  
Figure 4: The structure of the ANFIS.