Fish-inspired robotic algorithm: mimicking behaviour and communication of schooling fish

This study aims to present a novel flocking algorithm for robotic fish that will aid the study of fish in their natural environment. The algorithm, fish-inspired robotic algorithm (FIRA), amalgamates the standard flocking behaviors of attraction, alignment, and repulsion, together with predator avoidance, foraging, general obstacle avoidance, and wandering. The novelty of the FIRA algorithm is the combination of predictive elements to counteract processing delays from sensors and the addition of memory. Furthermore, FIRA is specifically designed to work with an indirect communication method that leads to superior performance in collision avoidance, exploration, foraging, and the emergence of realistic behaviors. By leveraging a high-latency, non-guaranteed communication methodology inspired by stigmergy methods inherent in nature, FIRA successfully addresses some of the obstacles associated with underwater communication. This breakthrough enables the realization of inexpensive, multi-agent swarms while concurrently harnessing the advantages of tetherless communication. FIRA provides a computational light control algorithm for further research with low-cost, low-computing agents. Eventually, FIRA will be used to assimilate robots into a school of biological fish, to study or influence the school. This study endeavors to demonstrate the effectiveness of FIRA by simulating it using a digital twin of a bio-inspired robotic fish. The simulation incorporates the robot’s motion and sensors in a realistic, real-time environment with the algorithm used to direct the movements of individual agents. The performance of FIRA was tested against other collective flocking algorithms to determine its effectiveness. From the experiments, it was determined that FIRA outperformed the other algorithms in both collision avoidance and exploration. These experiments establish FIRA as a viable flocking algorithm to mimic fish behavior in robotics.


Introduction
In nature, it is common to see social behaviors emerge, often stemming from the need to survive, improve efficiency when moving, or a group collectively working towards a common goal.These social behaviors are structured in numerous ways, from a wolf pack that has a clear leader hierarchy [1] to an ant or bee colony that has set rules [2,3] or a school of fish with no clear leader [4].Whilst these behaviors stem from biological needs, researchers have capitalized on these principles to develop algorithms capable of addressing optimization problems and effectively controlling large groups of robots, giving rise to swarm intelligence and swarm robotics.Most algorithms focus on their ability to solve complex optimization problems.However, as swarm robotics has become more popular, optimization algorithms have been modified or additional algorithms created to control a swarm of real or virtual robots [5].The main research areas focus on spatial organization, navigation, and decision-making [5,6].
A sub-section of spatial organization is collective motion, which focuses on a set of robots aggregating or moving together.One popular spatial organization algorithm, Boids, was created to mimic the flocking behaviors of birds and fish for computer simulations [7].Since its creation, the Boids algorithm has expanded, and modified algorithms have also arisen [8], improving its performance and controlling robotic fish swimming with biological fish in a controlled environment [8,9].Other algorithms, including PSO [10], artificial fish swarm algorithm (AFSA) [11], and a slew of other algorithms, have been designed to create flocking motions [12,13].For this paper, the focus is on algorithms designed to mimic the behaviors of fish, which also include behaviors of foraging and predator avoidance.
Among these behaviors is one common aspect: to form social behaviors, all agents must have some form of communication.Communication can be in either one of two forms: direct or indirect communication [14].Direct communication can be thought of as two people having a face-to-face conversation or via technology, such as a voice or video call.Indirect communication can be thought of as people leaving a note for one another or interpreting the meaning of another person's actions [6].In animals, indirect communication is referred to as stigmergy [15].
In the animal kingdom, direct and indirect communication is present and often mixed, from wolves, which communicate directly via howling [16].Bees use a waggle dance to communicate where a food source is [3].In contrast, indirect communication between birds or fish uses the position and direction of their neighbors [17], while ants drop pheromones to indicate paths toward food sources [18].While animals in nature rely on their senses and can often infer meaning from their surroundings [19], swarm robotics primarily relies on direct communication among robots.This approach often requires large amounts of data to be communicated across the entire swarm, and even with today's high-speed communication methods, this can quickly lead to bottlenecks in real time settings [20].
Underwater environments pose a significant challenge to swarm robotics, particularly in response to communication delays and bandwidth.Conventional communication methods such as Wi-Fi, Bluetooth, and RADAR prove ineffective underwater due to having a very short range in the underwater mediam.This necessitates slower techniques such as SONAR and ultrasonic [6] to be used.These methods come with inherent challenges, as they often require bulky equipment to function or more significant areas to operate at high speeds [21].Bio-inspired electrocommunication presents a potential alternative, but, like ultrasonic, it suffers from slow communication rates and high levels of noise in swarm environments [22][23][24].In contrast, optical communication methods offer faster speeds and have recently experienced notable advances.Nevertheless, they require a direct line of sight and often use high-powered lasers to achieve high speeds and longer distances [25].Furthermore, using optical or ultrasonic communication methods in marine environments can disrupt or harm aquatic life [6,26].
This paper presents a new swarm algorithm that emulates the collective behavior of schooling fish while also addressing the challenges of applying current flocking algorithms to individual robotic agents in environments with low data rate communication.The fish inspired robotic algorithm (FIRA) algorithm is designed to work effectively even when communication is not guaranteed, ensuring reliable system performance.While some of the difficulties encountered underwater, such as limited communication, sensor noise, and localizing, were also considered in the design of the algorithm.This algorithm aims to enhance the realism of the behaviors used by robotic fish and enable them to blend seamlessly within a school of biological fish.As a result, they can observe and study the natural behavior of fish without disrupting it or directing schools towards or away from specific areas of interest.
The remainder of this article is as follows.Section 2 thoroughly examines the background information on schooling fish and flocking algorithms.Section 3 introduces and describes the FIRA.The simulation environment is explained in section 4. The simulated experiment is detailed in section 5, with the results presented in section 6.Finally, sections 7 and 8 cover the discussion and future research areas.

Background
Flocking-based swarm algorithms have been around since the late 1980 s with the creation of the Boids algorithm [7].From there, additional algorithms have been derived from the behaviors of the flocking algorithm.This section specifically focuses on the behaviors of schooling fish and the algorithms they have inspired.

