Collective Cognition on Global Density in Dynamic Swarm

Swarm density plays a key role in the performance of a robot swarm, which can be averagely measured by swarm size and the area of a workspace. In some scenarios, the swarm workspace may not be fully or partially observable, or the swarm size may decrease over time due to out-of-battery or faulty individuals during operation. This can result in the average swarm density over the whole workspace being unable to be measured or changed in real-time. The swarm performance may not be optimal due to unknown swarm density. If the swarm density is too low, inter-robot communication will rarely be established, and robot swarm cooperation will not be effective. Meanwhile, a densely-packed swarm compels robots to permanently solve collision avoidance issues rather than performing the main task. To address this issue, in this work, the distributed algorithm for collective cognition on the average global density is proposed. The main idea of the proposed algorithm is to help the swarm make a collective decision on whether the current global density is larger, smaller or approximately equal to the desired density. During the estimation process, the swarm size adjustment is acceptable for the proposed method in order to reach the desired swarm density.


Introduction
Swarm robotics is a sub-field of multi-agent robotics that employs distributed controllers, where inter-robot local communication is the key component. Due to the use of distributed controllers in a self-organized manner, swarm robot systems are expected to have three main advantages: flexibility, scalability and robustness. However, to design selforganized mechanisms is challenging, as desired behavior at the macroscopic level must be accomplished based on a set of behaviors programmed in each individual robot. Many task-based controllers have been designed for self-organized swarm robot systems such as collective transporting [1][2][3], collective foraging [4,5], collective decision-making [6,7] and collective exploration [8]. These controllers primarily focus on the scalability of swarm systems, in which changes to the swarm size within a reasonable range do not dramatically affect the performance of the swarm robots.
The average performance of a robot swarm which uses previous controllers actually depends on the swarm density, and it only depends on the swarm size if the operating area is kept constant. The analyses in previous works [1,3,9] has shown that the performance of swarms can be optimized by determining a suitable swarm density. In high-density environments, robots are compelled to put in more effort and attention to address interrobot collision avoidance tasks rather than concentrating on their core responsibility, which lowers the swarm's overall performance. If the robot density is raised much further, performance will likely decrease to negligible levels due to interference halting almost all motion. However, when there are too few robots present in a large area, robot collaborations are noticeably ineffective, and the same outcome could be observed. In some cases, lowdensity swarms can have more impact than high density situations, as observed in selforganized aggregation processes [10,11]. Hence, in order to optimize the performance of the swarm, the swarm density must be predetermined. (1) where |·| denotes the set area operator. Following the preliminary introduction, it is assumed that the swarm operates in a fully or partially unknown domain, and the size of the swarm may vary. Hence, λ is a time-varying variable that can only be estimated. However, in this study, we do not attempt to propose the method used to estimate λ. The key issue we will tackle is how to answer the question of whether a swarm's actual swarm density surpasses, falls short of or is roughly equal to a given desired swarm density, λ d , by introducing a distributed algorithm that aids swarms. Furthermore, we assume that robots in a swarm do not have any prior knowledge of the size of the workspace, and the decision of robots in the swarm is based solely on the information related to the inter-robot encounter rate. However, the rate of encounters experienced by the robots will depend on their motion in the domain. We initially restrict the motion characteristics of the robots in their workspace in order to make specific claims about inter-robot encounters. Let x i (t) ∈ D be the position of i th robot at time t. Then, for any given subset U ⊆ D, the average time spent by the robot in that set should be equal to the ratio defined in Equation (2). If the Equation (2) is held in the swarm, then we can state that the motion pattern of robots in the swarm is ergodic.
The developed encounter model is applicable as long as the ergodicity assumptions are satisfied, which enables us to make generalizations about the types of motion patterns that arise from the task's execution. The consistently ergodic trajectories of the robots imply that their density over the domain D at any given instant is also uniform. In our study, the motion of robots in a swarm can be summarized by the following steps: (1) a robot moves forward; (2) if a robot comes close to the workspace boundaries or collides with other robots, it turns in a randomly selected direction and reverts back to step (1). As long as the ergodicity assumption is still valid, the other motion models can be used even when robots are performing other tasks while executing the suggested mechanism.

