1 import interfaces.Controller;
2 import interfaces.AbstractRobot;
3
4
12 public class GBN1 extends Controller {
13
14 AbstractRobot r;
15 boolean initcalled;
16 boolean running;
17 boolean paused=false;
18
19 private int[] sensors={Controller.SENSOR_TYPE_LIGHT,Controller.SENSOR_TYPE_LIGHT,Controller.SENSOR_TYPE_LIGHT};
20
21
25 float input0;
26 float input1;
27 float input2;
28
29
31 float output0;
32
33 final float weight00=-1.474f;
34 final float weight10=1.188f;
35 final float weight20=3.93f;
36 final float weightb0=-1.988f;
37
38 public void run(){
39
40 running=true;
41
42 while(running) {
43
45 input0=r.getSensor1()/100.0f;
46 input1=r.getSensor2()/100.0f;
47 input2=r.getSensor3()/100.0f;
48
49
51 output0 = 1.0f/(1.0f+(float)(Math.exp( weight00*input0+
52 weight10*input1+
53 weight20*input2+
54 weightb0)));
55
56
58 if (output0<0.4) {r.right();}
59 if (output0<0.6 && output0>=0.4) {r.forward();}
60 if (output0>=0.6) {r.left();}
61
62 try{Thread.sleep(500);}catch(Exception e){}
63 }
64 }
65
66 public void initController(AbstractRobot r) {
67
68 this.r=r;
69 initcalled=true;
70 }
71
72 public int[] getSensors(){
73
74 return sensors;
75 }
76
77 public void halt(){
78
79 running=false;
80 r.stopMoving();
81 }
82
83 public AbstractRobot getRobot(){
84
85 return r;
86 }
87
88 public GBN1() { }
89 }
90