Fish behaviors
The behaviors of teleost fish are shaped by a range of external factors, including predator attacks, foraging and mating needs, hydrodynamic efficiency, and environmental variables such as water temperature, currents, light intensity, and turbidity [27,28], with these factors and behaviors being extensively studied and modeled.In 1986, T. J Pitcher presented a relationship model shown in figure 1 for fish behaviors, comprising three primary behaviors: shoaling, schooling, and a range of predator avoidance tactics [29].The model also included the foraging and mating behaviors of fish.
Shoaling is when a group of fish can consist of one or multiple species of fish and is distinguishable from schooling by the lack of polarity in the group.A shoaling group remains together for social reasons and not just because of an external stimulus [29].However, shoals are often formed in more constricted environments, such as rivers and reefs [29].In contrast, a school is highly polarized, with a uniform distance between members [30], and is often formed due to the threat of a predator, migration, or protection in an open water environment [29].Within a school, individual fish strive to position themselves as far away from the edge of the school as possible, enhancing their survivability.Schooling fish use both their vision and lateral lines to measure the velocities of their neighbors and will adjust their own accordingly [31].It has been demonstrated that the school's polarity enables information to be transmitted in the presence of a predator [32].The efficient transmission of information throughout the school via collective behavior may also explain the observed phenomenon that fish with all their sensory organs intact have yet to collide with each other during predator attacks [33].Researchers have also observed that fish can use pheromones [34] and sounds [35] to distribute information throughout the school.In the case of mackerel, it has been observed that schooling marks play a crucial role in inferring meaning from the velocity of neighboring fish [34].While an important topic, the communication methods between fish is not well studied.
Significantly, schooling fish do not operate under the guidance of a single leader, as each fish possesses the capacity to exert varying degrees of influence on the collective heading of the school [33].Consequently, the school assumes the leader role, while each fish is a follower within this dynamic system [30].During certain behaviors, individual fish may lead the school; for example, when a fish is in front of the school [36].Alternatively, in the case of an attack, those closest to the predator will act first, causing the rest of the school to act accordingly [37].
Researchers that have studied fish behaviors typically use a particle model to study the interactions between individuals and the effect they can have on the collective.Initially, a large portion of the research has focused on the schooling behaviors of fish.This research observed that three distinct behaviors of attraction, alignment, and repulsion could be used to model and mimic both shoaling and schooling behaviors of fish.By using the particle models, other collective behaviors such as milling, bait balling, and vertical towers have arisen under the right conditions and weightings used in the models.In contrast, other researchers have devised specific models to replicate these behaviors [38].
Aside from schooling behaviors, researchers have also focused on the anti-predator behaviors that schooling fish can use.Pitcher et al and Magurran et al identified a combined total of 12 behaviors.These include a herd, flash, ball, avoid, vacuole, split, hourglass, join, cruise, skitter, compact, and fountain.When modeling these behaviors, researchers have shown that a complex model can be needed to allow all of the collective behaviors to emerge [39,40].In contrast, Deng and Liu demonstrated that many behaviors can arise depending on the predator's behavior [41].For anti-predator behavior, it has also been observed that the existence and use of an escape wave within the school can be beneficial from both marine and avian attacks [42,43].
Aside from using particle models and observation studies, robotic fish embedded within a school of fish are being used to observe and influence the behaviors of fish [44,45].Researchers have demonstrated that the appearance and locomotion of a robot play crucial roles in its successful assimilation within a school of biological fish [46,47].
Most models utilize similar cohesion, alignment, and repulsion behaviors, where all behaviors are always active.Subsequently, the Couzin model splits each behavior into different zones based on the distance between the agents, unlike Boids, which have all behaviors acting congruently [48].
Later in 1999, Craig Reynolds extended the Boids algorithm to include steering behaviors.These behaviors included; seeking, fleeing, pursuit, evading, and wandering, as well as other behaviors outside the scope of mimicking fish [58].
Since 1999, the Boids algorithm has been implemented and modified in numerous ways, including modifying the extended behaviors to more accurately mimic schooling fish [50] to improve behavior for UAVs [58].Furthermore, efforts have been made to refine the escaping behaviors within swarm robotics [59].It should also be noted that while current models can respond to a predator, they cannot produce the same dynamic response of schooling fish due to the information being 'diluted' as it moves through the school [60].The Couzin model was also used in a study to control a bio-inspired robotic guppy that swam with a school of biological guppies [8,9].Another group of researchers combined birds, wolves, and fish behaviors to create a swarm that could school, circle an object, and produce the torus formation found in fish [61].For both research groups, an overhead camera was placed above the pool to provide accurate positioning and headings of all agents and fish within the area.While Boids and the Couzin model have been around for many years, they continue to be the primary algorithms utilized for controlling robots intended for swimming alongside biological fish [8,9,62].Nevertheless, conventional particle-based models face challenges in effectively being utilized by robots with limited perception and delays associated with sensor data [63].
Aside from Boids, another popular flocking algorithm is the Vicsek model.Proposed in 1995 by physicist Tamas Vicsek, the Vicsek model is a simple model used to study the emergence of selfordering motion in systems [64].Since its conception, the Vicsek model has been modified in numerous ways.However, it should be noted that unlike the Boids algorithm, which was extended to include evading and pursuing, the research on the Vicsek model focuses on unbounded flocking behaviors and does not include obstacle and predator avoidance or the foraging behaviors [13,52,65].However, an exception to this was by Mohapatra and Mahapatra who delivered a bounded predator-prey model [53], which also creates a hybrid between the Vicsek model and the Boids algorithm.Therefore, this method was not considered a fair comparison to algorithms based on the motion of schooling fish.
Researchers at Harvard University also used a similar algorithm that used the behaviors of Boids to control their Blueswarm platform.The algorithm was modeled after the Lennard-Jones potential model and only had the attraction and repulsive forces to create the schooling behaviors [38].The flocking behaviors of fireflies were also incorporated via flashing LEDs on the robots.As well as additional behaviors for milling, the Harvard researchers also studied selforganized predator evasion [66].
Another algorithm inspired by and has many fish behaviors is the AFSA.Developed initially as an optimization algorithm, AFSA encompasses many of the desired behaviors sought after in this study's context [67].It should be noted that most work on the AFSA algorithm focuses on its ability to optimize and for path planning within robotics [68].However, researchers have modified AFSA to work on robotic fish in a simulated physical environment [69].
The algorithm uses artificial fish (AF) to represent the agents within the school.Each AF is a solution within the search space and can retain their data about themselves and data concerning the other members around them.Unlike other swarm algorithms, AFSA agents mostly communicate directly with their local neighbors within their field of vision.While the algorithm still uses some global communication, only communicating with their local neighbors reduces the overall communication needed in the swarm [70].
The AFSA algorithm comprises foraging, swarming, following, and random behaviors.Unlike the traditional flocking algorithms, AFSA is not concerned with alignment or repulsion behaviors.While predominantly used as an optimization algorithm, as it mimics fish behaviors, it has been improved to be used in robotics as simulated by research conducted by Gao and Wen [69].This iteration of AFSA involves several modifications, such as the addition of avoidance behavior, general formation, and the modification of the foraging behavior.

