# Particle Swarm Optimization of a Passivity-Based Controller for Dynamic Positioning of Ships
## 3 The IDA-PBC Controller Design  
In this section, we design a control law for DP system of the ship using the classical IDA-PBC and by incorporating a state-transformation which enables adding an integral action and damping controllers to achieve asymptotic stabilization. This method is resulted in a dynamic control law while preserving the PH structure. In the IDA-PBC method, the control law can be found by matching the open loop system (3) with the desired closed-loop model:  
\[\dot{\mathbf{x}} =[\mathcal{J}_{d}(\mathbf{x})-\Re_{d}(\mathbf{x})]\
abla H_{d} \tag{6}\] \[y =G^{\top}(\mathbf{x})\
abla H_{d},\]  
where \(\mathcal{J}_{d}(\mathbf{x})\) is the desired interconnection matrix, \(\Re_{d}(\mathbf{x})\) is the desired damping matrix and \(H_{d}\) is the desired Hamiltonian. The following proposition establishes procedures for the design of the controller:  
**Proposition 1**. : _Consider the PCH system (4). Define the coordinates transformation_  
\[\mathbf{x}=f(q,p)\Rightarrow\mathbf{z}=f(z_{1},z_{2},z_{3}),\]  
_with_  
\[\mathbf{z}_{1} =q, \tag{7}\] \[\mathbf{z}_{2} =\mathbf{p}-\mathbf{M}K_{l}\mathbf{z}_{3}+\mathbf{M}\mathbf{T}^{-1}(q_{3} )K_{q}\
abla_{\mathbf{z}_{1}}\Psi,\] \[\mathbf{z}_{3} =-\int\mathbf{T}^{\top}(q_{3})\
abla_{\mathbf{z}_{1}}H_{d}.\]  
_Define the desired Hamiltonian function_  
\[H_{d}=\Psi(\mathbf{z}_{1})+\frac{1}{2}\mathbf{z}_{2}^{\top}\mathbf{M}^{-1}\mathbf{z}_{2}+ \frac{1}{2}\mathbf{z}_{3}^{\top}K_{l}\mathbf{z}_{3}, \tag{8}\]  
_where \(\Psi(\mathbf{z}_{1})\) is desired potential energy function which has a minimum at \(\mathbf{z}_{1}=0\). Then the closed-loop PCH system is obtained as_  
\[ \begin{bmatrix}\dot{\mathbf{z}}_{1}\\ \dot{\mathbf{z}}_{2}\\ \dot{\mathbf{z}}_{3}\end{bmatrix} = \begin{bmatrix}-K_{q}&\mathbf{T}(q_{3})&\mathbf{ T}(q_{3})\\ -\mathbf{T}^{\top}(q_{3})&-K_{p}&0_{3\times 3}\\ -\mathbf{T}^{\top}(q_{3})&0_{3\times 3}&0_{3\times 3}\end{bmatrix} \begin{bmatrix}\
abla_{z_{1}}H_{d}\\ \
abla_{z_{2}}H_{d}\\ \
abla_{z_{3}}H_{d}.\end{bmatrix}  \tag{9}\]  
_and the dynamic control law_  
\[\mathbf{u} =\Big{[}-\mathbf{T}^{\top}(q_{3})-\mathbf{M}K_{l}\mathbf{T}^{ \top}(q_{3})-K_{p}\mathbf{T}^{-1}(q_{3})K_{q}+\mathbf{M}\mathbf{T}^{-1}(q_{3}) \frac{d}{dt}[\mathbf{T}(q_{3})]\mathbf{T}^{-1}(q_{3})K_{\mathbf{z}_{1}}\Big{]} \
abla_{\mathbf{z}_{1}}\Psi \tag{10}\] \[-(K_{p}-D)\mathbf{M}^{-1}\mathbf{p}+K_{p}K_{l}\mathbf{z}_{3}-\mathbf{M} \mathbf{T}^{-1}(q_{3})K_{q}\frac{d}{dt}[\
abla_{\mathbf{z}_{1}}\Psi]-\mathbf{T}^{ \top}(q_{3})\mathbf{b},\]  
_with the update law_  
\[\dot{\mathbf{z}}_{3}=-\mathbf{T}^{\top}(q_{3})\
abla_{\mathbf{z}_{1}}H_{d}, \tag{11}\]  
_(asymptotically) stabilized the ship at the desired equilibrium point \((\mathbf{z}_{1},\mathbf{z}_{2},\mathbf{z}_{3})=(0,0,0)\)._  
**Remark 1**. : _In the closed-loop model (9), \(K_{q}=diag\{k_{q_{1}},k_{q_{2}},k_{q_{3}}\}>0\) and \(K_{p}=diag\{r_{1},r_{2},r_{3}\}>0\) are the damping matrices injected in the configuration \(\mathbf{z}_{1}\) and momenta \(\mathbf{z}_{2}\) coordinates, respectively, which ensure asymptotic stability. \(K_{l}=diag\{k_{i_{1}},k_{i_{2}},k_{i_{3}}\}>0\) is a constant integral matrix which improves the robustness of the closed-loop system against external disturbances and steady-state errors._Proof of Proposition 1.: Considering the function (8) as a candidate Lyapunov function, the time derivative of this function along the trajectories of (9) is given by:  
\[ \begin{split}\dot{H}_{d}&=\
abla_{z_{1}}H_{d}^{\top} \dot{z}_{1}+\
abla_{z_{2}}H_{d}^{\top}\dot{z}_{2}+\
abla_{z_{3}}H_{d}^{\top} \dot{z}_{3}\\ &=\
abla_{z_{1}}H_{d}^{\top}(-K_{q}\
abla_{z_{1}}H_{d}+\mathbf{T }(q_{3})\
abla_{z_{2}}H_{d}+\mathbf{T}(q_{3})\
abla_{z_{3}}H_{d})\\ &\quad+\
abla_{z_{2}}H_{d}^{\top}(-\mathbf{T}^{\top}(q_{3}) \
abla_{z_{1}}H_{d}-K_{p}\
abla_{z_{2}}H_{d})+\
abla_{z_{3}}H_{d}^{\top}(- \mathbf{T}^{\top}(q_{3})\
abla_{z_{1}}H_{d})\\ &=-\
abla_{z_{1}}H_{d}^{\top}K_{q}\
abla_{z_{1}}H_{d}-\
abla_{z_ {2}}H_{d}^{\top}K_{p}\
abla_{z_{2}}H_{d}.\end{split}