Encounter Rate
In the first section, we stated that the robots performing the collective task in a distributed manner are equipped with sensors that can help the robot detect the presence of its neighbor within the range of r s . We first denote that F i (t) ⊂ S(t) is the set of robots in range of r s within R i , called neighbor set of R i , in which if R j ∈ F i (t), then x i (t) − x j (t) < r r + r s must be satisfied. Hence, we define a robot as having an "encounter" when a neighbor set of given robots is not empty, F i (t) = ∅. Based on the given motion pattern of robots in the swarm, upon colliding with another robot, each robot executes a collision avoidance maneuver to prevent the collision and continue along its trajectory. Consequently, the presence of the complement state of "encounter" is called "disjoin" where no robots are present in the sensory range of a given robot or F i (t) = ∅.
We first need to construct a model for how frequently encounters happen among the robots, or the encounter rate, in order to be able to use encounter information to estimate the swarm density. The robot's encounter rate can be calculated from its time in the encounter and disjoin states. However, the durations indicating how long a robot stays in an encounter or disjoin state are stochastic variables due to the randomness of the motion model. Obviously, these random variables are dependent on swarm density as well as on different distribution parameters with regard to how quickly the task of avoiding collisions may be solved and the robot speed. These factors can be modeled, but they can also complicate the estimation process and reduce its generality. Firstly, the collision avoidance strategy and time spent on different locomotion methods-for example, differential-drive robots and omnidirectional robots that share physical parameters-are significantly different. Furthermore, although robot density is maintained as constant, the ratio of encounter duration to total process duration varies during the process due to the varying speed of robots. To ensure the generalizability of the proposed method, the measurement of travelled distance in which these states are occupied are implemented instead of measuring in terms of time. From now on, s will be used as the discrete index parameter indicating the travelled distance of a given robot. We should note that the travelling distances among robots in a swarm are not the same with respect to time.
Hence, now, the states of each robot in the swarm can be modelled as a continuous stochastic chain {X(s) : s ≥ 0} defined by index parameter s and state space {0, 1} where 0 denotes the "disjoin state" and 1 denotes the "encounter state". Due to the exponential decrease in probability of travelling distance for a single encounter event and single disjoin event, and their independence from each other, this process can be considered as a continuous Markov process with an index parameter in terms of the travelled distance. The travelled distance on the single encounter event and single disjoin event can be modelled as the exponential distribution with rate parameters λ e and λ d , respectively. Let π e be the average encounter rate of robots in the swarm, and π e (t) can be defined as a stationary probability of the encounter state at time t.
However, because λ e and λ d are unknown variables and depend on the number of robots in the swarm, it is possible to estimate π e solely by using estimators for λ e and λ d . Letπ e,i be the encounter rate estimator of R i , which can be defined as Equation (4) by applying the moment method.π whereλ e,i andλ d,i are the estimators of the inverse of the mean of travelled distance on the encounter state and disjoin state of the given continuous Markov process estimated by R i . The estimation procedure can be carried out by using the maximum likelihood estimation method on two sets of random samples. The first set consists of the length of travelled distance a robot spends in the encounter state, while the second set consists of the sum of its travelled distance spent in both states. k represents the size of each set. The value of k can be viewed as the number of cycles of the Markov process that a particular robot has gone through. However, directly determining the value ofπ e,i can be very complicated. To ease this problem, the auxiliary estimator z i is employed which is defined in Equation (5).
where s e,i,j and s d,i,j are the travelled distance of the j th encounter event and j th disjoin event measured by R i . Both s e,i,j and s d,i,j are random variables which have a probability density function represented by an exponential model. Hence, if the change of average global density is slow enough, then we can approximate that ∑ k i j=1 s e,i,j ∼ Γ(k, kλ e ) and ∑ k i j=1 s e,i,j + s d,i,j ∼ Γ(k, kλ c ) where Γ(a, b) represents the gamma distribution parameter- ized in term of shape parameter a and an inverse scale parameter b; λ c can be defined as Equation (6).
According to [19], the probability distribution of z i (t) can be approximate to the generic beta model of the second kind, i.e., z i ∼ GB2 k, k, 1, λ c λ e where the first three parameters are shape parameters and λ c /λ e is the scale parameter. The distribution of z i is defined in terms of the probability density function (Equation (7)).
In which Γ(.) is the gamma function of a given parameter. Note that if k < 1, then the mean of z i is infinite and if k < 2, then the variance of z i is not defined. Hence, to be able to determine these values, k should be chosen as greater than 2. We assume that k > 2; then, the mean and variance of z i are defined in Equations (8) and (9), respectively.
According to Equation (8),π e,i can be estimated by E(z i ) via Equation (10).
The choice of k affects both the correctness of the estimated valueπ e,i and the sensitivity of robots to the change of average global density. If k is increased, then the range of possible values ofπ e,i is narrowed down to E(π e,i ), but in order to notice changes in the swarm density, the robot needs to take a longer time. Another issue is that the time required to finish k samples depends on the swarm density when the number of samples k is fixed, rather than using a fixed sampling time. In other words, if the swarm density approaches 0, collecting k samples could take an infinitely long time. Therefore, the maximum sample period in terms of travelled distance S s is provided as a solution to this issue. During the sampling time, if any measured event duration s e,i,j or s d,i,j of R i exceeds S s , then the estimating process will be terminated and considered as completed. In this case, if ∑ k i j=1 s e,i,j < ∑ k i j=1 s d,i,j , thenπ e,i := 0 and vice versa,π e,i := 1. The selection of S s affects the minimum and maximum measurable value ofπ e,i and the sensitivity of the robot to the change of swarm density. In the next section, we will estimate the likelihood of a robot encountering another robot at a specific timeπ e,i (t) as a function of the partial distribution of robots throughout the relevant domain.