FIRA
In swarm robotics, most algorithms are developed for robots operating above the water; this, along with the many challenges of underwater robotics, has led to limited algorithms designed to mimic behaviors found underwater or to account for the problems that arise.To this end, this paper proposes a new robotic algorithm called FIRA.FIRA is a behavior-based algorithm that aims to mimic the schooling, predator avoidance, and foraging behaviors of real-life schooling fish.It provides high-level control to individual agents in a swarm, enabling them to execute the desired behaviors and perform tasks such as foraging and avoiding predators.
The purpose of developing the FIRA algorithm is specifically to be used to control bio-inspired robotic fish that can mimic and to be able to assimilate within a school of fish without disrupting their behavior.
With this objective in mind, the algorithm has selectively incorporated a set of crucial behaviors to emulate, chosen based on their ability to encompass a wide range of behaviors without rendering the algorithm overly complex or specific to particular situations.The chosen behaviors include schooling, shoaling, foraging, and predator avoidance.With the specific schooling sub-behaviors of milling, bait balling, and vertical towers and the sub-behaviors of predator avoidance, herd, flash, ball, avoid, vacuole, split, hourglass, join, cruise, skitter, compact, and fountain, not being individual modeled.
The following aspects of the algorithm will be discussed and explained in this section: wandering, schooling, including attraction, alignment, and repulsion behaviors, predator and obstacle avoidance, foraging, the combined FIRA algorithm, the Fish Memory, and the indirect communication method used.

Wander
The wandering behavior is used by FIRA to primarily allow an agent to explore an area when no other state is active.It utilizes a random function to determine the next position within a minimum and maximum range around an agent where W is the wander weighting coefficient, and the X, Y, and Z are random positions between the minimum and maximum range.
The wander behavior's main aim is to act as the default state for an agent when no other behavior is in effect.However, it is still active when other FIRA behaviors, such as schooling, are activated to increase exploration further.

Schooling behavior
The schooling behavior comprises three individual behaviors, which, when combined, allow the agents to mimic the schooling behaviors of fish.These behaviors are attraction, alignment, and repulsion.The three schooling behaviors have been modified from traditional flocking algorithms to account for some of the limitations of current robotics.

Attraction
The attraction behavior incorporates a force that steers an agent toward the center of the most densely populated cluster of agents within its visual range.However, if there is an equal number of agents on both sides, all available agents will be utilized.The attraction behavior is denoted by: where n is the number of agents, AttW is the attraction weighting coefficient, Pos j is the position of the other agents, Pt is the prediction time, v j is the velocity of the other agents and Fd j is the distance from the agent to the jth agent.
The Attraction behavior in the FIRA algorithm differs from previous algorithms, using an exponential function to increase the attraction force based on the distance to each agent.As opposed to using an equal attraction force that would place the summation force in the center, the exponential power keeps the agent moving across the school, allowing more constant movement and exploration.As well as reducing the number of collisions and allowing the alignment and repulsion behaviors to have more influence at closer distances.
Depending on the number of agents that can be seen by both the left and the right sensor, the agent will only use the information from the left or right side, dependent on which one has the highest number of agents.If both sensors detect an equal number of agents, information from both sensors will be used, as the agent perceives itself as in the 'middle' of the school.This decision was made to replicate the survival instinct observed in fish, which tend to congregate at the center of the school.Given the constraints of limited perception and communication abilities, a single agent may not be able to perceive the entire swarm and determine its true center, thus relying on the sensor data to approximate the center of the school.

Alignment
The Alignment behavior adds the velocity vectors of other agents that are detected to improve the alignment of the agent relative to the school.The Alignment behavior is denoted by: where the AliW is the alignment weighting coefficient and v j is the velocity vector of the other agents.
The alignment behavior will only sum a select number of agents based on which side has the highest total of agents.If they are even, it will use both sides as it will deem itself in the 'middle' of the school.

Repulsion
The repulsion behavior pushes the agent away from other schooling agents if they get too close.For this behavior, the agent exclusively focuses on the closest agent in its proximity at any given time.The repulsion behavior is denoted by: where RepW is the repulsion weighting coefficient, P is the position of the closest agent, Pt is the prediction time, v is the agent's velocity, ReplD is the repulsion force coefficient, and Fd is the distance from the agent to the closest agent.By using the multiplicative inverse of the distance between the two agents, the repulsion force drastically increases as the agent gets closer, thus, improving collision avoidance compared to traditional behaviorbased algorithms.

Schooling
The schooling behavior is the summation of each of the previously discussed behaviors.The schooling behavior is denoted by: where SchW is the schooling weighting, Attraction is the attraction force, Alignment is the alignment force, and Repulsion is the repulsion force.
The schooling behavior can be modified to produce different outputs dependent on the weighting coefficient chosen within each of the three behaviors.

