# Control for Ship Course-Keeping Using Optimized Support Vector Machines
## 4 Example Study  
To confirm the validity of the controller designed, a numerical simulation is performed combined with a surface ship. Firstly, the state space equation form of (5) can be obtained as  
\[\dot{\mathbf{X}}=g(\mathbf{X})+h(\mathbf{X})\delta_{c} \tag{45}\]  
where \(\mathbf{X}=[\psi\quad\dot{\psi}\quad\delta]^{\mathrm{T}}\), \(g(\mathbf{X})=[g_{1}\quad g_{2}\quad g_{3}]^{\mathrm{T}}\), \(h(\mathbf{X})=[0\quad 0\quad 1/T_{E}]^{\mathrm{T}}\)  
\[g_{1}=\dot{\psi},g_{2}=-\dot{\psi}-\alpha\dot{\psi}^{3}-\Delta(\psi,\dot{\psi} )-w+K\delta,g_{3}=-\delta/T_{E}\]  
The model parameters are [41]  
\[T=10.31\,(\mathrm{s}),\ \alpha=81.75\,(\mathrm{s}/\mathrm{rad}^{2})\] \[K=-0.95\,(1/\mathrm{s}),\ T_{E}=0.72\,(\mathrm{s})\]  
From the point of view of ship manoeuvrability, this ship is unstable because \(K\) is negative. Therefore, an appropriate robust controller is required for the purpose of course-keeping. The controller gains in (31) are selected as \(\lambda_{1}=\lambda_{2}=2\). The constant in (14) is selected as \(\lambda=0.1\). For the SVM identification, a Gaussian kernel is adopted as  
\[K(\mathbf{x}_{i(j)},\mathbf{x})=\exp\left(\frac{-||\mathbf{x}_{i(j)}-\mathbf{x}||^{2}}{2\sigma^{2 }}\right) \tag{46}\]  
where \(\sigma\) is the kernel width that has an impressive effect on SVM learning ability. The input variable is defined as  
\[\mathbf{x}=\mathbf{x}(t)=\left[ \begin{array}{cc}e(t),&\dot{e}\ \ (t)\end{array}  \right]^{T} \tag{47}\]  
For the support vectors \(\mathbf{x_{i}}\) and \(\mathbf{x_{j}}\), both of them are selected as two successive former input variables which means that \(l_{1}=l_{2}=2\) for identifiers in (30). Denote \(\mathbf{x}(t)=\mathbf{x}(k)\), the support vectors can be expressed as  
\[\mathbf{x}_{1}=\left[ \begin{array}{cc}e(k-1),&\dot{e}\ (k-1)\end{array}  \right]^{\mathrm{T}} \tag{48}\] \[\mathbf{x}_{2}=\left[ \begin{array}{cc}e(k-2),&\dot{e}\ (k-2)\end{array}  \right]^{\mathrm{T}}\]  
where \(k\) is the sampling time. To obtain a optimized SVM, PSO is incorporated to obtain the optimal \(\sigma\) in (46). Moreover, the parameters \(\varepsilon_{1}\) and \(\varepsilon_{2}\) in the tuning algorithms of Lagrangian factors given by (33) are also determined by PSO. The fitness in PSO algorithm adopts the root of mean square error (RSME) as  
\[\mathrm{RMSE}=\sqrt{\frac{1}{n}{\sum_{i=1}^{n}{(\dot{\psi}_{di}-\dot{\psi}_{i}) }^{2}}} \tag{49}\]  
The number of particles in PSO is set to 20, as is the number of iteration. The initial particle's positions and velocities are assumed randomly distributed within a given range. Figure 2 presents the results of RMSE, \(\sigma\), \(\varepsilon_{1}\) and \(\varepsilon_{2}\). As can be seen from the results, the fitness and the parameters converge to stable values, obtained as \(\mathrm{RSME}=0.0117,\sigma=0.4356\), \(\varepsilon_{1}=\varepsilon_{2}=0.1\). The three parameters, i.e., \(\sigma\), \(\varepsilon_{1}\) and \(\varepsilon_{2}\), are used in the SVM based controller. Figure 2: Parameter optimization by PSO. In the study, the control objective is to track a desired heading angle. Without loss of generality, the desired heading angle \(\psi_{d}\) is assumed as a harmonic signal. To verify the stability and robustness of the controller designed, deviation of the heading angle is assumed at the start, which indicates that \(\psi(t=0)\
eq\psi_{d}(t=0)\). For uncertainties, the modeling error is assumed \(\Delta(\psi,\dot{\psi})=\zeta\) and the external disturbance is assumed as an instantaneous impulse with the amplitude of \(1.5\) (\(\circ\)/s) at the time \(50\leq t\leq 51\)s. Figure 3 presents the tracking results, including the histories of heading angle \(\psi\), yaw rate \(r\), demand rudder angle \(\delta_{C}\), actual rudder angle \(\delta\), and Lagrangian factors (\(\alpha^{\prime},\beta^{\prime}\)) as well. From the simulation results, it can be seen that both stability and robustness of the tracking system are achieved. The tracking accuracy is satisfactory as well.