Nearest Neighbor Distance Distribution
Under the definition of an encounter state, an encounter is said to occur if the given robot, whose position is denoted as x i , has at least one neighbor that is equivalent to the distance from x i to the nearest neighbor of a given robot, whose position is denoted as x j and is less than r r + r s . Hence, the encounter rate or the ratio that R i experienced the encounter state in terms of travelled distance can also be determined by the probability that the random variable denoting the distance between R i and its nearest neighbor R j is less than r r + r s . Due to the time invariance of the encounter rate, this kind of probability only depends on the partial distribution of swarm robots over the domain. Hence, the patterns of geometrical swarm over the interested domain must be constructed first.
Point processes are most commonly used as a mechanism to interpret patterns of geometrical objects-for example, the position of swarm robot in our case. In this study, we describe the spatial distribution of the swarm of robots in a certain workspace using a homogeneous point process. Each robot is represented by a point in the point process, which also indicates where it is in the workspace. The Poisson process is the most basic type of point process. The selection of completely independent random points without observing the minimum distance is modelled by the Poisson process. However, the Poisson process is not suitable for modelling the position distribution of robots since it assumes that the locations of the robots are independent and uniformly distributed, which does not take into account the physical footprint of the robots or the fact that they cannot overlap.
The purely random selection of positions without observing a minimum distance is modelled by the Poisson process. Meanwhile, a hard-core process is a stochastic point process in which successive events maintain a specified minimum distance from one another. It is suitable for modelling the partial distribution of robots in a swarm. From the perspective of stochastic geometry, there exist n-dimensional point fields generated by hard-core processes using the center of n-dimensional balls that do not overlap and have a given diameter. Depending on the way in which the points are generated, different hard-core processes with different properties can be described.
Performing a dependent-thinning approach on an underlying "parent" spatial Poisson process, where points are gradually deleted until the appropriate hard-core requirements are satisfied by all the remaining points, is a typical technique for creating hard-core point processes. In this study, we focus on MHC type-II, fully detailed in [20]. To construct an MHC type-II process, we start with a real number δ > 0 and a parent stationary parent Poisson process denoted by Φ p , having a homogeneous intensity λ p (points per unit area) and then for each point x ∈ Φ p , a uniformly distributed random mark M(x) ∼ U(0, 1) is assigned. If the mark of point x ∈ Φ p is not the lowest relative to all other points in a ball with radius δ, b(x, δ), around it, that point will be marked for removal. Only after this test is done for all points in Φ p , the points that were flagged-for-removal are removed. The retained points constitute the resulting MHC process Φ hc . The distribution of robots over D can be modelled by using Φ hc with parent Φ p over D. Due to the removal of some points in the origin process, the point density of Φ hc is not larger than the one in Φ p . Let λ hc denote the hard-core point process density; the relation between λ hc and λ p can be formulated as the following: where δ is also called the hard-core distance of Φ hc which is illustrated in Figure 1. In our case, δ can also be interpreted as the minimum distance between two robots, i.e., δ = 2r r . Furthermore, the distribution of the point in Φ hc over D represents the partial distribution of the swarm robot over the same domain, resulting in λ hc = λ. According to the proposed motion model, in this study, the MHC process Φ hc with population density λ is used to describe the partial distribution of the swarm robot over D. Based on the constructed partial distribution of the swarm robots, the probability of experiencing an encounter state of R i will be calculated. the constructed partial distribution of the swarm robots, the probability of experiencing an encounter state of i R will be calculated. To construct the nearest neighbor distance model, a geometric function must be determined first. According to Figure 1, let r be the distance between i R and its nearest neighbor;   , l r  be the area of the symmetrical lens formed by the intersection of To construct the nearest neighbor distance model, a geometric function must be determined first. According to Figure 1, let r be the distance between R i and its nearest neighbor; l 1 (r, δ) be the area of the symmetrical lens formed by the intersection of b(x i , δ) and b x j , δ ; and l 2 (r, δ) be the area of the asymmetrical lens formed by the intersection of b(x i , r) and b x j , δ . l 1 (r, δ) and l 2 (r, δ) are illustrated in Figure 2 and can be defined as in Equations (12) and (13), respectively. To construct the nearest neighbor distance model, a geometric function must be determined first. According to Figure 1, let r be the distance between i R and its nearest neighbor;   1 , l r  be the area of the symmetrical lens formed by the intersection of l r  be the area of the asymmetrical lens formed by the l r  are illustrated in Figure 2 and can be defined as in Equations (12) and (13), respectively. According to [18], the cumulative probability function of the distance between a given point and its neighbor, who is likewise provided by the MHC process hc  , can be approximated as Equation (14). According to [18], the cumulative probability function of the distance between a given point and its neighbor, who is likewise provided by the MHC process Φ hc , can be approximated as Equation (14).
where R is the random variable of nearest neighbor distance of a given point and κ 1 (r, δ) can be expressed by Equation (15) with the components; a = λ p πδ 2 , b 1 = λ p l 1 (r, δ) and b 2 = λ p l 2 (r, δ) are the expected numbers of the point occupying b(x i , δ), l 1 (r, δ) and l 2 (r, δ) in the parent Poisson process Φ p , respectively.
As stated, the likelihood that the random variable expressing the distance between the given robot and its nearest neighbor is smaller than r r + r s can also be used to calculate the encounter rate or probability that the given robot experienced an encounter state in terms of travelled distance. Hence, according to (3) and (14), the relation between nearest neighbor distance distribution and encounter rate is determined as in Equation (16).
Based on Equation (16), if the desired swarm density λ d is given, the desired encounter rate can be defined. Let π e,d be the preassigned desired encounter rate for the swarm, and let Q ∈ {−1, 0, 1} be the desired decision of the swarm, where the value of Q is determined based on the comparison between the current encounter rate and the desired encounter rate, as well as the threshold error σ.
However, due to the randomness of encounter rate estimators, the values of Q i , the decision of R i based onπ e,i instead of π e , are different among swarm robots. This variation increases when π e → π e,d or σ → 0 . The technique that allows the entire swarm to make the same conclusion is introduced in the following section.

