Преглед изворни кода

Arrumando problemas repositorio

capellaresumo пре 7 година
родитељ
комит
e5378d4881
100 измењених фајлова са 3 додато и 21247 уклоњено
  1. 3 0
      .gitignore
  2. 0 244
      .metadata/.plugins/org.eclipse.core.resources/.history/10/d0078ed7ddb90017124d9f37712eb7c1
  3. 0 276
      .metadata/.plugins/org.eclipse.core.resources/.history/11/5067e43bd0b90017124d9f37712eb7c1
  4. 0 279
      .metadata/.plugins/org.eclipse.core.resources/.history/11/a095259ad0b90017124d9f37712eb7c1
  5. 0 265
      .metadata/.plugins/org.eclipse.core.resources/.history/12/e0c1a89b8eba001711b8bf632416c20d
  6. 0 249
      .metadata/.plugins/org.eclipse.core.resources/.history/14/806d736491ba001711b8bf632416c20d
  7. 0 5
      .metadata/.plugins/org.eclipse.core.resources/.history/17/30aebf350cb9001711c7a09600ea5d68
  8. 0 304
      .metadata/.plugins/org.eclipse.core.resources/.history/18/30e132d2d2b90017124d9f37712eb7c1
  9. 0 262
      .metadata/.plugins/org.eclipse.core.resources/.history/19/a0960bafdeb90017124d9f37712eb7c1
  10. 0 242
      .metadata/.plugins/org.eclipse.core.resources/.history/1a/a0151c13a4ba001711b8bf632416c20d
  11. 0 272
      .metadata/.plugins/org.eclipse.core.resources/.history/1c/a0c27aa6e2b90017124d9f37712eb7c1
  12. 0 264
      .metadata/.plugins/org.eclipse.core.resources/.history/1d/c0369cb78eba001711b8bf632416c20d
  13. 0 274
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/4082a00be4b90017124d9f37712eb7c1
  14. 0 91
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/903d0c74c3b90017124d9f37712eb7c1
  15. 0 273
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/d0976df3e3b90017124d9f37712eb7c1
  16. 0 113
      .metadata/.plugins/org.eclipse.core.resources/.history/1f/a032661708b9001711c7a09600ea5d68
  17. 0 264
      .metadata/.plugins/org.eclipse.core.resources/.history/2/b0b6886cceb90017124d9f37712eb7c1
  18. 0 88
      .metadata/.plugins/org.eclipse.core.resources/.history/21/a03c38182cb80017145c9b6064c27648
  19. 0 273
      .metadata/.plugins/org.eclipse.core.resources/.history/22/f0670576e3b90017124d9f37712eb7c1
  20. 0 113
      .metadata/.plugins/org.eclipse.core.resources/.history/23/300f450808b9001711c7a09600ea5d68
  21. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/27/707c77822cb80017145c9b6064c27648
  22. 0 269
      .metadata/.plugins/org.eclipse.core.resources/.history/28/d032e1488eba001711b8bf632416c20d
  23. 0 129
      .metadata/.plugins/org.eclipse.core.resources/.history/2a/70201882c3b90017124d9f37712eb7c1
  24. 0 279
      .metadata/.plugins/org.eclipse.core.resources/.history/2d/f0faeaddd0b90017124d9f37712eb7c1
  25. 0 276
      .metadata/.plugins/org.eclipse.core.resources/.history/2e/c01a8e5fe4b90017124d9f37712eb7c1
  26. 0 297
      .metadata/.plugins/org.eclipse.core.resources/.history/2f/7047bc93d2b90017124d9f37712eb7c1
  27. 0 287
      .metadata/.plugins/org.eclipse.core.resources/.history/30/0055086ed2b90017124d9f37712eb7c1
  28. 0 258
      .metadata/.plugins/org.eclipse.core.resources/.history/32/2025fb61ceb90017124d9f37712eb7c1
  29. 0 256
      .metadata/.plugins/org.eclipse.core.resources/.history/33/208d50b7a1ba001711b8bf632416c20d
  30. 0 256
      .metadata/.plugins/org.eclipse.core.resources/.history/33/b08bfb86a2ba001711b8bf632416c20d
  31. 0 233
      .metadata/.plugins/org.eclipse.core.resources/.history/34/60767e52ddb90017124d9f37712eb7c1
  32. 0 242
      .metadata/.plugins/org.eclipse.core.resources/.history/39/00ab9643a4ba001711b8bf632416c20d
  33. 0 126
      .metadata/.plugins/org.eclipse.core.resources/.history/3c/c0b98aeac7b90017124d9f37712eb7c1
  34. 0 264
      .metadata/.plugins/org.eclipse.core.resources/.history/3d/a08c22e3deb90017124d9f37712eb7c1
  35. 0 274
      .metadata/.plugins/org.eclipse.core.resources/.history/3d/c0a7c75ce4b90017124d9f37712eb7c1
  36. 0 269
      .metadata/.plugins/org.eclipse.core.resources/.history/3e/f0da7d79e5b90017124d9f37712eb7c1
  37. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/4/005579132cb80017145c9b6064c27648
  38. 0 132
      .metadata/.plugins/org.eclipse.core.resources/.history/4/f054a86fc8b90017124d9f37712eb7c1
  39. 0 239
      .metadata/.plugins/org.eclipse.core.resources/.history/40/a02abf9addb90017124d9f37712eb7c1
  40. 0 232
      .metadata/.plugins/org.eclipse.core.resources/.history/41/40d22eaddcb90017124d9f37712eb7c1
  41. 0 231
      .metadata/.plugins/org.eclipse.core.resources/.history/41/f01bff8dcdb90017124d9f37712eb7c1
  42. 0 220
      .metadata/.plugins/org.eclipse.core.resources/.history/42/3097ab76dcb90017124d9f37712eb7c1
  43. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/43/400443aa2cb80017145c9b6064c27648
  44. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/43/b0cc582f2cb80017145c9b6064c27648
  45. 0 90
      .metadata/.plugins/org.eclipse.core.resources/.history/46/c01a5ad02bb80017145c9b6064c27648
  46. 0 124
      .metadata/.plugins/org.eclipse.core.resources/.history/48/f0cb5087c3b90017124d9f37712eb7c1
  47. 0 262
      .metadata/.plugins/org.eclipse.core.resources/.history/4a/708032d3deb90017124d9f37712eb7c1
  48. 0 237
      .metadata/.plugins/org.eclipse.core.resources/.history/4b/40c35f80ddb90017124d9f37712eb7c1
  49. 0 253
      .metadata/.plugins/org.eclipse.core.resources/.history/5/f0befc5edeb90017124d9f37712eb7c1
  50. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/52/305247498fba001711b8bf632416c20d
  51. 0 253
      .metadata/.plugins/org.eclipse.core.resources/.history/52/902a9128deb90017124d9f37712eb7c1
  52. 0 266
      .metadata/.plugins/org.eclipse.core.resources/.history/53/102741b7e1b90017124d9f37712eb7c1
  53. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/53/b0f9cebd8eba001711b8bf632416c20d
  54. 0 287
      .metadata/.plugins/org.eclipse.core.resources/.history/57/00f0d28ad2b90017124d9f37712eb7c1
  55. 0 276
      .metadata/.plugins/org.eclipse.core.resources/.history/57/40a15267e4b90017124d9f37712eb7c1
  56. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/57/e0d3de7d10b9001711c7a09600ea5d68
  57. 0 259
      .metadata/.plugins/org.eclipse.core.resources/.history/5d/90056840ceb90017124d9f37712eb7c1
  58. 0 133
      .metadata/.plugins/org.eclipse.core.resources/.history/5e/70ed22dfcab90017124d9f37712eb7c1
  59. 0 278
      .metadata/.plugins/org.eclipse.core.resources/.history/6/103971d6d0b90017124d9f37712eb7c1
  60. 0 90
      .metadata/.plugins/org.eclipse.core.resources/.history/67/d07cb9c22bb80017145c9b6064c27648
  61. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/6a/9092fb0d8fba001711b8bf632416c20d
  62. 0 257
      .metadata/.plugins/org.eclipse.core.resources/.history/6b/103bd28991ba001711b8bf632416c20d
  63. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/6b/c0fb27ad2cb80017145c9b6064c27648
  64. 0 261
      .metadata/.plugins/org.eclipse.core.resources/.history/6f/80b8097e91ba001711b8bf632416c20d
  65. 0 261
      .metadata/.plugins/org.eclipse.core.resources/.history/7/8067c68091ba001711b8bf632416c20d
  66. 0 220
      .metadata/.plugins/org.eclipse.core.resources/.history/71/0055be67dcb90017124d9f37712eb7c1
  67. 0 126
      .metadata/.plugins/org.eclipse.core.resources/.history/75/709c8c69c8b90017124d9f37712eb7c1
  68. 0 126
      .metadata/.plugins/org.eclipse.core.resources/.history/77/10383aefc7b90017124d9f37712eb7c1
  69. 0 281
      .metadata/.plugins/org.eclipse.core.resources/.history/77/3040316bd2b90017124d9f37712eb7c1
  70. 0 262
      .metadata/.plugins/org.eclipse.core.resources/.history/7c/00b84db4deb90017124d9f37712eb7c1
  71. 0 262
      .metadata/.plugins/org.eclipse.core.resources/.history/7c/c08abb5f91ba001711b8bf632416c20d
  72. 0 251
      .metadata/.plugins/org.eclipse.core.resources/.history/7e/2028eb0edeb90017124d9f37712eb7c1
  73. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/80/10020a9e2bb80017145c9b6064c27648
  74. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/80/f051cfab8fba001711b8bf632416c20d
  75. 0 273
      .metadata/.plugins/org.eclipse.core.resources/.history/81/a06cf2bfe3b90017124d9f37712eb7c1
  76. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/81/c02176f28eba001711b8bf632416c20d
  77. 0 254
      .metadata/.plugins/org.eclipse.core.resources/.history/83/7030314aa4ba001711b8bf632416c20d
  78. 0 276
      .metadata/.plugins/org.eclipse.core.resources/.history/83/a09eb1fbcfb90017124d9f37712eb7c1
  79. 0 88
      .metadata/.plugins/org.eclipse.core.resources/.history/84/f075ec6c2bb80017145c9b6064c27648
  80. 0 219
      .metadata/.plugins/org.eclipse.core.resources/.history/86/6048d52fdcb90017124d9f37712eb7c1
  81. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/88/900e1b5f2cb80017145c9b6064c27648
  82. 0 7
      .metadata/.plugins/org.eclipse.core.resources/.history/88/90ecdad50cb9001711c7a09600ea5d68
  83. 0 256
      .metadata/.plugins/org.eclipse.core.resources/.history/88/d0913708a1ba001711b8bf632416c20d
  84. 0 263
      .metadata/.plugins/org.eclipse.core.resources/.history/8e/a011523fe2b90017124d9f37712eb7c1
  85. 0 256
      .metadata/.plugins/org.eclipse.core.resources/.history/8f/c02e6840a1ba001711b8bf632416c20d
  86. 0 269
      .metadata/.plugins/org.eclipse.core.resources/.history/9/803562b9e5b90017124d9f37712eb7c1
  87. 0 233
      .metadata/.plugins/org.eclipse.core.resources/.history/92/10ea7ebbdcb90017124d9f37712eb7c1
  88. 0 90
      .metadata/.plugins/org.eclipse.core.resources/.history/92/40a917d22bb80017145c9b6064c27648
  89. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/92/f039214b2cb80017145c9b6064c27648
  90. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/96/903059312cb80017145c9b6064c27648
  91. 0 304
      .metadata/.plugins/org.eclipse.core.resources/.history/9b/301965d6d2b90017124d9f37712eb7c1
  92. 0 236
      .metadata/.plugins/org.eclipse.core.resources/.history/9d/d0156e58ddb90017124d9f37712eb7c1
  93. 0 268
      .metadata/.plugins/org.eclipse.core.resources/.history/9d/f0d28dbce5b90017124d9f37712eb7c1
  94. 0 262
      .metadata/.plugins/org.eclipse.core.resources/.history/a/a0aea77491ba001711b8bf632416c20d
  95. 0 274
      .metadata/.plugins/org.eclipse.core.resources/.history/a0/f0cecdf5e3b90017124d9f37712eb7c1
  96. 0 256
      .metadata/.plugins/org.eclipse.core.resources/.history/a2/d042f403a1ba001711b8bf632416c20d
  97. 0 89
      .metadata/.plugins/org.eclipse.core.resources/.history/a3/603140a12cb80017145c9b6064c27648
  98. 0 255
      .metadata/.plugins/org.eclipse.core.resources/.history/a3/d082b469a4ba001711b8bf632416c20d
  99. 0 275
      .metadata/.plugins/org.eclipse.core.resources/.history/a3/d0afc10fcfb90017124d9f37712eb7c1
  100. 0 304
      .metadata/.plugins/org.eclipse.core.resources/.history/a8/00c67dc3d2b90017124d9f37712eb7c1

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.metadata/
+.recommenders/
+

+ 0 - 244
.metadata/.plugins/org.eclipse.core.resources/.history/10/d0078ed7ddb90017124d9f37712eb7c1

@@ -1,244 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			// TODO Auto-generated method stub
-			countsema.acquire();
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 276
.metadata/.plugins/org.eclipse.core.resources/.history/11/5067e43bd0b90017124d9f37712eb7c1

@@ -1,276 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-//		if (data.getDistance() == 255)
-//			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 279
.metadata/.plugins/org.eclipse.core.resources/.history/11/a095259ad0b90017124d9f37712eb7c1

@@ -1,279 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.addRead(p, data.getDistance(), data.getSensorAngle(), 0);
-			scanner.clean();
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 265
.metadata/.plugins/org.eclipse.core.resources/.history/12/e0c1a89b8eba001711b8bf632416c20d

@@ -1,265 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() <= creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		countsema.release(180);
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 249
.metadata/.plugins/org.eclipse.core.resources/.history/14/806d736491ba001711b8bf632416c20d

@@ -1,249 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 5
.metadata/.plugins/org.eclipse.core.resources/.history/17/30aebf350cb9001711c7a09600ea5d68

@@ -1,5 +0,0 @@
-package config;
-
-public class SonarModel {
-
-}

+ 0 - 304
.metadata/.plugins/org.eclipse.core.resources/.history/18/30e132d2d2b90017124d9f37712eb7c1

