# Fuzzy Risk Evaluation and Collision Avoidance Control of Unmanned Surface Vessels
## 3 Design of Smart Collision Avoidance Control System for USVs
### Generation of Collision Advoidance Course
#### 3.3.3 Optimal Collision Free Trajectory  
Once the optimal collision avoidance waypoints are determined, a new desired trajectory with a collision avoidance property should be defined. In this investigation, the cubic spline interpolation method [15] was used to generate this desired collision avoidance trajectory. Cubic spline interpolation method is produced using multiple third-order polynomials, and each route is generated by two waypoints and two third-order polynomials, which are shown as follows:  
\[x_{d}(\varpi)=a_{4}\varpi^{3}+a_{3}\varpi^{2}+a_{2}\varpi+a_{1} \tag{15}\]  
\[y_{d}(\varpi)=d_{4}\varpi^{3}+d_{3}\varpi^{2}+d_{2}\varpi+d_{1} \tag{16}\]  
where (\(x_{d}  
\[U_{d}(t)=\sqrt{{x^{\prime}}_{d}(\varpi)^{2}+{y^{\prime}}_{d}(\varpi)^{2}}\;\dot{ \varpi}(t) \tag{22}\]  
The second order differential equations with respect to \(\varpi\) of Equations (15) and (16) are:  
\[{x^{\prime\prime}}_{d}(\varpi)=\frac{d^{2}x_{d}(\varpi)}{d\varpi^{2}}=6a_{4} \varpi+2a_{3} \tag{23}\]  
\[{y^{\prime\prime}}_{d}(\varpi)=\frac{d^{2}y_{d}(\varpi)}{d\varpi^{2}}=6d_{4} \varpi+2d_{3} \tag{24}\]  
There are three conditions that must be satisfied when using the cubic spline interpolation method to generate a 2D trajectory:  
Condition 1: the trajectory generated by waypoints (\(x_{k}\), \(y_{k}\)) and (\(x_{k+1}\), \(y_{k+1}\)) has to satisfy Equations (25) and (26). \[x_{d}(\varpi_{k})=x_{k}\;,\;x_{d}(\varpi_{k+1})=x_{k+1} \tag{25}\]  
\[y_{d}(\varpi_{k})=y_{k}\;,\;y_{d}(\varpi_{k+1})=y_{k+1} \tag{26}\]  
Condition 2: To make the trajectory more smoothly, it has to satisfy Equations (27) and (28). \[\left\{ \begin{array}{l}\lim_{\varpi\to\varpi_{k}^{-}}x_{d}(\varpi)=\lim_{ \varpi\to\varpi_{k}^{+}}x_{d}(\varpi)\\ \lim_{\varpi\to\varpi_{k}^{-}}x_{d}^{\prime}(\varpi)=\lim_{\varpi\to\varpi_{k} ^{+}}x_{d}^{\prime}(\varpi)\\ \lim_{\varpi\to\varpi_{k}^{-}}x_{d}^{\prime\prime}(\varpi)=\lim_{\varpi\to\varpi _{k}^{+}}x^{\prime\prime}(\varpi)\\ \end{array} \right. \tag{27}\]  
\[\left\{ \begin{array}{l}\lim_{\varpi\to\varpi_{k}^{-}}y_{d}(\varpi)=\lim_{ \varpi\to\varpi_{k}^{+}}y_{d}(\varpi)\\ \lim_{\varpi\to\varpi_{k}^{-}}y_{d}^{\prime}(\varpi)=\lim_{\varpi\to\varpi_{k }^{+}}y_{d}^{\prime}(\varpi)\\ \lim_{\varpi\to\varpi_{k}^{-}}y_{d}^{\prime\prime}(\varpi)=\lim_{\varpi\to\varpi _{k}^{+}}y_{d}^{\prime\prime}(\varpi)\\ \end{array} \right. \tag{28}\]  
Condition 3: To prevent the slope of the trajectory from changing drastically, the variable \(\varpi\) is generated as follows:  
\[ \begin{array}{l}\varpi_{1}=1\\ \varpi_{2}=\varpi_{1}+\sqrt{\left(x_{2}{-}x_{1}\right)^{2}+\left(y_{2}{-}y_{ 1}\right)^{2}}\\ \varpi_{3}=\varpi_{2}+\sqrt{\left(x_{3}{-}x_{2}\right)^{2}+\left(y_{3}{-}y_{ 2}\right)^{2}}\\ \vdots\\ \varpi_{k}=\varpi_{k-1}+\sqrt{\left(x_{k}{-}x_{k-1}\right)^{2}+\left(y_{k}{-} y_{k-1}\right)^{2}}\end{array}  \tag{29}\]  
where \(k=1,2,\ldots,n\). As shown in Figure 13, if \(n\) waypoints exist, \(4(n-1)\) coefficients as (30) and (31) must be identified. \[\mathbf{c}=\left[a_{1},a_{2},\ldots,a_{n-1}\right]^{T},\mathbf{a}_{j}=\left[ a_{4j},a_{3j},a_{2j},a_{1j}\right] \tag{30}\]  
\[\mathbf{s}=\left[\mathbf{d}_{1},\mathbf{d}_{2}\ldots,\mathbf{d}_{n-1}\right] ^{T},\mathbf{d}_{j}=\left[d_{4j},d_{3j},d_{2j},d_{1j}\right] \tag{31}\]  
where \(j=1,2,\ldots,n-1\). Rewriting the equation into a linear regression vector-matrix form, it is shown as (32) and (33). \[\mathbf{g}=\mathbf{A}(\varpi_{1},\varpi_{2},\dots,\varpi_{n})\mathbf{c} \tag{32}\]  
\[\mathbf{h}=\mathbf{A}(\varpi_{1},\varpi_{2},\dots,\varpi_{n})\mathbf{s} \tag{33}\]  
where \(\mathbf{g}\) and \(\mathbf{h}\) are:  
\[\mathbf{g}=\left[ \begin{array}{cccccccccccccccc}x_{S}&x_{1}&x_{2}&x_{2}&0&0& x_{3}&x_{3}&0&0&\dots&x_{n}&x_{E}\end{array} \right]^{T} \tag{34}\]  
\[\mathbf{h}=\left[ \begin{array}{cccccccccccccccc}y_{S}&y_{1}&y_{2}&y_{2}&0&0& y_{3}&y_{3}&0&0&\dots&y_{n}&y_{E}\end{array}