Collective Decision Making
According to Section 3, the estimated encounter rateπ e,i of R i can be determined by Equation (5). Once each robot has computedπ e,i , they need to achieve consensus on the global value. However, the randomness ofπ e,i prevents Q i from sharing the same value across the whole swarm. This problem falls into a broader class of distributed consensus or agreement problems in multi-agent coordination and wireless sensor networks [21]. These protocols allow a swarm to reach an agreement on a quantity of interest by exchanging information over the communication network. Consensus algorithms have the attractive property that, at termination, the computed value is available throughout the swarm, so a swarm user can query any robot and immediately receive a response, rather than waiting for the query and response to propagate to and from a fusion center. Additionally, there is no single-dead-point where the result of in-swarm computation can be biased due to undesired values from failed robots. However, previous consensus algorithms require a fixed network topology and multi-hop data transmission. In this section, we propose an implementation of the quasi-distributed average consensus algorithm that does not rely on multi-hop communication and can adapt to a dynamic swarm. The main idea of the proposed method is that each robot updates its value by a weighted sum of values from itself and its neighbor, i.e., π e,i (n i + 1) = N ∑ j=1 W ij (n i )π e,j (n i ) (18) where n i is a discrete-time index taking values in the non-negative integers. In this section, we only considerπ e,j in the consensus process, and we use n i as its index value. Obviously, we have thatπ e,j (0) =π e,j , whereπ e,j represents the estimated encounter rate which is obtained by estimating the process. Here, W ij (n i ) is the linear weight onπ e,j (n i ) at R i . Now, the question is how to choose the weight W ij (n i ) such that everyπ e,i (n i ) converges to the average of their initial value, i.e., lim n i →∞π Equation (18) can be interpreted as a local average if the value of W ij (n i ) is chosen to follow the nearest neighbor rules proposed in [22]. This weight can simplify the communication method since it depends only on the value of the neighbor set and the number of neighbors.
in which t i (n i ) represents the time that R i determines π e,i (n i + 1). To simplify the notation, vector notation is used. Letπ e (m) = [π e,1 (n 1 ),π e,2 (n 2 ), . . .π e,N (n N )] T be the vector that represents the set of the estimated encounter rate of the swarm, in which m is a discrete-time  (13) can be written as Equation (21).π e (m + 1) = W(m)π e (m) (21) where the weight matrix W(m) ∈ R NxN is given by (20) and it satisfies the conditions required for the asymptotic average consensus W(m)1 = 1, 1 T W(m) = 1 T and ρ W(m) − N −1 11 T < 1, in which 1 stands for the vector of ones and ρ(.) is the spectral radius of a given matrix. If Equation (16) is expanded by recursively replacing π e,j (t) by Equation (16), then the value ofπ e (m + 1) can be derived fromπ e (0).
By applying the weight matrix with components defined in Equation (20) to Equation (22), Morse et al. [22] proved that every individual in the robot swarm will converge to the same value as in Equation (19), resulting in Equation (23).
To make the proposed method able to be applied, the inter-robot communication mechanism must be clarified first. The first requirement of the communication mechanism is that each robot must have both broadcast and directional communication. To do that, infrared-based communication is employed [23]. Fortunately, this type of communication using an infrared medium can prevent most signals, and messages created by infrared transceivers can be modulated. The second requirement is bidirectional communication in which if a robot receives any messages from its neighbor, it has the responsibility to reply to the sender.
The consensus algorithm is asynchronously applied to the robot as soon as the robot acquiresπ e,i (0). In this process, the robot will broadcast its current estimated encounter rateπ e,i (n i ) to its neighbors if it has no received messages for the duration S q in terms of travelling distance. According to the second requirement, all robots receiving that message will reply to their current estimated encounter rate first; then, it applies the recorded value to Equation (18). After receiving all replies, R i also applies all recorded values to Equation (18).
Equation (18) is the ideal result that can make a member ofπ e (m) converge to N −1 11 Tπ e (0); by this, the decisions of the whole swarm approach is totally collective. However, to help the swarm make the decision based on Equation (17), the sign to indicate the complete process must be pointed out. Let range(a) denote the range of the arbitrary set of number a; the main purpose of this method is narrowing down range(π e (m)) to a value that can make the swarm have a collective sense about the estimated value. Let ϑ indicate the acceptable range ofπ e . Obviously, if range(π e (m)) ≤ ϑ, then the condition in Equation (24) must be held.
P π e,i (n i ) −π e,j n j ≤ ϑ = 1, ∀i, R j ∈ F i (t(n i )) Based on this condition, the consensus process of the swarm can be considered as finished. Let S u be the discrete sampling duration of π e,i (n i ) −π e,j n j in terms of the travelling distance of robots in the swarm. S u will start counting if the condition in Equation (24) is satisfied. During the travelled distance S u , if the given condition is continuously satisfied, then the consensus process is considered as finished. At any time, if the above condition is not satisfied, S u will be reset and pause until Equation (24) is satisfied again. Therefore, S u should be chosen so as to achieve a trade-off between the steady-state of convergence and the ability of the robot to track changing densities. In case ofπ e,i (0) = 0 orπ e,i (0) = 1, if the robot has not received a message during the travelled distance S s in the consensus process, the robot will terminate the consensus process. In this case, the decision is based onπ e,i (0).

