Simple Examples

These examples show some basic functions of PySwarming, like target, aggregation, and repulsion.

For more examples, you can see the notebooks and examples directories of PySwarming.

Target behavior

[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 = ['target']) # list of behaviors
my_swarm.behaviors_dict['r_out']['target']['T'] = [-40, -40, 0] # setting the target position [x, y, z]
anim = my_swarm.simulate(mode='anim')

from IPython.display import HTML
HTML(anim.to_jshtml())
[1]:
../_images/example_notebooks_02_Simple_Examples_2_1.png

Aggregation behavior

[2]:
# 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 = [[-40.0, -40.0, 0.0], [40.0, 40.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 = ['aggregation']) # list of behaviors
anim = my_swarm.simulate(mode='anim')

from IPython.display import HTML
HTML(anim.to_jshtml())
[2]:
../_images/example_notebooks_02_Simple_Examples_4_1.png

Repulsion behavior

[3]:
%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())
[3]:
../_images/example_notebooks_02_Simple_Examples_6_1.png

Aggregation + Repulsion + Target behaviors

[4]:
%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 = ['aggregation', 'repulsion', 'target']) # list of behaviors
my_swarm.behaviors_dict['r_out']['target']['T'] = [-20, -20, 0] # setting the target position [x, y, z]
anim = my_swarm.simulate(mode='anim')

from IPython.display import HTML
HTML(anim.to_jshtml())
[4]:
../_images/example_notebooks_02_Simple_Examples_8_1.png