This page was automatically generated by NetLogo 5.0.
The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.
powered by NetLogo
view/download model file: formation_chain.nlogo
This is an extension of “formation_newton.nlogo,” for the book entitled “Physicomimetics: Physics-Based Swarm Intelligence.”
Multiple particles use F = ma and an elliptical “split Newtonian” force law to self-organize into chain formations.
This is the second simulation for Chapter 4 of the book, which pushes the envelope of physicomimetics. This simulation creates chain formations using a simple and elegant change to the standard physicomimetics model.
In the previous simulations we assume that the force laws are “circularly symmetric,” which means that the force is the same regardless of direction. If we want chain formations, it is possible to create them using force laws that are elliptical rather than circular. In this implementation the major axis of the ellipse is aligned with the heading of the particle (robot).
Once again, we deliberately break Newton’s third law. This occurs because the force law is no longer circularly symmetric and particles do not necessarily experience equal and opposite forces. Hence linear and angular momenta will not be conserved. Given that, what should we expect from our simulation? First, if angular momentum is violated, this should create chains that are curved. But that isn’t an issue, because we don’t want our chains to be straight lines - we want them to be able to bend according to the environment. A violation of linear momentum is more important, because the center of mass will move. However, this is not catastrophic. It suffices to have some nodes in the chain remain close to the initial cluster. In terms of practical use, we are assuming (as we have throughout this book) that robots are initially deployed from a central location. Since the applications of interest include surveillance of sewers, tunnels and caves, it is imperative that some robots remain near their original location, so that the eventual communication chain can be easily monitored.
You can place obstacles in the environment with your mouse, to create an obstacle course. The OBSTACLE_FORCE slider controls the size of the obstacles (i.e., the extent at which the repulsive obstacle force is felt).
A MAX DISTANCE monitor shows the distance between the two particles that are farthest from each other. This gives an indication of how straight (or curved) the chain formation is.
Click SETUP AGENTS to initialize the particles, and click MOVE AGENTS to have them move.
The CLEAR button will erase the particle paths, which becomes handy when particles have their pens down (more on this below).
The NUMBER_OF_PARTICLES slider allows you to control the number of particles created at initialization. Changing this slider while the simulation is running will have no effect. You can change the number of particles while the simulation is running by using the ONE IS BORN and KILL ONE buttons. However, the ONE IS BORN and KILL ONE buttons do not change the number of initial particles when the simulation is restarted by clicking SETUP AGENTS.
The ONE IS BORN button creates a new particle.
The KILL ONE button randomly kills an existing particle.
Obstacles can be placed in the environment by placing the mouse where you want the obstacle to be, and then clicking the mouse. The obstacle is shown as a green disk. The OBSTACLE_FORCE slider changes the size of the obstacle. This affects all obstacles and the change is shown visually as the sizes of the disks change.
All other sliders will affect the simulation when it is running.
Particles are initialized in a random cluster in the middle of the graphics pane, and self-organize into a chain formation. First, the particles collapse into a small linear structure. The orientation of that structure depends on the initial positions of the particles. Then the small structure slowly expands into a chain. The behavior is quite emergent.
The POWER controls the value of “p” in the generalized law. The DESIRED_SEPARATION is the desired distance between neighboring particles. The gravitational constant is computed automatically, using the theory established in Chapter 3.
Again, FRICTION is enabled. This allows the system to stabilize.
Note that when creating chain formations, angular and linear momenta are not conserved. The reason for this is explained in Chapter 4 of the book.
The large yellow circle in the simulation shows the initial center of mass of the system. A small red dot shows the current center of mass. Because linear momentum is not conserved the red dot will usually move away from the large yellow circle. However, it suffices to have some particles remain close to the large yellow circle, since that is where they are initially dispersed.
This model allows you to add and remove particles. Removing particles allows you to test how robust the system is to particle failure. Adding particles allows you to see how scalable the system is, and illustrates just how nicely new particles are incorporated into the formation.
Add particles and see what happens. Usually they are incorporated easily into the chain.
Remove particles. What happens and why?
Add obstacles while the chain is expanding.
What happens when you increase the MINOR_AXIS at the beginning of a simulation run? This parameter adjusts the width of the elliptical force law. You may need to try this a few times to get a feel for how the behavior changes.
What happens if you start with a large DESIRED_SEPARATION and then decrease the value?
What happens if you start with a small DESIRED_SEPARATION and then increase the value?
Extend the simulation so that it copes with the removal of particles and a decreasing DESIRED_SEPARATION. Chapter 12 will provide some hints.
Note, in order to change any NetLogo simulation, you must have the source code (i.e., “formation_chain.nlogo”) downloaded to your computer, as well as NetLogo itself. You can not change the code when you are running the simulation with your browser.
This simulation allows the user to create new particles and kill existing ones.
Killing a particle is accomplished via a call to the NetLogo procedure “die.”
To create a particle, the “hatch” command is used - this clones an existing particle and moves it away from the original. Also, the new particle has the “pen down,” which means that you will see the path that the particle takes. If the graphics pane becomes too busy, click on the CLEAR button.
This simulation makes use of NetLogo mouse events to allow the user to place obstacles in the environment.
This is an extension of “formation_newton.nlogo” to create chain formations.
To see the first papers that outlined the work presented in this simulation:
Hettiarachchi, S., Maxim, P., Spears, W. M., and Spears, D. F. (2008) Connectivity of collaborative robots in partially observable domains. In Proceedings of the International Conference on Control, Automation, and Systems.
Maxim, P., Spears, W. M., and Spears, D. F. (2009) Robotic chain formations. In Proceedings of the IFAC Workshop on Networked Robotics.
If you mention this model in an academic publication, we ask that you include these citations for the model itself and for the NetLogo software:
- Spears, W. M. and Spears, D. F. (eds.) Physicomimetics: Physics-Based Swarm Intelligence, Springer-Verlag, (2011).
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
Copyright 2011 William M. Spears. All rights reserved.
Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:
a) this copyright notice is included, and
b) this model will not be redistributed for profit without permission from William M. Spears. Contact William M. Spears for appropriate licenses for redistribution for profit.
; William M. Spears and Diana F. Spears September 2011
; Chain Formation Tutorial, with Obstacles
; For research and educational use only
breed [particles particle] ; Introduce the "particle" breed
breed [obstacles obstacle] ; Introduce the "obstacle" breed
globals [total_lmx total_lmy total_angular_mom G p FR D maxr obstacleF
center_of_mass_x center_of_mass_y FMAX DeltaT a2 b2 heavy]
turtles-own [hood deltax deltay r F Fx Fy v vx vy dvx dvy mass theta c1 s1
lmx lmy lever_arm_x lever_arm_y lever_arm_r angular_mom dradius]
to setup ; Clear everything
clear-all
set maxr 0
set heavy 100000 ; Used for obstacles
; Create and initialize particles
create-particles Number_of_Particles [setup-particles]
update-info
; Computes center of mass and displays location
set center_of_mass_x (sum [xcor * mass] of particles) / (sum [mass] of particles)
set center_of_mass_y (sum [ycor * mass] of particles) / (sum [mass] of particles)
ask patch (round center_of_mass_x) (round center_of_mass_y)
[ask patches in-radius 6 [set pcolor yellow]] ; Initial center of mass is displayed in yellow
reset-ticks
end
to run-and-monitor
if (count turtles < 1) [user-message "Please click HALT and then SETUP AGENTS first" stop]
update-info
ask particles [ap-particles]
ask obstacles [ap-obstacles]
ask turtles [move]
; Use mouse click to create obstacles. Must make sure that mouse is within black graphics pane.
if (mouse-down? and mouse-inside?) [
ifelse ((count obstacles) = 0)
[create-obstacles 1 [setxy mouse-xcor mouse-ycor set vx 0 set vy 0 set shape "circle"
set size (2 * obstacleF) set mass heavy set color green]]
[ask one-of obstacles [hatch 1 [setxy mouse-xcor mouse-ycor set vx 0 set vy 0]]]
wait 0.2 ; Pause so don't get a bunch of obstacles at once
]
; Computes center of mass and displays location
set center_of_mass_x (sum [xcor * mass] of particles) / (sum [mass] of particles)
set center_of_mass_y (sum [ycor * mass] of particles) / (sum [mass] of particles)
ask patch (round center_of_mass_x) (round center_of_mass_y) [set pcolor red]
set total_lmx sum [lmx] of particles ; Total linear momentum, x-component
set total_lmy sum [lmy] of particles ; Total linear momentum, y-component
set total_angular_mom sum [angular_mom] of particles ; Total angular momentum of objects
tick
do-plots
end
to setup-particles ; Set up the particles
setxy (random-normal 0 4) (random-normal 0 4) ; Start in a cluster
set heading random 360 ; Everyone has a random heading
set vx 0 set vy 0 set mass 1 ; Start with no motion and mass = 1
set size 8 set color white set theta 0
end
to ap-particles ; Run artificial physics on the particles
set Fx 0 set Fy 0 ; Initialize force components to zero
set vx (1 - FR) * vx ; Slow down according to friction
set vy (1 - FR) * vy
set hood [who] of other particles ; Get the IDs of all other particles
foreach hood [
set deltax (([xcor] of particle ?) - xcor)
set deltay (([ycor] of particle ?) - ycor)
set r sqrt (deltax * deltax + deltay * deltay)
if (r > maxr) [set maxr r]
if (r < D) [ ; The generalized split Newtonian law
set F (G * mass * ([mass] of turtle ?) / (r ^ p))
if (F > FMAX) [set F FMAX] ; Bounds check on force magnitude
if ((deltax != 0) or (deltay != 0))
[set theta (atan deltay deltax)] ; The bearing to the neighbor
set c1 (sin (heading + theta))
set s1 (cos (heading + theta)) ; See Chapter 4 for details
set dradius (sqrt (1.0 / ((c1 * c1 / a2) + (s1 * s1 / b2))))
ifelse (r > dradius) ; Creates elliptical force law
[set Fx (Fx + F * (deltax / r)) ; Attractive force, x-component
set Fy (Fy + F * (deltay / r))] ; Attractive force, y-component
[set Fx (Fx - F * (deltax / r)) ; Repulsive force, x-component
set Fy (Fy - F * (deltay / r))] ; Repulsive force, y-component
]
]
; Now include obstacles
set hood [who] of obstacles ; Get the IDs of obstacles
foreach hood [
set deltax (([xcor] of obstacle ?) - xcor)
set deltay (([ycor] of obstacle ?) - ycor)
set r sqrt (deltax * deltax + deltay * deltay)
if (r <= obstacleF) [
set F (obstacleF - r) ; Simple linear force law
set Fx (Fx - (F * (deltax / r))) ; Repulsive force, x-component
set Fy (Fy - (F * (deltay / r))) ; Repulsive force, y-component
]
]
set dvx DeltaT * (Fx / mass)
set dvy DeltaT * (Fy / mass)
set vx (vx + dvx) ; The x-component of velocity
set vy (vy + dvy) ; The y-component of velocity
set v sqrt (vx * vx + vy * vy)
set deltax DeltaT * vx
set deltay DeltaT * vy
if ((deltax != 0) or (deltay != 0))
[set heading (atan deltax deltay)]
end
to ap-obstacles ; Run artificial physics on the obstacles
set Fx 0 set Fy 0 ; Initialize force components to zero
set vx (1 - FR) * vx ; Slow down according to friction
set vy (1 - FR) * vy
set hood [who] of particles ; Get the IDs of all particles
foreach hood [
set deltax (([xcor] of particle ?) - xcor)
set deltay (([ycor] of particle ?) - ycor)
set r sqrt (deltax * deltax + deltay * deltay)
if (r <= obstacleF) [
set F (obstacleF - r) ; Simple linear force law
set Fx (Fx - F * (deltax / r)) ; Repulsive force, x-component
set Fy (Fy - F * (deltay / r)) ; Repulsive force, y-component
]
]
set dvx DeltaT * (Fx / mass)
set dvy DeltaT * (Fy / mass)
set vx (vx + dvx) ; The x-component of velocity
set vy (vy + dvy) ; The y-component of velocity
set v sqrt (vx * vx + vy * vy)
set deltax DeltaT * vx
set deltay DeltaT * vy
if ((deltax != 0) or (deltay != 0))
[set heading (atan deltax deltay)]
end
to move
fd sqrt (deltax * deltax + deltay * deltay) ; Move the turtle
set lmx (mass * vx) ; Linear momentum of the turtle
set lmy (mass * vy)
set lever_arm_x (xcor - center_of_mass_x)
set lever_arm_y (ycor - center_of_mass_y)
set lever_arm_r sqrt (lever_arm_x * lever_arm_x + lever_arm_y * lever_arm_y)
if (((vx != 0) or (vy != 0)) and ((lever_arm_x != 0) or (lever_arm_y != 0)))
[set theta (atan (mass * vy) (mass * vx)) - (atan lever_arm_y lever_arm_x)]
set angular_mom (lever_arm_r * mass * v * (sin theta)) ; Angular momentum of the turtle
end
to update-info ; Update information from the sliders
set a2 (Major_Axis ^ 2) / 4
set b2 (Minor_Axis ^ 2) / 4
set p Power
set FMAX Force_Maximum
set FR Friction
set DeltaT Time_Step
set D Desired_Separation
set obstacleF Obstacle_Force
set G (0.3 * FMAX * (D ^ p)) ; Compute best G from theory!
ask obstacles [set size (2 * obstacleF)] ; Update obstacle size if necessary
end
to do-plots
set-current-plot "Linear and Angular Momenta" ; Select the Momenta plot
set-current-plot-pen "Lmx" ; Select the Lmx pen
plot total_lmx ; Plot the linear momentum, x-component
set-current-plot-pen "Lmy"
plot total_lmy ; Plot the linear momentum, y-component
set-current-plot-pen "Angular"
plot total_angular_mom ; Plot the angular momentum
end
; Kill a particle
to one-dies
if (count (particles with [mass = 1]) > 1) [ ; Don't kill last particle
ask one-of particles with [mass = 1] [die] ; Ask one particle to die
clear-drawing ; A little cleanup is required
]
end
; Create a new particle
to one-is-born
if (count (particles with [mass = 1]) > 0) [
ask one-of particles with [mass = 1] ; Clone an existing particle
[hatch 1 [set deltax 0 set deltay 0 pd
setxy (xcor + (random-normal 0 0.1))
(ycor + (random-normal 0 0.1))]]
]
end