# Novel Online Optimized Control for Underwater Pipe-Cleaning Robots
## 3 Fusion Bat Algorithm-Optimized Fuzzy Controller
### Bat Algorithm Optimization  
In order to ensure the fuzzy controller's good performance, scale factors of the inputs and the output must be properly determined. However, fixed scale factors are not suitable for different deviations, and therefore an online optimization method is required. Many algorithms can be used to optimize parameters, such as the simplex method, a genetic algorithm (GA), the simulated annealing method (SAM), particle swarm optimization (PSO), a bat algorithm (BA), etc. Considering that online optimization requires the high efficiency of the optimization algorithm, BA was selected to optimize the scale factors. A BA is a nature-inspired algorithm developed by [PERSON] in 2012, which was formulated based on the behavior of bats finding their prey [31]. In this algorithm, each \"bat\" represents one solution of the optimization problem, which is a set of the three scale factors (i.e., \(K_{pos}\), \(K_{ori}\), and \(K_{l}\)) in this paper. A certain number of bats are applied to constitute a swarm moving around the search space and searching for the best solution. In order to evaluate the quality of solutions, a fitness function is required. In this paper, integral time absolute error (ITAE) was used, and the fitness function based on \(e_{pos}\) and \(e_{ori}\) is formulated as follows:  
\[W=\omega_{1}\int_{0}^{5}\bigl{|}e_{pos}\bigl{|}dt+\omega_{2}\int_{0}^{5}|e_{ori }|tdt \tag{14}\]  
where \(\omega_{1}\) and \(\omega_{2}\) are weight coefficients. As biofouling can be stripped from the pipe only when the cleaning equipment arrives, it is better to eliminate the position error as a priority. Therefore, \(\omega_{1}\) and \(\omega_{2}\) are set as 0.7 and 0.3, respectively. A BA provides a quick convergence by switching between exploration and exploitation, but it may lead to stagnation or premature convergence if it switches to exploitation too early [32]. Even though BA parameters have been properly optimized according to published research [33], stagnation and premature convergence still occur in our application. As the velocity update rule in the BA mainly influences its convergence speed, the dynamic inertia weight is used to solve the stagnation problem. The velocity update rule is changed as follows:  
\[v_{i}^{t}=\omega_{i}^{t}v_{i}^{t-1}+\Bigl{(}x_{i}^{t}-x^{t}\Bigr{)}f_{i} \tag{15}\]  
where \(v,x,f\), and \(\omega\) denote velocity, location, velocity adjusting frequency, and the newly introduced dynamic inertia weight, respectively, while \(i\), \(t\), and \(t\)-\(1\) denote bat \(i\), time step \(t\), and its previous time \begin{table}
\begin{tabular}{c|c c c c c c} \hline \(\mathbf{a_{t}}\)\(\mathbf{e_{ori}}\) & **NB** & **NM** & **NS** & **ZO** & **PS** & **PM** & **PB** \\ \hline NB & ZO & NS & NM & NB & NB & NB \\ \hline NM & ZO & ZO & NS & NM & NM & NB \\ \hline NS & PS & ZO & ZO & NS & NM & NB \\ \hline ZO & PM & PS & PS & ZO & NS & NM \\ \hline PS & PB & PM & PM & PS & ZO & NS \\ \hline PM & PB & PB & PM & PM & PS & ZO \\ \hline PB & PB & PB & PB & PM & PS & ZO \\ \hline \end{tabular}
\end{table} 
Table 1: Fuzzy rules of the fuzzy controller for path tracking. step, respectively. \(x^{*}\) denotes the optimal location in the current iteration. Considering that most bats can find better locations during exploration, the dynamic inertia weight need not decrease a lot. When most bats cannot find better locations, exploitation starts and a small dynamic inertia weight can lead to fast convergence. Thus, a success rate of finding better locations is defined to automatically adjust the dynamic inertia weight, which is formulated in Equations (16)-(18):  
\[\omega_{i}^{t}=\omega_{\text{min}}+(\omega_{\text{max}}-\omega_{\text{min}})P _{s}^{t} \tag{16}\]  
\[P_{s}^{t}=\frac{\sum\limits_{i=1}^{N}S_{i}^{t}}{N} \tag{17}\]  
\[S_{i}^{t}=\left\{ \begin{array}{ll}1&if\left(W_{i}^{t}<W_{i}^{t-1}\right)\\ 0&else\end{array} \right.