# Particle Swarm Optimization of a Passivity-Based Controller for Dynamic Positioning of Ships
## 2 The Port-Hamiltonian Modeling of the Surface Ship
### The Mathematical Model  
The motion of the marine vessel whether in maneuvering or sea-keeping state is described in 6-DOF model as shown in Figure 1[24]. The first 3-DOF is to define translations and the other 3-DOF to define the orientation accounting for the 6 typical motion components of the marine vessels; longitudinal motion (surge), transverse (sideways) motion (sway), rotation around the vertical axis (yaw), rotation about the longitudinal axis (roll), rotation about the transverse axis (pitch), and vertical motion (heave). Typically, the position and orientation of a ship are expressed relative to two coordinate frames: the earth coordinate frame (inertial fixed frame) with origin \(\mathbf{O}\) and (X,Y,Z) coordinates, and the body coordinate frame, which is fixed to the ship and moves along with it, with \(\mathbf{b}\) origin and \((x,y,z)\) coordinates. In most DP system control applications, which are featured by low-frequency and low-speed motion, rolling and pitching actions induce negligible motions and thus roll, pitch and heave motions are ignored and the control problem is reduced to a 3-DOF vessel model having a coupled surge-sway-yaw components [24; 37]. An illustration of the ship model with a motion described in a horizontal plane is shown in Figure 2, with the 3-DOF (surge, sway, yaw) described in the two-coordinate frames. The nonlinear mathematical model for vessel dynamics in horizontal plane can be expressed as [38; 39]:  
\[ \begin{bmatrix}\ddot{\boldsymbol{\eta}}\\ \dot{\boldsymbol{v}}\end{bmatrix} = \begin{bmatrix}0_{3\times 3}&\mathbf{T}( \boldsymbol{\psi})\\ 0_{3\times 3}&-\mathbf{M}^{-1}D\end{bmatrix}\begin{bmatrix}\boldsymbol{\eta} \\ \boldsymbol{v}\end{bmatrix} + \begin{bmatrix}0_{3\times 3}\\ \mathbf{M}^{-1}\mathbf{T}^{\top}(\boldsymbol{\psi})\end{bmatrix} \mathbf{b}, \tag{1}\]  
where \(\boldsymbol{\eta}=[X,Y,\boldsymbol{\psi}]^{\top}\) is the configuration variables vector gives the position and heading angle (orientation) in the earth coordinate frame, the vector \(\boldsymbol{v}=[u,v,r]^{\top}\) represents the velocity vector expressed in the vessel's body coordinate frame. \(\boldsymbol{\tau}\in R^{3}\) is the control vector of the forces and moments produced by the ship's propulsion system and \(\boldsymbol{b}\in R^{3}\) is the disturbances vector. The transformation  
Figure 1: Ship motion in 6-DOF [24]. matrix \(\mathbf{T}\) represents the rotation matrix that gives the relative orientation of the inertial and body frames, the damping matrix \(D\) and the mass matrix \(\mathbf{M}\) are all given by:  
\[ \begin{split}\mathbf{T}=\begin{bmatrix}\cos(\psi)&-\sin(\psi)&0\\ \sin(\psi)&\cos(\psi)&0\\ 0&0&1\end{bmatrix},\qquad D=\begin{bmatrix}d_{11}&0&0\\ 0&d_{22}&d_{23}\\ 0&d_{23}&d_{33}\end{bmatrix}\\ \mathbf{M}=\mathbf{M}^{\top}=\begin{bmatrix}m_{11}&0&0\\ 0&m_{22}&m_{23}\\ 0&m_{23}&m_{33}\end{bmatrix},\end{split}  \tag{2}\]  
where \(0_{3\times 3}\) is the \(3\times 3\) zero matrix. The PH formalism for general nonlinear systems is given by [25]:  
\[ \begin{split}\dot{\mathbf{x}}&=(\mathcal{J}(\mathbf{x})-\Re(\mathbf{x})) \
abla H+G(\mathbf{x})\mathbf{\tau}\\ y&=G^{\top}(\mathbf{x})\
abla H,\end{split}  \tag{3}\]  
where \(\mathcal{J}(\mathbf{x})=-\mathcal{J}^{\top}(\mathbf{x})\) is the interconnection matrix, \(\Re(\mathbf{x})=\Re^{\top}(\mathbf{x})\geq 0\) is the damping matrix, \(H\) is the Hamiltonian (total energy ) of the system, \(G(\mathbf{x})\) is the input matrix and \(\
abla H\) is the gradient vector of the Hamiltonian. The ship model (1) can be described by pH form as [27]:  
\[ \begin{split}\dot{\mathbf{x}}=\begin{pmatrix}\begin{bmatrix}0_{3 \times 3}&\mathbf{T}(q_{3})\\ -\mathbf{T}^{\top}(q_{3})&0_{3\times 3}\end{bmatrix}-\begin{bmatrix}0_{3 \times 3}&0_{3\times 3}\\ 0_{3\times 3}&D\end{bmatrix}\end{pmatrix}\begin{bmatrix}\
abla_{\mathbf{q}}H\\ \
abla_{\mathbf{p}}H\end{bmatrix}\\ +\begin{bmatrix}0_{3\times 3}\\ I_{3}\end{bmatrix}\mathbf{\tau}+\begin{bmatrix}0_{3\times 3}\\ \mathbf{T}^{\top}(q_{3})\end{bmatrix}\mathbf{b}\end{split}