Dynamic Swarm Case
The iterative estimate and consensus processes must be used alternatively to be able to adjust to changes in swarm density in real time. The robots will perform these processes at different speeds due to the randomness of the process completion time, though, when the robot instantly switches to the estimating process to estimate the new value as soon as the consensus process is complete. The opinions of the robots in the swarm may no longer be consistent if this procedure is out of phase among them.
After consensus is reached and before the entire process starts over again, an intermediate phase called synchronization is implemented in order to address this issue. The procedure helps robots that have completed the consensus process to wait for other robots that are still in the process of reaching the consensus, without synchronizing the clocks of the robots in the swarm. Figure 3 provides a summary of the full procedure for the swarm's collective perception of density tailored to dynamic swarm.
above condition is not satisfied, u S will be reset and pause until Equation (24) is satisfied again. Therefore, u S should be chosen so as to achieve a trade-off between the steadystate of convergence and the ability of the robot to track changing densities. In case of

Dynamic Swarm Case
The iterative estimate and consensus processes must be used alternatively to be able to adjust to changes in swarm density in real time. The robots will perform these processes at different speeds due to the randomness of the process completion time, though, when the robot instantly switches to the estimating process to estimate the new value as soon as the consensus process is complete. The opinions of the robots in the swarm may no longer be consistent if this procedure is out of phase among them.
After consensus is reached and before the entire process starts over again, an intermediate phase called synchronization is implemented in order to address this issue. The procedure helps robots that have completed the consensus process to wait for other robots that are still in the process of reaching the consensus, without synchronizing the clocks of the robots in the swarm. Figure 3 provides a summary of the full procedure for the swarm's collective perception of density tailored to dynamic swarm. As shown in Figure 3, the robot will transition to the sync procedure after completing the consensus process. The robot will keep track of the travelled distance w S during this operation. The sync procedure ends and the robot resumes to the estimating process if the counter reaches w S . The robot will not automatically send any messages during the sync process. However, if it receives a message from another robot from the consensus phase, it will reply with its decision rather than an estimated value ,e i  . The asymptotic average consensus is maintained in this manner. Robotic consensus processes can be considered As shown in Figure 3, the robot will transition to the sync procedure after completing the consensus process. The robot will keep track of the travelled distance S w during this operation. The sync procedure ends and the robot resumes to the estimating process if the counter reaches S w . The robot will not automatically send any messages during the sync process. However, if it receives a message from another robot from the consensus phase, it will reply with its decision rather than an estimated valueπ e,i . The asymptotic average consensus is maintained in this manner. Robotic consensus processes can be considered completed when the correlation between the robot's present estimated value and the intended value matches the majority decision the robot has received. The comparison between the estimated value at the time and the desired value will lead to the decision of the robots in this scenario.

