PySwarming: a research toolkit for Swarm Robotics

When considering a system composed of a group of robots, swarm robotics is an approach that can be used to coordinate this group. These swarms can be inspired or not by social insects or other animal societies (Trianni, 2008), where basic behaviors are usually used to compose complex tasks. These previously mentioned basic behaviors have been studied for a long time, with applications, for example, to flocks, herds, and schools (Reynolds, 1987) and multi-robot teams (T. Balch & Arkin, 1998). Here we introduce PySwarming, a tool that makes easy the coordination of swarms and serves as a centerpiece, organizing different methods developed in the swarm robotics field. Its flexibility (written in Python) and customizability (easily customized by users) encourage interaction and scientific progress in the research community.


Introduction
Controlling a system composed of a group of robots can be a challenge, then, swarm robotics is an approach that is widely used to coordinate this kind of system.Furthermore, the changes that the field of swarm robotics has experienced in the last decade are unprecedented, with various demonstrations showing the potential of this technology (Dorigo et al., 2021).Moreover, it is important to note that swarm robotics is a subfield of multi-robot systems, itself a subfield of mobile robot research (Dias et al., 2021).Additionally, these swarms may or may not be inspired by social insects and other animal societies (Trianni, 2008), where basic behaviors are typically used to compose complex tasks.The aforementioned behaviors have long been studied and applied, for instance, to herds, flocks, schools, etc. (Reynolds, 1987;Toner & Tu, 1998), self-driven particles (Vicsek et al., 1995), large collections of robots (Reif & Wang, 1999;Spears & Gordon, 1999), and multi-robot teams (T.Balch & Arkin, 1998).

Related Software Packages
For more than 20 years software for swarm robotics has been created, adapted, and tested in different ways (Calderón-Arce et al., 2022).Software packages that allow the creation of virtual scenarios and swarm robots with sensing, processing, and actuating capabilities are crucial for the swarm robotics field.These software packages may be split into two categories: (1) Swarm Simulators, which in general can simulate swarm robots with sensors and actuators, and (2) Behavior Packages, which are composed of a bunch of ready-to-use collective behaviors.Also, these software are written in different programming languages, which may be an initial barrier for new users, depending on how much this language is difficult to learn or previous knowledge by the user.
Concerning swarm robotics, (Calderón-Arce et al., 2022) presents a good review regarding swarm robotics simulators, platforms, and applications.Therefore, for software packages we have, for instance: (1) Buzz, which is a programming language for heterogeneous robot swarms (C.Pinciroli et al., 2015).It offers primitives to define swarm behaviors and also single-robot instructions; (2) ChoiRbot by (Testa et al., 2021), which is a toolbox for distributed cooperative robotics based on the Robot Operating System (ROS) 2; (3) ROS2Swarm, which is a package for applications of swarm robotics that provides a library of ready-to-use swarm behavioral primitives (Kaiser et al., 2022); (4) ARGoS, which is a multi-physics robot simulator, able to simulating large-scale swarms of robots (Carlo Pinciroli et al., 2011); (5) Stage Simulator, which provides a virtual world populated by mobile robots and sensors, along with various objects for the robots to sense and manipulate (Vaughan, 2008); (6) USARSim is a free 3D simulator similar to Gazebo (Carpin et al., 2007); (7) The Swarm-bots project (Mondada et al., 2004) is also a robotic simulator with swarm-intelligence-based control mechanisms, but it is not publicly available; (8) and TeamBots is a Java-based collection of application programs and Java packages for multiagent mobile robotics research (T.R. Balch, 1998).Table 1 shows a summary of these software and their respective category and programming languages.

Statement of Need
Concerning the Swarm Simulators, there is an enormous variety of excellent candidates, but it is hard to compare each other since each one has been developed with different objectives (Erez et al., 2015).Then, recommendations regarding this choice can be found in (Calderón-Arce et al., 2022).Regarding Behavior Packages, their objective is to offer ready-to-use collective behaviors, depending on the programming language in which they are implemented they can be used inside different simulators.However, as can noticed from the previous section, in general, different packages are written in different languages, imposing a possible barrier for new users and the use of the package inside simulators written in a different programming language.Moreover, important characteristics regarding the software are the possibility of leveraging existing datasets, develop new algorithms, and quick prototyping, which are not commonly found together.