Predator avoidance
Predator avoidance behavior steers the agent away from dangers within the environment.To accomplish this, it first predicts the future position of the predator.Then dependent on the position of the predator relative to the agent, it will produce an escaping vector that is ±90 • of its current heading if the predator is within ±45 • of its forward velocity.The future position of a predator is calculated by: where RP is the position of the predator rotated around the agents ±90 • , P is the original position of the predator, v is the position of the predator, and v is the predator's velocity.The future position of the predator is then used to determine the predator avoidance force, which is denoted by: FPP j * PreD Pd j (7) where n is the number of predators that an agent has seen, PreW is the predator avoidance weighting coefficient, FPP j is the future position of the predator, PreD is the coefficient used to increase the repulsion forces as the predator gets closer and Pd j is the distance between the agent and the predator.
To mimic the quick and evasive motion of scattering fish in response to a predator, the predator avoidance behavior in FIRA increases an agent's speed by three when the predator is within a certain distance.This behavior also utilizes the multiplicative inverse of the distance from the predator to drastically amplify the output force as the predator proximity increases, similar to the repulsion behavior.

General avoidance
The general avoidance behavior steers the agent around any obstacle in its way.The general avoidance behavior is denoted by: where n is the number of obstacles, GenW is the general avoidance weighting coefficient, GP j is the position of the obstacle, Pt is the prediction time, Gv j is the velocity of the obstacle.GenD is the coefficient that increases the repulsion forces as the obstacle approaches closer, and Gdis is the distance between the agent and the obstacles.
The general avoidance behavior adjusts the avoidance vector by rotating it ±90 • , depending on the relative position of the obstacle in relation to the agent.The rotation allows the agents to move around an object instead of completely turning around.The general avoidance behavior uses the multiplicative inverse of the distance from the obstacle to drastically increase the behavior's output as the proximity of the obstacle increases.

Foraging
The foraging behavior steers the agent towards points of interest or 'food' in the environment.The foraging behavior is denoted by: where n is the number of food sources, ForW is the foraging weighting coefficient, fP j is the position of the food, Pt is the prediction time, fv j is the velocity of the food, ForD is the coefficient used to increase the attraction of a food source the closer an agent is to the food, and FoodD is the distance between the agent and the food.Adding the multiplicative inverse attraction portion of the behavior ensured that an agent would not stray from a school unless a food source were significantly close.It also has the effect of having a slight pull toward the closest known food source.
The foraging behavior also increases the agent's speed by a factor of two.The speed only increases when a food source is within a certain distance of the agent.

FIRA algorithm
The FIRA Algorithm integrates all the behaviors to generate a single positional vector relative to the agent, simplifying the complexity and enabling a variety of behaviors to emerge based on the assigned weights.For instance, the agent can avoid a known threat while maintaining its ability to school.The resultant vector generated from these behaviors serves the desired target for the agent, allowing the agent to determine its movement toward the target autonomously.The FIRA algorithm is as follows: It should be noted that the output of FIRA is a position vector and does not directly affect the speed of an agent.As previously mentioned, the predator and foraging behaviors change the agent's speed.Otherwise, the agent will move at a typical cruising speed.When implementing the FIRA algorithm, each behavior has its weighting values that can be changed to produce different behaviors from the algorithm.
FIRA provides each agent with a single positional vector that combines all the above mentioned behaviors.This vector becomes the desired target for the agent to move towards, allowing a range of emergent behaviors to arise based on the weights assigned to each behavior.Agents can effectively navigate their environment by avoiding known threat areas while still maintaining schooling behavior.FIRA's flexibility lies in its ability to be applied to any robot capable of moving toward a given vector without considering the underlying mechanics of individual agents.

Fish memory
As part of implementing the FIRA algorithm, each agent is equipped with a fish memory, which stores information that an agent has detected.Thus, allowing different behaviors to emerge, such as actively avoiding areas where a threat was seen, continuing to search areas of interest, or moving toward the last known position of other agents.
Fish memory allows the agent to retain a picture of its environment for a finite time.Each agent will hold an array of memory for each side of its body and utilize it in its behaviors.The fish memory is defined as: where O is the object detected, either another agent, predator, food, or obstacle, P is the object's position, v is its velocity, and T is the time at which the object was detected.
Each object type has its own decay rate, determining how long it will be stored in the Fish Memory.The decay rates are denoted as S decay for the schooling fish decay, P decay for the predator decay, F decay for the foraging decay, and O decay for the obstacle decay.
Each of the behaviors utilizes the fish memory in different ways.The alignment, repulsion, and general avoidance all use the most current objects within memory.For the attraction, it will use the most current objects if present.Otherwise, it will use the previous positions held in memory to guide it back to where it last saw an agent.Predator avoidance will look at all predator locations within memory; this allows the agent to avoid areas that pose a risk.Lastly, the foraging behavior will look at all food objects in memory.Different behavior can emerge by changing the decay rate for each object type.

Indirect communication
FIRA is paired with a novel form of indirect communication, allowing agents to communicate if a food source or a predator is detected.While FIRA could work with forms of direct communication, the algorithm was designed to work with indirect communication specifically.Thus, ensuring it would work underwater, where communication can be limited or impractical for a given task.The indirect communication method is based on the speed of the neighboring agents, which provides limited amounts of information that can be transferred.
The FIRA algorithm features three different speeds based on an agent's state, which enables indirect communication to infer the state of other agents.The indirect communication method works by calculating the speed of a neighboring agent.If it is above the thresholds for food or a predator, it will be inferred that that agent has seen a food source or predator.While the agent cannot know the position of the food source or predator, it will use the position of the neighboring agent, thus, driving it towards or away from desired or threatening areas.While it cannot precisely locate a predator or food source, the position of other agents can be used to either flee or move toward their position.This interpretation of the communication can result in packets of information being lost or misidentified by individual agents.
Nonetheless, it accounts for limitations of underwater communication and reduces communication bottlenecks, making it scalable for swarms of varying sizes.While the method of indirect communication is an innovative approach, it is not the primary focus of this study.The benefits, best implementation method, and effectiveness will be explored in future work.

Simulation
In order to validate the suitability of the FIRA algorithm for underwater robotics applications, a comprehensive simulation was developed within the Unity3D framework [71].The simulation was developed for testing swarms of robotic fish, where the model used is a digital twin of a generic research platform [71,72].Unity is a 3D gaming engine that has a built-in physics engine.The basic movements of the robotic fish and its sensors can be replicated in real-time, with the approximation sufficient for testing the devised algorithm.

