Revision 638
New robot movement works. Battery meters work with new timing scheme. Still have some repainting issues.
VectorController.java | ||
---|---|---|
14 | 14 |
// State variables |
15 | 15 |
int x, y, cx, cy; |
16 | 16 |
final Colonet colonet; |
17 |
final ColonetServerInterface csi; |
|
18 | 17 |
|
19 | 18 |
// Painting constants |
20 | 19 |
final int WIDTH, HEIGHT; |
... | ... | |
22 | 21 |
final int BOT_SIZE = 70; |
23 | 22 |
final int WHEEL_SIZE = 15; |
24 | 23 |
|
25 |
public VectorController (Image img, Colonet colonet, ColonetServerInterface csi) {
|
|
24 |
public VectorController (Image img, Colonet colonet) { |
|
26 | 25 |
super (img); |
27 | 26 |
WIDTH = img.getWidth(null); |
28 | 27 |
HEIGHT = img.getHeight(null); |
... | ... | |
36 | 35 |
SIDE = HEIGHT; |
37 | 36 |
} |
38 | 37 |
this.colonet = colonet; |
39 |
this.csi = csi; |
|
40 | 38 |
|
41 | 39 |
this.addMouseListener(this); |
42 | 40 |
this.addMouseMotionListener(this); |
... | ... | |
266 | 264 |
public void sendToServer () { |
267 | 265 |
// Determine destination ID |
268 | 266 |
String dest = ColonetServerInterface.GLOBAL_DEST; |
267 |
ColonetServerInterface csi = colonet.getCSI(); |
|
269 | 268 |
/*if (cmbRobotNum != null && cmbRobotNum.getSelectedIndex() > 0) { |
270 | 269 |
dest = (String)cmbRobotNum.getSelectedItem(); |
271 | 270 |
}*/ |
272 | 271 |
|
273 | 272 |
if (csi == null) |
274 | 273 |
return; |
275 |
|
|
276 |
String motor1_string; |
|
277 |
String motor2_string; |
|
278 | 274 |
int motor1 = eliminateDeadZone(getMotorL()); |
279 | 275 |
int motor2 = eliminateDeadZone(getMotorR()); |
276 |
String motor1_string = (motor1 > 0) ? " 1 " + motor1 : " 0 " + (-motor1); |
|
277 |
String motor2_string = (motor2 > 0) ? " 1 " + motor2 : " 0 " + (-motor2); |
|
280 | 278 |
|
281 |
if (motor1 > 0) { |
|
282 |
motor1_string = " 1 " + motor1; |
|
283 |
} else { |
|
284 |
motor1_string = " 0 " + (-motor1); |
|
285 |
} |
|
286 |
if (motor2 > 0) { |
|
287 |
motor2_string = " 1 " + motor2; |
|
288 |
} else { |
|
289 |
motor2_string = " 0 " + (-motor2); |
|
290 |
} |
|
291 |
|
|
292 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + motor1_string, dest); |
|
293 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + motor2_string, dest); |
|
294 |
|
|
295 |
/* |
|
296 |
// Directional commands |
|
297 |
if (x > cx && y == cy) { //move right |
|
298 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + " 0 200", dest); |
|
299 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + " 1 200", dest); |
|
300 |
} else if (x < cx && y == cy) { //move left |
|
301 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + " 1 200", dest); |
|
302 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + " 0 200", dest); |
|
303 |
} else if (x == cx && y > cy) { //move forward |
|
304 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + " 0 225", dest); |
|
305 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + " 0 225", dest); |
|
306 |
} else if (x == cx && y < cy) { //move backward |
|
307 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + " 1 225", dest); |
|
308 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + " 1 225", dest); |
|
309 |
} else if (x == cx && y == cy) { //stop! |
|
310 |
csi.sendData(ColonetServerInterface.MOTOR2_SET + " 1 0", dest); |
|
311 |
csi.sendData(ColonetServerInterface.MOTOR1_SET + " 1 0", dest); |
|
312 |
} |
|
313 |
*/ |
|
314 |
|
|
315 |
/* |
|
316 |
// Atomic Directional commands |
|
317 |
if (x > cx && y == cy) { //move right |
|
318 |
csi.sendData(ColonetServerInterface.MOVE_R, dest); |
|
319 |
} else if (x < cx && y == cy) { //move left |
|
320 |
csi.sendData(ColonetServerInterface.MOVE_L, dest); |
|
321 |
} else if (x == cx && y > cy) { //move forward |
|
322 |
csi.sendData(ColonetServerInterface.MOVE_F, dest); |
|
323 |
} else if (x == cx && y < cy) { //move backward |
|
324 |
csi.sendData(ColonetServerInterface.MOVE_B, dest); |
|
325 |
} else if (x == cx && y == cy) { //stop |
|
326 |
csi.sendData(ColonetServerInterface.MOTORS_OFF, dest); |
|
327 |
} |
|
328 |
*/ |
|
279 |
csi.sendData(ColonetServerInterface.MOVE + motor1_string + motor2_string, dest); |
|
329 | 280 |
} |
330 | 281 |
|
331 | 282 |
} |
Also available in: Unified diff