Project

General

Profile

Revision 459

Added by Greg Tress about 16 years ago

updated some colonet stuff

View differences:

Colonet.java
525 525
		}
526 526
	}
527 527
	
528
	/**
529
	* Parses a String containing visual robot position information along with 
530
	* canonical ID assignments.
531
	*/
532
	public void parsePositions (String line) {
533
		String [] str = line.split(" ");
534
		java.util.List <RobotIcon> newList = new ArrayList <RobotIcon> ();
535
		
536
		for (int i = 2; i < str.length; i+=3) {
537
			int id = Integer.parseInt(str[i]);
538
			int x = Integer.parseInt(str[i+1]);
539
			int y = Integer.parseInt(str[i+2]);
540
			RobotIcon newIcon = new RobotIcon(x, y);
541
			newIcon.id = id;
542
			newList.add(newIcon);
543
		}
544
		
545
		robotIcons = newList;
546
	
547
	}
548
	
549
	
528 550
	//
529 551
	// MouseListener methods
530 552
	//
......
642 664
		        return;
643 665
		    }
644 666
		    // Assign new ID and update display  
667
			csi.sendIDAssignment(curID, newID);
645 668
		    robotIcons.get(selectedBot).id = newID;
646 669
		    robotIcons.get(selectedBot).color = Color.GREEN;
647 670
		    lblSelected.setText(" " + newID);
......
939 962
			super();
940 963
		}
941 964
		
942
		public synchronized void setImage (BufferedImage newimg) {
965
		public void setImage (BufferedImage newimg) {
943 966
			if (img != null) {
944 967
				img.flush();
945
				img = null;
946
				img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
947
				txtMatrix.append("c");
948 968
			}
949 969
			System.gc();
950 970
			img = newimg;
951 971
		}
952 972
		
953
		public synchronized void setPoints (Point [] newpoints) {
973
		public void setPoints (Point [] newpoints) {
954 974
			// test code -- need to remove later
955 975
			if (newpoints == null) {
956 976
				Point [] p = new Point [3];
......
1027 1047
	*/
1028 1048
	class WebcamLoader extends Thread 
1029 1049
	{
1030
		final int WEBCAMLOADER_DELAY = 1000;
1050
		final int WEBCAMLOADER_DELAY = 200;
1031 1051
		final String IMAGE_PATH = "http://roboclub9.frc.ri.cmu.edu/colonet.jpg";
1032
		final String LOCATIONS_PATH = "http://roboclub9.frc.ri.cmu.edu/colonet/locations.txt";
1033
		
1052
				
1034 1053
		URL imagePath;
1035
		URI locationsPath;
1036 1054
		
1037 1055
		MediaTracker mt;
1038 1056
		BufferedImage image;
......
1047 1065
			} catch (MalformedURLException e) {
1048 1066
				System.out.println("Malformed URL: could not form URL from: [" + IMAGE_PATH + "]\n");
1049 1067
			}
1050
			try {
1051
				locationsPath = new URI(LOCATIONS_PATH);
1052
			} catch (URISyntaxException x) {
1053
				System.out.println("Malformed URI: could not form URI from: [" + LOCATIONS_PATH + "]\n");
1054
			}
1055 1068
			
1056 1069
		}
1057 1070
		
......
1071 1084
					mt.removeImage(image);
1072 1085
					// Save
1073 1086
					panelWebcam.setImage(image);
1074
					parseLocations(locationsPath.toURL());
1075
					//panelWebcam.setPoints(null);  //temporary simulation code
1076 1087
				} catch (InterruptedException e) {
1077 1088
					return;
1078 1089
				} catch (java.security.AccessControlException e) {
......
1084 1095
			}
1085 1096
		}
1086 1097
		
1087
		private void parseLocations (URL url) {
1088
			URLConnection conn = null;
1089
			DataInputStream data = null;
1090
			String line;
1091
			String [] lines = new String[30];
1092
			StringBuffer buf = new StringBuffer();
1093
			int i = 0;
1098
	}
1099
	
1100
	/*
1101
	*	PositionsLoader class
1102
	*	Handles the loading of the robot positions as seen by the vision technology.
1103
	*/
1104
	class PositionsLoader extends Thread 
1105
	{
1106
	
1107
		final int POSITIONSLOADER_DELAY = 600;
1108
	
1109
		public PositionsLoader () {
1110
			super("PositionsLoader");
1111
		}
1094 1112
		
1095
			try {
1096
				conn = url.openConnection();
1097
				conn.connect();
1098
				data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
1099
				while ((line = data.readLine()) != null) {
1100
					buf.append(line + ";");
1101
					lines[i] = line;
1102
					i++;
1113
		public void run () {
1114
			while (true) {
1115
				try {
1116
					Thread.sleep(POSITIONSLOADER_DELAY);
1117
					if (csi != null)
1118
						csi.sendPositionRequest();
1119
				} catch (InterruptedException e) {
1103 1120
				}
1104
				data.close();
1105
			} catch (IOException e) {
1106
				System.out.println("IOException:" + e.getMessage());
1107 1121
			}
1108
			//log.append("Got robot locations: " + buf + "\n");
1109
			
1110
			// Get Point values from strings
1111
			Point [] points = new Point[i];
1112
			for (int j = 0; j < i; j++) {
1113
				String [] parts = lines[j].split(",");
1114
				int xval = Integer.parseInt(parts[0]);
1115
				int yval = Integer.parseInt(parts[1]);
1116
				Point p = new Point(xval, yval);
1117
				points[j] = p;
1118
			}
1119
			if (points.length != 0)
1120
				panelWebcam.setPoints(points);
1121
			
1122 1122
		}
1123
	
1123 1124
	}
1124 1125
	
1125 1126
	/*
......
1128 1129
	*/
1129 1130
	class RobotIcon {
1130 1131
		public final int RADIUS = 30;
1131
		public final int CLOSE = 70;
1132
		public final int CLOSE = 80;
1132 1133
		
1133 1134
		public int x, y;
1134 1135
		public int destx, desty;
......
1517 1518
	        g2d.drawString(level + "%", greenX + greenWidth/2 - 10, greenY + greenHeight/2 + 5);
1518 1519
	        
1519 1520
	        g2d.dispose();
1520
	        System.out.println("Painted icon");
1521 1521
	    }
1522 1522
	    
1523 1523
		/**

Also available in: Unified diff