Environment
The simulation environment created in Unity was a 10 m × 6 m × 5 m deep pool.For initial testing, a bounded environment was chosen instead of an open ocean with water currents, as it simplified the control algorithms of the robotic fish.This decision was made to create a testbed representative of the initial testing environment for the algorithm when transferred to an actual robot.

Robotic fish
The simulated robotic fish, depicted in figure 2 is the digital twin of a physical robot built and tested underwater for previous works [72].The robotic fish is actuated by servos, with one on each pectoral fin to provide pitch and roll and three in the tail to provide forward thrust.The locomotion of the robot is based off the oscillation wing form as described by Tzeranis  et al [73].The parameters of the robotic fish are shown in table 1.
The accuracy of the robot's underwater movements was validated by recording video footage of diverse underwater objects and subsequently comparing them to their digitally replicated counterparts within the Unity engine [71].This comparison ensured that the physical and simulated robots exhibited the same behavior and that the Unity physics engine accurately reflected the kinetics of the robot's movements in the water.The robot's stability during swimming was enhanced by designing the robot to have its center of mass positioned below its center of buoyancy, as well as being designed to be neutrally buoyant.This design choice allowed the fish to have a hydrodynamic similarity with its physical counterpart, with Unity's drag coefficient being set to 11 rather than the traditional drag coefficient.
For this study, the robot uses the camera sensor, as it has been shown in the literature that cameras can be used to get the distance and position of objects relative to themselves [38,74].
The simulated camera sensor used in this study offered a range of adjustable parameters, including maximum distance, field of view (FOV), and processing delays.The distance was capped at 1 meter for the study, and a FOV of 120 • was used.However, it is essential to note that the simulation was not designed to enable the use of real computer vision techniques.Therefore, this study did not explore all the challenges of underwater computer vision.Instead, object identification, position, and rotation were obtained using the engine's camera and a ray cast to detect objects within its frame.

