1 package real;
2
3 import interfaces.*;
4
5 import josx.platform.rcx.*;
6
7
14 public class RealRCX extends Thread implements AbstractRobot, SensorConstants
15 {
16 public static int MOTOR_POWER;
17 public void run(){}
18
19
24 public RealRCX(Controller controller)
25 {
26 MOTOR_POWER=3;
27 Motor.A.setPower(MOTOR_POWER);
28 Motor.B.setPower(MOTOR_POWER);
29 Motor.C.setPower(MOTOR_POWER);
30
31 int[] sensors=controller.getSensors();
33
34 if(sensors[0]==Controller.SENSOR_TYPE_LIGHT)
35 {
36 Sensor.S1.setTypeAndMode (SensorConstants.SENSOR_TYPE_LIGHT, SensorConstants.SENSOR_MODE_PCT);
37 Sensor.S1.activate();
38 }
39 else if(sensors[0]==Controller.SENSOR_TYPE_TOUCH)
40 {
41 Sensor.S1.setTypeAndMode (SensorConstants.SENSOR_TYPE_TOUCH, SensorConstants.SENSOR_MODE_PCT);
42 Sensor.S1.activate();
43 }
44
45 if(sensors[1]==Controller.SENSOR_TYPE_LIGHT)
46 {
47 Sensor.S2.setTypeAndMode (SensorConstants.SENSOR_TYPE_LIGHT, SensorConstants.SENSOR_MODE_PCT);
48 Sensor.S2.activate();
49 }
50 else if(sensors[1]==Controller.SENSOR_TYPE_TOUCH)
51 {
52 Sensor.S2.setTypeAndMode (SensorConstants.SENSOR_TYPE_TOUCH, SensorConstants.SENSOR_MODE_PCT);
53 Sensor.S2.activate();
54 }
55
56 if(sensors[2]==Controller.SENSOR_TYPE_LIGHT)
57 {
58 Sensor.S3.setTypeAndMode (SensorConstants.SENSOR_TYPE_LIGHT, SensorConstants.SENSOR_MODE_PCT);
59 Sensor.S3.activate();
60 }
61 else if(sensors[2]==Controller.SENSOR_TYPE_TOUCH)
62 {
63 Sensor.S3.setTypeAndMode (SensorConstants.SENSOR_TYPE_TOUCH, SensorConstants.SENSOR_MODE_PCT);
64 Sensor.S3.activate();
65 }
66 }
67
68
69
72
73
77 public void forward()
78 {
79 Motor.A.forward();
80 Motor.C.forward();
81 }
82
83
88 public void forward(int time)
89 {
90 Motor.A.forward();
91 Motor.C.forward();
92 try{sleep(time);}catch(Exception e){}
93 Motor.A.stop();
94 Motor.C.stop();
95 }
96
97
101 public void backward()
102 {
103 Motor.A.backward();
104 Motor.C.backward();
105 }
106
107
112 public void backward(int time)
113 {
114 Motor.A.backward();
115 Motor.C.backward();
116 try{sleep(time);}catch(Exception e){}
117 Motor.A.stop();
118 Motor.C.stop();
119 }
120
121
125 public void right()
126 {
127 Motor.A.stop();
128 Motor.C.stop();
129 Motor.A.forward();
130 Motor.C.backward();
131 }
132
133
138 public void right(int time)
139 {
140 Motor.A.stop();
141 Motor.C.stop();
142 Motor.A.forward();
143 Motor.C.backward();
144 try{sleep(time);}catch(Exception e){}
145 Motor.A.stop();
146 Motor.C.stop();
147 }
148
149
153 public void left()
154 {
155 Motor.A.stop();
156 Motor.C.stop();
157 Motor.A.backward();
158 Motor.C.forward();
159 }
160
161
166 public void left(int time)
167 {
168 Motor.A.stop();
169 Motor.C.stop();
170 Motor.A.backward();
171 Motor.C.forward();
172 try{sleep(time);}catch(Exception e){}
173 Motor.A.stop();
174 Motor.C.stop();
175 }
176
177
180 public void stopMoving()
181 {
182 Motor.A.stop();
183 Motor.C.stop();
184 }
185
186
189 public void beep()
190 {
191 Sound.beep();
192 }
193
194
199 public int getSensor1()
200 {
201 return Sensor.S1.readValue();
202 }
203
204
209 public int getSensor2()
210 {
211 return Sensor.S2.readValue();
212 }
213
214
219 public int getSensor3()
220 {
221 return Sensor.S3.readValue();
222 }
223 }
224