| 1 function [Command,Exp]=Example_random(Exp,Initialization) |
| 2 |
| 3 if Initialization |
| 4 Exp.Robots=2; |
| 5 Exp.Workspace=[0 0; 0 10; 10 10; 10 0]; |
| 6 Exp.Animation.Title=’[Random movements]’; |
| 7 Exp.Initial_pose=[1 3 0; 9 7 pi]’; |
| 8 Exp.Animation.Grid=0; |
| 9 |
| 10 Exp.Addons=’Map’; |
| 11 V(1).Vertex=[ 5 2; 4 3; 6 4; 5 3]; |
| 12 V(2).Vertex=[ 4 5; 3 7; 2 8; 1 6; 2 5]; |
| 13 V(3).Vertex=[ 6 6; 7 7; 8 6]; |
| 14 V(4).Vertex=[10 0; 10 10]; |
| 15 V(5).Vertex=[ 0 0; 0 10]; |
| 16 V(6).Vertex=[ 0 10; 10 10]; |
| 17 V(7).Vertex=[ 0 0; 10 0]; |
| 18 Exp.Map.Obstacle=V; |
| 19 |
| 20 for i=1:Exp.Robots |
| 21 Exp=Add_sensor(Exp,i,’ProximitySensor’); |
| 22 Exp.Agent(i).Sensor(1).Range=0.3; |
| 23 end |
| 24 |
| 25 Command=[]; return |
| 26 end |
| 27 |
| 28 for i=1:Exp.Robots |
| 29 if Exp.Agent(i).Sensor(1).Presence |
| 30 Command(:,i)=[-0.2; 0]; |
| 31 elseif (Exp.Iteration>1)&&(Exp.History.Command(Exp.Iteration-1,1,i))<0, |
| 32 Command(:,i)=[0; pi/2+rand(1)*pi]; |
| 33 else |
| 34 Command(:,i)=[0.2; 0]; |
| 35 end |
| 36 end |