Swarm algorithm
The FIRA algorithm was run on each robotic fish within the simulation to determine its feasibility.Alongside FIRA, two other swarm algorithms, Boids, and AFSA, were used to compare and contrast.The mathematical explanation of the swarm algorithms used in the simulation has been described in sections 2 and 3.While other flocking algorithms exist, most focus solely on flocking and would only provide a good comparison for the schooling section of the algorithm.
Several pieces of information need to be obtained for the FIRA algorithm.The camera sensor can identify objects within the FOV as neighboring fish, predators, food, or an obstacle to avoid.Two options exist to determine the distance to an object using a camera.The first is by using two cameras next to one another and calculating the distance of an object within the two camera feeds.A single-camera approach offers an alternative solution that, despite its complexity, enables distance estimation by leveraging pixel density and object size information [74].For the simulation, the distance to an object was determined using the ray cast function within Unity to reduce the computation and complexity.
For the Boids algorithm, only the position and velocity of nearby objects are needed.The AFSA algorithm typically requires direct communication to transfer information, unlike the FIRA and Boids algorithms that only use sensors to perceive their environment.Therefore, it was decided that the AFSA algorithm would function as initially proposed, and the direct communication would be replaced by the indirect communication method used and developed for the FIRA.The AFSA behavior also requires a fitness function to determine the best behavior; this was replaced with prioritizing avoiding obstacles and predators, followed by the closest food source, then other fish Obstacles||Predator⟩Food⟩Fish. ( Each algorithm was applied as a high-level control algorithm overlaid over the robot's motion control.Each algorithm also outputs a single point in space which is constantly updated.However, the algorithms do not account for the positioning and limitations of the robots to reach that location.These limitations have not been observed to impact the algorithms' effectiveness severely and are outside this study's scope.
For this study, the low-level control has been abstracted, with the original implementation of the digital twin dealing with the performance metrics used to validate the twin's movements to that of the physical counterpart [71].
Figure 3 illustrates the control schema of the robot in the simulation.Perception sensors receive input from objects within the scene, and cameras process the data for the control algorithm.A simulated IMU and pressure sensor is used to measure the robot's position.The control algorithm incorporates the perceived data and runs the indirect communication method, while the FIRA algorithm determines the robot's current target.The resulting target position is used to calculate the required forces generated by the actuators, and the Unity physics engine handles the resulting force and kinetics.

Simulated experiment
The viability of FIRA and its comparison with existing algorithms were assessed through the execution of multiple trials, each utilizing different configurations.This experimental approach was guided by the understanding that collective behavior algorithms inherently elicit varied emergent behaviors dependent on the specific parameters chosen.Each trial consisted of a 5 min run with all robotic fish starting from the same position and orientation.Each trial ran for 5 min, with all robotic fish starting in the same position and orientation.The 5 min run time was selected to ensure sufficient time for all behaviors to emerge.The simulation is time-independent, and the duration is constant across all trials, eliminating any inconsistencies resulting from hardware limitations.
For the FIRA and subsequent comparison flocking algorithms, numerous parameters can be changed to modify the behaviors exhibited by each algorithm.To this end, it was decided to group the trials based on the following individual behaviors: alignment, attraction, repulsion, predator avoidance, and foraging.The predator and foraging behaviors have three separate configurations, as shown in figure 4, and a combined trial with a predator on the right side of the pool and a food source on the left.The first configuration had a predator or food source placed in the middle of the pool, the second had two separate sources on either side, and the third configuration had the source moving back and forth across the pool.For all predator and foraging trials, the predator and food sources stayed within the scene, even if a fish came into contact with it.Likewise, a robot fish was not removed in the same scenario.For all trials, the total number of robotic fish was set to 20, with all robotic fish having a camera distance of 1 m and a FOV of 120 • .For the camera sensor, the processing delay was modified for each trial.The delay values for the camera were determined in previous unpublished work, where 0.5 s and 1.32 s were on the lower end for image processing on small singleboard computers.The different camera delay values are shown in table 2.
For each algorithm, several parameters were changed for the different trials.The parameters for algorithms were tuned with trial and error to produce the best behaviors instead of tuning to get the best performance using the chosen metrics.Each corresponding variable that changed over each FIRA, Boids, and AFSA trial can be found in the tables below.
For FIRA, the values for the following weighting variables were consistent over all trials; wander was 0.004, fish decay was 2, obstacle decay was 2, schooling time decay was 1, predator weighting was 1.5, predator distance was 1.3, obstacle weighting was 2.65, obstacle distance was 1.5, with foraging weighting and distance being 1.5 and 1 respectively, schooling weight was 1.The values of repulsion distance, repulsion weighting, alignment weighting, and attraction weightings are shown in table 3.
The prediction time was also changed for each FIRA parameter configuration.The prediction time values are shown in table 4. The predator and food  decay times were also changed for the predator and foraging trials.The values for each are shown in table 5.
For the Boids algorithm, the values of the following weighting variables were consistent over all trials.Wander was 0.04, predator weighing was 1.5, obstacle weighting was 2, and foraging weighting was 1.4.The values of repulsion, alignment, and attraction weightings are shown in table 6.
For the predator and foraging trials, the Boids algorithm had a prediction time for both the pursuit and evading behaviors.The prediction time was changed to match the camera delay, like that of FIRA.The prediction time is shown in table 7.
For the AFSA algorithm, the coefficients were changed to prioritizing behaviors if they had an output force.For AFSA, the order of priority is as follows, avoiding obstacles and predators above all else, moving towards the closest food source, then swarming with other fish.

Metrics
Several metrics have been chosen to analyze the different behaviors that can emerge from the chosen algorithm.The chosen metrics also provide an analytical method to compare the effectiveness of the algorithms against one another.
Firstly, an agent is determined to be within a flock based on the distance between agents.As the camera distance is 1 m, using the method described by Harvey et al [75], any agent within half the maximum distance of the sensor is considered to be within a flock.
The cohesion of the swarm can be used to assess how close every agent in the swarm is to one another.Cohesion is determined by taking the average distance between an agent and the center of the flock.Firstly the center of the flock needs to be calculated, represented as cen(t), and expressed as [76]: where n is the number of agents within the swarm, and p i is the position of the agents.Using the centroid of the flock, cohesion is defined as coh(t) and is expressed by [76]: Thirdly, the total alignment or order of the swarm can be calculated.The order of a swarm is determined by [75]: where N is the total number of agents, and v i is the normalized velocity of the agent i.
As noted by Vicsek [75], if the order is ∼0, then the individual agents' direction is not aligned, whereas when the order is ∼1, the motion is coherent, and the agents are highly aligned.
The fourth metric is the number of collisions of agents within the swarm, which can be expressed as the number of collisions over time, the total number of collisions throughout a trial, and the average number of collisions over time.
To evaluate the swarm's ability to forage or avoid predators, an agent's time within a certain distance of a predator or food source is used as a metric.A shorter time within a predator's area is considered better, while more time spent near a food source is ideal.This study used a distance of 90% of the sensor's maximum range to determine if an agent was within the predator's or food source's range.
The last metric was how much of the given pool environment was explored by all agents within the swarm.

Results
Having run all three algorithms through a series of different trials, it is now possible to compare their results.Each trial was run in the Unity simulation, and the data was then processed using MATLAB.Each trial was analyzed using the given metrics in section 5.Each of the following subsections focuses on a particular behavior that can be exhibited by the algorithms, depending on different configurations of the weighting coefficients.

Attraction trials
In order to quantify the attraction behavior, the proximity of each agent to others in the swarm is assessed to ensure they are not colliding.This behavior is akin to the shoaling behavior of fish, where they swim within close proximity to each other, but the alignment between the agents can be relatively low.
The flocking, cohesion, order, collisions, and exploration metrics were compared for attraction.The results of the trials are presented in figure 7, with each figure being broken up into the different camera delay values on the x-axis and further categorized by the prediction time value, also on the x-axis.For attraction, only the FIRA algorithm predicts the future positions of other agents.
The analysis indicates that FIRA performed worse for flocking, with a lower average flocking size ranging from 2.43 to 3.6 compared to Boids 11.85-14.72,but similar to AFSA with 2.65-3.03.
The cohesion distance for the trials with camera delays of 0 and 0.5 s is lower for FIRA, with the average distance being between 100.52 cm to 135.306 cm.In contrast, Boid's cohesion distance was 123.06 cm and 134.07 cm, yet higher than the AFSA, which averaged 65.53 cm across the trials.While Boids had a higher flocking number, FIRA and AFSA agents were closer in proximity in the overall environment.The order of the Boids algorithm was significantly higher, with an average of 0.75, compared to 0.278 and 0.25 for FIRA and AFSA, respectively, putting Boid's behavior closer to schooling than shoaling.
Over the trials, AFSA and FIRA had significantly fewer collisions than the Boids algorithm, with Boids having around 700-1000 collisions.
As shown in figure 5, having a high attraction for the different algorithms can cause them to exhibit quite different behaviors.Where FIRA will sometimes exhibit milling or shoaling behavior commonly seen in schooling fish [29,43], the Boids algorithm resulted in a colliding central mass, while AFSA exhibits a general shoaling behavior.

Alignment trials
The Alignment behavior focuses on the agents being highly ordered while not colliding with one another.Highly aligned agents can be akin to the schooling behavior of fish.Where order is high, cohesion is close, and collisions are low.
The flocking, cohesion, order, collisions, and exploration metrics were compared for alignment.From the results presented in figure 6, FIRA generally performed worse for flocking size with an average of 2.88 and an average cohesion distance of 114.94 cm compared to the Boids flocking size of 13.62 and cohesion distance of 115.09 cm and AFSAs flocking size 2.90 and 65.53 cm cohesion distance.For order, FIRA was considerably lower than Boids, with Boids on average having an order of 0.9, while FIRA was constantly around 0.5.FIRA's lower order is likely due to the influence of the wander function and prioritizing one side of agents over the other.In comparison, ASFA was significantly lower than both, with an order of around 0.25, due to AFSA's lack of weightings and alignment behavior.
FIRA, with an average of 13.2, outperforms Boid's average of 922.98 for collisions and explores 10.43% more of the environment than Boids.AFSA for collisions and exploration performs similarly to FIRA, with 12.4 average collisions and 7.8% more of the total area explored.

Repulsion trials
The Repulsion behavior focuses on agents keeping their distance from one another.Highly repelled agents will stay loosely coupled or completely lose one another and default to a wandering state.However, agents that have a low repulsion coefficient will tend to collide with one another.
The flocking, cohesion, order, collisions, and exploration metrics were compared for Repulsion.From the results presented in figure 8, the performance of both FIRA and Boids is similar for the average flock size and cohesion distance.While Boids still had a slightly higher order across the swarm, with 0.145 and 0.117 higher than FIRA and AFSA, respectively.For AFSA, flocking was considerably higher, and the cohesion distance was lower, indicating that they stayed relatively close to one another throughout the trial.
For the collision metric, both Boids and FIRA had relatively low collisions with an average of 0.1 and 0.9 collisions, respectively, with Boids not having any collisions throughout the 0.5 s and 1.32 s camera delay trials.In contrast, AFSA had an average of 15.25 collisions over all three trials.Overall, FIRA performed better for exploring the environment, covering around 79% on average.

Stationary predator trails
For the predator trials, the weightings for the schooling behaviors were set to fixed values.As such, the metric for flocking, cohesion, and alignment, while still a factor, is not of primary importance.
Like the first three trials, as shown in figure 9, FIRA has far lower collisions overall.FIRA had 2.02, 2.14, and 9.52 average collisions for the trials with the predator memory decay of 2 s, 10 s, and 100s, respectively.While Boids collided 80.62 times and AFSA averaged 16.25 collisions.It should be noted that none of the agents collided with the predator for any of the algorithms.Boids and AFSA have larger average flock sizes, and cohesion for Boids and FIRA is relatively similar, with AFSA being the closest.Again, exploration was generally higher for FIRA than for Boids and AFSA.
Given that the FIRA algorithm stores the positions of the predators, it would be expected to wander less into the predator zone than Boids or AFSA.However, as demonstrated in figure 9, which depicts the movement of each robotic fish over a trial from a top-down, front, and side view, the high order of the Boids agents limits their movement around the pool area, with the agents only changing direction when hitting a wall.For AFSA, they congregated around the top corner, further limiting their exploration.Whereas the FIRA agents thoroughly explore the pool with the exclusion of the predator zone.In the trials, when a camera delay of 1.32 s was used, FIRA spent the most time near the predator, with a total of 0.016% (2 s memory decay), 0.013% (10 s memory decay), and 0.08% (100s memory decay).While Boids only spent 0.0002% and AFSA only spent 0.006% of its time within the predator's vicinity for the 1.32 s camera delay trials.
For the second predator trials, with two separate predator entities, the results follow the trends of the first predator trials.

Moving predator trials
For the moving predator trials, the results shown in figure 11 follow that of the stationary predator trials, as shown in figure 10.It should be noted that as the predator moved around in the environment, it did cause some agents to collide with it.FIRA collided with the predator an average of 0.04 times, while Boids and AFSA averaged 0.01 and 0.0, respectively.Again, FIRA had the highest collisions due to its higher exploration.However, while FIRA did spend slightly more time in the predator zone, a general trend is that the higher the decay rate on the predator memory, the lower the time spent in the predator zone.

Stationary Foraging Trials
For the foraging trials, the weightings for the schooling behaviors were also set to the same generic values as the predator trials.As such, the metrics for flocking, cohesion, and alignment, while still a factor, are not of primary importance.Like the first three trials, FIRA has lower collisions overall with obstacles and other agents, averaging 130.62 compared to Boid's 198.43 collisions, yet more than the 13.36 average of AFSA, as shown in figure 12. FIRA does have slightly more interactions between the food source with an average of 1.96, followed by Boids at 1.04, and then AFSA with 0.43 interactions.It should be noted that collisions are higher between agents foraging as they want to be close to one another and the food source.It also accounts for the higher flocking value for the foraging behavior trials.
Exploration for all algorithms is lower than in previous trials, as the agents spend most of their time near the food source.With FIRA exploration percentage staying between 48% to 72%, Boids was 62% to 75%, and AFSA was 68% and 70%.As for the time spent within the vicinity of the food source, for 0 s and 0.5 s camera delay trials, FIRA spends far more time within the area.FIRA spends a maximum of 1.86% and 2.58% more time within the area than Boids and AFSA.With the expectation of 1.32 s camera delay trials, where FIRA spends approximately the same amount of time as the Boids algorithm, AFSA has a significantly lower ratio.
The results of the two stationary food sources are similar to the first foraging trials.As expected, the number of collisions and time spent within the area of a food source has increased, with FIRA, Boids, and AFSA spending 15.65%, 7.19%, and 2.89% of the swarms' time in the vicinity of a food source.It should be noted that Boids has marginally more collisions with the food sources than FIRA, averaging 2.43 collisions compared to the 1.04 collisions in the single food source trials.Whereas FIRA has similar collisions, AFSA has 1.045 more average collisions with a food source.

Moving foraging trials
The patterns observed in the initial foraging trials were consistent with those seen in the moving foraging trials, as shown in figure 13.In both sets of trials, higher flocking averages, increased collision rates, and reduced exploration levels were evident.Regarding interactions, FIRA had the highest average at 1.71, while Boids and AFSA averaged 1.33 and 0.75 collisions with the food source, respectively.Moreover, FIRA spent 0.53% more time near the food sources than Boids and 3.44% more than AFSA.Due to the moving food source, FIRA spent 11.45% less time near a food source than in the second foraging trials and 3.14% more than in the first trial.

Predator and foraging trials
The Trials, as shown in figure 14, with both a foraging and predator entity show similar traits as foraging and predator-only trials, with higher average flocking, similar cohesion, and order.On average, Boids exhibited the highest collisions, followed by FIRA and AFSA.Notably, FIRA demonstrates a greater frequency of interactions with the food source while spending more time within the predator zone as the camera delay increases.Exploration is similar to the first foraging trials, with 60%-80% being the average range.

Discussion
The experimental results show that the FIRA algorithm outperforms the other algorithms regarding collision avoidance, foraging, and exploration.However, other areas which significantly impact its performance, such as order and flocking, are not as impressive as the results from the Boids algorithm.While the cohesion distance of FIRA is within a similar range to that of Boids, its flocking is generally lower.Partly due to FIRA's inclusion of the wandering behavior in the overall output of the algorithm, which slightly affects the output and can move an agent closer or further away from its original target.Adding the wandering behavior and prioritizing the side with the highest density also lowers the swarm's overall order.
On the other hand, AFSA has the lowest cohesion distance and lower flocking.As an optimization algorithm, AFSA prioritizes behavior over individual components of the overall output, which makes it spend most of the trials in the top corner, accounting for the low cohesion.However, due to its priority to repel other agents and obstacles, it has lower flocking and order.In contrast, the Boids algorithm has a much higher order than FIRA and AFSA.However, without the impact of an outside factor, it would continue in unison in a straight line when close to other agents, limiting its exploration of the environment.
FIRA excels at collision avoidance with lower collisions while still being able to achieve the desired behaviors, as well as exploration.Instead of having linear repulsion behavior like Boids and AFSA, FIRA uses the multiplicative inverse to increase the repulsion force significantly as other agents move closer to it, allowing the repulsion force to overcome the other components of the algorithm if objects are close enough unless other weightings are drastically higher.A benefit not shared by the other algorithms.
Contrary to expectations, FIRA demonstrated suboptimal performance in dealing with predators.Despite incorporating memory, which was anticipated to reduce the time spent in the predator's proximity compared to the other algorithms, FIRA did not exhibit the desired effectiveness in predator avoidance.The addition of the indirect communication method should also have allowed the communication of an approximate of the predator's location.However, as shown in figure 9, FIRA has higher movement around the environment than Boids and AFSA.The exploratory nature most likely contributed to more agents wandering back into the area over time.Nonetheless, as shown in figure 10, the memory component has the expected effect, with agents spending less time within the predator's vicinity as the decay time increases.More research will need to be conducted into the effect indirect communication has on the algorithm, as the study did not focus on its effects.
Conversely, the memory of the FIRA algorithm provided benefits for the foraging trials.For all trials, FIRA spent more time within the food source's area and, on average, had higher interactions with them.One benefit that allowed this was the food source staying within the environment for the whole trial, leading to agents passing through it and losing sight of it.For Boids and AFSA, having no memory of the food source once they had lost sight of the food, they would have a higher chance of moving away from the area.FIRA's memory allowed it to circle back once it had lost sight of the food source, resulting in higher interactions with the food source.
FIRA's benefit is further highlighted when observing the algorithms and contrasting them against the behaviors of gregarious fish.In figure 9, which plots the movement of each agent across the trial, it is clear that AFSA suffers from clustering a single corner of the environment.Whereas the Boids algorithm, when coupled with the limitation of robotics and their sensory perception, exhibits a rigid swarm that would continue in a fixed formation if not for the boundaries of the simulation.On the other hand, FIRA behavior whilst schooling more closely resembles its biological counterpart.The swarm is more free-flowing, as agents contest for the school's center, providing an observer with a more realistic school behavior.
Based on observations, FIRA's anti-predator avoidance behavior resembles the natural scattering behavior often observed in nature.Unlike AFSA and Boids, which exhibit a fleeing behavior of 180 • away from the predator, FIRA's behavior involves a distinctive 90 • out-of-phase movement away from the predator.Consequently, the AFSA and Boids agents are actively chased instead of conforming to the typical scattering response typically seen in nature.Regarding foraging behavior, FIRA demonstrated only a marginal improvement in realism.Its memory component prevented the agents from swimming off independently when they lost sight of the food source.
An observational analysis indicates that FIRA achieves heightened realism when deployed on robotic fish that possess limited perception, experience sensor delays, and exhibit restricted movement.These constraints were the main impetus behind the algorithm's development.Nevertheless, it is crucial to acknowledge that this study is confined to existing schooling algorithms, and future research should expand to compare FIRA directly with biological fish.Furthermore, integrating individual agents into a cohesive school is an essential area for future exploration.

Conclusion and future work
This paper presents a new swarming algorithm, FIRA, inspired by the natural behaviors of schooling fish.It utilizes the behaviors found in schooling fish, and unlike typical particle-based models, it was designed to overcome the specific limitations of swarm robotics when placed underwater.The innovation of the FIRA algorithms is its ability to provide realistic fish schooling behavior when placed on agents with limited perception of their surroundings while continuing to be a computationally light algorithm.Thus, allowing further research into using cheap robotic fish that behave like and one day monitor biological fish.
Overall, FIRA inherently provides better collision avoidance, exploration, ability to forage, and additional emergent behaviors than traditional models.At the same time, it is a lightweight algorithm that can be used on low-cost swarm robots without the need for high computing power, which drives the complexity and cost of the swarm robots.However, work can be done to improve the algorithm's performance further.
Future work on this research will look at expanding the FIRA algorithm and its use cases in underwater robotics, including using the algorithm on physical robotic fish to determine if it will have similar behaviors and outcomes.Practical implementation of the algorithm will also bring new challenges, as variable sensor delays and errors will be a compounding problem when placing sensors underwater.Accompanying this research will be a study of its performance when placed on a robot assimilated with a school of fish.
Another area of research to explore further is the effects of the processing delay on swarming algorithms when using sensors such as cameras.In previously unpublished work, it was observed that camera delays had a detrimental effect on swarming algorithms; this is also evident across the trials presented here.However, a more in-depth study would highlight at which point the delays are detrimental and if preventative measures are needed.In conjunction with camera delays, another vital aspect of the FIRA algorithm is the communication method used between agents.Further research will be undertaken to assess the effectiveness of the chosen method and explore alternative indirect communication approaches to determine their suitability for the intended objectives.
The FIRA algorithm was developed to mimic the behaviors of schooling fish while trying to overcome the issues with sensors and the lack of communication.From the results, one surprising area that FIRA excelled in compared to the other algorithms was the ability to explore an area.To this end, more research will be conducted to determine the potential for FIRA to follow schooling fish for underwater search and rescue missions or locate and retrieve missions.
The results show that FIRA can contend with existing algorithms and exhibit new behaviors, such as milling, which does not naturally occur with traditional algorithms.Its main areas of improvement lay in its inversed square repulsion force, the addition of its memory, and its indirect communication method.

Figure 1 .
Figure 1.Relationship of definitions of shoaling and schooling behaviors.Reproduced from [29], with permission from Springer Nature.

Figure 2 .
Figure 2. Model of the robotic fish.