{'fraction_non_alphanumeric': 0.024786899955136832, 'fraction_numerical': 0.00452370270674443, 'mean_word_length': 5.002917414721724, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Collective Conditioned Reflex: A Bio-Inspired Fast Emergency Reaction Mechanism for Designing Safe Multi-Robot Systems

A multi-robot system (MRS) is a group of coordinated robots designed to cooperate with each other and accomplish given tasks. Due to the uncertainties in operating environments, the system may encounter emergencies, such as unobserved obstacles, moving vehicles, and extreme weather. Animal groups such as bee colonies initiate collective emergency reaction behaviors such as bypassing obstacles and avoiding predators, similar to muscle-conditioned reflex which organizes local muscles to avoid hazards in the first response without delaying passage through the brain. Inspired by this, we develop a similar collective conditioned reflex mechanism for multi-robot systems to respond to emergencies. In this study, Collective Conditioned Reflex (CCR), a bio-inspired emergency reaction mechanism, is developed based on animal collective behavior analysis and multi-agent reinforcement learning (MARL). The algorithm uses a physical model to determine if the robots are experiencing an emergency; then, rewards for robots involved in the emergency are augmented with corresponding heuristic rewards, which evaluate emergency magnitudes and consequences and decide local robots' participation. CCR is validated on three typical emergency scenarios: \textit{turbulence, strong wind, and hidden obstacle}. Simulation results demonstrate that CCR improves robot teams' emergency reaction capability with faster reaction speed and safer trajectory adjustment compared with baseline methods.


I. INTRODUCTION
A Multi-robot system (MRS) is a system consisting of a collection of coordinated robots. Compared with a single robot system, MRS often has a larger action scope and can handle more complex tasks with multiple targets, larger workspaces, and more sophiscated mission procedures. For example, multiple unmanned aerial vehicle (UAVs) and multiple unmanned ground vehicle (UGVs) teams have been successfully applied to disaster relief, explosive ordinance disposal, structural inspection, reconnaissance, cargo freight, hostage search, and many other complex scenarios.
MRS deployments usually rely on real-time human teleoperation. However, the complexity of these tasks presents a heavy workload for the operator, leading to delayed or unsafe guidance for robots. Unexpected emergencies that require rapid adjustments of the MRS inevitably happen during missions, exacerbating the problem. This causes performance degradation and physical system damages to the robot team and can even threaten the safety of personnels involved [1], [2]. Therefore, to ensure task success and safety, an emergency reaction mechanism is highly desired for realworld MRS deployments.
Due to the dynamic and uncertain nature of emergencies and the complexity of MRS control, it is challenging to ensure the safety of MRS in real-world deployments. Traditional autonomous MRS mainly relies on centralized control to plan paths [3], [4]. However, centralized emergency reactions require going through the central decision-making node, limiting reaction speed, and creating a single point of failure which is fragile during an emergency. On the other hand, simple decentralized control suffers from the opposite problem of weak coordination among multiple robots and global suboptimality in task executions. A common drawback of both centralized and decentralized methods is the failure to incorporate the physical properties such as the type and degree of emergent situations, thus decreasing overall task performance. In addition, traditional planning methods lack robustness against unexpected emergencies which have not been sufficiently explored by the robots.
To address these issues, the bio-inspired Collective Conditioned Reflex (CCR) algorithm is developed for fast emergency reactions. Similar to some other bio-inspired MRS researches [3], [5], CCR is inspired by the collective behaviors of animal groups responding to predators and obstacles [6]. When a fish school encounters a predator, the fish making the contact will quickly react and escape together along safe directions. Meanwhile, they also share the emergency information with other nearby fish, who adjust their behaviors to help the whole school to avoid the predator. These behaviors of local-global collective emergency reaction maximally avoid the loss in danger as the most urgent fish/robots react first and reduce response time by using local analysis and avoiding going through a global analysis. This collective intelligence in emergency reaction effectively helps an animal team to avoid danger; the reaction mechanism is similar to spinal reflexes in human muscles, which are fast response mechanisms that react to stimulation without going through the central decision-maker -the brain [7]. These collective behaviors help them react to dangers preemptively and rapidly, providing safety guidance at an early stage for the whole team. Such observations inspire us to apply a similar approach in training multi-robot systems (Fig. 1). In particular, we encourage pioneer robots encountering danger to locally collaborate to avoid dangers without going through centralized analysis for global optimal strategy searching; meanwhile, pioneer robots share danger information with other robots to guide their motion behaviors to achieve the goal of team emergency avoidance.
The contributions in this study are mainly three folds: (a) A novel bio-inspired emergency reaction model is developed by mimicking animals' emergency reaction behavior. The module can be integrated with any existing cooperative multi-agent reinforcement learning algorithm to improve the emergency reaction capabilities of robot teams. (b) An environment-adaptive safe learning framework is developed by considering safety assessment and safety adjustment. This framework provides a pipeline for customizing the robot teams' trade-offs between safety and efficiency when handling different levels of dangers. (c) Emergencies typically encountered by multi-UGV and multi-UAV systems are summarized and modeled into three scenarios: hidden obstacle, turbulence, and strong wind. The simulation results reveal that with a small sacrifice of efficiency, CCR significantly reduces the risky robotic behavior and largely improves the MRS resilience towards common unexpected dangers.

II. RELATED WORK
Safe Multi-Robot System. Due to its attractive capability in performing large-scale and complex tasks, the safety of robot teams has been researched in recent years. Some methods [8], [9], [10] used a prior map to help avoid unexpected or dynamic obstacles. One of the popular ways to achieve safety in the MRS was eliminating dangerous behaviors among robots and between robots and the environment [11], [12]. Such algorithms, like control barrier function [13], [14], formulated the problem into a constrained optimization problem and planned collision-free trajectories. A more relaxed approach tolerated unsafe behaviors and robot failures [15], [16], [17], which was more robust to complex environments. However, both methods are based on an explicit mathematical model of the emergency situation, which assumes full knowledge of its type, size, location, and intensity. On the other hand, the CCR algorithm introduced in this paper can adapt to emergency situations with high randomness and poor observability.
Safe Reinforcement Learning for MRS. There has been an increasing effort to incorporate reinforcement learning (RL) into safe multi-robot systems. A carefully-designed reward function was usually a necessity for such methods to work. Existing related works were classified into two paradigms: communicative emergency reflex and non-communicative emergency reflex. In [18], a multi-scenario multi-stage training framework was developed to train a fully decentralized sensor-level collision avoidance policy for MRS. To improve system coordination without adding more communication assumptions, Chen et al. proposed to use value networks to directly generate trajectories, which showed great performance [19] for non-communicating MRS. Although these previous works developed safer robot behaviors, important real-world metrics such as minimum safety distance and group response time were not considered. In contrast, CCR offers a tunable parameter that controls these properties through controlling the trade-off between efficiency and safety. This allows for more leniency when applying to real-world systems.

III. COLLECTIVE CONDITIONED REFLEX (CCR)
Ensuring safety and efficiency during emergency reactions in multi-robot systems has been an open research topic. Existing approaches tend to focus only on control commands at the physical level while ignoring heuristic awareness of the danger that the robot itself can build. To help build this recognition and use it to achieve better performance, we propose Collective Conditioned Reflex (CCR), a novel bioinspired emergency reaction mechanism that can be attached to most MARL algorithms.
Preliminaries of MRS Reinforcement Learning. The standard setup of reinforcement learning assumes a Markov decision process (MDP) model for the agent-environment interaction. A MDP consists of a 5-tuple (S, A, R, T , γ), representing the set of states, set of actions, reward function, transition function, and the discount factor, respectively. The agent is tasked with learning a policy π : S × A → [0, 1] such that the total expected discounted reward t γ t r t is maximized. This study uses the multi-agent extension of the MDP, where each of the N agents has its own state s 1 , . . . , s N and action a 1 , . . . , a N . The agents are tasked with maximizing their own expected total discounted reward.

A. Overview of CCR Design
Fig. 2 is an overview of the CCR framework. On the lefthand side, a MARL algorithm learns a policy for each of the N robots by interacting with the environment. Let s i t , r i t , and a i t denote the state, the reward, and the action of ith robot at time t, respectively. The CCR module comes into play by redefining the reward and state received by the robots based on the emergency score derived from the learned physical model. The physical model is a group of polynomial dynamics functions with learnable parameters. Its input is robots' control commands while the output is the robots' next states. The previous step state s i t−1 and action a i t−1 are stored and used to compute the ideal current stateŝ i t for each robot. This represents how the environment dynamics is expected to flow without disturbance. Then, the difference betweenŝ i t and s i t is used to compute an emergency score for each robot, which is appended to other robots' states within robot i's communication range. This gives the robots more explicit information about the emergency. Then, the emergency scores are used to compute an intrinsic reward for each robot via a heuristic algorithm, which is added to the reward received from the environment. The intrinsic reward provides the robots with additional information about the potential consequences of actions. Robots will be discouraged from getting close with other robots in danger and encouraged to approach other robots in safety.

B. Emergency Score Assessment
The idea of emergency score derives from the perception of animals to external emergencies and is used to measure how dangerous they are. In general, animal groups have different levels of responses to crises of different emergency scores. In MRS, emergency scores can remind robots to learn adaptive local reaction policies to different levels of danger. CCR assumes access to the previous step transition of robot i at time t − 1: The predicted statesŝ i t is obtained by passing the last step transition to the physical model: where the states s i t−1 include the following information: the Cartesian coordinates of robot i, the velocity of robot i, the distances and directions to other robots, the distance and direction to the destination. The emergency score is computed as a form of prediction error and then propagated to other nearby robots within its communication range: In practice, we observe that smoothing the emergency score with a rolling average can further strengthen the performance. Let m be the number of time steps to take on average. Then, This step is repeated for all N robots.

C. Potential Consequences Evaluation
Reward in reinforcement learning can be understood as an evaluation of how advantageous the action of a robot is. In the traditional setting, this evaluation is done by the environment, and the robot gets the reward as a return. However, it is also possible for the robot to evaluate with a metric different than the environment. This is the motivation behind intrinsic reward. In this work, the intrinsic reward is designed to estimate the potential consequences caused by the emergency.
Specifically, the emergency score introduced in the previous section is used to compute the intrinsic reward as the estimation of potential consequences. The intrinsic reward is then augmented to the reward returned by the environment to form the final reward used to train policy for each robot.
First, the emergency scores for robots are compared pairwise. Intuitively, within each pair, the robot with the lower emergency score should be at a safer state than the other robot. When this difference is significant, it hints the existence of an "emergency" at the other robot's location. For example, when robot i is at a safer state than robot j, E i < E j and therefore robot i should be rewarded for moving away from j and penalized for moving towards j. This motivates us to define the change in distance h i (j), which corresponds to the change in Euclidean distance between robot i and robot j from time t to t + 1, Then, we define the intrinsic reward for robot i induced by robot j, In the previous example, R i in (j) is negative when robot i is moving towards robot j, and positive when robot i is moving away from robot j. The opposite is true when robot j is at a safer state than robot j, which means E j < E i . Note that robot i computes its intrinsic reward entirely through observing the effect of the emergency on robot j, assuming no knowledge on the emergency itself. Summing the intrinsic reward induced by other robots will give us the final intrinsic reward for robot i: Each r i t received from the environment is added with the intrinsic reward, with a tunable λ coefficient multiplying R i in . The augmented reward replaces the reward obtained from the environment, and the transition is then saved to the experience replay or summed into the return. Regular MARL algorithms take on from here.

D. Developing Emergent Collective Behaviors
Emergency scores prompt robots with immediate emergency hazard information which will stimulate them to take the corresponding reactions at the same time. Otherwise, robots will miss the best first reaction time window that may lead to global failure. Since the estimation of potential consequences is computed from the emergency scores of other robots, the behavior of each robot is influenced heavily by the states and actions of its neighbors. Thus, CCR enhances emergent behavior in the MRS by actively propagating the emergency information from local to the whole team. Local robots in the danger zone will be self-organized to form local first response to the emergency.

A. Simulation Setting
A simulated environment is constructed to evaluate the effectiveness of the CCR algorithm. Similar to other related researches [3], [20], [21], the goal of the simulations is to investigate how the behaviors of the robots change when CCR is applied and to quantitatively measure the effect of this change. Our simulation environment is based on the Multi-Agent Particle Environment 1 [22], a simple planar multi-agent particle world based on basic simulated physics with velocity as control inputs. The environment is modified to include more objects and improve rendering. We implement three scenarios to simulate how MRS might encounter dangers in the real world: turbulence, strong wind, and hidden obstacle. Specifically, turbulence and strong wind aim at simulating multi-UAV systems under the influence of unpredictable turbulent or laminar airflow, while hidden obstacle aims at simulating multi-UGV systems encountering obstacles with low detectability or in adversarial weather. The simulation environment, although basic, serves as a proof of concept for CCR's overall framework and fundamental idea. Details of the simulation setting and scenarios are shown in Fig. 3 and introduced as follows: Emergency 1: turbulence: The robots are tasked to find their way to a circular target area marked with green color. 1 https://github.com/openai/multiagent-particle-envs A circular turbulence area will appear on their way and apply forces with random directions on them. Coordinates of the turbulence area is only observable for robots inside the area. The task is considered successful for each robot that arrives in the target area.
Emergency 2: strong wind: The robots are tasked to navigate to a green target point. A square strong wind area with random sizes will appear on their way and apply force with a fixed direction. Coordinates of the strong wind area is only observable for robots inside the area. The task is considered successful for each robot that arrives at the other side of the strong wind area.
Emergency 3: hidden obstacle: The robots are tasked to navigate to a green target point. A rectangular solid obstacle with random lengths is located on their way. Robots can only sense whether they are in collision with the obstacle, but not the coordinates of the obstacle. The task is considered successful for each robot that arrives at the other side of the obstacle.
In all scenarios, the robots are homogeneous and have a fixed communication range. Any robot can send and receive simple information such as a floating point number to other robots only if they are within its communication range. The environmental rewards in such three scenarios are all based on the distance from each robot to the destination.
Metrics. We evaluate the performance of MARL algorithms equipped with the CCR module with four metrics designed to quantify both the safety and the efficiency of the robot trajectories. The safety aspect is evaluated with the average distance from each robot to the center of the danger area at every time step and the proportion of time steps robots are in dangerous states in the whole episode (dangerous behavior frequency). The efficiency aspect is evaluated with the proportion of robots that successfully accomplish the task (success rate) and the reward.
Baseline. Simulations are conducted with three popular MARL algorithms -independent DDPG [23], MADDPG [22], and MAAC [24] as baselines. In addition, we also implement a common safety mechanism of augmenting the external reward with a penalty term when a dangerous step is taken, named as pessimistic DDPG, pessimistic MADDPG, and pessimistic MAAC, respectively [25], [26]. We take them as baselines to help demonstrate the effectiveness of CCR in improving MRS safety. The state space is continuous for all three algorithms, but the action space is continuous only for IDDPG and MADDPG and discrete for MAAC. This is to diversify the settings that we test the CCR module on and contribute to proving the broad applicability of our approach.
To illustrate that robots equipped with CCR can have a timely reaction effect, different colors are assigned to the trajectory of robots when CCR is running in different steps. The color pattern is explained in Fig. 3. The trajectory is blue when the robot is operating normally and the CCR module is on standby, yellow when the robot senses the danger, and pink when CCR is activated and triggers an intrinsic reward. Fig. 3 also illustrates the unsafe behavior and success criteria as described above. The robot operator can tune the efficiency-safety tradeoff by changing the hyperparameter λ, which controls the weight of the intrinsic reward added to the environment reward. After conducting a parameter search, we find that setting λ = 30 gives a fairly balanced trade-off between efficiency decrease and safety improvement, and generalizes well across all three scenarios. Therefore, all simulations shown here are conducted with λ = 30. MADDPG and DDPG policies are trained for 16000 steps, and the MAAC policy is trained for 16000 × 35 steps.

B. Overall Performance
We measure the task success rate and the dangerous behavior frequency to validate CCR's overall effectiveness in safety improvement and to investigate the tradeoff between safety and efficiency. The results are shown in Tables I and  II. Compared with policies trained by the original MARL algorithms, it is found that with exception of strong wind with MAAC, the dangerous behavior frequency of those trained by CCR-aided algorithms is lower in all scenarios. On average, applying CCR can effectively reduce the dangerous behavior frequency by 42.24%. The effect on task success rates vary across different scenarios. For hidden obstacle, the success rate of policies trained by MARL+CCR is significantly higher than those of the original algorithms. For turbulence, however, MARL+CCR algorithms suffer from an average of 23.81% lower success rate. For strong wind, the success rate of MARL+CCR is higher than the original when using DDPG and MAAC, but lower when using MADDPG. This discrepancy is caused by the different dynamics between robots and the emergency in the three scenarios. For example, in hidden obstacle, MARL policies are often held back by the obstacle, which simultaneously increases chance of collision and decreases the task success rate. MARL+CCR policies can more effectively circumvent the obstacle, which decreases chance of collision and increases the task success rate. On the other hand, the turbulence area in turbulence can be traveled through, which leads to both higher success rate and higher dangerous behavior frequency for MARL policies. MARL+CCR policies often try to avoid the turbulence area, which contributes to decreased dangerous behavior frequency but also decreased success rate.
Compared with policies trained by the modified pessimistic MARL algorithms, those trained by CCR-aided algorithms are safer in all scenarios. On average, the dangerous behavior frequency of MARL+CCR policies is 38.37% lower than MARL (pessimistic) policies. The task success rate for MARL+CCR algorithms is higher than that of MARL (pessimistic) algorithms in 7 out of 9 cases, with the exception being MADDPG in strong wind and MAAC in turbulence. The success rate is increased by 35.90% on average. The pessimistic approach cannot achieve ideal performance because information about the emergency events is sparse and myopic in nature: robots can only sense collision with the hidden obstacle but not its exact location and size, and they can only observe the turbulence or wind area when they are already inside these areas. This lack of information removes assumptions about prior knowledge to the environment, making MARL algorithms more practical for real world MRS applications. Because MARL (pessimistic) algorithms cannot associate the pessimistic penalty with an apparent change in the observations, they will either fail to improve safety or overfit to an overly cautious policy and reduce task success rate.
To examine the effect of CCR during training, the timedriven plot of dangerous behavior frequency and task success rate during training for both original MADDPG and MADDPG+CCR are shown in Fig. 5. It is found that CCR facilitates safe exploration in the training process, with an episodic dangerous behavior frequency of mostly below 0.20, compared to the maximum of 0.56 for the original MADDPG. Meanwhile, the success rate of MADDPG+CCR remains higher or on par with that of the original MADDPG throughout training. During the training process, the cumulative number of dangerous behaviors of MADDPG+CCR is only 28.09% of that of MADDPG. We examine the results from other scenarios and algorithms and observed similar trends. These results show that CCR is capable of reducing training time dangerous behavior frequency in a wide range of MRS tasks. This offers great potential for deploying the algorithm to real-world systems, where exploration in complex environments can be costly and dangerous.
Meanwhile, we also notice some limitations of our approach. From Fig. 5, we can observe that CCR may slow down the convergence rate compared with baselines, which can be attributed to the appended states (higher dimensions) and intrinsic rewards being more difficult to infer. Another disadvantage is that CCR needs to trade efficiency for safety to some extent. Fig. 4 illustrates how the behavior of the robots in the hidden obstacle scenario is substantially affected when the CCR module is introduced into training. In the hidden  obstacle scenario, since the robots can only sense the obstacle when they get sufficiently close to it, all the robots trained with the baseline MADDPG algorithm will repeat the process of running into the obstacle, then moving away from it. On the other hand, for the robots trained with CCR-aided MADDPG, only the first two robots will run into the obstacle, while others steer away from it without even observing the obstacle. This is because the obstacle is not present in the physical model, and therefore robots that run into the obstacle will have high emergency scores because they do not expect there to be an obstacle. Other robots will thus receive positive intrinsic rewards for moving away from them and negative intrinsic rewards for moving towards them. Essentially, the following robots will obtain danger information from observing the emergency reaction behavior of the leading robot and react in advance. This is eventually reflected in the policy after training. The behavior is confirmed by the average distance to the obstacle in Fig.  4, which shows that in total, the robots trained with CCRaided MADDPG get much farther to the obstacle than those trained with MADDPG, by approximately 1.2x to 4.7x. We also provide a video detailing this phenomenon 2 .

V. CONCLUSION
This paper introduces Collective Conditioned Reflex (CCR), a biology-inspired fast emergency reaction module based on multi-agent reinforcement learning for multi-robot systems. In the future, more realistic 3D physical dynamic simulators can be deployed to evaluate the effectiveness of our method.