Getting Started
Depending on your knowledge of Python and swarm behaviors, you can take two approaches to using PySwarming:
Simple and low-code simulations: start using the PySwarming.Swarm class, which allows the creation of virtual swarms to be used with some behaviors functions.
Custom animated simulations: here you are able to use all the available behaviors, however, you will need to code a little bit more, i.e., the creation of the swarm, the animation, and so on.
Below you have examples of each approach mentioned above. For more examples, you can see the notebooks and examples directories of PySwarming.
(Approach 1) Low-code: PySwarming.Swarm
Non-Beginners: If you’re already familiar with Python and swarm behaviors, you can see a more customized example here.
Simulating repulsion behavior among the swarm
The idea of this simulation is to use the low-code tool from PySwarming, which enables us to carry out simplified animations with some behaviors.
Firstly, we need to set some parameters to create our swarm, such as the number of robots, the linear speed of the robots, and so on. After that, we simply call simulate()
.
For details, see the code below.
[1]:
%matplotlib inline
# importing the swarm creator
import pyswarming.swarm as ps
# creating the swarm
my_swarm = ps.Swarm(n = 10, # number of robots
linear_speed = 0.5, # linear speed of each robot
dT = 1.0, # sampling time
deployment_point_limits = [[0.0, 0.0, 0.0], [5.0, 5.0, 0.0]], # lower and upper limits for the position deployment
deployment_orientation_limits = [[0.0, 0.0, 0.0], [0.0, 0.0, 2*3.1415]], # lower and upper limits for the orientation deployment
distribution_type = 'uniform', # type of distribution used to deploy the robots
plot_limits = [[-50.0, 50.0], [-50.0, 50.0]], # plot limits x_lim, y_lim
behaviors = ['repulsion']) # list of behaviors
anim = my_swarm.simulate(mode='anim')
from IPython.display import HTML
HTML(anim.to_jshtml())
[1]: