Revision 682
Added colonet functionality, remote control driver
Colonet.java | ||
---|---|---|
54 | 54 |
JButton btnAssignID; |
55 | 55 |
boolean setWaypoint; |
56 | 56 |
int setWaypointID; |
57 |
JButton btnSetBounds; |
|
58 |
RobotBoundary boundary; |
|
57 |
JButton btnSetBounds; |
|
58 |
JButton btnClearBounds; |
|
59 |
RobotBoundary boundary; |
|
59 | 60 |
JButton btnCommand_MoveTo; |
60 | 61 |
JButton btnCommand_MoveAll; |
61 | 62 |
JButton btnCommand_StopTask; |
... | ... | |
218 | 219 |
panelRobotCommands.add(new JLabel("Selected Icon: ")); |
219 | 220 |
panelRobotCommands.add(lblSelected); |
220 | 221 |
panelRobotCommands.add(btnAssignID); |
222 |
panelRobotCommands.add(new JLabel(" ")); |
|
221 | 223 |
panelRobotCommands.add(btnSetBounds); |
224 |
panelRobotCommands.add(btnClearBounds); |
|
222 | 225 |
panelRobotCommands.add(btnCommand_MoveTo); |
223 | 226 |
panelRobotCommands.add(btnCommand_MoveAll); |
224 | 227 |
//panelRobotCommands.add(btnCommand_StopTask); |
... | ... | |
278 | 281 |
|
279 | 282 |
// Disable components before connecting |
280 | 283 |
btnConnect.setText("Connect"); |
281 |
lblConnectionStatus.setText("Status: Disconnected"); |
|
282 |
btnF.setEnabled(false); |
|
283 |
btnB.setEnabled(false); |
|
284 |
btnL.setEnabled(false); |
|
285 |
btnR.setEnabled(false); |
|
286 |
btnActivate.setEnabled(false); |
|
287 |
btnAssignID.setEnabled(false); |
|
288 |
btnSetBounds.setEnabled(false); |
|
289 |
btnCommand_MoveTo.setEnabled(false); |
|
290 |
btnCommand_MoveAll.setEnabled(false); |
|
284 |
lblConnectionStatus.setText("Status: Disconnected"); |
|
285 |
btnF.setEnabled(false); |
|
286 |
btnB.setEnabled(false); |
|
287 |
btnL.setEnabled(false); |
|
288 |
btnR.setEnabled(false); |
|
289 |
btnActivate.setEnabled(false); |
|
290 |
btnAssignID.setEnabled(false); |
|
291 |
btnSetBounds.setEnabled(false); |
|
292 |
btnClearBounds.setEnabled(false); |
|
293 |
btnCommand_MoveTo.setEnabled(false); |
|
294 |
btnCommand_MoveAll.setEnabled(false); |
|
291 | 295 |
|
292 | 296 |
/* Add all listeners here */ |
293 | 297 |
// Task Management |
... | ... | |
317 | 321 |
btnConnect.addActionListener(this); |
318 | 322 |
btnGetXBeeIDs.addActionListener(this); |
319 | 323 |
btnAssignID.addActionListener(this); |
320 |
btnSetBounds.addActionListener(this); |
|
324 |
btnSetBounds.addActionListener(this); |
|
325 |
btnClearBounds.addActionListener(this); |
|
321 | 326 |
panelWebcam.addMouseListener(this); |
322 | 327 |
panelWebcam.addMouseMotionListener(this); |
323 | 328 |
} |
... | ... | |
385 | 390 |
} |
386 | 391 |
|
387 | 392 |
public void connect () { |
388 |
if (csi != null) |
|
389 |
return; |
|
390 |
csi = new ColonetServerInterface(self); |
|
391 |
csi.connect(txtHost.getText(), txtPort.getText()); |
|
392 |
if (!csi.isReady()) { |
|
393 |
csi = null; |
|
394 |
return; |
|
395 |
} |
|
396 |
webcamLoader = new WebcamLoader(self); |
|
397 |
dataUpdater = new DataUpdater(); |
|
398 |
dataUpdater.start(); |
|
399 |
webcamLoader.start(); |
|
400 |
Runnable r = new Runnable() { |
|
401 |
public void run () { |
|
402 |
btnConnect.setText("Disconnect"); |
|
403 |
lblConnectionStatus.setText("Status: Connected"); |
|
404 |
btnF.setEnabled(true); |
|
405 |
btnB.setEnabled(true); |
|
406 |
btnL.setEnabled(true); |
|
407 |
btnR.setEnabled(true); |
|
408 |
btnActivate.setEnabled(true); |
|
409 |
btnAssignID.setEnabled(true); |
|
410 |
btnSetBounds.setEnabled(true); |
|
411 |
btnCommand_MoveTo.setEnabled(true); |
|
412 |
btnCommand_MoveAll.setEnabled(true); |
|
413 |
} |
|
414 |
}; |
|
415 |
SwingUtilities.invokeLater(r); |
|
393 |
if (csi != null) |
|
394 |
return; |
|
395 |
csi = new ColonetServerInterface(self); |
|
396 |
csi.connect(txtHost.getText(), txtPort.getText()); |
|
397 |
if (!csi.isReady()) { |
|
398 |
csi = null; |
|
399 |
return; |
|
400 |
} |
|
401 |
webcamLoader = new WebcamLoader(self); |
|
402 |
dataUpdater = new DataUpdater(); |
|
403 |
dataUpdater.start(); |
|
404 |
webcamLoader.start(); |
|
405 |
Runnable r = new Runnable() { |
|
406 |
public void run () { |
|
407 |
btnConnect.setText("Disconnect"); |
|
408 |
lblConnectionStatus.setText("Status: Connected"); |
|
409 |
btnF.setEnabled(true); |
|
410 |
btnB.setEnabled(true); |
|
411 |
btnL.setEnabled(true); |
|
412 |
btnR.setEnabled(true); |
|
413 |
btnActivate.setEnabled(true); |
|
414 |
btnAssignID.setEnabled(true); |
|
415 |
btnSetBounds.setEnabled(true); |
|
416 |
btnClearBounds.setEnabled(true); |
|
417 |
btnCommand_MoveTo.setEnabled(true); |
|
418 |
btnCommand_MoveAll.setEnabled(true); |
|
419 |
} |
|
420 |
}; |
|
421 |
SwingUtilities.invokeLater(r); |
|
416 | 422 |
} |
417 | 423 |
|
418 | 424 |
public void disconnect () { |
... | ... | |
432 | 438 |
btnActivate.setEnabled(false); |
433 | 439 |
btnAssignID.setEnabled(false); |
434 | 440 |
btnSetBounds.setEnabled(false); |
441 |
btnClearBounds.setEnabled(false); |
|
435 | 442 |
btnCommand_MoveTo.setEnabled(false); |
436 | 443 |
btnCommand_MoveAll.setEnabled(false); |
437 | 444 |
} |
... | ... | |
538 | 545 |
robotIcons = newList; |
539 | 546 |
repaint(); |
540 | 547 |
} |
548 |
|
|
549 |
/** |
|
550 |
* Parses a message that indicates a robot has reached its destination |
|
551 |
*/ |
|
552 |
public void parseMoveUpdate (String line) { |
|
553 |
System.out.println("Got move update: " + line); |
|
554 |
String [] str = line.split(" "); |
|
555 |
int id = Integer.parseInt(str[1]); |
|
556 |
robotIcons.cancelMoveTo(id); |
|
557 |
} |
|
541 | 558 |
|
542 | 559 |
/** |
543 | 560 |
* Set the ID of the selected robot |
... | ... | |
787 | 804 |
} else if (source == btnSetBounds) { |
788 | 805 |
boundary.set = true; |
789 | 806 |
panelWebcam.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
807 |
} else if (source == btnClearBounds) { |
|
808 |
boundary.active = false; |
|
809 |
boundary.set = false; |
|
810 |
boundary.img_p1 = new Point(-1, -1); |
|
811 |
boundary.img_p2 = new Point(-1, -1); |
|
812 |
boundary.panel_p1 = new Point(-1, -1); |
|
813 |
boundary.panel_p2 = new Point(-1, -1); |
|
814 |
boundary.sendToServer(); |
|
790 | 815 |
} else if (source == btnCommand_MoveTo) { |
791 | 816 |
if (selectedBot < 0) { |
792 | 817 |
return; |
... | ... | |
1111 | 1136 |
} |
1112 | 1137 |
|
1113 | 1138 |
public void sendToServer () { |
1114 |
if (csi != null) {
|
|
1115 |
csi.sendBoundary(img_p1.x, img_p1.y, img_p2.x, img_p2.y);
|
|
1116 |
}
|
|
1139 |
if (csi != null) { |
|
1140 |
csi.sendBoundary(img_p1.x, img_p1.y, img_p2.x, img_p2.y); |
|
1141 |
} |
|
1117 | 1142 |
} |
1118 | 1143 |
} |
1119 | 1144 |
|
Also available in: Unified diff