## 4 The FO PI\({}^{\lambda}\)D\({}^{\mu}\) Controller of a Ship's Course
### Autotuning of the FO PI\({}^{\lambda}\)D\({}^{\mu}\) Controller Based on the IPSO Algorithm  
However, as the FO PI\({}^{\lambda}\)D\({}^{\mu}\) controller is designed for ship course control at a rated speed, if the ship speed changes dynamically, the non-linear model of the ship will also change accordingly, which will result in the original controller parameters no longer meeting the needs of the ship's course control and needing to be recalculated. Therefore, many novel optimization algorithms [40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54] are used to tune the parameters of the controller. This paper proposes an IPSO algorithm for dynamic adjustment of the FO PI\({}^{\lambda}\)D\({}^{\mu}\) controller parameters. The PSO algorithm was originally designed to optimize the unpredictable movement of simulated flocks of birds. It is an iterative random search algorithm that is easy to implement, is robust, has good parallel processing capabilities, and is likely to obtain a global optimal solution [55; 56]. However, in the later stages of optimization, the convergence time is long, the accuracy of the optimization is not high, and it easily falls into local extremes [57; 58; 59]. The mathematical description of the PSO algorithm [55; 56] is as follows. We set the population size to \(N\). At the iteration time, the position vector of each particle in the \(D\)-dimensional space is expressed as \(\overline{x}_{i}(t)=\big{(}x_{i}^{1},x_{i}^{2},\ldots,x_{i}^{d},\ldots,x_{i}^{ D}\big{)}\). The velocity of each particle in the \(D\)-dimensional space is \(\overline{v}_{i}(t)=\big{(}v_{i}^{1},v_{i}^{2},\ldots,v_{i}^{d},\ldots,v_{i}^{ D}\big{)}\). The optimal position for the particle \(i\) to search thus far is \(\overline{p_{i}}(t)=\big{(}p_{i}^{1},p_{i}^{2},\ldots,p_{i}^{d},\ldots,p_{i}^{ D}\big{)}\). The optimal position for all of the particles searched thus far is \(\overline{p_{g}}(t)=\big{(}p_{g}^{1},p_{g}^{2},\ldots,p_{g}^{d},\ldots,p_{g}^{ D}\big{)}\). The velocity \(\overline{v}_{i}(t)\) and the position \(\overline{x}_{i}(t)\) of particle \(i\) are adjusted at time \(t+1\) as follows:  
\[\overline{v}_{i}(t+1)\;=\;\omega\overline{v}_{i}(t)\;+\;c_{1}r_{1}(\overline{ p}_{i}(t)\;-\;\overline{x}_{i}(t))\;+c_{2}r_{2}\Big{(}\overline{p}_{g}(t)\;-\; \overline{x}_{i}(t)\Big{)} \tag{27}\]  
\[\overline{x}_{i}(t+1)\;=\;\overline{x}_{i}(t)\;+\;\overline{v}_{i}(t+1) \tag{28}\]  
\[\left\{ \begin{array}{l}v_{i}^{d}=v_{max},if\;v_{i}^{d}>v_{max}\\ v_{i}^{d}=-v_{max},if\;v_{i}^{d}<-v_{max}\end{array} \right. \tag{29}\]  
where \(i=[1,N]\), \(\omega\) is the inertia weight and non-negative, learning factors \(c_{1}\) and \(c_{2}\) are non-negative, and \(r_{1}\) and \(r_{2}\) are pseudo-random numbers that obey a uniform distribution on \([0,\;1]\). \(v_{i}^{d}\in[-v_{max},v_{max}]\), where \(v_{max}\) is a constant. If the search space is in \([-x_{max},x_{max}]\), one can set \(v_{max}=kv_{max}\), where \(0.1\leq k\leq 1.0\). From Equation (27), it can be seen that in the PSO algorithm, the particle seeking performance is related to the learning factors \(c_{1}\) and \(c_{2}\), which are used to regulate the maximum step size in the direction of motion of the particles \(\overline{p_{i}}(t)\) and \(\overline{p_{g}}(t)\) respectively. A small learning factor can make the particles oscillate in the region away from the target, while a large learning factor can make the particles move rapidly toward the target region or even move away from the target. The learning factors \(c_{1}\) and \(c_{2}\) reflect the exchange of information between particle swarms and determine the influence of a single particle and swarm experience on the particle trajectories.