Performance Evaluation
The performances of the proposed model are evaluated according to the test which is conducted in a real experiment. All tests use the same robot platform which has a top and perspective view illustrated in Figure 4. The robot platform is cylindrical in shape with a radius r r of 25 mm and height h r of 40 mm, respectively. The inter-wheel distance l w and radius of each wheel r w are 40 mm and 10 mm, respectively. Given that the robot is equipped with 6 infrared modules, as shown in Figure 4, arranged in a specific order, the maximum number of neighbors of robot |F i | max , ∀i ∈ {1, 2, . . . , N(t)} obviously is 6.
The performances of the proposed model are evaluated according to the test which is conducted in a real experiment. All tests use the same robot platform which has a top and perspective view illustrated in Figure 4. The robot platform is cylindrical in shape with a radius r r of 25 mm and height r h of 40 mm, respectively. The inter-wheel distance w l and radius of each wheel w r are 40 mm and 10 mm, respectively. Given that the robot is equipped with 6 infrared modules, as shown in Figure 4, arranged in a specific order, the maximum number of neighbors of robot ously is 6.  Table 1.   Without adding information, the default communication range and default sensing range r s of these infrared modules are approximately 180 mm. Finally, the robot's linear speed can reach 35 mm/s. Due to the communication speed not being fast enough, the maximum linear speed has been set to 20 mm/s according to our experiments. The default initiation constants and parameters used in this section were listed in Table 1. The test area for the swarm robots in this experiment is a square-shaped workspace measuring 2000 × 2000 mm 2 , marked by a black line to indicate the boundaries. Three infrared sensors are installed at the bottom of each robot to determine the boundaries of the work area. The message transmission process, which contains the message protocol and estimated value time of the robot, takes approximately 10 ms.