@@ -1,304 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			int r = Integer.parseInt(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-			return;
-		}
-		
-	}
-
-	private void rotateRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-	
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter distance (cm):");
-			double r = Double.parseDouble(rs);
-			robot.move(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 262
.metadata/.plugins/org.eclipse.core.resources/.history/19/a0960bafdeb90017124d9f37712eb7c1

@@ -1,262 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= xxxx) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		try {
-			countsema.acquire();
-			reads.clear();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 242
.metadata/.plugins/org.eclipse.core.resources/.history/1a/a0151c13a4ba001711b8bf632416c20d

@@ -1,242 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	public static final byte TYPE_INT = 1;
-	public static final byte TYPE_CMD = 2;
-	public static final byte TYPE_POSE = 3;
-	public static final byte TYPE_FLOAT = 4;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(y, -x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private class Sender extends Thread {
-		
-	}
-	
-	private class SendData {
-		float f;
-		int i;
-		int cmd;
-		Pose p;
-		int type;
-		SendData(int cmd) {
-			this.cmd = cmd;
-			this.type = TYPE_CMD
-		}
-		SendData(int cmd, int i) {
-			this.cmd = cmd;
-			this.i = i;
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(y, -x, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 272
.metadata/.plugins/org.eclipse.core.resources/.history/1c/a0c27aa6e2b90017124d9f37712eb7c1

@@ -1,272 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-
-		reads.clear();
-		try {
-			countsema.acquire();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 264
.metadata/.plugins/org.eclipse.core.resources/.history/1d/c0369cb78eba001711b8bf632416c20d

@@ -1,264 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 274
.metadata/.plugins/org.eclipse.core.resources/.history/1e/4082a00be4b90017124d9f37712eb7c1

@@ -1,274 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		try {
-			countsema.acquire();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 91
.metadata/.plugins/org.eclipse.core.resources/.history/1e/903d0c74c3b90017124d9f37712eb7c1

@@ -1,91 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 273
.metadata/.plugins/org.eclipse.core.resources/.history/1e/d0976df3e3b90017124d9f37712eb7c1

@@ -1,273 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-
-		reads.clear();
-//		try {
-//			countsema.acquire();
-//		} catch (InterruptedException e1) {
-//			// TODO Auto-generated catch block
-//			e1.printStackTrace();
-//		}
-//		
-//		try {
-//			send(SETSCANANGLE, scannangle);
-//			countsema.acquire();
-//			return reads;
-//		} catch (InterruptedException e) {
-//			e.printStackTrace();
-//		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 113
.metadata/.plugins/org.eclipse.core.resources/.history/1f/a032661708b9001711c7a09600ea5d68

@@ -1,113 +0,0 @@
-import java.awt.Color;
-import java.awt.Graphics;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import javax.swing.JPanel;
-
-import lejos.geom.Line;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class ScannerImage extends JPanel {
-	private Pose pose;
-	private LineMap map;
-	private ArrayList<SonarRead> lista_leituras;
-	private Semaphore semaphore;
-	
-	class SonarRead {
-		public double distance;
-		public double ang;
-		SonarRead (double distance, double ang) {
-			this.ang = ang;
-			this.distance = distance;
-		}
-	}
-	
-    @Override
-    protected void paintComponent(Graphics g) {
-    		int w = this.getWidth()/2;
-    		int h = this.getHeight();
-    		int distance = h*2/25;
-    		g.setColor(new Color(0f, 0f, 0f, 0.4f));
-    		for (int i = 1; i <= 18; i++) {
-    			int r = distance * i;
-        		g.drawArc(w-r, h-r, 2*r, 2*r, 0, 180);
-        		g.drawString(new Integer(i*20).toString(), w-7, h-r);
-    		}
-    		g.setColor(new Color(0f, 0f, 0f, 0.5f));
-    		for (int i = 1; i < 6; i++) {
-    			int lw = (int)(Math.cos(Math.PI/6.0*i)*distance * 18);
-    			int lh = (int)(Math.sin(Math.PI/6.0*i)*distance * 18);
-    			g.drawLine(w, h, lw+w, h-lh);
-    		}
-    		g.setColor(new Color(0f, 0f, 0f, 0.1f));
-    		for (int i = 1; i < 12; i++) {
-    			int lw = (int)(Math.cos(Math.PI/12.0*i)*distance * 18);
-    			int lh = (int)(Math.sin(Math.PI/12.0*i)*distance * 18);
-    			g.drawLine(w, h, lw+w, h-lh);
-    		}
-    		
-
-    		if (semaphore.tryAcquire()) {
-    			double d = h*2.0/25.0/200.0;
-    			
-    			g.setColor(new Color(0f, 1f, 0f));
-		    	if (map != null && pose!= null) {
-		    		Line[] lines = map.getLines();
-		    		for (int i = 0; i < lines.length; i++) {
-		    			Line l = lines[i];
-		            g.drawLine(
-			                (int)(w+(l.x1-pose.getX())*d),
-			                (int)(h-(l.y1-pose.getY())*d), 
-			                (int)(w+(l.x2-pose.getX())*d),
-			                (int)(h-(l.y2-pose.getY())*d)
-			        );
-		    		}
-		    	}
-    		
-    			drawDots(g, w, h);
-    	        semaphore.release();
-    		}
-    	}
-
-	private void drawDots(Graphics g, int w, int h) {
-		g.setColor(new Color(1f, 0f, 0f));
-		int oval_size = 30;
-		int distance = h*2/25;
-		double d = distance/20.0;
-		double a = -oval_size/4;
-		for (SonarRead r: lista_leituras) {
-			double x = a+(d*r.distance)*Math.sin(Math.toRadians(r.ang));
-			double y = a+(d*r.distance)*Math.cos(Math.toRadians(r.ang));
-			x = w - x;
-			y = h - y;
-		g.fillOval((int)(x-oval_size/2.0), (int)(y-oval_size/2.0), oval_size/2, oval_size/2);
-		}
-		if (map == null) return;
-	}
-   
-
-	public Pose getPose() {
-		return pose;
-	}
-
-	public void addRead(Pose p, double distance, double ang) {
-		if (semaphore.tryAcquire()) {
-			if (pose == null || !(p.getX() == pose.getX() && p.getY() == pose.getY() 
-					&& p.getHeading() == pose.getHeading())) {
-				pose = new Pose(p.getX(), p.getY(), p.getHeading());
-				lista_leituras.clear();
-			}
-			lista_leituras.add(new SonarRead(distance, ang+90));
-	        semaphore.release();
-		}
-		repaint();
-	}
-	
-	public ScannerImage(LineMap map) {
-		this.map = map;
-		semaphore = new Semaphore(1);
-		lista_leituras =  new ArrayList<SonarRead>();
-	}
-}

+ 0 - 264
.metadata/.plugins/org.eclipse.core.resources/.history/2/b0b6886cceb90017124d9f37712eb7c1

@@ -1,264 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean global map.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void setRobotPose() {
-		String xs = JOptionPane.showInputDialog("Enter x (cm):");
-		if (xs.length() == 0) return;
-		String ys = JOptionPane.showInputDialog("Enter y (cm):");
-		if (ys.length() == 0) return;
-		String as = JOptionPane.showInputDialog("Enter heading (degress):");
-		if (as.length() == 0) return;
-		try {
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 88
.metadata/.plugins/org.eclipse.core.resources/.history/21/a03c38182cb80017145c9b6064c27648

@@ -1,88 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 273
.metadata/.plugins/org.eclipse.core.resources/.history/22/f0670576e3b90017124d9f37712eb7c1

@@ -1,273 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-
-		reads.clear();
-		try {
-			countsema.acquire();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 113
.metadata/.plugins/org.eclipse.core.resources/.history/23/300f450808b9001711c7a09600ea5d68

@@ -1,113 +0,0 @@
-import java.awt.Color;
-import java.awt.Graphics;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import javax.swing.JPanel;
-
-import lejos.geom.Line;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class ScannerImage extends JPanel {
-	private Pose pose;
-	private LineMap map;
-	private ArrayList<SonarRead> lista_leituras;
-	private Semaphore semaphore;
-	
-	class SonarRead {
-		public double distance;
-		public double ang;
-		SonarRead (double distance, double ang) {
-			this.ang = ang;
-			this.distance = distance;
-		}
-	}
-	
-    @Override
-    protected void paintComponent(Graphics g) {
-    		int w = this.getWidth()/2;
-    		int h = this.getHeight();
-    		int distance = h*2/25;
-    		g.setColor(new Color(0f, 0f, 0f, 0.4f));
-    		for (int i = 1; i <= 18; i++) {
-    			int r = distance * i;
-        		g.drawArc(w-r, h-r, 2*r, 2*r, 0, 180);
-        		g.drawString(new Integer(i*20).toString(), w-7, h-r);
-    		}
-    		g.setColor(new Color(0f, 0f, 0f, 0.5f));
-    		for (int i = 1; i < 6; i++) {
-    			int lw = (int)(Math.cos(Math.PI/6.0*i)*distance * 18);
-    			int lh = (int)(Math.sin(Math.PI/6.0*i)*distance * 18);
-    			g.drawLine(w, h, lw+w, h-lh);
-    		}
-    		g.setColor(new Color(0f, 0f, 0f, 0.1f));
-    		for (int i = 1; i < 12; i++) {
-    			int lw = (int)(Math.cos(Math.PI/12.0*i)*distance * 18);
-    			int lh = (int)(Math.sin(Math.PI/12.0*i)*distance * 18);
-    			g.drawLine(w, h, lw+w, h-lh);
-    		}
-    		
-
-    		if (semaphore.tryAcquire()) {
-    			double d = h*2.0/25.0/100.0;
-    			
-    			g.setColor(new Color(0f, 1f, 0f));
-		    	if (map != null && pose!= null) {
-		    		Line[] lines = map.getLines();
-		    		for (int i = 0; i < lines.length; i++) {
-		    			Line l = lines[i];
-		            g.drawLine(
-			                (int)(w+(l.x1-pose.getX())*d),
-			                (int)(h-(l.y1-pose.getY())*d), 
-			                (int)(w+(l.x2-pose.getX())*d),
-			                (int)(h-(l.y2-pose.getY())*d)
-			        );
-		    		}
-		    	}
-    		
-    			drawDots(g, w, h);
-    	        semaphore.release();
-    		}
-    	}
-
-	private void drawDots(Graphics g, int w, int h) {
-		g.setColor(new Color(1f, 0f, 0f));
-		int oval_size = 30;
-		int distance = h*2/25;
-		double d = distance/20.0;
-		double a = -oval_size/4;
-		for (SonarRead r: lista_leituras) {
-			double x = a+(d*r.distance)*Math.sin(Math.toRadians(r.ang));
-			double y = a+(d*r.distance)*Math.cos(Math.toRadians(r.ang));
-			x = w - x;
-			y = h - y;
-		g.fillOval((int)(x-oval_size/2.0), (int)(y-oval_size/2.0), oval_size/2, oval_size/2);
-		}
-		if (map == null) return;
-	}
-   
-
-	public Pose getPose() {
-		return pose;
-	}
-
-	public void addRead(Pose p, double distance, double ang) {
-		if (semaphore.tryAcquire()) {
-			if (pose == null || !(p.getX() == pose.getX() && p.getY() == pose.getY() 
-					&& p.getHeading() == pose.getHeading())) {
-				pose = new Pose(p.getX(), p.getY(), p.getHeading());
-				lista_leituras.clear();
-			}
-			lista_leituras.add(new SonarRead(distance, ang+90));
-	        semaphore.release();
-		}
-		repaint();
-	}
-	
-	public ScannerImage(LineMap map) {
-		this.map = map;
-		semaphore = new Semaphore(1);
-		lista_leituras =  new ArrayList<SonarRead>();
-	}
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/27/707c77822cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 269
.metadata/.plugins/org.eclipse.core.resources/.history/28/d032e1488eba001711b8bf632416c20d

@@ -1,269 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						}
-						countsema.release(180/creads);
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(180);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			scann(null);
-			countsema.acquire(180);
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		stopScann();
-		countsema.release(180);
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 129
.metadata/.plugins/org.eclipse.core.resources/.history/2a/70201882c3b90017124d9f37712eb7c1

@@ -1,129 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void disconnect() {
-		// TODO Auto-generated method stub
-		
-	}
-
-}

+ 0 - 279
.metadata/.plugins/org.eclipse.core.resources/.history/2d/f0faeaddd0b90017124d9f37712eb7c1

@@ -1,279 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(p);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 276
.metadata/.plugins/org.eclipse.core.resources/.history/2e/c01a8e5fe4b90017124d9f37712eb7c1

@@ -1,276 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			countsema.acquire();
-			startScann();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			countsema.acquire();
-			stopScann();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 297
.metadata/.plugins/org.eclipse.core.resources/.history/2f/7047bc93d2b90017124d9f37712eb7c1

@@ -1,297 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void rotateRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.move(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-	
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 287
.metadata/.plugins/org.eclipse.core.resources/.history/30/0055086ed2b90017124d9f37712eb7c1

@@ -1,287 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseFloat(r);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 258
.metadata/.plugins/org.eclipse.core.resources/.history/32/2025fb61ceb90017124d9f37712eb7c1

@@ -1,258 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean global map.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void setRobotPose() {
-		String xs = JOptionPane.showInputDialog("Enter x (cm):");
-		if (xs.length() == 0) return;
-		String ys = JOptionPane.showInputDialog("Enter y (cm):");
-		if (ys.length() == 0) return;
-		String as = JOptionPane.showInputDialog("Enter heading (degress):");
-		if (as.length() == 0) return;
-		try {
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 256
.metadata/.plugins/org.eclipse.core.resources/.history/33/208d50b7a1ba001711b8bf632416c20d

@@ -1,256 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(-y, x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(-x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 256
.metadata/.plugins/org.eclipse.core.resources/.history/33/b08bfb86a2ba001711b8bf632416c20d

@@ -1,256 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(y, -x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(y, -x, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 233
.metadata/.plugins/org.eclipse.core.resources/.history/34/60767e52ddb90017124d9f37712eb7c1

@@ -1,233 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SCANN = 11;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SCANN, interval);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 242
.metadata/.plugins/org.eclipse.core.resources/.history/39/00ab9643a4ba001711b8bf632416c20d

@@ -1,242 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	public static final byte TYPE_INT = 1;
-	public static final byte TYPE_CMD = 2;
-	public static final byte TYPE_POSE = 3;
-	public static final byte TYPE_FLOAT = 4;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(y, -x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private class Sender extends Thread {
-		
-	}
-	
-	private class SendData {
-		float f;
-		int i;
-		int cmd;
-		Pose p;
-		int type;
-		SendData(int cmd) {
-			this.cmd = cmd;
-			this.type = TYPE_CMD;
-		}
-		SendData(int cmd, int i) {
-			this.cmd = cmd;
-			this.i = i;
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(y, -x, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 126
.metadata/.plugins/org.eclipse.core.resources/.history/3c/c0b98aeac7b90017124d9f37712eb7c1

@@ -1,126 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	private LineMap map;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-		this.map = map;
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 264
.metadata/.plugins/org.eclipse.core.resources/.history/3d/a08c22e3deb90017124d9f37712eb7c1

@@ -1,264 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		receivethread.startCount();
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 274
.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0a7c75ce4b90017124d9f37712eb7c1

@@ -1,274 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			countsema.acquire();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 269
.metadata/.plugins/org.eclipse.core.resources/.history/3e/f0da7d79e5b90017124d9f37712eb7c1

@@ -1,269 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			scann(null);
-			countsema.acquire(180);
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		stopScann();
-		countsema.release(180);
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/4/005579132cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 132
.metadata/.plugins/org.eclipse.core.resources/.history/4/f054a86fc8b90017124d9f37712eb7c1

@@ -1,132 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	private LineMap map;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				
-
-				Pose tmppose = new Pose(p.getX(), p.getY(), (float) (pose.getHeading() + ang));
-				float dist = map.range(tmppose);
-				
-				
-				data.setDistance((int)dist);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(200);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-		this.map = map;
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 239
.metadata/.plugins/org.eclipse.core.resources/.history/40/a02abf9addb90017124d9f37712eb7c1

@@ -1,239 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 232
.metadata/.plugins/org.eclipse.core.resources/.history/41/40d22eaddcb90017124d9f37712eb7c1

@@ -1,232 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 231
.metadata/.plugins/org.eclipse.core.resources/.history/41/f01bff8dcdb90017124d9f37712eb7c1

@@ -1,231 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null) {
-			result = robot.connect();
-			robot.scann(this);
-		}
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean global map.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "h - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		char input = e.getKeyChar();
-		if (input == '1')
-			imap.setVisual(0);
-		else if (input == '2')
-			imap.setVisual(1);
-		else if (input == '3')
-			imap.setVisual(2);
-		else if (input == 'l')
-			imap.showLine();
-		else if (input == 'g')
-			imap.save();
-		else if (input == 'c')
-			imap.clean();
-		else if (input == 's')
-			setRobotPose();
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void setRobotPose() {
-		String xs = JOptionPane.showInputDialog("Enter x (cm):");
-		if (xs.length() == 0) return;
-		String ys = JOptionPane.showInputDialog("Enter y (cm):");
-		if (ys.length() == 0) return;
-		String as = JOptionPane.showInputDialog("Enter heading (degress):");
-		if (as.length() == 0) return;
-		try {
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 220
.metadata/.plugins/org.eclipse.core.resources/.history/42/3097ab76dcb90017124d9f37712eb7c1

@@ -1,220 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-		
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/43/400443aa2cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 180) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/43/b0cc582f2cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 90
.metadata/.plugins/org.eclipse.core.resources/.history/46/c01a5ad02bb80017145c9b6064c27648

@@ -1,90 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 124
.metadata/.plugins/org.eclipse.core.resources/.history/48/f0cb5087c3b90017124d9f37712eb7c1

@@ -1,124 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 262
.metadata/.plugins/org.eclipse.core.resources/.history/4a/708032d3deb90017124d9f37712eb7c1

@@ -1,262 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= xxxx) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 237
.metadata/.plugins/org.eclipse.core.resources/.history/4b/40c35f80ddb90017124d9f37712eb7c1

@@ -1,237 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 253
.metadata/.plugins/org.eclipse.core.resources/.history/5/f0befc5edeb90017124d9f37712eb7c1

@@ -1,253 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			// TODO Auto-generated method stub
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/52/305247498fba001711b8bf632416c20d

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 253
.metadata/.plugins/org.eclipse.core.resources/.history/52/902a9128deb90017124d9f37712eb7c1

@@ -1,253 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			// TODO Auto-generated method stub
-			try {
-				countsema.acquire();
-				count = 0;
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 266
.metadata/.plugins/org.eclipse.core.resources/.history/53/102741b7e1b90017124d9f37712eb7c1

@@ -1,266 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		receivethread.startCount();
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/53/b0f9cebd8eba001711b8bf632416c20d

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 287
.metadata/.plugins/org.eclipse.core.resources/.history/57/00f0d28ad2b90017124d9f37712eb7c1

@@ -1,287 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 276
.metadata/.plugins/org.eclipse.core.resources/.history/57/40a15267e4b90017124d9f37712eb7c1

@@ -1,276 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			countsema.acquire();
-			start();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			countsema.acquire();
-			stopScann();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/57/e0d3de7d10b9001711c7a09600ea5d68

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -180 || ang == 0) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 259
.metadata/.plugins/org.eclipse.core.resources/.history/5d/90056840ceb90017124d9f37712eb7c1

@@ -1,259 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null) {
-			result = robot.connect();
-			robot.scann(this);
-		}
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean global map.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void setRobotPose() {
-		String xs = JOptionPane.showInputDialog("Enter x (cm):");
-		if (xs.length() == 0) return;
-		String ys = JOptionPane.showInputDialog("Enter y (cm):");
-		if (ys.length() == 0) return;
-		String as = JOptionPane.showInputDialog("Enter heading (degress):");
-		if (as.length() == 0) return;
-		try {
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 133
.metadata/.plugins/org.eclipse.core.resources/.history/5e/70ed22dfcab90017124d9f37712eb7c1

@@ -1,133 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	private LineMap map;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				
-
-				Pose tmppose = new Pose(pose.getX(), pose.getY(), (float) (pose.getHeading() + ang));
-				float dist = map.range(tmppose);
-				if (dist == -1) dist =  255;
-				
-				
-				data.setDistance((int)dist);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(200);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-		this.map = map;
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 278
.metadata/.plugins/org.eclipse.core.resources/.history/6/103971d6d0b90017124d9f37712eb7c1

@@ -1,278 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 90
.metadata/.plugins/org.eclipse.core.resources/.history/67/d07cb9c22bb80017145c9b6064c27648

@@ -1,90 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/6a/9092fb0d8fba001711b8bf632416c20d

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-//		send(SETSCANANGLE, scannangle);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 257
.metadata/.plugins/org.eclipse.core.resources/.history/6b/103bd28991ba001711b8bf632416c20d

@@ -1,257 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/6b/c0fb27ad2cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -180 || ang == 0) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 261
.metadata/.plugins/org.eclipse.core.resources/.history/6f/80b8097e91ba001711b8bf632416c20d

@@ -1,261 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 261
.metadata/.plugins/org.eclipse.core.resources/.history/7/8067c68091ba001711b8bf632416c20d

@@ -1,261 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-//		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 220
.metadata/.plugins/org.eclipse.core.resources/.history/71/0055be67dcb90017124d9f37712eb7c1

@@ -1,220 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 126
.metadata/.plugins/org.eclipse.core.resources/.history/75/709c8c69c8b90017124d9f37712eb7c1

@@ -1,126 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	private LineMap map;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(map.range(pose));
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(200);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-		this.map = map;
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 126
.metadata/.plugins/org.eclipse.core.resources/.history/77/10383aefc7b90017124d9f37712eb7c1

@@ -1,126 +0,0 @@
-package robots;
-
-import java.util.ArrayList;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	private LineMap map;
-
-	private class Simulate extends Thread {
-		public boolean run = true;
-
-		public void run() {
-			int ang = 0;
-			int add = -5;
-			while (run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-
-				rr.robotData(data);
-
-				ang += add;
-				if (ang == -180 || ang == 0)
-					add *= -1;
-
-				try {
-					Thread.sleep(200);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-		this.map = map;
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) dx, (float) -dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading())) * 5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading())) * 5;
-		pose.translate((float) -dx, (float) dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {
-	}
-
-	@Override
-	public void move(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void rotate(double x) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void disconnect() {
-
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-
-	}
-
-}

+ 0 - 281
.metadata/.plugins/org.eclipse.core.resources/.history/77/3040316bd2b90017124d9f37712eb7c1

@@ -1,281 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 262
.metadata/.plugins/org.eclipse.core.resources/.history/7c/00b84db4deb90017124d9f37712eb7c1

@@ -1,262 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= xxxx) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			try {
-				countsema.acquire();
-				reads.clear();
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		try {
-			send(SETSCANANGLE, scannangle);
-			return reads;
-			countsema.acquire();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 262
.metadata/.plugins/org.eclipse.core.resources/.history/7c/c08abb5f91ba001711b8bf632416c20d

@@ -1,262 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 251
.metadata/.plugins/org.eclipse.core.resources/.history/7e/2028eb0edeb90017124d9f37712eb7c1

@@ -1,251 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		private int count;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-		public void startCount() {
-			// TODO Auto-generated method stub
-			try {
-				countsema.acquire();
-				count = 0;
-			} catch (InterruptedException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		receivethread.startCount();
-		
-		send(SETSCANANGLE, scannangle);
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/80/10020a9e2bb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/80/f051cfab8fba001711b8bf632416c20d

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 273
.metadata/.plugins/org.eclipse.core.resources/.history/81/a06cf2bfe3b90017124d9f37712eb7c1

@@ -1,273 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-
-//		reads.clear();
-//		try {
-//			countsema.acquire();
-//		} catch (InterruptedException e1) {
-//			// TODO Auto-generated catch block
-//			e1.printStackTrace();
-//		}
-//		
-//		try {
-//			send(SETSCANANGLE, scannangle);
-//			countsema.acquire();
-//			return reads;
-//		} catch (InterruptedException e) {
-//			e.printStackTrace();
-//		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/81/c02176f28eba001711b8bf632416c20d

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		send(SETSCANANGLE, scannangle);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 254
.metadata/.plugins/org.eclipse.core.resources/.history/83/7030314aa4ba001711b8bf632416c20d

@@ -1,254 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	public static final byte TYPE_INT = 1;
-	public static final byte TYPE_CMD = 2;
-	public static final byte TYPE_POSE = 3;
-	public static final byte TYPE_FLOAT = 4;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(y, -x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private class Sender extends Thread {
-		
-	}
-	
-	private class SendData {
-		float f;
-		int i;
-		int cmd;
-		Pose p;
-		int type;
-		SendData(int cmd) {
-			this.cmd = cmd;
-			this.type = TYPE_CMD;
-		}
-		SendData(int cmd, int i) {
-			this.cmd = cmd;
-			this.i = i;
-		}
-		public boolean send() {
-			if (type == 0) return false;
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				return false;
-			}
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(y, -x, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 276
.metadata/.plugins/org.eclipse.core.resources/.history/83/a09eb1fbcfb90017124d9f37712eb7c1

@@ -1,276 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 88
.metadata/.plugins/org.eclipse.core.resources/.history/84/f075ec6c2bb80017145c9b6064c27648

@@ -1,88 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-	}
-
-	@Override
-	public void moveForward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 219
.metadata/.plugins/org.eclipse.core.resources/.history/86/6048d52fdcb90017124d9f37712eb7c1

@@ -1,219 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		// TODO Auto-generated method stub
-		
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/88/900e1b5f2cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 7
.metadata/.plugins/org.eclipse.core.resources/.history/88/90ecdad50cb9001711c7a09600ea5d68

@@ -1,7 +0,0 @@
-package config;
-
-public class SonarModel {
-	public static double expectedRead () {
-		
-	}
-}

+ 0 - 256
.metadata/.plugins/org.eclipse.core.resources/.history/88/d0913708a1ba001711b8bf632416c20d

@@ -1,256 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(-x, -y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 263
.metadata/.plugins/org.eclipse.core.resources/.history/8e/a011523fe2b90017124d9f37712eb7c1

@@ -1,263 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		receivethread.startCount();
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 256
.metadata/.plugins/org.eclipse.core.resources/.history/8f/c02e6840a1ba001711b8bf632416c20d

@@ -1,256 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(-x, -y, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 269
.metadata/.plugins/org.eclipse.core.resources/.history/9/803562b9e5b90017124d9f37712eb7c1

@@ -1,269 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						} else {
-							countsema.release(180/creads);
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(180);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			scann(null);
-			countsema.acquire(180);
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		stopScann();
-		countsema.release(180);
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 233
.metadata/.plugins/org.eclipse.core.resources/.history/92/10ea7ebbdcb90017124d9f37712eb7c1

@@ -1,233 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SCANN = 11;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 90
.metadata/.plugins/org.eclipse.core.resources/.history/92/40a917d22bb80017145c9b6064c27648

@@ -1,90 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading();
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveRight() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void moveBackward() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/92/f039214b2cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/96/903059312cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)-dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 304
.metadata/.plugins/org.eclipse.core.resources/.history/9b/301965d6d2b90017124d9f37712eb7c1

@@ -1,304 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		try {
-			String rs = JOptionPane.showInputDialog("Interval (degress):");
-			int r = Integer.parseInt(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-			return;
-		}
-		
-	}
-
-	private void rotateRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-	
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter distance (cm):");
-			double r = Double.parseDouble(rs);
-			robot.move(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 236
.metadata/.plugins/org.eclipse.core.resources/.history/9d/d0156e58ddb90017124d9f37712eb7c1

@@ -1,236 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	private static final float scannangle = 0;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha+90));
-						
-						rr.robotData(d);						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-
-}

+ 0 - 268
.metadata/.plugins/org.eclipse.core.resources/.history/9d/f0d28dbce5b90017124d9f37712eb7c1

@@ -1,268 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(d);
-						}
-						countsema.release(180/creads);
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(180);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		send(SETSCANANGLE, scannangle);
-		try {
-			scann(null);
-			countsema.acquire(180);
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		stopScann();
-		countsema.release(180);
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 262
.metadata/.plugins/org.eclipse.core.resources/.history/a/a0aea77491ba001711b8bf632416c20d

@@ -1,262 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-						if (reads != null && reads.size() < creads) {
-							reads.add(d);
-						}
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		send(SETSCANANGLE, interval);
-		creads = 180/interval;
-		reads = new ArrayList<DataPose>();
-		scann(null);
-		
-		while(reads.size() <= creads) { };
-		
-		stopScann();
-		creads = -1;
-		return reads;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 274
.metadata/.plugins/org.eclipse.core.resources/.history/a0/f0cecdf5e3b90017124d9f37712eb7c1

@@ -1,274 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private Semaphore countsema;
-	private int creads = -1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						if (reads.size() <= creads) {
-							reads.add(e);
-						} else {
-							countsema.release();
-						}
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		reads = new ArrayList<DataPose>();
-		semaphore = new Semaphore(1);
-		countsema = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-		stopScann();
-		send(SETSCANANGLE, interval);
-		
-		creads = 180/interval;
-		reads.clear();
-		try {
-			countsema.acquire();
-		} catch (InterruptedException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		try {
-			send(SETSCANANGLE, scannangle);
-			countsema.acquire();
-			return reads;
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 256
.metadata/.plugins/org.eclipse.core.resources/.history/a2/d042f403a1ba001711b8bf632416c20d

@@ -1,256 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(x, y, alpha-90));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private void send(int command) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-
-	private void send(int command, float f) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.writeFloat(f);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(int command, int i) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(command);
-				output.write(i);
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(x, y, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 89
.metadata/.plugins/org.eclipse.core.resources/.history/a3/603140a12cb80017145c9b6064c27648

@@ -1,89 +0,0 @@
-package robots;
-
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-
-public class VirtualRobot implements Robot {
-	private Pose pose;
-	private Simulate simthread;
-	private RobotReturn rr;
-	
-	private class Simulate extends Thread {
-		public boolean run = true;
-		public void run() {
-			int ang = 0;
-			int add = 5;
-			while(run) {
-				DataPose data = new DataPose();
-				data.setDistance(60);
-				data.setPose(pose);
-				data.setSensorAngle(ang);
-				
-				rr.robotData(data);
-				
-				ang += add;
-				if (ang == -90 || ang == 90) add *= -1;
-				
-				try {
-					Thread.sleep(100);
-				} catch (InterruptedException e) {
-				}
-			}
-		}
-		
-	}
-
-	public VirtualRobot(LineMap map) {
-		simthread = new Simulate();
-		pose = new Pose();
-		pose.setHeading(90);
-	}
-
-	@Override
-	public void moveForward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)dx, (float)-dy);
-	}
-
-	@Override
-	public void moveLeft() {
-		pose.rotateUpdate(45);
-	}
-
-	@Override
-	public void moveRight() {
-		pose.rotateUpdate(-45);
-	}
-
-	@Override
-	public void moveBackward() {
-		double dx = Math.sin(Math.toRadians(pose.getHeading()))*5;
-		double dy = Math.cos(Math.toRadians(pose.getHeading()))*5;
-		pose.translate((float)-dx, (float)dy);
-	}
-
-	@Override
-	public boolean connect(RobotReturn r) {
-		rr = r;
-		simthread.start();
-		return true;
-	}
-
-	@Override
-	public void stop() {		
-	}
-
-	@Override
-	public void exit() {
-		simthread.run = false;
-		try {
-			simthread.join();
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-		
-	}
-
-}

+ 0 - 255
.metadata/.plugins/org.eclipse.core.resources/.history/a3/d082b469a4ba001711b8bf632416c20d

@@ -1,255 +0,0 @@
-package robots;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
-import lejos.pc.comm.NXTComm;
-import lejos.pc.comm.NXTCommException;
-import lejos.pc.comm.NXTCommFactory;
-import lejos.pc.comm.NXTInfo;
-import lejos.robotics.navigation.Pose;
-
-public class BluetoothRobot implements Robot {
-	private String name;
-	private NXTComm nxtComm;
-	private RobotReturn rr;
-	private Semaphore semaphore;
-	private int creads = 1;
-	
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-	
-	public static final byte STOPSCANN = 6;
-	public static final byte STARTSCANN = 7;
-	public static final byte MOVE = 8;
-	public static final byte ROTATE = 9;
-	public static final byte SETPOSE = 10;
-	public static final byte SETSCANANGLE = 11;
-	
-	public static final byte TYPE_INT = 1;
-	public static final byte TYPE_CMD = 2;
-	public static final byte TYPE_POSE = 3;
-	public static final byte TYPE_FLOAT = 4;
-	
-	private static final int scannangle = 5;
-
-	private DataOutputStream output;
-	private DataInputStream input;
-	private Receiver receivethread;
-	
-	private ArrayList<DataPose> reads;
-		
-	private class Receiver extends Thread {
-		public boolean run = true;
-		@Override
-		public void run() {
-			int bytes_valiable = -1;
-			
-			while(run) {
-				try {
-					bytes_valiable = input.available();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				if (bytes_valiable >= 0) {
-					try {
-						if (input.readByte() != '@') continue;
-						int angle = input.readByte();
-						float alpha = input.readFloat();
-						float x = input.readFloat();
-						int distance = input.readByte();
-						float y = input.readFloat();
-						DataPose d = new DataPose();
-						d.setDistance(distance);
-						d.setSensorAngle(angle);
-						d.setPose(new Pose(y, -x, alpha));
-						if (rr != null)
-							rr.robotData(d);	
-						
-					} catch (IOException e1) {
-						continue;
-					}
-				}
-			}
-		}
-	}
-
-	private class Sender extends Thread {
-		
-	}
-	
-	private class SendData {
-		float f;
-		int i;
-		int cmd;
-		Pose p;
-		int type;
-		SendData(int cmd) {
-			this.cmd = cmd;
-			this.type = TYPE_CMD;
-		}
-		SendData(int cmd, int i) {
-			this.cmd = cmd;
-			this.i = i;
-		}
-		public boolean send() {
-			if (type == 0) return false;
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				return false;
-			}
-			return true;
-		}
-	}
-	
-	private void send(Pose p) {
-		if (semaphore.tryAcquire()) {
-			try {
-				output.write(SETPOSE);
-				output.writeFloat(p.getX());
-				output.writeFloat(p.getY());
-				output.writeFloat(p.getHeading());
-				output.flush();
-			} catch (IOException e) {
-				System.out.println("Erro ao enviar...");
-			}
-			semaphore.release();
-		}
-	}
-	
-	public BluetoothRobot (String name) {
-		semaphore = new Semaphore(1);
-		receivethread = new Receiver();
-		this.name = name;
-	}
-
-	@Override
-	public void moveForward() {
-		send(FORWARD);
-	}
-
-	@Override
-	public void moveLeft() {
-		send(LEFT);
-	}
-
-	@Override
-	public void moveRight() {
-		send(RIGHT);
-	}
-
-	@Override
-	public void moveBackward() {
-		send(BACKWARD);
-	}
-
-	@Override
-	public boolean connect () {
-		try {
-			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
-			NXTInfo[] nxtInfo = nxtComm.search(name); //find brick with NXT_ID by doing a Bluetooth inquiry
-			if (nxtInfo.length == 0) { // failed to find a brick with the ID
-				System.err.println("NO NXT found");
-				return false;
-			}
-			if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
-				System.err.println("Failed to open NXT");
-				return false;
-			}
-			
-			input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
-			output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
-			send(SETSCANANGLE, scannangle); // vai scanear em 5 em 5 graus
-		} catch (NXTCommException e) {
-			return false;
-		}
-		
-		receivethread.start();
-		
-		return true;	
-	}
-
-	@Override
-	public void stop() {
-		send(STOP);
-	}
-
-
-	@Override
-	public void move(double x) {
-		send(MOVE, (float)x);
-	}
-
-	@Override
-	public void rotate(double x) {
-		send(ROTATE, (float)x);
-	}
-
-	@Override
-	public ArrayList<DataPose> scann(int ini, int end, int interval) {
-//		send(SETSCANANGLE, interval);
-//		creads = 180/interval;
-//		reads = new ArrayList<DataPose>();
-//		scann(null);
-//		
-//		while(reads.size() <= creads) { };
-//		
-//		stopScann();
-//		creads = -1;
-		return null;
-	}
-
-	@Override
-	public void scann(RobotReturn r) {
-		rr = r;
-		send(STARTSCANN);
-	}
-
-	@Override
-	public void stopScann() {
-		send(STOPSCANN);
-	}
-
-	@Override
-	public void disconnect() {
-		send(EXIT);
-		if (receivethread == null) return;
-		receivethread.run = false;
-		try {
-			receivethread.join();
-		} catch (InterruptedException e1) {
-			System.out.println("Nao foi possivel finalizar as threads...");
-		}
-		try {
-			nxtComm.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-
-	@Override
-	public void setPose(float x, float y, float a) {
-		send(new Pose(y, -x, a));
-	}
-	
-	
-	@Override
-	public String toString() {
-		return "Bluetooth Mestre/Escravo";
-	}
-
-}

+ 0 - 275
.metadata/.plugins/org.eclipse.core.resources/.history/a3/d0afc10fcfb90017124d9f37712eb7c1

@@ -1,275 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			moveRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void moveRobot() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255)
-			return;
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

+ 0 - 304
.metadata/.plugins/org.eclipse.core.resources/.history/a8/00c67dc3d2b90017124d9f37712eb7c1

@@ -1,304 +0,0 @@
-import java.awt.BorderLayout;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JSplitPane;
-import javax.swing.SwingUtilities;
-
-import config.Map;
-import config.Models;
-import lejos.robotics.mapping.LineMap;
-import lejos.robotics.navigation.Pose;
-import robots.BluetoothRobot;
-import robots.DataPose;
-import robots.Robot;
-import robots.RobotReturn;
-import robots.VirtualRobot;
-
-public class MainProgram extends JPanel implements KeyListener, WindowListener, RobotReturn {
-
-	private MapImage imap;
-	private Robot robot;
-	private ScannerImage scanner;
-	private Models smodel;
-
-	public static final byte FORWARD = 0;
-	public static final byte STOP = 1;
-	public static final byte EXIT = 2;
-	public static final byte LEFT = 3;
-	public static final byte RIGHT = 4;
-	public static final byte BACKWARD = 5;
-
-	public MainProgram(LineMap map, Robot robot) {
-		this.robot = robot;
-		JFrame frame = new JFrame("Mapa MAC0318");
-
-		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		frame.setLayout(new BorderLayout());
-		imap = new MapImage(map);
-		scanner = new ScannerImage(map);
-		smodel = new Models(map);
-		// frame.add(this.map);
-		frame.setSize(800, 800);
-		frame.setVisible(true);
-
-		frame.setFocusable(true);
-		frame.requestFocusInWindow();
-		frame.addKeyListener(this);
-		frame.addWindowListener(this);
-
-		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scanner, imap);
-		splitPane.setOneTouchExpandable(true);
-		splitPane.setDividerLocation((int) (frame.getHeight() / 2));
-		frame.add(splitPane);
-
-		boolean result = false;
-		if (robot != null)
-			result = robot.connect();
-	
-
-		if (result == false) {
-			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
-		}
-
-		showHelp();
-	}
-
-	private void showHelp() {
-		String text = "1,2,3 - Change global map view\n";
-		text += "s - Set Pose.\n";
-		text += "l - Show global map trace.\n";
-		text += "c - Clean maps.\n";
-		text += "m - Enter robot movement.\n";
-		text += "r - Enter robo rotation.\n";
-		text += "a - Colect sonar data.\n";
-		text += "z - Make sonar continuous scanner.\n";
-		text += "i - Stop continuous scanner.\n";
-		text += "g - Save global map image.\n";
-		text += "f - Save scanner image.\n";
-		text += "<arrows> - Move robot.\n";
-		text += "h - help.\n";
-		JOptionPane.showMessageDialog(null, text, "HELP", JOptionPane.PLAIN_MESSAGE);
-	}
-
-	public void addPoint(Pose p) {
-		imap.addPoint(p);
-	}
-
-	@Override
-	public void keyPressed(KeyEvent e) {
-		
-		char input = e.getKeyChar();
-		switch (input) {
-		case '1':
-			imap.setVisual(0);
-			break;
-		case '2':
-			imap.setVisual(1);
-			break;
-		case '3':
-			imap.setVisual(2);
-			break;
-		case 'l':
-			imap.showLine();
-			break;
-		case 'g':
-			imap.save();
-			break;
-		case 'c':
-			imap.clean();
-			scanner.clean();
-			break;
-		case 's':
-			setRobotPose();
-			break;
-		case 'm':
-			moveRobot();
-			break;
-		case 'r':
-			rotateRobot();
-			break;
-		case 'a':
-			colectSonar();
-			break;
-		case 'z':
-			robot.scann(this);
-			break;
-		case 'i':
-			robot.stopScann();
-			break;
-		case 'h':
-			showHelp();
-			break;
-		default:
-			break;
-		}
-
-	
-
-		if (robot == null)
-			return;
-
-		scanner.clean();
-		switch (e.getKeyCode()) {
-		case KeyEvent.VK_UP:
-			robot.moveForward();
-			break;
-		case KeyEvent.VK_DOWN:
-			robot.moveBackward();
-			break;
-		case KeyEvent.VK_LEFT:
-			robot.moveLeft();
-			break;
-		case KeyEvent.VK_RIGHT:
-			robot.moveRight();
-			break;
-		}
-	}
-
-	private void colectSonar() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			int r = Integer.parseInteger(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-			return;
-		}
-		
-	}
-
-	private void rotateRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.rotate(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-	
-
-	private void moveRobot() {
-		try {
-			String rs = JOptionPane.showInputDialog("Enter rotation (degress-clockwise):");
-			double r = Double.parseDouble(rs);
-			robot.move(r);
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	private void setRobotPose() {
-		try {
-			String xs = JOptionPane.showInputDialog("Enter x (cm):");
-			if (xs.length() == 0) return;
-			String ys = JOptionPane.showInputDialog("Enter y (cm):");
-			if (ys.length() == 0) return;
-			String as = JOptionPane.showInputDialog("Enter heading (degress):");
-			if (as.length() == 0) return;
-		
-			float x = Float.parseFloat(xs);
-			float y = Float.parseFloat(ys);
-			float a = Float.parseFloat(as);
-			robot.setPose(x, y, a);
-			scanner.setPose(new Pose(x, y, a));
-			scanner.clean();
-		} catch (Exception e) {
-		}
-	}
-
-	@Override
-	public void keyReleased(KeyEvent arg0) {
-		if (robot == null)
-			return;
-		robot.stop();
-	}
-
-	@Override
-	public void keyTyped(KeyEvent arg0) {
-	}
-
-	@Override
-	public void windowOpened(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		System.err.println("Fechando...");
-		if (robot == null)
-			return;
-		robot.disconnect();
-
-	}
-
-	@Override
-	public void windowClosed(WindowEvent e) {
-	}
-
-	@Override
-	public void windowIconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeiconified(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) {
-
-	}
-
-	@Override
-	public void windowDeactivated(WindowEvent e) {
-	}
-
-	@Override
-	public void robotData(DataPose data) {
-		// posicao do robo
-		Pose p = data.getPose();
-
-		imap.addPoint(p);
-		if (data.getDistance() == 255) {
-			scanner.setPose(p);
-			return;
-		}
-
-		// ponto do ultrasonico
-		double sensor_ang = Math.toRadians(data.getSensorAngle() + p.getHeading());
-		double dx = Math.cos(sensor_ang) * data.getDistance();
-		double dy = Math.sin(sensor_ang) * data.getDistance();
-		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
-		imap.addRead(p.getX() + dx, p.getY() + dy);
-		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
-	}
-
-	public static void main(String[] args) {
-
-		LineMap map = Map.makeMap();
-		Robot robotv = new VirtualRobot(map);
-		Robot robotbt = new BluetoothRobot(null);
-
-		Object[] possibleValues = { robotv, robotbt };
-		Object robot = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.PLAIN_MESSAGE, null,
-				possibleValues, possibleValues[0]);
-
-		SwingUtilities.invokeLater(new Runnable() {
-			public void run() {
-				new MainProgram(map, (Robot) robot);
-			}
-		});
-	}
-}

Неке датотеке нису приказане због велике количине промена