## 4 Control Algorithm
### Leader-Follower Swarm-Control Algorithm
#### 4.1.2 Virtual Point Based on Waypoint  
The virtual point generated based on the waypoint was used to create a trajectory that the follower should follow. When the virtual point was generated based on the leader's target point, the distance errors for both the leader and follower USVs to reach the target point were similar. Therefore, if the controller weights of each USV were designed to be the same, the speed output for each USV to reach the target point would be similar, allowing for a linear formation.  
To effectively maintain a linear formation, a control algorithm that considers the rotational situation, as depicted in Figure 4, is necessary.  
In this study, to design a swarm controller that could effectively maintain the swarm formation considering rotational situations, the \"exact formation control\" method proposed in [20] was employed. Equation (23) represents the expression for exact formation control.  
\[v_{F}=v_{L}\frac{\cos(\beta_{LF}-\psi_{ref})}{\cos(\psi_{ref})}, \tag{23}\]  
where \(v_{F}\) and \(v_{L}\) represent the linear velocities of the follower and leader USVs, respectively, and \(\beta_{LF}\) denotes the difference between the heading angles of the leader and follower USVs. Additionally, \(\psi_{ref}\) represents the target heading angle of the leader USV. The relationship between the turning radius of each USV and the \((d,\ \psi)\) formation control can be described as in Figure 5.  
Figure 4: Rotational situation of leader–follower swarm control.  
Figure 5: Relationship between the turning radius and \((d,\ \psi)\) formation control.  
To maintain a linear formation, the follower must move along a circle with radius \(r_{F}\), and it should move faster than the leader along the circle. To achieve this, the relationship between the turning radii of the leader and follower is expressed as follows:  
\[r_{L}=(d_{ref})^{2}+(r_{F})^{2}-2d_{ref}r_{F}\cos{(\frac{\pi}{2}-\psi_{ref})}, \tag{24}\]  
where \(d_{ref}\) represents the straight-line distance between a point on the turning radius of the leader and a point on the turning radius of the follower. \(\psi_{ref}\) denotes the angle between \(d_{ref}\) and the turning radius of the follower. Rearranging (24) in terms of \(r_{F}\) and simplifying it using a quadratic formula gives (25):  
\[\begin{split} r_{F}=d_{ref}\sin{(\psi_{ref})}+\alpha\sqrt{{d_{ ref}}^{2}}(\sin{(\psi_{ref})})^{2}+{r_{L}}^{2}-{d_{ref}}^{2},\\ \alpha=1\text{ if }r_{L}\;\geq\;r_{F}\\ \alpha=-1\text{ if }r_{L}\;\leq\;r_{F}\end{split} \tag{25}\]  
The sign in front of the square root leads to both negative and positive values of the turning radius of the follower. A negative value indicates a linear formation where the leader's turning radius is smaller than that of the follower, implying that the follower is positioned on the right-hand side of the leader. In contrast, a positive value indicates a linear formation in which the leader's turning radius is greater than that of the follower, placing the follower to the left-hand side of the leader.  
Finally, the turning radii of the leader and follower USVs are given by \(r_{L}=\frac{v_{L}}{\omega_{L}}\) and \(r_{F}=\frac{v_{F}}{\omega_{F}}\), respectively. To maintain linear formation, \(\omega_{L}\) must be equal to \(\omega_{F}\). Therefore, the speed control input for the follower can be expressed as indicated in (26).  
\[r_{F}=v_{L}+(r_{F}-r_{L})\omega_{L}, \tag{26}\]  
Thus, utilizing the speed control input derived from (26) in the error term of the follower's swarm controller allows for sustained \((d,\,\psi)\) formation control between the leader and the follower even as they turn. Detailed definitions of the control algorithm that considers rotational scenarios can be found in related studies [21,22].