Parameter
Since the swarm's decision-making is based on the estimated encounter rate of the robots, the value that all robots converge to is crucial. Therefore, the convergence of estimated encounter rates of the swarm is first evaluated under the static swarm size. In this case, we set ϑ = 0, i.e., the consensus process will continue to run until the experiment is terminated by the experimenter. Three experiments, in which the swarm size is set to 20, 40 and 60, are conducted to evaluate the convergence. According to Equations (11) and (16), the desired encounter rates π e ∈ {0.4811, 0.7339, 0.865} correspond to N ∈ {20, 40, 60}. In order to obtain the results, a central server was set up for the task of collecting data from all robots in the swarm. Each robot was equipped with a Wi-Fi communication system previously connected to the server. The robot will continuously stream its data to the server, and the type of data collected depends on the experiment. For this experiment, robots presenting in the workspace will continuously transmit their current estimated encounter rate to the server. The results of these experiments are plotted in Figure 5.
20, 40 and 60, are conducted to evaluate the convergence. According to Equations (11) and (16), the desired encounter rates   . In order to obtain the results, a central server was set up for the task of collecting data from all robots in the swarm. Each robot was equipped with a Wi-Fi communication system previously connected to the server. The robot will continuously stream its data to the server, and the type of data collected depends on the experiment. For this experiment, robots presenting in the workspace will continuously transmit their current estimated encounter rate to the server. The results of these experiments are plotted in Figure 5.  In Figure 5, at the initial time of all conducted experiments, the estimated encounter rate of the robots is unknown, so the time from the beginning to the appearance of the first complete estimated robot is not recorded. The values min(π e ) and max(π e ) are only recorded when any robot enters the consensus process; therefore, at the initial time on the graphs, min(π e ) = max(π e ). However, soon after, as other robots join the consensus process, the range between the maximum and minimum estimated encounter rates begins to increase, leading to a rise in range(π e ). The consensus process gradually decreases range(π e ) until the values converge if t → ∞ . During the consensus process, not all communication between robots is successful, which can cause the swarm to deviate from the original mean value of the encounter rate. Specifically, in the case of π e = 0.4811, at t = 650s, when range(π e ) < ϑ satisfies the consensus process condition, then 0.4736 ≤π e,i ≤ 0.474, ∀R i ∈ S. However, this deviation is not significant enough to affect the collective decision of the swarm.
Based on the results of the experiments, it can be affirmed that the convergent rate of the encounter rate is dependent on the density of the swarm, but not in a linear fashion. In general, as the number of robots in the swarm increases, the number of transmissions required for achieving a consensus also tends to increase. This is because each robot needs to communicate its current state to its neighbors in order to reach a consensus, and the number of neighbors increases with the number of robots. As a result, the overall communication overhead increases. However, this relationship may not always be straightforward, as the nature of the coordination problem, communication protocol and other factors can also impact the number of transmissions required. In our case, since the workspace remains constant, the encounter rate increases as the swarm size increases. As a result, the consensus time does not depend linearly on the swarm density.
To be able to demonstrate that the method is available for a swarm of robots with varying sizes, an experiment was performed on an initial swarm size N(0) = 20, and a new robot was added every minute. The desired encounter rate π e,d is set to 0.8. The robot swarm is tasked with continuously making collective decisions about whether the current population of robots will satisfy a given desired encounter rate. The results of the experimental process are shown in two graphs: (1) range(π e ), E(π e ) and π e over time; (2) different number of robot decisions over time. Snapshots of this experiment are recorded and shown in Figure 6. According to Figure 7, the mean of the estimated encounter rate over the swarm is underestimated compared to the actual encounter rate due to the latency of the proposed According to Figure 7, the mean of the estimated encounter rate over the swarm is underestimated compared to the actual encounter rate due to the latency of the proposed algorithm. When new robots are added, the desired encounter rate increases instantly, but the encounter rate estimation value for previous robots depends on the robot density in the past. These robots only update the new value when they complete the sync process and start a new estimation process. Therefore, if the change rate of the desired encounter rate increases at a higher rate, this requires the algorithm to respond faster; otherwise, the difference between the desired encounter and mean of the estimated encounter rate will increase significantly, resulting in the robot's inability to make accurate decisions. algorithm. When new robots are added, the desired encounter rate increases instantly, but the encounter rate estimation value for previous robots depends on the robot density in the past. These robots only update the new value when they complete the sync process and start a new estimation process. Therefore, if the change rate of the desired encounter rate increases at a higher rate, this requires the algorithm to respond faster; otherwise, the difference between the desired encounter and mean of the estimated encounter rate will increase significantly, resulting in the robot's inability to make accurate decisions. In Figure 8, it can be observed that the consensus process, most of the time, enables the swarm to make a collective decision, except for the newly added robots that are still in the estimating process. Additionally, the sync process ensures that the robots return to the estimating process almost simultaneously. Consequently, the decision delay depends on the total time taken from when the robot starts estimating the encounter rate to the end of the sync process. The threshold error and the rate of change of the encounter rate must be selected to match the latency of the method. In this case, with 0.02   and the swarm growth rate as 1 robot/min, the duration of satisfying the desired encounter rate is about 350 s. This interval allows the method to respond in time, and all robots capable of making a decision at this time interval can make the appropriate decision.  The recording of range of estimated encounter rate range(π e ), mean of estimated encounter rate E(π e ) and desired encounter rate π e over time during the experiment.
In Figure 8, it can be observed that the consensus process, most of the time, enables the swarm to make a collective decision, except for the newly added robots that are still in the estimating process. Additionally, the sync process ensures that the robots return to the estimating process almost simultaneously. Consequently, the decision delay depends on the total time taken from when the robot starts estimating the encounter rate to the end of the sync process. The threshold error and the rate of change of the encounter rate must be selected to match the latency of the method. In this case, with σ = 0.02 and the swarm growth rate as 1 robot/min, the duration of satisfying the desired encounter rate is about 350 s. This interval allows the method to respond in time, and all robots capable of making a decision at this time interval can make the appropriate decision. algorithm. When new robots are added, the desired encounter rate increases instantly, but the encounter rate estimation value for previous robots depends on the robot density in the past. These robots only update the new value when they complete the sync process and start a new estimation process. Therefore, if the change rate of the desired encounter rate increases at a higher rate, this requires the algorithm to respond faster; otherwise, the difference between the desired encounter and mean of the estimated encounter rate will increase significantly, resulting in the robot's inability to make accurate decisions. In Figure 8, it can be observed that the consensus process, most of the time, enables the swarm to make a collective decision, except for the newly added robots that are still in the estimating process. Additionally, the sync process ensures that the robots return to the estimating process almost simultaneously. Consequently, the decision delay depends on the total time taken from when the robot starts estimating the encounter rate to the end of the sync process. The threshold error and the rate of change of the encounter rate must be selected to match the latency of the method. In this case, with 0.02   and the swarm growth rate as 1 robot/min, the duration of satisfying the desired encounter rate is about 350 s. This interval allows the method to respond in time, and all robots capable of making a decision at this time interval can make the appropriate decision.

Conclusions
In this study, a methodology that enables robot swarms to collectively assess whether their actual swarm density exceeds, is insufficient or is approximately comparable to a specified desired swarm density is introduced. The main goal of the proposed method is to enable the robots to collectively estimate the swarm density by assessing how frequently they interact with their neighbors, which will enable the swarm to come to a consensus. The proposed method does not require robots to have knowledge about their workspace, swarm size or their localization in the workspace. However, the trajectories of the robots in the swarm must be uniformly ergodic and the communication system must be a bidirectional communication with explicit messages. The experiments conducted on our proposed swarm robot platform show that the method is applicable to a dynamic swarm.