## 2 Materials and Methods
### Docking Algorithm  
The docking algorithm described in this paper is realized using several components. The general control structure is shown in Figure 8. Docking phases implement a state machine which represents the highest level of control within the algorithm. Its output \(s_{state}\) represents the current state the system is in. Guidance and control algorithms generate references for low-level speed controllers in active use by the aPad's on-board systems with \(u_{ref}\) being the surge reference and \(r_{ref}\) being the yaw reference, while Image processing takes the image \(img\) acquired from the aPad's camera and employs traditional computer vision methods to output the aMussel image position estimate \(e_{line}\) and neural network object detection to produce the image position estimate \(e_{nn}\), then fusing them using a filtering node featuring an Extended Kalman Filter, in order to provide visual feedback. The final outputs of the filter node are \(\hat{e}_{x}\) and \(\hat{e}_{y}\), representing the estimates of the horizontal and vertical image coordinate of the aMussel, respectively. Figure 8: Control structure for autonomous docking on aPad. Figure 7: aPad-mounted docking mechanism comparison, initial design (**left**) and final design (**right**). In [28], the authors detail the dynamic and kinematic models of the aPad over-actuated surface platform and several of its control structures. This subsection discusses the aspects strictly related to achieving autonomous docking capabilities within the swarm. Figure 9 shows the aPad docking algorithm represented as a state machine. While docking, the aPad goes through three active states. An **Idle** state is also present to account for the times when the aPad is holding its position as the docked aMussels charge and transmit data. * **Search:** The aPad rotates at a set rate until it registers a camera frame in which the top cap of an aMussel is visible. * **Approach:** The aPad moves towards the detected aMussel, regulating its yaw and surge speeds in tandem, turning to keep it centered in its camera field of view. Should the aMussel be lost from view for a preset number of frames during this phase, the aPad will recommence Search. * **Grasp:** The aPad closes the servo-actuated gripper on its docking mechanism once the reported position of the aMussel is below a set height threshold. Wireless charging is started. Before each docking attempt starts (launching into the **Search** state), the pan mechanism rotates the Kinect sensor to face the chosen dock by giving it one of four preset positions. To compensate for any drift or other mechanical offsets accrued during the aPad's operation, after the initial rotation towards the selected dock, the pan movement will be subject to additional small adjustments if the dock is not completely centered in the current camera image. This is accomplished by applying a simple feature-matching algorithm based on Fast Library for Approximate Nearest Neighbors (FLANN) with Scale Invariant Feature Transform (SIFT) descriptors to the image, making use of the dock's very recognizable and known fixed features (mechanism prongs, servo motor housing) as a template. During the Approach phase, the servo-powered docking mechanism arm will close once the estimated image height of the located aMussel top cap falls below a vertical threshold, indicating that the agent has come close to the camera as well as the docking mechanism slot that the camera is pointing towards. This height threshold is a preset value that is calibrated with regards to the camera tilt angle and the buoyancy and floating height of an aMussel that has completely surfaced, and was set to 25% of the full image height for the experiments described in this paper. The aPad will consider the correct agent docked once it notes a rising edge in the charging status of the aMussel that was the docking target.