PySwarming
Because of the lack of a cross-platform Behavior Package, we introduce PySwarming, which is a tool that facilitates the coordination of swarms and serves as a centerpiece, organizing different methods developed in the swarm robotics field.The package is written in Python, which is one of the most accessible languages for learning and prototyping nowadays.Also, differently from other Python-based packages such as ChoiRbot and ROS2Swarm that are designed to work with ROS, the PySwarming package is implemented in a way that makes possible cross-platform use.In addition, the PySwarming package comes with a simple ready-to-use simulation feature, which helps lower the barrier for newcomers to the field.
Then, considering the challenge of organizing the various methods developed in the swarm robotics field, PySwarming comes as a focal point, being flexible (written in Python) and customizable (can be easily adapted by the user), increasing the interaction of the researcher community and the advance of science.Also, PySwarming's characteristic is to make the implementations easy to read, keeping the syntax simple and closer to their sources.For example, the target algorithm by (Zoss et al., 2017) is easily comparable with the mathematical formula of their article.
PySwarming differs from Buzz and TeamBots mainly by the fact that it focuses on swarm behaviors and it is written in Python, which has a thriving ecosystem of third-party libraries.Also, implementations like ChoiRbot and ROS2SWARM require ROS to run, which makes PySwarming more suitable for obtaining swarm behaviors through different platforms other than ROS.Lastly, unlike ARGoS, Stage, and USARSim the main goal of PySwaming is not to be a simulator itself, but a common place for different swarm coordination methods and other tools.
Concerning the algorithms, PySwarming contains implementations from different authors, for instance, Leaderless Coordination (Vicsek et al., 1995), Preferred Direction (Couzin et al., 2005), Aggregation (Zoss et al., 2017), and so on.Also, these algorithms are based on different design methods (Brambilla et al., 2013), for instance, a behavior-based design like the attraction-repulsion algorithm (for details see (Spears et al., 2004)) can drive the robotic swarming employing virtual forces, where the achieved configuration relies on minimizing the system's potential energy.More explanations regarding the algorithms and their use can be found in the API and PySwarming documentation.Also, an example usage (aggregation + heading consensus + repulsion) is described below.

Simulation Example
To start our example, we will define a set of four robots assuming we have access to their positions and orientations.Initially, they are positioned far from each other, and also they have different orientations, as can be observed in Figure 1.The above simulation can be done by using other PySwarming behaviors, such as Attraction and Alignment, with just a few lines of code, which demonstrates the simplicity of PySwarming.
Finally, the code for this simulation can be found in our examples directory.

How to create a new behavior and extend the package
To show PySwarming's flexibility and customizability here we illustrate a practical example.
Then, imagine that we want to create a flocking behavior.Based on the literature it is known that the classical "flocking"model is composed of three terms: (1) aggregation, (2) avoidance, and (3) alignment (Zoss et al., 2017).As we have all these previous behaviors implemented in PySwarming, you can simply do: Then, we have created a new behavior based on existing ones.Where, *args are the arguments that will be used by these functions, for details, please see the PySwarming documentation.However, you have the freedom to extend the package and implement other models, add new features, and so on, detailed instructions can be found here.

Algorithms covered
This library includes the following algorithms to be used in swarm robotics: • Leaderless heading consensus: the collective performs heading consensus (Vicsek et al., 1995); • Inverse power: adjustable attraction and repulsion laws (Reif & Wang, 1999); • Spring: allows the robots to maintain a desired distance between them (Reif & Wang, 1999); • Force law: mimics the gravitational force (Spears & Gordon, 1999); • Repulsive force: makes the individuals repulse each other (Helbing & Vicsek, 2000); • Body force: introduces a body force that considers the radii of the robots (Helbing & Vicsek, 2000); • Inter robot spacing: allows the robots to maintain a desired distance between them (Leonard & Fiorelli, 2001); • Dissipative: a dissipative force that reduces the "energy" of the robots (Leonard & Fiorelli, 2001); • Leader Following: the collective performs heading consensus with a leader (Jadbabaie et al., 2003); • Collision Avoidance: the robot stays away from neighbors in the vicinity (Couzin et al., 2005); • Attraction and Alignment: the robot becomes attracted and aligned (Couzin et al., 2005); • Preferred Direction: the robot has a preference to move toward a preset direction (Couzin et al., 2005)

Conclusion
Presented in this work is PySwarming, a package that facilitates the coordination of swarms and serves as a centerpiece, organizing different methods developed in the swarm robotics field.This package provides ready-to-use collective behaviors implementations based on the work of different authors.As shown through the examples, the fact that it is written in Python makes it more flexible and easily customizable, allowing quick prototyping.Therefore, PySwarming fills an important space, regarding the organization of the different swarming robotics methods developed over the last decade, and all the characteristics of the package confer a lower barrier for newcomers to the field, which helps to increase the interaction of the researcher community and the advancement of science.

Figure 1 :
Figure 1: The initial state of the four robots.Each colored circle is a robot and the arrows indicate their orientation.The iteration number is the red text.

Figure 2 :
Figure 2: Intermediate (left) and final (right) state of the four robots.The gray path is the plot of the last 30 iterations of each robot.