Obstacle Avoidance 2 NetLogo Model
Produced for the book series "Artificial Intelligence";
Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.
powered by NetLogo
view/download model file: Obstacle-Avoidance-2.nlogo
WHAT IS IT?
This model implements a boid (see Craig Reynold's work) that employs basic obstacle avoidance steering behaviour.
HOW IT WORKS
It does this by generating a wanderer turtle (boid) that simple wanders around randomly in the environment avoiding the obstacles. The boid is implemented using NetLogo's in-cone command that implements a turtle with a cone of vision.
The model's Interface buttons are defined as follows:
- Setup: This sets up the environment with a grid of obstacles and an outside border (drawn using blue patches). One turtle agent (the wanderer boid) is created and placed at a random location.
- Go: The boid starts wandering around the environment avoiding obstacles.
- Draw Obstacle: The user can draw further obstacles in the environment. These are coloured brown.
- Follow Wanderer: This allows the perspective of the visualisation to be altered so that it is centred on the wanderer.
- Plot: This instructs the wanderer turtle agent to put its pen down when wandering. Hence this will draw the path it has taken while wandering around.
The model's Interface sliders are defined as follows:
- boid-speed: This controls the speed of the boid i.e. how much it moves forward each tick.
- rate-of-random-turn: This controls how much the wandering boid turns each time tick. The boid has a tendency to head in a right turning direction as the rate of random turn to the right (as specified by the slider) is twice that of the rate of random turn to the left.
- radius-angle: This defines the radius angle of the boid's vision cone.
- radius-length: This defines the radius length of the boid's vision cone.
HOW TO USE IT
Press the Setup button first, then press Go. To see where the boid wanders, press Plot.
You can draw extra obstacles by pressing the Draw Obstacle button and then holding down the mouse at the point where you want the obstacles to be drawn. You can change the frame of reference so that the visualisation is centred around where the boid currently is situated by pressing the Follow Wanderer button.
THINGS TO NOTICE
Setting the boid-speed to 0.1, rate-of-random-turn to 40, radius-angle to 300, radius-length to 1, and pressing the Plot button once, followed by moving the speed slider (just below the Information tab in the Interface) from "normal speed" to "faster" will result in the boid rapidly covering the entire environment while reliably avoiding the blue obstacles.
Increasing the radius-length to 5 (while keeping the other variables the same) discernibly changes the behaviour of the boid. Instead of covering most of the environment, the boid covers a rectangular path of width 4 to 5 around the outside of the environment but indented by about 3 to 4 patches in from the outer boundary. The boid seems to refrain from going inside of the rectangular path. Sometimes the boid can get stuck spinning around one of the obstacles.
THINGS TO TRY
Try adjusting the boid's speed, radius angle and radius length to see how this affects the boid's behaviour. Also try changing the Interface Settings to see if this has any affect.
Try adding obstacles to see how this affects the boid's ability to cover the entire environment. For example, add obstacles in the form of a maze. Try to create "black spots" where the boid never visits. Alternatively, try to trap the boid into a small area.
EXTENDING THE MODEL
The model could be extended to add gradual acceleration and deceleration. This would enhance the simulation of the boids model.
The code uses the in-cone command to simulate the boid's cone of vision.
See the following models: Crowd Path Following, Flocking With Obstacles, Follow and Avoid, Obstacle Avoidance 1, Obstacle Avoidance 2, Vision Cone Example 2, Wall Following Example 2. These are basic implementations of various Craig Reynold's steering behaviours for boids.
Another boid related model is the Biology/Flocking model in the Models Library.
CREDITS AND REFERENCES
This model was created by Thomas Christy at Bangor University 2009 and modified by William John Teahan. Part of the code was based on the Look Ahead Example model in NetLogo's Models Library.
; Obstacle Avoidance 1 model ; ; Demonstrates obstacle avoidance for a boid. ; ; Written by Thomas Christy (2009) ; Modified by Bill Teahan (2009) breed [wanderers wanderer] ; name of the breed of boids to setup clear-all set-default-shape wanderers "Directional Circle" ; sets shapes for each breed ; creates colour, size and random location of single wanderer create-wanderers 1 [default red ] draw-obstacles end to draw-obstacles ask patches with [pxcor mod 3 = 0 and pycor mod 3 = 0] [ set pcolor blue ] ask patches with [count neighbors != 8] [ set pcolor blue ] end to default [colour] ; creates default settings for boid set color colour ; sets colour using passed parameter setxy random-xcor random-ycor ; sets an initial random position set size 1 ; default turtle size end to make-obstacle if mouse-down? [ ask-concurrent patches [ if ((abs (pxcor - mouse-xcor)) < 1) and ((abs (pycor - mouse-ycor)) < 1) [set pcolor brown]] ] end to go ask-concurrent wanderers ; wanderers instructions [ rt random-float rate-of-random-turn lt (rate-of-random-turn / 2) ; randomly turns randomly as defined by the random-rate-of-turn variable in the interface ; with a tendency to turn to the right fd boid-speed avoid-patches ] tick end to avoid-patches ask-concurrent patches in-cone radius-length radius-angle [ if pcolor != black [ set pcolor blue ask wanderer 0 [ bk boid-speed lt 90 ] ] ] end ; ; Copyright 2009 by Thomas Christy and William John Teahan. 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. ; b) this model will not be redistributed for profit without permission ; from William John Teahan. ; Contact William John Teahan for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in publications, please use: ; ; Obstacle Avoidance 2 NetLogo model. ; Artificial Intelligence. Teahan, W. J. (2010). Ventus Publishing Aps. ;