{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Examples\n", "\n", "These examples show some basic functions of PySwarming, like target, aggregation, and repulsion.\n", "\n", "For more examples, you can see the [notebooks](https://github.com/mrsonandrade/pyswarming/tree/main/notebooks) and [examples](https://github.com/mrsonandrade/pyswarming/tree/main/examples) directories of PySwarming." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Target behavior" ] }, { "cell_type": "code", "execution_count": null, "id": "051ef3c4", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "# importing the swarm creator\n", "import pyswarming.swarm as ps\n", "\n", "# creating the swarm\n", "my_swarm = ps.Swarm(n = 10, # number of robots\n", " linear_speed = 0.5, # linear speed of each robot\n", " dT = 1.0, # sampling time\n", " deployment_point_limits = [[0.0, 0.0, 0.0], [5.0, 5.0, 0.0]], # lower and upper limits for the position deployment\n", " deployment_orientation_limits = [[0.0, 0.0, 0.0], [0.0, 0.0, 2*3.1415]], # lower and upper limits for the orientation deployment\n", " distribution_type = 'uniform', # type of distribution used to deploy the robots\n", " plot_limits = [[-50.0, 50.0], [-50.0, 50.0]], # plot limits x_lim, y_lim\n", " behaviors = ['target']) # list of behaviors\n", "my_swarm.behaviors_dict['r_out']['target']['T'] = [-40, -40, 0] # setting the target position [x, y, z]\n", "anim = my_swarm.simulate(mode='anim')\n", "\n", "from IPython.display import HTML\n", "HTML(anim.to_jshtml())" ] }, { "cell_type": "markdown", "id": "35bcb062", "metadata": {}, "source": [ "## Aggregation behavior" ] }, { "cell_type": "code", "execution_count": null, "id": "32e10bb6", "metadata": {}, "outputs": [], "source": [ "# importing the swarm creator\n", "import pyswarming.swarm as ps\n", "\n", "# creating the swarm\n", "my_swarm = ps.Swarm(n = 10, # number of robots\n", " linear_speed = 0.5, # linear speed of each robot\n", " dT = 1.0, # sampling time\n", " deployment_point_limits = [[-40.0, -40.0, 0.0], [40.0, 40.0, 0.0]], # lower and upper limits for the position deployment\n", " deployment_orientation_limits = [[0.0, 0.0, 0.0], [0.0, 0.0, 2*3.1415]], # lower and upper limits for the orientation deployment\n", " distribution_type = 'uniform', # type of distribution used to deploy the robots\n", " plot_limits = [[-50.0, 50.0], [-50.0, 50.0]], # plot limits x_lim, y_lim\n", " behaviors = ['aggregation']) # list of behaviors\n", "anim = my_swarm.simulate(mode='anim')\n", "\n", "from IPython.display import HTML\n", "HTML(anim.to_jshtml())" ] }, { "cell_type": "markdown", "id": "0d6c573c", "metadata": {}, "source": [ "## Repulsion behavior" ] }, { "cell_type": "code", "execution_count": null, "id": "014abcee", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "# importing the swarm creator\n", "import pyswarming.swarm as ps\n", "\n", "# creating the swarm\n", "my_swarm = ps.Swarm(n = 10, # number of robots\n", " linear_speed = 0.5, # linear speed of each robot\n", " dT = 1.0, # sampling time\n", " deployment_point_limits = [[0.0, 0.0, 0.0], [5.0, 5.0, 0.0]], # lower and upper limits for the position deployment\n", " deployment_orientation_limits = [[0.0, 0.0, 0.0], [0.0, 0.0, 2*3.1415]], # lower and upper limits for the orientation deployment\n", " distribution_type = 'uniform', # type of distribution used to deploy the robots\n", " plot_limits = [[-50.0, 50.0], [-50.0, 50.0]], # plot limits x_lim, y_lim\n", " behaviors = ['repulsion']) # list of behaviors\n", "anim = my_swarm.simulate(mode='anim')\n", "\n", "from IPython.display import HTML\n", "HTML(anim.to_jshtml())" ] }, { "cell_type": "markdown", "id": "50eca133", "metadata": {}, "source": [ "## Aggregation + Repulsion + Target behaviors" ] }, { "cell_type": "code", "execution_count": null, "id": "983c7cd3", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "# importing the swarm creator\n", "import pyswarming.swarm as ps\n", "\n", "# creating the swarm\n", "my_swarm = ps.Swarm(n = 10, # number of robots\n", " linear_speed = 0.5, # linear speed of each robot\n", " dT = 1.0, # sampling time\n", " deployment_point_limits = [[0.0, 0.0, 0.0], [5.0, 5.0, 0.0]], # lower and upper limits for the position deployment\n", " deployment_orientation_limits = [[0.0, 0.0, 0.0], [0.0, 0.0, 2*3.1415]], # lower and upper limits for the orientation deployment\n", " distribution_type = 'uniform', # type of distribution used to deploy the robots\n", " plot_limits = [[-50.0, 50.0], [-50.0, 50.0]], # plot limits x_lim, y_lim\n", " behaviors = ['aggregation', 'repulsion', 'target']) # list of behaviors\n", "my_swarm.behaviors_dict['r_out']['target']['T'] = [-20, -20, 0] # setting the target position [x, y, z]\n", "anim = my_swarm.simulate(mode='anim')\n", "\n", "from IPython.display import HTML\n", "HTML(anim.to_jshtml())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.0 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.0" }, "vscode": { "interpreter": { "hash": "7e1998ff7f8aa20ada591c520b972326324e5ea05489af9e422744c7c09f6dad" } } }, "nbformat": 4, "nbformat_minor": 5 }