Revision 776 trunk/code/projects/colonet/client/Colonet.java
| Colonet.java (revision 776) | ||
|---|---|---|
| 492 | 492 |
|
| 493 | 493 |
RobotIcon r = robotIcons.get(botNum); |
| 494 | 494 |
if (r != null) {
|
| 495 |
r.battery = batteryIcon.convert(level); // set contextual battery meter |
|
| 495 |
r.setBattery(batteryIcon.convert(level)); // set contextual battery meter |
|
| 496 | 496 |
batteryIcon.setLevel(level); // set solo battery meter |
| 497 | 497 |
} |
| 498 | 498 |
super.repaint(); |
| ... | ... | |
| 514 | 514 |
// Save previous robot information |
| 515 | 515 |
RobotIcon oldIcon = robotIcons.get(id); |
| 516 | 516 |
if (oldIcon != null) {
|
| 517 |
newIcon.battery = oldIcon.battery; |
|
| 518 |
newIcon.destx = oldIcon.destx; |
|
| 519 |
newIcon.desty = oldIcon.desty; |
|
| 517 |
newIcon.setBattery(oldIcon.getBattery()); |
|
| 518 |
newIcon.setDestination(oldIcon.getDestination()); |
|
| 520 | 519 |
} |
| 521 |
if (newIcon.id >= 0) {
|
|
| 522 |
newIcon.color = Color.GREEN; |
|
| 520 |
if (newIcon.getID() >= 0) {
|
|
| 521 |
newIcon.setColor(Color.GREEN); |
|
| 523 | 522 |
} |
| 524 | 523 |
newList.put(id, newIcon); |
| 525 | 524 |
} |
| ... | ... | |
| 534 | 533 |
System.out.println("Got move update: " + line);
|
| 535 | 534 |
String [] str = line.split(" ");
|
| 536 | 535 |
int id = Integer.parseInt(str[1]); |
| 537 |
robotIcons.cancelMoveTo(id); |
|
| 536 |
robotIcons.get(id).clearDestination(); |
|
| 538 | 537 |
} |
| 539 | 538 |
|
| 540 | 539 |
/** |
| ... | ... | |
| 620 | 619 |
|
| 621 | 620 |
RobotIcon r = robotIcons.get(selectedBot); |
| 622 | 621 |
if (r != null) {
|
| 623 |
r.destx = pt.x; |
|
| 624 |
r.desty = pt.y; |
|
| 622 |
r.setDestination(pt); |
|
| 625 | 623 |
if (csi != null) {
|
| 626 |
csi.sendAbsoluteMove(r.id, r.destx, r.desty); |
|
| 624 |
csi.sendAbsoluteMove(r.getID(), pt.x, pt.y); |
|
| 627 | 625 |
} |
| 628 | 626 |
} |
| 629 | 627 |
return; |
| ... | ... | |
| 633 | 631 |
if ((e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) |
| 634 | 632 |
&& e.getID() == MouseEvent.MOUSE_PRESSED |
| 635 | 633 |
&& station != null && station.contains(e.getX(), e.getY())) {
|
| 636 |
if (selectedBot >= 0) |
|
| 634 |
if (selectedBot >= 0) {
|
|
| 635 |
RobotIcon r = robotIcons.get(selectedBot); |
|
| 636 |
if (r != null) {
|
|
| 637 |
Point p = panelWebcam.convertPoint(station.getX(), station.getY()); |
|
| 638 |
r.setDestination(p); |
|
| 639 |
} |
|
| 637 | 640 |
csi.sendRecharge(selectedBot); |
| 641 |
} |
|
| 638 | 642 |
return; |
| 639 | 643 |
} |
| 640 | 644 |
|
| ... | ... | |
| 648 | 652 |
if (selectedBot < 0) {
|
| 649 | 653 |
return; |
| 650 | 654 |
} |
| 651 |
|
|
| 652 | 655 |
RobotIcon r = robotIcons.get(selectedBot); |
| 653 | 656 |
if (r != null) {
|
| 654 |
r.destx = pt.x; |
|
| 655 |
r.desty = pt.y; |
|
| 657 |
r.setDestination(pt); |
|
| 656 | 658 |
if (csi != null) {
|
| 657 |
csi.sendAbsoluteMove(r.id, r.destx, r.desty); |
|
| 659 |
csi.sendAbsoluteMove(r.getID(), pt.x, pt.y); |
|
| 658 | 660 |
} |
| 659 | 661 |
} |
| 660 | 662 |
return; |
| ... | ... | |
| 670 | 672 |
panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
| 671 | 673 |
for (Map.Entry<Integer,RobotIcon> entry : robotIcons.entrySet()) {
|
| 672 | 674 |
RobotIcon r = entry.getValue(); |
| 673 |
r.destx = pt.x; |
|
| 674 |
r.desty = pt.y; |
|
| 675 |
r.setDestination(pt); |
|
| 676 |
//TODO: send absolute move commands |
|
| 675 | 677 |
} |
| 676 | 678 |
return; |
| 677 | 679 |
} |
| ... | ... | |
| 711 | 713 |
// Otherwise, we are selecting a bot, or doing nothing |
| 712 | 714 |
RobotIcon r = robotIcons.getBoundingIcon(pt); |
| 713 | 715 |
if (r != null) |
| 714 |
selectedBot = r.id; |
|
| 716 |
selectedBot = r.getID(); |
|
| 715 | 717 |
} |
| 716 | 718 |
} |
| 717 | 719 |
|
| ... | ... | |
| 793 | 795 |
} else if (source == btnF) { // Robot Movement Controls
|
| 794 | 796 |
vectorController.setMaxForward(); |
| 795 | 797 |
vectorController.sendToServer(); |
| 796 |
robotIcons.cancelMoveTo(selectedBot); |
|
| 798 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 797 | 799 |
} else if (source == btnB) {
|
| 798 | 800 |
vectorController.setMaxReverse(); |
| 799 | 801 |
vectorController.sendToServer(); |
| 800 |
robotIcons.cancelMoveTo(selectedBot); |
|
| 802 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 801 | 803 |
} else if (source == btnL) {
|
| 802 | 804 |
vectorController.setMaxLeft(); |
| 803 | 805 |
vectorController.sendToServer(); |
| 804 |
robotIcons.cancelMoveTo(selectedBot); |
|
| 806 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 805 | 807 |
} else if (source == btnR) {
|
| 806 | 808 |
vectorController.setMaxRight(); |
| 807 | 809 |
vectorController.sendToServer(); |
| 808 |
robotIcons.cancelMoveTo(selectedBot); |
|
| 810 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 809 | 811 |
} else if (source == btnActivate) {
|
| 810 | 812 |
vectorController.setZero(); |
| 811 | 813 |
vectorController.sendToServer(); |
| 812 |
robotIcons.cancelMoveTo(selectedBot); |
|
| 814 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 813 | 815 |
} else if (source == btnSetBounds) {
|
| 814 | 816 |
boundary.set = true; |
| 815 | 817 |
panelWebcam.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
| ... | ... | |
| 842 | 844 |
else |
| 843 | 845 |
csi.sendRecharge(2); |
| 844 | 846 |
} else if (source == btnCommand_StopCharging) {
|
| 845 |
if (selectedBot >= 0) |
|
| 847 |
if (selectedBot >= 0) {
|
|
| 848 |
robotIcons.get(selectedBot).clearDestination(); |
|
| 846 | 849 |
csi.sendRechargeStop(selectedBot); |
| 847 |
else |
|
| 850 |
} else {
|
|
| 851 |
robotIcons.get(2).clearDestination(); |
|
| 848 | 852 |
csi.sendRechargeStop(2); |
| 853 |
} |
|
| 849 | 854 |
} else if (source == btnAddTask) { // Queue Management
|
| 850 | 855 |
taskAddWindow.prompt(); |
| 851 | 856 |
} else if (source == btnRemoveTask) {
|
| ... | ... | |
| 896 | 901 |
if (count % 30 == 0) {
|
| 897 | 902 |
for (Map.Entry<Integer,RobotIcon> entry : robotIcons.entrySet()) {
|
| 898 | 903 |
RobotIcon r = entry.getValue(); |
| 899 |
int id = r.id; |
|
| 904 |
int id = r.getID(); |
|
| 900 | 905 |
if (id >= 0) {
|
| 901 | 906 |
csi.sendBatteryRequest(id); |
| 902 | 907 |
} |
| ... | ... | |
| 999 | 1004 |
bufferedGraphics.setStroke(new BasicStroke(2)); |
| 1000 | 1005 |
for (Map.Entry<Integer,RobotIcon> entry : robotIcons.entrySet()) {
|
| 1001 | 1006 |
RobotIcon r = entry.getValue(); |
| 1002 |
bufferedGraphics.setColor(r.color); |
|
| 1007 |
bufferedGraphics.setColor(r.getColor()); |
|
| 1003 | 1008 |
// Identifier circle |
| 1004 |
int px = (int) (x + r.x * scale); |
|
| 1005 |
int py = (int) (y + r.y * scale); |
|
| 1009 |
int px = (int) (x + r.getLocation().x * scale); |
|
| 1010 |
int py = (int) (y + r.getLocation().y * scale); |
|
| 1006 | 1011 |
int radius = ColonetConstants.ROBOT_RADIUS; |
| 1007 | 1012 |
bufferedGraphics.drawOval(px-radius, py-radius, 2*radius, 2*radius); |
| 1008 | 1013 |
// ID, if applicable |
| 1009 |
if (r.id > 0) {
|
|
| 1014 |
if (r.getID() > 0) {
|
|
| 1010 | 1015 |
bufferedGraphics.setFont(new Font("arial", Font.PLAIN, 36));
|
| 1011 |
bufferedGraphics.drawString("" + r.id, px-10, py+10);
|
|
| 1016 |
bufferedGraphics.drawString("" + r.getID(), px-10, py+10);
|
|
| 1012 | 1017 |
} |
| 1013 | 1018 |
// Battery |
| 1014 |
if (r.battery >= 0) {
|
|
| 1015 |
int pixels = r.battery * ColonetConstants.BATTERY_WIDTH / 100; |
|
| 1016 |
if (r.battery > 50) |
|
| 1019 |
if (r.getBattery() >= 0) {
|
|
| 1020 |
int pixels = r.getBattery() * ColonetConstants.BATTERY_WIDTH / 100; |
|
| 1021 |
if (r.getBattery() > 50) |
|
| 1017 | 1022 |
bufferedGraphics.setColor(Color.GREEN); |
| 1018 |
else if (r.battery > 25) |
|
| 1023 |
else if (r.getBattery() > 25) |
|
| 1019 | 1024 |
bufferedGraphics.setColor(Color.YELLOW); |
| 1020 | 1025 |
else |
| 1021 | 1026 |
bufferedGraphics.setColor(Color.RED); |
| ... | ... | |
| 1024 | 1029 |
bufferedGraphics.drawRect(px+20, py+20, ColonetConstants.BATTERY_WIDTH, ColonetConstants.BATTERY_HEIGHT); |
| 1025 | 1030 |
} |
| 1026 | 1031 |
// If the robot has a destination, draw the vector |
| 1027 |
if (r.destx >= 0) {
|
|
| 1028 |
bufferedGraphics.drawLine(px, py, (int)(x + r.destx * scale), (int)(y + r.desty * scale)); |
|
| 1032 |
if (r.hasDestination()) {
|
|
| 1033 |
bufferedGraphics.drawLine(px, py, (int)(x + r.getDestination().x * scale), (int)(y + r.getDestination().y * scale)); |
|
| 1029 | 1034 |
} |
| 1030 | 1035 |
} |
| 1031 | 1036 |
} |
| ... | ... | |
| 1033 | 1038 |
// Identify currently-selected robot |
| 1034 | 1039 |
RobotIcon r = robotIcons.get(selectedBot); |
| 1035 | 1040 |
if (r != null) {
|
| 1036 |
int px = (int) (x + r.x * scale); |
|
| 1037 |
int py = (int) (y + r.y * scale); |
|
| 1041 |
int px = (int) (x + r.getLocation().x * scale); |
|
| 1042 |
int py = (int) (y + r.getLocation().y * scale); |
|
| 1038 | 1043 |
int radius = ColonetConstants.ROBOT_RADIUS; |
| 1039 | 1044 |
bufferedGraphics.setColor(Color.BLACK); |
| 1040 | 1045 |
bufferedGraphics.drawOval(px-radius-6, py-radius-6, 2*radius+12, 2*radius+12); |
| ... | ... | |
| 1052 | 1057 |
if (img == null) {
|
| 1053 | 1058 |
return new Point(e.getX(), e.getY()); |
| 1054 | 1059 |
} |
| 1060 |
return convertPoint(e.getX(), e.getY()); |
|
| 1061 |
} |
|
| 1062 |
|
|
| 1063 |
/** |
|
| 1064 |
* Convert a point on the webcam panel to a coordinate that is consistent with the |
|
| 1065 |
* original size of the image that the panel contains. |
|
| 1066 |
*/ |
|
| 1067 |
public Point convertPoint (int panelx, int panely) {
|
|
| 1055 | 1068 |
|
| 1056 | 1069 |
// Calculate scaling |
| 1057 | 1070 |
int border = ColonetConstants.WEBCAM_BORDER; |
| 1058 |
int clickx = e.getX(); |
|
| 1059 |
int clicky = e.getY(); |
|
| 1071 |
int clickx = panelx; |
|
| 1072 |
int clicky = panely; |
|
| 1060 | 1073 |
int maxWidth = getWidth() - 2*border; |
| 1061 | 1074 |
int maxHeight = getHeight() - 2*border; |
| 1062 | 1075 |
double widthRatio = 1.0 * maxWidth / img.getWidth(); |
Also available in: Unified diff