Obstacle Avoidance 1 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-1.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 simply wanders around randomly in the environment avoiding the obstacles that are drawn with white patches. 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 tree-like arrangement of obstacles drawn with white 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 also coloured white.
- Follow Wanderer: This allows the perspective of the visualisation to be altered so that it is centred on the wanderer.
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.
You can draw extra obstacles by pressing the Draw Obstacle button and then by 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's vision cone radius-length or radius-angle will result in the boid not seeing the obstacles and as a result will run right over the top of them. Why? What needs to be fixed so that even without any sensing ability, it will still bounce off the obstacles?
Increasing the radius-length (while keeping the other variables the same) discernibly changes the behaviour of the boid. (Try doing this dynamically while moving the radius-length slider back and forth). Instead of covering most of the environment, when the radius length is large then the boid covers a much smaller more constrained area usually at the top of the environment. Sometimes it can get stuck, seemingly trapped in the same place.
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.
; 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 the boid ; create colour, size and random location of single wanderer create-wanderers 1 [default blue ] draw-obstacles end to default [colour] ; creates default settings for boid print "Got here" set color colour ; sets colour using passed parameter setxy random-xcor random-ycor ; sets an initial random position set size 5 ; default tutle size end to draw-obstacles ask patches with [pxcor = 0 and pycor <= 15 or abs pxcor = (pycor + 40) and pycor < 40 or abs pxcor = (pycor + 15) and pycor < 6] [ set pcolor white ] end to make-obstacle if mouse-down? [ ask patches [ if ((abs (pxcor - mouse-xcor)) < 1) and ((abs (pycor - mouse-ycor)) < 1) [ set pcolor white ] ] ] end to go ask 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 ] end to avoid-patches ask patches with [pcolor = sky] [ set pcolor black ] ask patches in-cone radius-length radius-angle [ if pcolor = black [ set pcolor sky ] if pcolor = white [ set pcolor red ]] if count patches in-cone radius-length radius-angle with [pcolor = white or pcolor = red] > 0 [ ask wanderer 0 [ bk boid-speed lt 90 ] ] end ; ; Copyright 2010 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: ; ; Teahan, W. J. (2010). Obstacle Avoidance 1 NetLogo model. ; Artificial Intelligence. Ventus Publishing Aps ;