问题
I'm really new at programming in NetLogo and i need help. I am doing research project in which i created a world like real world in which roads and buildings were created. Building are of black color and roads are of white. A robot can only walk on white patches i.e. on roads. I am having problem with obstacle avoidance algorithm and not visiting the visited places. I need human like behavioral-based algorithm for obstacle avoidance i.e. humans see an obstacle in front of them, then they move backward (or take a step backward then move to right or left to check for obstacle again) OR see on right then turn to left and vice versa. Right now in my code i am using a random 360 rotate to avoid obstacle but i don't need that i need that behavioral-based algorithm. Here is the code which i have done till this time.
breed [robots robot] ;robot breed
robots-own [goal velocity]
globals[ ;set of global variables
road-colour
building-colour
]
to setup
clear-all
set road-colour white
set building-colour black
let block-area grid-x ; desired area for a grid block in km²
let patch-area grid-y ; area represented by a patch in km²
let num-patches-in-block (block-area / patch-area)
let side round sqrt num-patches-in-block
let goals (patch-set patch -16 12 patch 12 12 patch -6 15 patch 9 12)
ask patches [ set pcolor 10 ]
let roads patches with [
(pxcor mod (side + 1) = 0 ) or
(pycor mod (side + 1) = 0 )
]
ask roads [ set pcolor white ]
create-robots num [ set size 1
set goal one-of goals
set velocity speed
]
set-default-shape turtles "person"
end
to move
fd velocity
if patch-here = goal [ die ]
end
to go
ifelse [pcolor] of patch-ahead 1 = road-colour
[ move ]
[ lt random-float 360 ]
;[avoid-obstacle]
end
to avoid-obstacle
;code here
end
回答1:
Your question is a little vague, but you may want to read about some "classic" algorithms (from Sun and Lumelsky) known as "Bug" algorithms for collision detection and avoidance. The Bug algorithms make few assumptions about knowledge of the terrain/course and work even with robots which don't have any "vision" other than the ability to detect collisions. Overview PDF of various bug algorithms can be read here.
来源:https://stackoverflow.com/questions/23927463/robot-obstacle-avoidance-and-skipping-visited-patches-places