capellaresumo 7 жил өмнө
commit
56756990f2
100 өөрчлөгдсөн 14649 нэмэгдсэн , 0 устгасан
  1. 0 0
      .metadata/.lock
  2. 1233 0
      .metadata/.log
  3. BIN
      .metadata/.mylyn/.taskListIndex/segments_1
  4. 0 0
      .metadata/.mylyn/.taskListIndex/write.lock
  5. BIN
      .metadata/.mylyn/.tasks.xml.zip
  6. BIN
      .metadata/.mylyn/repositories.xml.zip
  7. BIN
      .metadata/.mylyn/tasks.xml.zip
  8. 16 0
      .metadata/.plugins/org.eclipse.core.resources/.history/0/102195ce0eb9001711c7a09600ea5d68
  9. 112 0
      .metadata/.plugins/org.eclipse.core.resources/.history/0/607d0a7c31b80017145c9b6064c27648
  10. 248 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1/30dc958315b80017145c9b6064c27648
  11. 244 0
      .metadata/.plugins/org.eclipse.core.resources/.history/10/d0078ed7ddb90017124d9f37712eb7c1
  12. 16 0
      .metadata/.plugins/org.eclipse.core.resources/.history/10/d06397d611b80017145c9b6064c27648
  13. 276 0
      .metadata/.plugins/org.eclipse.core.resources/.history/11/5067e43bd0b90017124d9f37712eb7c1
  14. 166 0
      .metadata/.plugins/org.eclipse.core.resources/.history/11/60e7755ef9b00017155fe9ac88a695a6
  15. 279 0
      .metadata/.plugins/org.eclipse.core.resources/.history/11/a095259ad0b90017124d9f37712eb7c1
  16. 53 0
      .metadata/.plugins/org.eclipse.core.resources/.history/12/200fd8fb1eb80017145c9b6064c27648
  17. 0 0
      .metadata/.plugins/org.eclipse.core.resources/.history/15/80dd4a5808b80017145c9b6064c27648
  18. 222 0
      .metadata/.plugins/org.eclipse.core.resources/.history/17/1089c19fcbb90017124d9f37712eb7c1
  19. 5 0
      .metadata/.plugins/org.eclipse.core.resources/.history/17/30aebf350cb9001711c7a09600ea5d68
  20. 206 0
      .metadata/.plugins/org.eclipse.core.resources/.history/17/d09a8a6ec6b90017124d9f37712eb7c1
  21. 304 0
      .metadata/.plugins/org.eclipse.core.resources/.history/18/30e132d2d2b90017124d9f37712eb7c1
  22. 25 0
      .metadata/.plugins/org.eclipse.core.resources/.history/18/6065aa100fb9001711c7a09600ea5d68
  23. 51 0
      .metadata/.plugins/org.eclipse.core.resources/.history/18/c0cda01a14b9001711c7a09600ea5d68
  24. 52 0
      .metadata/.plugins/org.eclipse.core.resources/.history/19/603b73fbe2b000171eb4aea94a5e3c6b
  25. 262 0
      .metadata/.plugins/org.eclipse.core.resources/.history/19/a0960bafdeb90017124d9f37712eb7c1
  26. 115 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1a/3088cad90ab9001711c7a09600ea5d68
  27. 286 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1a/d0b3319f18b80017145c9b6064c27648
  28. 89 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1b/20730e7d21b80017145c9b6064c27648
  29. 135 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1b/6001ad73d5b90017124d9f37712eb7c1
  30. 53 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1c/0061834ce4b000171eb4aea94a5e3c6b
  31. 25 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1c/50d569cdafb90017124d9f37712eb7c1
  32. 272 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1c/a0c27aa6e2b90017124d9f37712eb7c1
  33. 206 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1d/50193f6bc6b90017124d9f37712eb7c1
  34. 206 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1d/50c61970c6b90017124d9f37712eb7c1
  35. 274 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/4082a00be4b90017124d9f37712eb7c1
  36. 91 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/903d0c74c3b90017124d9f37712eb7c1
  37. 273 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1e/d0976df3e3b90017124d9f37712eb7c1
  38. 24 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1f/6039ae6bc7b90017124d9f37712eb7c1
  39. 204 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1f/705f6c47c5b90017124d9f37712eb7c1
  40. 25 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1f/70948cf90eb9001711c7a09600ea5d68
  41. 113 0
      .metadata/.plugins/org.eclipse.core.resources/.history/1f/a032661708b9001711c7a09600ea5d68
  42. 264 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2/b0b6886cceb90017124d9f37712eb7c1
  43. 60 0
      .metadata/.plugins/org.eclipse.core.resources/.history/20/20af339020b80017145c9b6064c27648
  44. 269 0
      .metadata/.plugins/org.eclipse.core.resources/.history/20/80f4cd6218b80017145c9b6064c27648
  45. 88 0
      .metadata/.plugins/org.eclipse.core.resources/.history/21/a03c38182cb80017145c9b6064c27648
  46. 139 0
      .metadata/.plugins/org.eclipse.core.resources/.history/22/30fac574cfb90017124d9f37712eb7c1
  47. 13 0
      .metadata/.plugins/org.eclipse.core.resources/.history/22/90210b881eb80017145c9b6064c27648
  48. 114 0
      .metadata/.plugins/org.eclipse.core.resources/.history/22/b0dc773632b80017145c9b6064c27648
  49. 52 0
      .metadata/.plugins/org.eclipse.core.resources/.history/22/d05cb20ce3b000171eb4aea94a5e3c6b
  50. 273 0
      .metadata/.plugins/org.eclipse.core.resources/.history/22/f0670576e3b90017124d9f37712eb7c1
  51. 67 0
      .metadata/.plugins/org.eclipse.core.resources/.history/23/104082ed20b80017145c9b6064c27648
  52. 113 0
      .metadata/.plugins/org.eclipse.core.resources/.history/23/300f450808b9001711c7a09600ea5d68
  53. 16 0
      .metadata/.plugins/org.eclipse.core.resources/.history/23/b07ddeb41ab80017145c9b6064c27648
  54. 116 0
      .metadata/.plugins/org.eclipse.core.resources/.history/24/302f98100ab9001711c7a09600ea5d68
  55. 16 0
      .metadata/.plugins/org.eclipse.core.resources/.history/24/f09094cd11b80017145c9b6064c27648
  56. 88 0
      .metadata/.plugins/org.eclipse.core.resources/.history/25/60f61ae129b80017145c9b6064c27648
  57. 139 0
      .metadata/.plugins/org.eclipse.core.resources/.history/25/a03ad027d5b90017124d9f37712eb7c1
  58. 153 0
      .metadata/.plugins/org.eclipse.core.resources/.history/26/10b31e95d1b90017124d9f37712eb7c1
  59. 179 0
      .metadata/.plugins/org.eclipse.core.resources/.history/26/30f7b5eac1b90017124d9f37712eb7c1
  60. 128 0
      .metadata/.plugins/org.eclipse.core.resources/.history/26/f0f5d5d0e2b000171eb4aea94a5e3c6b
  61. 89 0
      .metadata/.plugins/org.eclipse.core.resources/.history/27/707c77822cb80017145c9b6064c27648
  62. 48 0
      .metadata/.plugins/org.eclipse.core.resources/.history/27/e02acfa4e1b000171eb4aea94a5e3c6b
  63. 185 0
      .metadata/.plugins/org.eclipse.core.resources/.history/29/10b4e4650db9001711c7a09600ea5d68
  64. 26 0
      .metadata/.plugins/org.eclipse.core.resources/.history/29/10dc8f6111b9001711c7a09600ea5d68
  65. 26 0
      .metadata/.plugins/org.eclipse.core.resources/.history/29/b0aac23c12b9001711c7a09600ea5d68
  66. 148 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2a/2031f4bed0b90017124d9f37712eb7c1
  67. 129 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2a/70201882c3b90017124d9f37712eb7c1
  68. 5 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2a/e02068fa1db80017145c9b6064c27648
  69. 220 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2b/c0680f0ecbb90017124d9f37712eb7c1
  70. 113 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2b/d09491ff07b9001711c7a09600ea5d68
  71. 60 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2d/b0888cb01ab80017145c9b6064c27648
  72. 279 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2d/f0faeaddd0b90017124d9f37712eb7c1
  73. 186 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2e/4015b9dc0db9001711c7a09600ea5d68
  74. 24 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2e/80965eacc7b90017124d9f37712eb7c1
  75. 276 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2e/c01a8e5fe4b90017124d9f37712eb7c1
  76. 181 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2f/306eeab11eb80017145c9b6064c27648
  77. 297 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2f/7047bc93d2b90017124d9f37712eb7c1
  78. 114 0
      .metadata/.plugins/org.eclipse.core.resources/.history/2f/80b91ae231b80017145c9b6064c27648
  79. 59 0
      .metadata/.plugins/org.eclipse.core.resources/.history/3/60f5422f19b80017145c9b6064c27648
  80. 64 0
      .metadata/.plugins/org.eclipse.core.resources/.history/3/f018d8e820b80017145c9b6064c27648
  81. 120 0
      .metadata/.plugins/org.eclipse.core.resources/.history/30/0030ab1defb000171877feeee34c61ac
  82. 287 0
      .metadata/.plugins/org.eclipse.core.resources/.history/30/0055086ed2b90017124d9f37712eb7c1
  83. 16 0
      .metadata/.plugins/org.eclipse.core.resources/.history/30/2030788317b80017145c9b6064c27648
  84. 150 0
      .metadata/.plugins/org.eclipse.core.resources/.history/30/50641629d7b90017124d9f37712eb7c1
  85. 274 0
      .metadata/.plugins/org.eclipse.core.resources/.history/30/c0e5893e18b80017145c9b6064c27648
  86. 126 0
      .metadata/.plugins/org.eclipse.core.resources/.history/31/30b8c624e2b000171eb4aea94a5e3c6b
  87. 285 0
      .metadata/.plugins/org.eclipse.core.resources/.history/31/5006dba518b80017145c9b6064c27648
  88. 26 0
      .metadata/.plugins/org.eclipse.core.resources/.history/32/107c0d9713b9001711c7a09600ea5d68
  89. 137 0
      .metadata/.plugins/org.eclipse.core.resources/.history/32/2023c245cbb90017124d9f37712eb7c1
  90. 258 0
      .metadata/.plugins/org.eclipse.core.resources/.history/32/2025fb61ceb90017124d9f37712eb7c1
  91. 233 0
      .metadata/.plugins/org.eclipse.core.resources/.history/34/60767e52ddb90017124d9f37712eb7c1
  92. 306 0
      .metadata/.plugins/org.eclipse.core.resources/.history/34/e02fcc20d3b90017124d9f37712eb7c1
  93. 188 0
      .metadata/.plugins/org.eclipse.core.resources/.history/35/405ba1e50db9001711c7a09600ea5d68
  94. 181 0
      .metadata/.plugins/org.eclipse.core.resources/.history/35/905643571eb80017145c9b6064c27648
  95. 152 0
      .metadata/.plugins/org.eclipse.core.resources/.history/35/f09bc35fdfb90017124d9f37712eb7c1
  96. 285 0
      .metadata/.plugins/org.eclipse.core.resources/.history/36/f0945d7722b80017145c9b6064c27648
  97. 176 0
      .metadata/.plugins/org.eclipse.core.resources/.history/37/20e590971cb80017145c9b6064c27648
  98. 113 0
      .metadata/.plugins/org.eclipse.core.resources/.history/37/60acc8f807b9001711c7a09600ea5d68
  99. 180 0
      .metadata/.plugins/org.eclipse.core.resources/.history/37/90dce55b1eb80017145c9b6064c27648
  100. 179 0
      .metadata/.plugins/org.eclipse.core.resources/.history/37/d010c503c2b90017124d9f37712eb7c1

+ 0 - 0
.metadata/.lock


+ 1233 - 0
.metadata/.log

@@ -0,0 +1,1233 @@
+!SESSION 2017-10-13 16:42:10.473 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.jface 2 0 2017-10-13 17:04:14.936
+!MESSAGE Keybinding conflicts occurred.  They may interfere with normal accelerator operation.
+!SUBENTRY 1 org.eclipse.jface 2 0 2017-10-13 17:04:14.936
+!MESSAGE A conflict occurred for COMMAND+W:
+Binding(COMMAND+W,
+	ParameterizedCommand(Command(org.eclipse.ui.cocoa.closeDialog,Close Dialog,
+		Closes the active Dialog,
+		Category(org.eclipse.ui.category.window,Window,null,true),
+		org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@26bc84dc,
+		,,true),null),
+	org.eclipse.ui.defaultAcceleratorConfiguration,
+	org.eclipse.ui.contexts.dialog,,,system)
+Binding(COMMAND+W,
+	ParameterizedCommand(Command(org.eclipse.ui.file.close,Close,
+		Close the active editor,
+		Category(org.eclipse.ui.category.file,File,null,true),
+		org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@3b4e6329,
+		,,true),null),
+	org.eclipse.ui.defaultAcceleratorConfiguration,
+	org.eclipse.ui.contexts.window,,,system)
+!SESSION 2017-10-13 17:27:34.218 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 4 4 2017-10-13 17:27:40.055
+!MESSAGE Exception loading preferences from: /SonarBrick/.settings/org.eclipse.jdt.core.prefs.
+!STACK 1
+org.eclipse.core.internal.resources.ResourceException: File not found: /Users/gabrielcapella/eclipse-workspace/SonarBrick/.settings/org.eclipse.jdt.core.prefs.
+	at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:836)
+	at org.eclipse.core.internal.resources.File.getContents(File.java:277)
+	at org.eclipse.core.internal.resources.ProjectPreferences.load(ProjectPreferences.java:507)
+	at org.eclipse.core.internal.resources.ProjectPreferences.load(ProjectPreferences.java:492)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:370)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:623)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:766)
+	at org.eclipse.core.resources.ProjectScope.getNode(ProjectScope.java:69)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$EclipsePreferencesAdapter.getNode(JavaEditor.java:363)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$EclipsePreferencesAdapter.addPropertyChangeListener(JavaEditor.java:369)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore$PropertyChangeListener.register(ChainedPreferenceStore.java:74)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore.registerChildListeners(ChainedPreferenceStore.java:476)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore.addPropertyChangeListener(ChainedPreferenceStore.java:123)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.setPreferenceStore(AbstractTextEditor.java:2830)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.setPreferenceStore(JavaEditor.java:2582)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:2529)
+	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:1418)
+	at org.eclipse.ui.texteditor.AbstractTextEditor$5.run(AbstractTextEditor.java:3154)
+	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2137)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3172)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3197)
+	at org.eclipse.ui.internal.EditorReference.initialize(EditorReference.java:362)
+	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:333)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:990)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:955)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
+	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
+	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1293)
+	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:97)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$1.run(PartRenderingEngine.java:546)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:530)
+	at org.eclipse.e4.ui.workbench.renderers.swt.ElementReferenceRenderer.createWidget(ElementReferenceRenderer.java:70)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveRenderer.processContents(PerspectiveRenderer.java:49)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.showTab(PerspectiveStackRenderer.java:79)
+	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:97)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.postProcess(PerspectiveStackRenderer.java:61)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.processContents(WBWRenderer.java:704)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1076)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
+	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
+	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
+	at org.eclipse.ui.internal.Workbench$$Lambda$15/687685057.run(Unknown Source)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
+	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
+	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
+	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
+	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
+	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
+!SUBENTRY 1 org.eclipse.core.resources 4 368 2017-10-13 17:27:40.057
+!MESSAGE File not found: /Users/gabrielcapella/eclipse-workspace/SonarBrick/.settings/org.eclipse.jdt.core.prefs.
+
+!ENTRY org.eclipse.equinox.preferences 4 4 2017-10-13 17:27:40.060
+!MESSAGE Exception loading preferences from: /Users/gabrielcapella/eclipse-workspace/SonarBrick/.settings/org.eclipse.jdt.core.prefs.
+!STACK 0
+org.osgi.service.prefs.BackingStoreException: Exception loading preferences from: /SonarBrick/.settings/org.eclipse.jdt.core.prefs.
+	at org.eclipse.core.internal.resources.ProjectPreferences.load(ProjectPreferences.java:515)
+	at org.eclipse.core.internal.resources.ProjectPreferences.load(ProjectPreferences.java:492)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.create(EclipsePreferences.java:370)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.internalNode(EclipsePreferences.java:623)
+	at org.eclipse.core.internal.preferences.EclipsePreferences.node(EclipsePreferences.java:766)
+	at org.eclipse.core.resources.ProjectScope.getNode(ProjectScope.java:69)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$EclipsePreferencesAdapter.getNode(JavaEditor.java:363)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$EclipsePreferencesAdapter.addPropertyChangeListener(JavaEditor.java:369)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore$PropertyChangeListener.register(ChainedPreferenceStore.java:74)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore.registerChildListeners(ChainedPreferenceStore.java:476)
+	at org.eclipse.ui.texteditor.ChainedPreferenceStore.addPropertyChangeListener(ChainedPreferenceStore.java:123)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.setPreferenceStore(AbstractTextEditor.java:2830)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.setPreferenceStore(JavaEditor.java:2582)
+	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:2529)
+	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:1418)
+	at org.eclipse.ui.texteditor.AbstractTextEditor$5.run(AbstractTextEditor.java:3154)
+	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2137)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3172)
+	at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3197)
+	at org.eclipse.ui.internal.EditorReference.initialize(EditorReference.java:362)
+	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:333)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:990)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:955)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:124)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:399)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:318)
+	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
+	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
+	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1293)
+	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:97)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$1.run(PartRenderingEngine.java:546)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:530)
+	at org.eclipse.e4.ui.workbench.renderers.swt.ElementReferenceRenderer.createWidget(ElementReferenceRenderer.java:70)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveRenderer.processContents(PerspectiveRenderer.java:49)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.showTab(PerspectiveStackRenderer.java:79)
+	at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:97)
+	at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.postProcess(PerspectiveStackRenderer.java:61)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:69)
+	at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.processContents(WBWRenderer.java:704)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1076)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
+	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
+	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
+	at org.eclipse.ui.internal.Workbench$$Lambda$15/687685057.run(Unknown Source)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
+	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
+	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
+	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
+	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
+	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
+
+!ENTRY org.eclipse.ui 4 4 2017-10-13 17:31:53.896
+!MESSAGE Conflicting handlers for org.eclipse.ui.navigate.backwardHistory: {ActionHandler(org.eclipse.ui.internal.dialogs.PreferencePageHistory$1@1000fbae)} vs {ActionHandler(org.eclipse.ui.internal.NavigationHistoryAction@5f5923ef)}
+
+!ENTRY org.eclipse.ui 4 4 2017-10-13 17:31:53.923
+!MESSAGE Conflicting handlers for org.eclipse.ui.navigate.backwardHistory: {ActionHandler(org.eclipse.ui.internal.dialogs.PreferencePageHistory$1@1000fbae)} vs {ActionHandler(org.eclipse.ui.internal.NavigationHistoryAction@5f5923ef)}
+
+!ENTRY org.eclipse.ui 4 4 2017-10-13 17:31:53.923
+!MESSAGE Conflicting handlers for org.eclipse.ui.navigate.forwardHistory: {ActionHandler(org.eclipse.ui.internal.NavigationHistoryAction@2f262474)} vs {ActionHandler(org.eclipse.ui.internal.dialogs.PreferencePageHistory$2@2463a9ec)}
+
+!ENTRY org.eclipse.ui 4 4 2017-10-13 17:31:53.923
+!MESSAGE Conflicting handlers for org.eclipse.ui.navigate.forwardHistory: {ActionHandler(org.eclipse.ui.internal.NavigationHistoryAction@2f262474)} vs {ActionHandler(org.eclipse.ui.internal.dialogs.PreferencePageHistory$2@2463a9ec)}
+!SESSION 2017-10-13 17:55:11.498 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.recommenders.models.rcp 1 11 2017-10-13 18:02:03.729
+!MESSAGE The model index service was accessed either before it started or after it finished running.
+!STACK 0
+org.eclipse.recommenders.utils.Logs$LogTraceException
+	at org.eclipse.recommenders.utils.Logs$LogTraceException.newTrace(Logs.java:381)
+	at org.eclipse.recommenders.utils.Logs.log(Logs.java:134)
+	at org.eclipse.recommenders.utils.Logs.log(Logs.java:126)
+	at org.eclipse.recommenders.internal.models.rcp.EclipseModelIndex.suggest(EclipseModelIndex.java:211)
+	at org.eclipse.recommenders.models.SimpleModelProvider.acquireModel(SimpleModelProvider.java:70)
+	at org.eclipse.recommenders.models.PoolingModelProvider.access$0(PoolingModelProvider.java:1)
+	at org.eclipse.recommenders.models.PoolingModelProvider$ModelPoolFactoryMediator.makeObject(PoolingModelProvider.java:96)
+	at org.eclipse.recommenders.models.PoolingModelProvider$ModelPoolFactoryMediator.makeObject(PoolingModelProvider.java:1)
+	at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1220)
+	at org.eclipse.recommenders.models.PoolingModelProvider.acquireModel(PoolingModelProvider.java:67)
+	at org.eclipse.recommenders.internal.overrides.rcp.RcpOverrideModelProvider.acquireModel(RcpOverrideModelProvider.java:66)
+	at org.eclipse.recommenders.internal.overrides.rcp.OverrideCompletionSessionProcessor.hasModel(OverrideCompletionSessionProcessor.java:121)
+	at org.eclipse.recommenders.internal.overrides.rcp.OverrideCompletionSessionProcessor.startSession(OverrideCompletionSessionProcessor.java:86)
+	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.fireStartSession(IntelligentCompletionProposalComputer.java:305)
+	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.computeCompletionProposals(IntelligentCompletionProposalComputer.java:171)
+	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:333)
+	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:337)
+	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:331)
+	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:288)
+	at org.eclipse.jface.text.contentassist.ContentAssistant$3.run(ContentAssistant.java:2007)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:2004)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:560)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$7(CompletionProposalPopup.java:555)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:489)
+	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:482)
+	at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1823)
+	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:184)
+	at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:84)
+	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
+	at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:81)
+	at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
+	at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:118)
+	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:92)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:305)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:239)
+	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
+	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
+	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
+	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
+	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:287)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:527)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:577)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:385)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:331)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:88)
+	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
+	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1097)
+	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4252)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1502)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1525)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1510)
+	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1539)
+	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1535)
+	at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:518)
+	at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:1090)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5890)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
+	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68)
+	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:601)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5800)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
+	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:228)
+	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2148)
+	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2411)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5862)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
+	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5290)
+	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5440)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
+	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
+	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3695)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
+	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
+	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
+	at org.eclipse.ui.internal.Workbench$$Lambda$15/373342545.run(Unknown Source)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
+	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
+	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
+	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
+	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
+	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
+!SESSION 2017-10-14 11:49:36.937 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 11:49:42.788
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+!SESSION 2017-10-14 11:51:52.519 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 11:51:54.344
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+!SESSION 2017-10-14 11:53:04.238 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 11:53:05.983
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+!SESSION 2017-10-14 11:54:03.911 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 11:54:05.687
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+!SESSION 2017-10-14 13:07:25.142 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 13:07:26.999
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+!SESSION 2017-10-14 13:40:58.787 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.core.resources 2 10035 2017-10-14 13:41:00.827
+!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
+
+!ENTRY org.eclipse.recommenders.models.rcp 1 11 2017-10-14 13:41:42.238
+!MESSAGE The model index service was accessed either before it started or after it finished running.
+!STACK 0
+org.eclipse.recommenders.utils.Logs$LogTraceException
+	at org.eclipse.recommenders.utils.Logs$LogTraceException.newTrace(Logs.java:381)
+	at org.eclipse.recommenders.utils.Logs.log(Logs.java:134)
+	at org.eclipse.recommenders.utils.Logs.log(Logs.java:126)
+	at org.eclipse.recommenders.internal.models.rcp.EclipseModelIndex.suggest(EclipseModelIndex.java:211)
+	at org.eclipse.recommenders.models.SimpleModelProvider.acquireModel(SimpleModelProvider.java:70)
+	at org.eclipse.recommenders.models.PoolingModelProvider.access$0(PoolingModelProvider.java:1)
+	at org.eclipse.recommenders.models.PoolingModelProvider$ModelPoolFactoryMediator.makeObject(PoolingModelProvider.java:96)
+	at org.eclipse.recommenders.models.PoolingModelProvider$ModelPoolFactoryMediator.makeObject(PoolingModelProvider.java:1)
+	at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1220)
+	at org.eclipse.recommenders.models.PoolingModelProvider.acquireModel(PoolingModelProvider.java:67)
+	at org.eclipse.recommenders.internal.overrides.rcp.RcpOverrideModelProvider.acquireModel(RcpOverrideModelProvider.java:66)
+	at org.eclipse.recommenders.internal.overrides.rcp.OverrideCompletionSessionProcessor.hasModel(OverrideCompletionSessionProcessor.java:121)
+	at org.eclipse.recommenders.internal.overrides.rcp.OverrideCompletionSessionProcessor.startSession(OverrideCompletionSessionProcessor.java:86)
+	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.fireStartSession(IntelligentCompletionProposalComputer.java:305)
+	at org.eclipse.recommenders.completion.rcp.processable.IntelligentCompletionProposalComputer.computeCompletionProposals(IntelligentCompletionProposalComputer.java:171)
+	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:333)
+	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:337)
+	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:331)
+	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:288)
+	at org.eclipse.jface.text.contentassist.ContentAssistant$3.run(ContentAssistant.java:2007)
+	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
+	at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:2004)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:560)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$7(CompletionProposalPopup.java:555)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:489)
+	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
+	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:482)
+	at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1823)
+	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:184)
+	at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:84)
+	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
+	at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:81)
+	at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
+	at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:118)
+	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:92)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:305)
+	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:239)
+	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
+	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
+	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
+	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
+	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:287)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:527)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:577)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:385)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:331)
+	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:88)
+	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
+	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1097)
+	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4252)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1502)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1525)
+	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1510)
+	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1539)
+	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1535)
+	at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:518)
+	at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:1090)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5890)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
+	at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68)
+	at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:601)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5800)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
+	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:228)
+	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2148)
+	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2411)
+	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5862)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
+	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5290)
+	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5440)
+	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
+	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
+	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3695)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
+	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
+	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
+	at org.eclipse.ui.internal.Workbench$$Lambda$15/468950278.run(Unknown Source)
+	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
+	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
+	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
+	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
+	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
+	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
+	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
+	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
+	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
+	at java.lang.reflect.Method.invoke(Method.java:483)
+	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
+	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
+	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
+!SESSION 2017-10-15 10:40:07.841 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:41:22.769
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:41:28.472
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:41:53.229
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:42:34.434
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:42:35.276
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-15 11:56:29.224
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+!SESSION 2017-10-23 13:23:22.478 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.epp.logging.aeri.ide 2 17 2017-10-23 13:23:32.214
+!MESSAGE Server ‘org.eclipse.epp.logging.aeri.ide.server’ failed with exception: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down. ; version: 2.0.6.v20170906-1226
+!STACK 0
+org.apache.http.conn.HttpHostConnectException: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
+	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
+	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
+	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
+	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
+	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
+	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
+	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
+	at org.apache.http.client.fluent.Request.internalExecute(Request.java:173)
+	at org.apache.http.client.fluent.Executor.execute(Executor.java:262)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.request(IO.java:170)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.refreshConfiguration(IO.java:64)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.ServerConnection.startUp(ServerConnection.java:124)
+	at com.google.common.util.concurrent.AbstractIdleService$DelegateService$1.run(AbstractIdleService.java:62)
+	at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
+	at java.lang.Thread.run(Thread.java:745)
+Caused by: java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337)
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
+	... 17 more
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-23 14:04:05.825
+!MESSAGE Unable to connect to repository http://www.lejos.org/tools/eclipse/plugin/nxj/content.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-23 14:04:05.849
+!MESSAGE Unable to connect to repository http://download.eclipse.org/oomph/updates/milestone/latest/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-23 14:04:05.854
+!MESSAGE Unable to connect to repository http://download.eclipse.org/eclipse/updates/4.7/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-23 14:04:06.934
+!MESSAGE Unable to connect to repository http://download.eclipse.org/releases/oxygen/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.jdt.core 4 4 2017-10-23 15:44:02.417
+!MESSAGE Could not retrieve declared methods
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.internal.compiler.lookup.TypeSystem.getWildcard(TypeSystem.java:369)
+	at org.eclipse.jdt.internal.compiler.lookup.AnnotatableTypeSystem.getWildcard(AnnotatableTypeSystem.java:195)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromVariantTypeSignature(LookupEnvironment.java:2007)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeArgumentsFromSignature(LookupEnvironment.java:1645)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1931)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethod(BinaryTypeBinding.java:796)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethods(BinaryTypeBinding.java:910)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:529)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:1022)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:1003)
+	at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:303)
+	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:249)
+	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:105)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:215)
+	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.resolve(ParameterizedTypeBinding.java:1050)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:186)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveTypesFor(BinaryTypeBinding.java:1507)
+	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:396)
+	at org.eclipse.jdt.core.dom.TypeBinding.getDeclaredMethods(TypeBinding.java:302)
+	at org.eclipse.jdt.internal.corext.dom.Bindings.findOverriddenMethodInType(Bindings.java:494)
+	at org.eclipse.jdt.internal.corext.dom.Bindings.findOverriddenMethodInHierarchy(Bindings.java:511)
+	at org.eclipse.jdt.internal.corext.dom.Bindings.findOverriddenMethods(Bindings.java:567)
+	at org.eclipse.jdt.internal.corext.dom.Bindings.findOverriddenMethod(Bindings.java:538)
+	at org.eclipse.jdt.internal.ui.javaeditor.OverrideIndicatorManager$1.visit(OverrideIndicatorManager.java:184)
+	at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:611)
+	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2796)
+	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2867)
+	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470)
+	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2796)
+	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2867)
+	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470)
+	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2796)
+	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2867)
+	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:257)
+	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2796)
+	at org.eclipse.jdt.internal.ui.javaeditor.OverrideIndicatorManager.updateAnnotations(OverrideIndicatorManager.java:176)
+	at org.eclipse.jdt.internal.ui.javaeditor.OverrideIndicatorManager.reconciled(OverrideIndicatorManager.java:258)
+	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.reconciled(CompilationUnitEditor.java:1688)
+	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconciled(JavaReconcilingStrategy.java:219)
+	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconciled(JavaCompositeReconcilingStrategy.java:164)
+	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:112)
+	at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:73)
+	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
+!SESSION 2017-10-24 20:05:01.984 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.epp.logging.aeri.ide 2 17 2017-10-24 20:05:11.934
+!MESSAGE Server ‘org.eclipse.epp.logging.aeri.ide.server’ failed with exception: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down. ; version: 2.0.6.v20170906-1226
+!STACK 0
+org.apache.http.conn.HttpHostConnectException: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
+	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
+	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
+	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
+	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
+	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
+	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
+	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
+	at org.apache.http.client.fluent.Request.internalExecute(Request.java:173)
+	at org.apache.http.client.fluent.Executor.execute(Executor.java:262)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.request(IO.java:170)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.refreshConfiguration(IO.java:64)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.ServerConnection.startUp(ServerConnection.java:124)
+	at com.google.common.util.concurrent.AbstractIdleService$DelegateService$1.run(AbstractIdleService.java:62)
+	at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
+	at java.lang.Thread.run(Thread.java:745)
+Caused by: java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337)
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
+	... 17 more
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-24 20:31:15.795
+!MESSAGE Unable to connect to repository http://www.lejos.org/tools/eclipse/plugin/nxj/content.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-24 20:31:15.803
+!MESSAGE Unable to connect to repository http://download.eclipse.org/oomph/updates/milestone/latest/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-24 20:31:15.807
+!MESSAGE Unable to connect to repository http://download.eclipse.org/eclipse/updates/4.7/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-24 20:31:16.083
+!MESSAGE Unable to connect to repository http://download.eclipse.org/releases/oxygen/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+!SESSION 2017-10-25 15:49:28.917 -----------------------------------------------
+eclipse.buildId=4.7.1.M20171009-0410
+java.version=1.8.0_20
+java.vendor=Oracle Corporation
+BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
+Framework arguments:  -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+Command-line arguments:  -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/gabrielcapella/.eclipse_keyring
+
+!ENTRY org.eclipse.epp.logging.aeri.ide 2 17 2017-10-25 15:49:37.874
+!MESSAGE Server ‘org.eclipse.epp.logging.aeri.ide.server’ failed with exception: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down. ; version: 2.0.6.v20170906-1226
+!STACK 0
+org.apache.http.conn.HttpHostConnectException: Connect to dev.eclipse.org:443 [dev.eclipse.org/198.41.30.200] failed: Host is down
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
+	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
+	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
+	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
+	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
+	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
+	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
+	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
+	at org.apache.http.client.fluent.Request.internalExecute(Request.java:173)
+	at org.apache.http.client.fluent.Executor.execute(Executor.java:262)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.request(IO.java:170)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.refreshConfiguration(IO.java:64)
+	at org.eclipse.epp.internal.logging.aeri.ide.server.mars.ServerConnection.startUp(ServerConnection.java:124)
+	at com.google.common.util.concurrent.AbstractIdleService$DelegateService$1.run(AbstractIdleService.java:62)
+	at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)
+	at java.lang.Thread.run(Thread.java:745)
+Caused by: java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337)
+	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
+	... 17 more
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-25 16:24:33.817
+!MESSAGE Unable to connect to repository http://www.lejos.org/tools/eclipse/plugin/nxj/content.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-25 16:24:33.825
+!MESSAGE Unable to connect to repository http://download.eclipse.org/oomph/updates/milestone/latest/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-25 16:24:33.829
+!MESSAGE Unable to connect to repository http://download.eclipse.org/eclipse/updates/4.7/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.eclipse.equinox.p2.transport.ecf 4 1002 2017-10-25 16:24:34.090
+!MESSAGE Unable to connect to repository http://download.eclipse.org/releases/oxygen/compositeContent.xml
+!STACK 0
+java.net.ConnectException: Host is down
+	at java.net.PlainSocketImpl.socketConnect(Native Method)
+	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
+	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
+	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
+	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
+	at java.net.Socket.connect(Socket.java:589)
+	at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:120)
+	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179)
+	at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:328)
+	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:612)
+	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:447)
+	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
+	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
+	at org.eclipse.ecf.provider.filetransfer.httpclient4.HttpClientFileSystemBrowser.runRequest(HttpClientFileSystemBrowser.java:263)
+	at org.eclipse.ecf.provider.filetransfer.browse.AbstractFileSystemBrowser$DirectoryJob.run(AbstractFileSystemBrowser.java:69)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 21:58:29.221
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 21:58:43.180
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 22:02:35.730
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 22:02:37.027
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 22:02:41.705
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
+
+!ENTRY org.lejos.nxt.ldt 4 0 2017-10-25 22:07:57.690
+!MESSAGE 
+!STACK 0
+java.lang.NullPointerException
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspathEntry(JavaRuntime.java:1164)
+	at org.eclipse.jdt.launching.StandardClasspathProvider.resolveClasspath(StandardClasspathProvider.java:91)
+	at org.eclipse.jdt.launching.JavaRuntime.resolveRuntimeClasspath(JavaRuntime.java:1517)
+	at org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate.getClasspath(AbstractJavaLaunchConfigurationDelegate.java:415)
+	at org.lejos.nxt.ldt.launch.LaunchNXTConfigDelegate.launch(LaunchNXTConfigDelegate.java:89)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
+	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
+	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
+	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

BIN
.metadata/.mylyn/.taskListIndex/segments_1


+ 0 - 0
.metadata/.mylyn/.taskListIndex/write.lock


BIN
.metadata/.mylyn/.tasks.xml.zip


BIN
.metadata/.mylyn/repositories.xml.zip


BIN
.metadata/.mylyn/tasks.xml.zip


+ 16 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/0/102195ce0eb9001711c7a09600ea5d68

@@ -0,0 +1,16 @@
+package config;
+
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class SonarModel {
+	private LineMap map;
+
+	public SonarModel(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedRead(Pose p) {
+		return 0;
+	}
+}

+ 112 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/0/607d0a7c31b80017145c9b6064c27648

@@ -0,0 +1,112 @@
+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 = distance/10;
+    			//System.out.println(d);
+    			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;
+		double d = h*2.0/25.0/20.0;
+		double a = -oval_size/2;
+		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>();
+	}
+}

+ 248 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1/30dc958315b80017145c9b6064c27648

@@ -0,0 +1,248 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+public class MapImage extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener  {
+    private double zoom = 2.0; // pixel per cm
+    private double grid = 10.0; // cm
+    private double centerx = 0.0;
+    private double centery = 0.0; // cm
+    private Point mousePt;
+    private ArrayList<Pose> lista_pontos;
+    private ArrayList<Pose> lista_ultra;
+    private int visual_method = 0;
+    private boolean line = false;
+    
+	public MapImage() {
+		super();
+		lista_pontos = new ArrayList<Pose>();
+		lista_ultra = new ArrayList<Pose>();
+		setBackground(Color.BLACK);
+		addMouseWheelListener(this);
+		addMouseListener(this);
+		addMouseMotionListener(this);
+	}
+	
+    private void drawModel (Graphics g) {
+        int width = (int) (getWidth()+2*centerx);
+        int height = (int) (getHeight()+2*centery);
+        int count = 0;
+        int x_tmp = 0, y_tmp = 0;
+        
+	    	for (Pose p : lista_pontos) {
+	    		int x = width/2+(int)(p.x*zoom);
+	    		int y = height/2+(int)(p.y*zoom)*-1;
+	    		
+			if (visual_method == 0) {
+				g.setColor(Color.getHSBColor((float) (p.z/(2.0*Math.PI)), 1, 1));
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+			} else if (visual_method == 1) {
+	            g.setColor(Color.RED);
+	            g.drawLine(
+	                width/2+(int)(p.x*zoom),
+	                height/2-(int)(p.y*zoom), 
+	                width/2+(int)(p.x*zoom+Math.sin(p.z)*zoom),
+	                height/2-(int)(p.y*zoom-Math.cos(p.z)*zoom)
+	            );
+	
+	           g.drawLine(
+	                width/2+(int)(p.x*zoom+zoom*Math.sin(p.z)),
+	                height/2-(int)(p.y*zoom-zoom*Math.cos(p.z)),
+	                width/2+(int)(p.x*zoom+0.6*zoom*Math.sin(Math.PI/8+p.z)),
+	                height/2-(int)(p.y*zoom-0.6*zoom*Math.cos(Math.PI/8+p.z))
+	            );
+			} else if (visual_method == 2) {
+				g.setColor(Color.RED);
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+	            g.setColor(Color.BLACK);
+	            g.drawLine(
+	                width/2+(int)(p.x*zoom),
+	                height/2-(int)(p.y*zoom), 
+	                width/2+(int)(p.x*zoom+Math.sin(p.z)*zoom),
+	                height/2-(int)(p.y*zoom-Math.cos(p.z)*zoom)
+	            );
+			}
+	
+		    	if (line && count != 0) {
+		    		g.setColor(Color.LIGHT_GRAY);
+		    		g.drawLine(x_tmp, y_tmp, x, y);
+		    	}
+	
+		    	x_tmp = x;
+		    	y_tmp = y;
+		    	count++;
+		}
+	    	
+	    	g.setColor(Color.RED);
+	    	for (Pose p : lista_ultra) {
+	    		int x = width/2+(int)(p.x*zoom);
+	    		int y = height/2+(int)(p.y*zoom)*-1;
+	    		g.fillRect(
+					x-(int)(zoom/2.0*1.0),
+					y-(int)(zoom/2.0*1.0),
+					(int)(zoom*1.0),
+					(int)(zoom*1.0)
+			);
+	    	}
+    }
+    
+    @Override
+    protected void paintComponent(Graphics g) {
+        int width = (int) (getWidth());
+        int height = (int) (getHeight());
+        int width2 = (int) (getWidth()+2*centerx);
+        int height2 = (int) (getHeight()+2*centery);
+        super.paintComponent(g);
+    
+        g.setColor(new Color(20, 20, 20));
+        
+        int initial_x = height2/2;
+        while (initial_x < width) {
+        	initial_x += grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        initial_x = height2/2;
+        while (initial_x > 0) {
+        	initial_x -= grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        int initial_y = width2/2;
+        while (initial_y < width) {
+        	initial_y += grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+        initial_y = width2/2;
+        while (initial_y > 0) {
+        	initial_y -= grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+
+        g.setColor(Color.ORANGE);
+        g.drawLine(width2/2, 0, width2/2, height);
+        g.drawLine(0, height2/2, width, height2/2);
+
+        drawModel(g);
+    }
+    
+    /**
+     * Adiciona um ponto ao mapa
+     * @param p ponto
+     */
+    public void addPoint(Pose p) {
+    		lista_pontos.add(p);
+    		repaint();
+	}
+
+    public void addPoint(double x, double y, double z) {
+    		lista_pontos.add(new Pose(x, y, z));
+    		repaint();
+	}
+    
+
+    public void addRead(double x, double y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+    public void showLine () {
+    		line = !line;
+    		repaint();
+    }
+
+    public void setVisual (int method) {
+    		visual_method = method;
+    		repaint();
+    }
+    
+    public void save () {
+	    	Integer name = new Integer((int) (Math.random()*1000000));
+	    	BufferedImage imagebuf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
+	    	Graphics g = imagebuf.createGraphics();
+	    	g.fillRect(0, 0, imagebuf.getWidth(), imagebuf.getHeight());
+	    	print(g);
+	    	try {
+			ImageIO.write(imagebuf, "png",  new File(name.toString()+".png"));
+			JOptionPane.showMessageDialog(null, "Image saved.");
+		} catch (IOException e) {
+			e.printStackTrace();
+			JOptionPane.showMessageDialog(null, "Image not saved.");
+		}
+    }
+    
+	public void clean() {
+		lista_pontos.clear();
+		lista_ultra.clear();
+		repaint();
+	}
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		centerx += e.getX() - mousePt.x;
+		centery += e.getY() - mousePt.y;
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseMoved(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseClicked(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mousePressed(MouseEvent e) {
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseReleased(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+	
+	@Override
+	public void mouseExited(MouseEvent e) {	
+	}
+	
+	@Override
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		if(e.getWheelRotation()<0){
+			if (zoom < 15.0)
+				zoom *= 1.1;
+			repaint();
+		}
+		//Zoom out
+		if(e.getWheelRotation()>0){
+			if (zoom > 1.0)
+				zoom /= 1.1;
+			repaint();
+		}
+	}
+}

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

@@ -0,0 +1,244 @@
+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));
+	}
+
+}

+ 16 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/10/d06397d611b80017145c9b6064c27648

@@ -0,0 +1,16 @@
+
+public class Pose {
+	public double x, y, z;
+	
+	public Pose(double x, double y, double z) {
+		this.x = x;
+		this.y = y;
+		this.z = z; // em radianos
+	}
+	
+	public Pose() {
+		this.x = (int )(Math.random() * 100 - 50);
+		this.y = (int )(Math.random() * 100 - 50);
+		this.z = (int )(Math.random() * Math.PI * 2.0);
+	}
+}

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

@@ -0,0 +1,276 @@
+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);
+			}
+		});
+	}
+}

+ 166 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/11/60e7755ef9b00017155fe9ac88a695a6

@@ -0,0 +1,166 @@
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+
+public class Map extends JPanel implements KeyListener {
+
+	private ImageMap map;
+	
+	private DataOutputStream output;
+	private DataInputStream input;
+	private int before;
+
+	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;
+	
+	private class Receiver extends Thread {
+		@Override
+		public void run() {
+			int bytes_valiable = -1;
+			
+			while(true) {
+				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();
+						System.out.println(x+" "+y);
+					} catch (IOException e1) {
+						continue;
+					}
+				}
+			}
+		}
+	}
+	
+	public Map (DataInputStream in, DataOutputStream out) {
+		JFrame frame = new JFrame("Mapa MAC0318");
+		Receiver r = new Receiver();
+		output = out;
+		input = in;
+		before = -1;
+		
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        map = new ImageMap();
+		frame.add(this.map);
+		frame.setSize(800, 800);
+		frame.setVisible(true);
+		
+		frame.setFocusable(true);
+		frame.requestFocusInWindow();
+		frame.addKeyListener(this);
+		
+		r.start();
+		
+		String text = "1,2,3 - Change view mode.\n";
+		text += "s - Save image.\n";
+		text += "l - Show trace.\n";
+		JOptionPane.showMessageDialog(null, text);
+	}
+	
+    public void addPoint(Point3D p) {
+    		map.addPoint(p);
+	}
+
+	@Override
+	public void keyPressed(KeyEvent e) {
+		char input = e.getKeyChar();
+		if (input == '1') map.setVisual(0);
+		else if (input == '2') map.setVisual(1);
+		else if (input == '3') map.setVisual(2);
+		else if (input == 'l') map.showLine();
+		else if (input == 's') map.save();
+		
+		 switch(e.getKeyCode()) { 
+	        case KeyEvent.VK_UP:
+	        		sendCmd(FORWARD);
+	            break;
+	        case KeyEvent.VK_DOWN:
+	        		sendCmd(BACKWARD);
+	            break;
+	        case KeyEvent.VK_LEFT:
+	        		sendCmd(LEFT);
+	            break;
+	        case KeyEvent.VK_RIGHT :
+	        		sendCmd(RIGHT);
+	            break;
+	    }			 
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		sendCmd(STOP);
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+	private void sendCmd (int cmd) {
+		if (before != cmd) {
+			try {
+				output.write(cmd);
+				output.flush();
+				System.out.println("Send cmd");
+			} catch (IOException e1) {
+				System.out.println("Erro send cmd");
+				before = -1;
+				sendCmd (cmd);
+			}
+			before = cmd;
+		}
+	}
+	
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+		NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); 
+		NXTInfo[] nxtInfo = nxtComm.search("NXT8"); //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");
+			System.exit(1);
+		}
+		if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
+			System.err.println("Failed to open NXT");
+			System.exit(1);
+		}
+		
+		final DataInputStream input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
+		final DataOutputStream output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
+		
+		SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+            	new Map(input, output);
+            }
+        });
+		
+	}
+}

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

@@ -0,0 +1,279 @@
+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);
+			}
+		});
+	}
+}

+ 53 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/12/200fd8fb1eb80017145c9b6064c27648

@@ -0,0 +1,53 @@
+package robots;
+
+import lejos.robotics.mapping.LineMap;
+
+public class VirtualRobot implements Robot {
+
+	public VirtualRobot(LineMap map) {
+		// TODO Auto-generated constructor stub
+	}
+
+	@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) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void stop() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void exit() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

+ 0 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/15/80dd4a5808b80017145c9b6064c27648


+ 222 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/17/1089c19fcbb90017124d9f37712eb7c1

@@ -0,0 +1,222 @@
+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.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.start(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):");
+		String ys = JOptionPane.showInputDialog("Enter y (cm):");
+		String as = JOptionPane.showInputDialog("Enter heading (degress):");
+		float x  = Float.parseFloat(xs);
+		float y  = Float.parseFloat(ys);
+		float a  = Float.parseFloat(as);
+		robot.setPose(x, y, a);
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

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

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

+ 206 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/17/d09a8a6ec6b90017124d9f37712eb7c1

@@ -0,0 +1,206 @@
+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.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(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";
+		 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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

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

@@ -0,0 +1,304 @@
+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);
+			}
+		});
+	}
+}

+ 25 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/18/6065aa100fb9001711c7a09600ea5d68

@@ -0,0 +1,25 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class SonarModel {
+	private LineMap map;
+
+	public SonarModel(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l: map.getLines()) {
+			d = l.ptSegDist(p.getX(), p.getY());
+			min = Math.min(min, d);
+		}
+		return min;
+	}
+}

+ 51 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/18/c0cda01a14b9001711c7a09600ea5d68

@@ -0,0 +1,51 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.geom.Rectangle;
+import lejos.robotics.mapping.LineMap;
+
+public class Map {
+	public static LineMap makeMap () {
+//		Line[] lines1 = {
+//			/* L-shape polygon */
+//			new Line(164,356,58,600),
+//			new Line(58,600,396,721),
+//			new Line(396,721,455,600),
+//			new Line(455,600,227,515),
+//			new Line(227,515,280,399),
+//			new Line(280,399,164,356),
+//			/* Triangle */
+//			new Line(778,526,1079,748),
+//			new Line(1079,748,1063,436),
+//			new Line(1063,436,778,526),
+//			/* Pentagon */
+//			new Line(503,76,333,267),
+//			new Line(333,267,481,452),
+//			new Line(481,452,730,409),
+//			new Line(730,409,704,150),
+//			new Line(704,150,503,76)
+//		};
+		Line[] lines2 = {
+			new Line(16.4,35.6,5.8,60.0),
+			new Line(5.8,60.0,39.6,72.1),
+			new Line(39.6,72.1,45.5,60.0),
+			new Line(45.5,60.0,22.7,51.5),
+			new Line(22.7,51.5,28.0,39.9),
+			new Line(28.0,39.9,16.4,35.6),
+			/* Triangle */
+			new Line(77.8,52.6,107.9,74.8),
+			new Line(107.9,74.8,106.3,43.6),
+			new Line(106.3,43.6,77.8,52.6),
+			/* Pentagon */
+			new Line(50.3,7.6,33.3,26.7),
+			new Line(33.3,26.7,48.1,45.2),
+			new Line(48.1,45.2,73.0,40.9),
+			new Line(73.0,40.9,70.4,15.0),
+			new Line(70.4,15.0,50.3,7.6)
+		};
+		Rectangle bounds = new Rectangle(0, 0, 1189, 841);
+		LineMap  map = new LineMap(lines2, bounds);
+
+		return map;
+	}
+}

+ 52 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/19/603b73fbe2b000171eb4aea94a5e3c6b

@@ -0,0 +1,52 @@
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class SendThread extends Thread{
+	
+	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;
+	
+	private int command;
+	private int before;
+	private boolean run;
+	private DataOutputStream output;
+	
+	public SendThread(DataOutputStream out) {
+		super();
+		command = -1;
+		before = command;
+		run = true;
+		output = out;
+	}
+	
+	@Override
+	public void run() {
+		while (run) {
+			if (before != command) {
+				try {
+					output.write(command);
+					output.flush();
+					System.out.println("Send cmd");
+				} catch (IOException e) {
+					System.out.println("Erro send cmd");
+				}
+				before = command;
+			}
+			
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	public void send (int c) {
+		command = c;
+	}
+}

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

@@ -0,0 +1,262 @@
+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));
+	}
+
+}

+ 115 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1a/3088cad90ab9001711c7a09600ea5d68

@@ -0,0 +1,115 @@
+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/20.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];
+		    			double sin = Math.sin(Math.toRadians(pose.getHeading()-90));
+		    			double cos = Math.cos(Math.toRadians(pose.getHeading()-90));
+		            g.drawLine(
+			                (int)(w+(l.x1/10.0-pose.getX())*d*sin),
+			                (int)(h-(l.y1/10.0-pose.getY())*d*cos), 
+			                (int)(w+(l.x2/10.0-pose.getX())*d*sin),
+			                (int)(h-(l.y2/10.0-pose.getY())*d*cos)
+			        );
+		    		}
+		    	}
+    		
+    			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 = 16;
+		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>();
+	}
+}

+ 286 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0b3319f18b80017145c9b6064c27648

@@ -0,0 +1,286 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class MapImage extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener  {
+    private double zoom = 2.0; // pixel per cm
+    private double grid = 10.0; // cm
+    private double centerx = 0.0;
+    private double centery = 0.0; // cm
+    private Point mousePt;
+    private ArrayList<Pose> lista_pontos;
+    private ArrayList<Pose> lista_ultra;
+    private int visual_method = 0;
+    private boolean line = false;
+    
+    private LineMap map;
+    
+	public MapImage() {
+		super();
+		lista_pontos = new ArrayList<Pose>();
+		lista_ultra = new ArrayList<Pose>();
+		setBackground(Color.BLACK);
+		addMouseWheelListener(this);
+		addMouseListener(this);
+		addMouseMotionListener(this);
+	}
+	
+	public MapImage(LineMap map) {
+		this();
+		this.map = map;
+	}
+	
+    private void drawModel (Graphics g) {
+        int width = (int) (getWidth()+2*centerx);
+        int height = (int) (getHeight()+2*centery);
+        int count = 0;
+        int x_tmp = 0, y_tmp = 0;
+        
+	    	for (Pose p : lista_pontos) {
+			double hading = Math.toRadians(p.getHeading());
+				
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		
+			if (visual_method == 0) {
+				g.setColor(Color.getHSBColor((float) (hading/(2.0*Math.PI)), 1, 1));
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+			} else if (visual_method == 1) {
+	            g.setColor(Color.RED);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+	
+	           g.drawLine(
+	                width/2+(int)(p.getX()*zoom+zoom*Math.sin(hading)),
+	                height/2-(int)(p.getY()*zoom-zoom*Math.cos(hading)),
+	                width/2+(int)(p.getX()*zoom+0.6*zoom*Math.sin(Math.PI/8+hading)),
+	                height/2-(int)(p.getY()*zoom-0.6*zoom*Math.cos(Math.PI/8+hading))
+	            );
+			} else if (visual_method == 2) {
+				g.setColor(Color.RED);
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+	            g.setColor(Color.BLACK);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+			}
+	
+		    	if (line && count != 0) {
+		    		g.setColor(Color.LIGHT_GRAY);
+		    		g.drawLine(x_tmp, y_tmp, x, y);
+		    	}
+	
+		    	x_tmp = x;
+		    	y_tmp = y;
+		    	count++;
+		}
+	    	
+	    	g.setColor(Color.RED);
+	    	for (Pose p : lista_ultra) {
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		g.fillRect(
+					x-(int)(zoom/2.0*1.0),
+					y-(int)(zoom/2.0*1.0),
+					(int)(zoom*1.0),
+					(int)(zoom*1.0)
+			);
+	    	}
+	    	
+	    	if (map != null) {
+	    		Line[] lines = map.getLines();
+	    		for (int i = 0; i < lines.length; i++) {
+	    			Line l = lines[i];
+	            g.drawLine(
+		                width/2+(int)(l.x1*zoom),
+		                height/2-(int)(l.y1*zoom), 
+		                width/2+(int)(l.x2*zoom),
+		                height/2-(int)(l.y2*zoom)
+		        );
+	    		}
+	    	}
+    }
+    
+    @Override
+    protected void paintComponent(Graphics g) {
+        int width = (int) (getWidth());
+        int height = (int) (getHeight());
+        int width2 = (int) (getWidth()+2*centerx);
+        int height2 = (int) (getHeight()+2*centery);
+        super.paintComponent(g);
+    
+        g.setColor(new Color(20, 20, 20));
+        
+        int initial_x = height2/2;
+        while (initial_x < width) {
+        	initial_x += grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        initial_x = height2/2;
+        while (initial_x > 0) {
+        	initial_x -= grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        int initial_y = width2/2;
+        while (initial_y < width) {
+        	initial_y += grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+        initial_y = width2/2;
+        while (initial_y > 0) {
+        	initial_y -= grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+
+        g.setColor(Color.ORANGE);
+        g.drawLine(width2/2, 0, width2/2, height);
+        g.drawLine(0, height2/2, width, height2/2);
+
+        drawModel(g);
+    }
+    
+    /**
+     * Adiciona um ponto ao mapa
+     * @param p ponto
+     */
+    public void addPoint(Pose p) {
+    		lista_pontos.add(p);
+    		repaint();
+	}
+
+    public void addPoint(float x, float y, float z) {
+    		lista_pontos.add(new Pose(x, y, z));
+    		repaint();
+	}
+    
+
+    public void addRead(float x, float y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+
+    public void addPoint(double x, double y, double z) {
+    		addPoint((float)x, (float)y, (float)z);
+	}
+    
+
+    public void addRead(double x, double y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+    
+    public void showLine () {
+    		line = !line;
+    		repaint();
+    }
+
+    public void setVisual (int method) {
+    		visual_method = method;
+    		repaint();
+    }
+    
+    public void save () {
+	    	Integer name = new Integer((int) (Math.random()*1000000));
+	    	BufferedImage imagebuf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
+	    	Graphics g = imagebuf.createGraphics();
+	    	g.fillRect(0, 0, imagebuf.getWidth(), imagebuf.getHeight());
+	    	print(g);
+	    	try {
+			ImageIO.write(imagebuf, "png",  new File(name.toString()+".png"));
+			JOptionPane.showMessageDialog(null, "Image saved.");
+		} catch (IOException e) {
+			e.printStackTrace();
+			JOptionPane.showMessageDialog(null, "Image not saved.");
+		}
+    }
+    
+	public void clean() {
+		lista_pontos.clear();
+		lista_ultra.clear();
+		repaint();
+	}
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		centerx += e.getX() - mousePt.x;
+		centery += e.getY() - mousePt.y;
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseMoved(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseClicked(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mousePressed(MouseEvent e) {
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseReleased(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+	
+	@Override
+	public void mouseExited(MouseEvent e) {	
+	}
+	
+	@Override
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		if(e.getWheelRotation()<0){
+			if (zoom < 15.0)
+				zoom *= 1.1;
+			repaint();
+		}
+		//Zoom out
+		if(e.getWheelRotation()>0){
+			if (zoom > 1.0)
+				zoom /= 1.1;
+			repaint();
+		}
+	}
+}

+ 89 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1b/20730e7d21b80017145c9b6064c27648

@@ -0,0 +1,89 @@
+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) {
+				System.out.println(ang);
+				DataPose data = new DataPose();
+				data.setDistance(100);
+				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();
+		}
+		
+	}
+
+}

+ 135 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1b/6001ad73d5b90017124d9f37712eb7c1

@@ -0,0 +1,135 @@
+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(50);
+				} catch (InterruptedException e) {
+				}
+			}
+		}
+
+	}
+
+	public VirtualRobot(LineMap map) {
+		pose = new Pose();
+		pose.setHeading(90);
+		this.map = map;
+	}
+
+	@Override
+	public void moveForward() {
+		move(5);
+	}
+
+	@Override
+	public void moveLeft() {
+		pose.rotateUpdate(45);
+	}
+
+	@Override
+	public void moveRight() {
+		pose.rotateUpdate(-45);
+	}
+
+	@Override
+	public void moveBackward() {
+		move(-5);
+	}
+
+	@Override
+	public boolean connect() {
+		return true;
+	}
+
+	@Override
+	public void stop() {
+	}
+
+	@Override
+	public void move(double x) {
+		double dx = Math.sin(Math.toRadians(pose.getHeading())) * x;
+		double dy = Math.cos(Math.toRadians(pose.getHeading())) * x;
+		pose.translate((float) dx, (float) -dy);
+	}
+
+	@Override
+	public void rotate(double x) {
+		pose.rotateUpdate((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;
+		simthread = new Simulate();
+		simthread.start();
+	}
+
+	@Override
+	public void stopScann() {
+		simthread.run = false;
+		try {
+			simthread.join();
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void disconnect() {
+
+	}
+
+	@Override
+	public void setPose(float x, float y, float a) {
+		pose.setHeading(a);
+		pose.setLocation(x, y);
+	}
+	
+	@Override
+	public String toString() {
+		return "Virtual Robot";
+	}
+
+}

+ 53 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1c/0061834ce4b000171eb4aea94a5e3c6b

@@ -0,0 +1,53 @@
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class SendThread extends Thread{
+	
+	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;
+	
+	private int command;
+	private int before;
+	private boolean run;
+	private DataOutputStream output;
+	
+	public SendThread(DataOutputStream out) {
+		super();
+		command = -1;
+		before = command;
+		run = true;
+		output = out;
+	}
+	
+	@Override
+	public void run() {
+		while (run) {
+			if (before != command) {
+//				try {
+//					output.write(command);
+//					output.flush();
+//					System.out.println("Send cmd");
+//				} catch (IOException e) {
+//					System.out.println("Erro send cmd");
+//				}
+				System.out.println("Send cmd");
+				before = command;
+			}
+			
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	public void send (int c) {
+		command = c;
+	}
+}

+ 25 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1c/50d569cdafb90017124d9f37712eb7c1

@@ -0,0 +1,25 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l : map.getLines()) {
+			d = l.ptSegDist(p.getX(), p.getY());
+			min = Math.min(min, d);
+		}
+		return min;
+	}
+}

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

@@ -0,0 +1,272 @@
+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";
+	}
+
+}

+ 206 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1d/50193f6bc6b90017124d9f37712eb7c1

@@ -0,0 +1,206 @@
+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.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(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 \t\t 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";
+		 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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

+ 206 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1d/50c61970c6b90017124d9f37712eb7c1

@@ -0,0 +1,206 @@
+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.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(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";
+		 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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

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

@@ -0,0 +1,274 @@
+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";
+	}
+
+}

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

@@ -0,0 +1,91 @@
+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();
+		}
+
+	}
+
+}

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

@@ -0,0 +1,273 @@
+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";
+	}
+
+}

+ 24 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1f/6039ae6bc7b90017124d9f37712eb7c1

@@ -0,0 +1,24 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p, double angle) {
+		Pose tmppose = (30, 25, 120);
+		float mindist = Float.POSITIVE_INFINITY;
+		for (int angulo=-cone/2; angulo <= cone/2; angulo++) {
+		tmppose.setHeading(mypose.getHeading() - angulo);
+		float dist = mymap.range(tmpPose);
+		if (dist > 0 && dist < mindist) mindist = dist;
+		} 
+		return 0;
+	}
+}

+ 204 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1f/705f6c47c5b90017124d9f37712eb7c1

@@ -0,0 +1,204 @@
+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.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");
+		
+
+	    JMenuBar bar = new JMenuBar();
+	    JMenu menu = new JMenu("Options");
+	    menu.setMnemonic(KeyEvent.VK_O);
+
+	    bar.add(menu);
+	    frame.setJMenuBar(bar);
+
+
+		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(this);
+
+		if (result == false) {
+			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
+		}
+
+		//
+		// String text = "1,2,3 - Change view mode.\n";
+		// text += "s - Save image.\n";
+		// text += "l - Show trace.\n";
+		// text += "c - Clean map.\n";
+		// JOptionPane.showMessageDialog(null, text);
+	}
+
+	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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

+ 25 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/1f/70948cf90eb9001711c7a09600ea5d68

@@ -0,0 +1,25 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class SonarModel {
+	private LineMap map;
+
+	public SonarModel(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l: map) {
+			d = l.ptSegDist(p.getX(), p.getY());
+			min = Math.min(min, d);
+		}
+		return 0;
+	}
+}

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

@@ -0,0 +1,113 @@
+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>();
+	}
+}

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

@@ -0,0 +1,264 @@
+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);
+			}
+		});
+	}
+}

+ 60 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/20/20af339020b80017145c9b6064c27648

@@ -0,0 +1,60 @@
+package robots;
+
+import lejos.robotics.mapping.LineMap;
+
+public class VirtualRobot implements Robot {
+	private Pose pose;
+	
+	private class Simulate extends Thread {
+		public void run() {
+			
+		}
+	}
+
+	public VirtualRobot(LineMap map) {
+		// TODO Auto-generated constructor stub
+	}
+
+	@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) {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	@Override
+	public void stop() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void exit() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

+ 269 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/20/80f4cd6218b80017145c9b6064c27648

@@ -0,0 +1,269 @@
+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 java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.AncestorEvent;
+import javax.swing.event.AncestorListener;
+
+import config.Map;
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+import robots.Robot;
+import robots.VirtualRobot;
+
+public class MainProgram extends JPanel implements KeyListener, WindowListener {
+
+	private MapImage imap;
+	
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	private Receiver receivethread;
+
+	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;
+	
+	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();
+						
+						// posicao do robo
+						imap.addPoint(x, y, Math.toRadians(alpha+90));
+						
+						// ponto do ultrasonico
+						double sensor_ang = Math.toRadians(alpha+angle);
+						double dx = Math.cos(sensor_ang)*distance;
+						double dy = Math.sin(sensor_ang)*distance;
+						imap.addRead(x+dx, y+dy);
+						
+					} catch (IOException e1) {
+						continue;
+					}
+				}
+			}
+		}
+	}
+
+	private class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	public MainProgram (LineMap map) {
+		JFrame frame = new JFrame("Mapa MAC0318");
+
+
+		receivethread= new Receiver();
+		sendthread = new Send();
+		
+//		output = out;
+//		input = in;
+
+//		receivethread.start();
+//		sendthread.start();
+		
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        imap = new MapImage(map);
+        ScannerImage scanner = new ScannerImage();
+//		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);
+		
+//		
+//		String text = "1,2,3 - Change view mode.\n";
+//		text += "s - Save image.\n";
+//		text += "l - Show trace.\n";
+//		text += "c - Clean map.\n";
+//		JOptionPane.showMessageDialog(null, text);
+	}
+	
+    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 == 's') imap.save();
+		else if (input == 'c') imap.clean();
+		
+		 switch(e.getKeyCode()) { 
+	        case KeyEvent.VK_UP:
+	        		sendthread.send(FORWARD);
+	            break;
+	        case KeyEvent.VK_DOWN:
+	        		sendthread.send(BACKWARD);
+	            break;
+	        case KeyEvent.VK_LEFT:
+	        		sendthread.send(LEFT);
+	            break;
+	        case KeyEvent.VK_RIGHT :
+	        		sendthread.send(RIGHT);
+	            break;
+	    }			 
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {		
+	}
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		
+		
+//		NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); 
+//		NXTInfo[] nxtInfo = nxtComm.search("NXT8"); //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");
+//			System.exit(1);
+//		}
+//		if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
+//			System.err.println("Failed to open NXT");
+//			System.exit(1);
+//		}
+//		
+//		final DataInputStream input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
+//		final DataOutputStream output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
+//		
+		SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+            	//new Map(input, output);
+
+            	new MainProgram(map);
+            }
+        });
+		
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+		
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		System.err.println("Fechando...");
+		receivethread.run = false;
+		sendthread.send(EXIT);
+		try {
+			receivethread.join();
+			sendthread.join();
+		} catch (InterruptedException e1) {
+			System.out.println("Nao foi possivel finalizar as threads...");
+		}
+		
+	}
+
+	@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) {		
+	}
+}

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

@@ -0,0 +1,88 @@
+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();
+		}
+		
+	}
+
+}

+ 139 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/22/30fac574cfb90017124d9f37712eb7c1

@@ -0,0 +1,139 @@
+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) {
+		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() {
+		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) {
+		rr = r;
+		simthread = new Simulate();
+		simthread.start();
+	}
+
+	@Override
+	public void stopScann() {
+		simthread.run = false;
+		try {
+			simthread.join();
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void disconnect() {
+
+	}
+
+	@Override
+	public void setPose(float x, float y, float a) {
+		pose.setHeading(a);
+		pose.setLocation(x, y);
+	}
+	
+	@Override
+	public String toString() {
+		return "Virtual Robot";
+	}
+
+}

+ 13 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/22/90210b881eb80017145c9b6064c27648

@@ -0,0 +1,13 @@
+package robots;
+
+public interface Robot {
+	public void moveForward ();
+	public void moveLeft ();
+	public void moveRight ();
+	public void moveBackward ();
+	
+	public boolean connect (RobotReturn m);
+	public void stop ();
+	public void exit ();
+	
+}

+ 114 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/22/b0dc773632b80017145c9b6064c27648

@@ -0,0 +1,114 @@
+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 = distance;
+    			//System.out.println(d);
+    			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 += a*Math.sin(Math.toRadians(r.ang+90));
+			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>();
+	}
+}

+ 52 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/22/d05cb20ce3b000171eb4aea94a5e3c6b

@@ -0,0 +1,52 @@
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class SendThread extends Thread{
+	
+	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;
+	
+	private int command;
+	private int before;
+	private boolean run;
+	private DataOutputStream output;
+	
+	public SendThread(DataOutputStream out) {
+		super();
+		command = -1;
+		before = command;
+		run = true;
+		output = out;
+	}
+	
+	@Override
+	public void run() {
+		while (run) {
+			if (before != command) {
+				try {
+//					output.write(command);
+//					output.flush();
+					System.out.println("Send cmd");
+				} catch (IOException e) {
+					System.out.println("Erro send cmd");
+				}
+				before = command;
+			}
+			
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	public void send (int c) {
+		command = c;
+	}
+}

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

@@ -0,0 +1,273 @@
+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";
+	}
+
+}

+ 67 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/23/104082ed20b80017145c9b6064c27648

@@ -0,0 +1,67 @@
+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() {
+			while(run) {
+				
+			}
+		}
+		
+	}
+
+	public VirtualRobot(LineMap map) {
+		simthread = new Simulate();
+	}
+
+	@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;
+		simthread.join();
+		
+	}
+
+}

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

@@ -0,0 +1,113 @@
+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>();
+	}
+}

+ 16 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/23/b07ddeb41ab80017145c9b6064c27648

@@ -0,0 +1,16 @@
+package robots;
+
+import lejos.robotics.navigation.Pose;
+
+public interface Robot {
+	public void moveForward ();
+	public void moveLeft ();
+	public void moveRight ();
+	public void moveBackward ();
+	
+	public boolean connect ();
+	public void stop ();
+	public void exit ();
+	
+	public Pose getData();
+}

+ 116 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/24/302f98100ab9001711c7a09600ea5d68

@@ -0,0 +1,116 @@
+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/20.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];
+		    			System.out.println(pose.getHeading());
+		    			double sin = Math.sin(Math.toRadians(pose.getHeading()));
+		    			double cos = Math.cos(Math.toRadians(pose.getHeading()));
+		            g.drawLine(
+			                (int)(w+(l.x1/10.0-pose.getX())*d*sin),
+			                (int)(h-(l.y1/10.0-pose.getY())*d*cos), 
+			                (int)(w+(l.x2/10.0-pose.getX())*d*sin),
+			                (int)(h-(l.y2/10.0-pose.getY())*d*cos)
+			        );
+		    		}
+		    	}
+    		
+    			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 = 16;
+		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>();
+	}
+}

+ 16 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/24/f09094cd11b80017145c9b6064c27648

@@ -0,0 +1,16 @@
+
+public class Point3D {
+	public double x, y, z;
+	
+	public Point3D(double x, double y, double z) {
+		this.x = x;
+		this.y = y;
+		this.z = z; // em radianos
+	}
+	
+	public Point3D() {
+		this.x = (int )(Math.random() * 100 - 50);
+		this.y = (int )(Math.random() * 100 - 50);
+		this.z = (int )(Math.random() * Math.PI * 2.0);
+	}
+}

+ 88 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/25/60f61ae129b80017145c9b6064c27648

@@ -0,0 +1,88 @@
+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(20);
+				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();
+		}
+		
+	}
+
+}

+ 139 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/25/a03ad027d5b90017124d9f37712eb7c1

@@ -0,0 +1,139 @@
+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(50);
+				} catch (InterruptedException e) {
+				}
+			}
+		}
+
+	}
+
+	public VirtualRobot(LineMap map) {
+		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() {
+		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) {
+		rr = r;
+		simthread = new Simulate();
+		simthread.start();
+	}
+
+	@Override
+	public void stopScann() {
+		simthread.run = false;
+		try {
+			simthread.join();
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void disconnect() {
+
+	}
+
+	@Override
+	public void setPose(float x, float y, float a) {
+		pose.setHeading(a);
+		pose.setLocation(x, y);
+	}
+	
+	@Override
+	public String toString() {
+		return "Virtual Robot";
+	}
+
+}

+ 153 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/26/10b31e95d1b90017124d9f37712eb7c1

@@ -0,0 +1,153 @@
+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;
+		public double expected;
+
+		SonarRead(double distance, double ang, double expected) {
+			this.ang = ang;
+			this.distance = distance;
+			this.expected = expected;
+		}
+	}
+
+	@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 / 20.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];
+					double sin = Math.sin(-Math.toRadians(pose.getHeading() - 180));
+					double cos = Math.cos(-Math.toRadians(pose.getHeading() - 180));
+
+					double x1 = (l.x1 - pose.getX()) * d;
+					double y1 = (l.y1 - pose.getY()) * d;
+
+					double x2 = (l.x2 - pose.getX()) * d;
+					double y2 = (l.y2 - pose.getY()) * d;
+
+					double xx1 = x1 * cos - y1 * sin;
+					double yy1 = y1 * cos + x1 * sin;
+
+					double xx2 = x2 * cos - y2 * sin;
+					double yy2 = y2 * cos + x2 * sin;
+
+					g.drawLine((int) (w + xx1), (int) (h - yy1), (int) (w + xx2), (int) (h - yy2));
+				}
+			}
+
+			drawDots(g, w, h);
+			semaphore.release();
+		}
+	}
+
+	private void drawDots(Graphics g, int w, int h) {
+		int oval_size = 16;
+		int distance = h * 2 / 25;
+		double d = distance / 20.0;
+		double a = -oval_size / 4;
+		double x, y;
+
+		g.setColor(new Color(1f, 0f, 0f));
+		for (SonarRead r : lista_leituras) {
+			x = a + (d * r.distance) * Math.sin(Math.toRadians(r.ang));
+			y = a + (d * r.distance) * Math.cos(Math.toRadians(r.ang));
+			x = w - x;
+			y = h - y;
+			g.setColor(new Color(1f, 0f, 0f));
+			g.fillOval((int) (x - oval_size / 2.0), (int) (y - oval_size / 2.0), oval_size / 2, oval_size / 2);
+
+			x = a + (d * r.expected) * Math.sin(Math.toRadians(r.ang));
+			y = a + (d * r.expected) * Math.cos(Math.toRadians(r.ang));
+			x = w - x;
+			y = h - y;
+			g.setColor(new Color(0f, 0f, 1f));
+			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 setPose (Pose p) {
+		pose = p;
+		if (semaphore.tryAcquire()) {
+			lista_leituras.clear();
+			semaphore.release();
+		}
+		repaint();
+	}
+
+	public void addRead(Pose p, double distance, double ang, double expected) {
+		if (semaphore.tryAcquire()) {
+//			if (pose == null
+//					|| !(p.getX() == pose.getX() && p.getY() == pose.getY() && p.getHeading() == pose.getHeading())
+//					|| lista_leituras.size() >= 180) {
+//				pose = new Pose(p.getX(), p.getY(), p.getHeading());
+//				lista_leituras.clear();
+//			}
+			lista_leituras.add(new SonarRead(distance, ang + 90, expected));
+			semaphore.release();
+		}
+		repaint();
+	}
+
+	public ScannerImage(LineMap map) {
+		this.map = map;
+		semaphore = new Semaphore(1);
+		lista_leituras = new ArrayList<SonarRead>();
+	}
+
+	public void clean() {
+		if (semaphore.tryAcquire()) {
+			lista_leituras.clear();
+			semaphore.release();
+		}
+		repaint();
+	}
+}

+ 179 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/26/30f7b5eac1b90017124d9f37712eb7c1

@@ -0,0 +1,179 @@
+package robots;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+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;
+	
+	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;
+
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	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 class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	
+	public BluetoothRobot (String name) {
+		this.name = name;
+	}
+
+	@Override
+	public void moveForward() {
+		sendthread.send(FORWARD);
+	}
+
+	@Override
+	public void moveLeft() {
+		sendthread.send(LEFT);
+	}
+
+	@Override
+	public void moveRight() {
+		sendthread.send(RIGHT);
+		
+	}
+
+	@Override
+	public void moveBackward() {
+		sendthread.send(BACKWARD);
+	}
+
+	@Override
+	public boolean connect (RobotReturn r) {
+		rr = r;
+		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();
+		sendthread.start();
+		
+		return true;	
+	}
+
+	@Override
+	public void stop() {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void exit() {
+		sendthread.send(EXIT);
+		receivethread.run = false;
+		sendthread.send(EXIT);
+		try {
+			receivethread.join();
+			sendthread.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();
+		}
+	}
+
+}

+ 128 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/26/f0f5d5d0e2b000171eb4aea94a5e3c6b

@@ -0,0 +1,128 @@
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.io.BufferedReader;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+
+public class Map extends JPanel {
+	private final class KeyboardEvent implements KeyListener {
+		private DataOutputStream output;
+		public KeyboardEvent(DataOutputStream output) {
+			super();
+			this.output = output;
+		}
+
+		public void keyTyped(KeyEvent e) {
+		}
+
+		public void keyReleased(KeyEvent e) {
+			
+		}
+
+		public void keyPressed(KeyEvent e) {
+			char input = e.getKeyChar();
+			if (input == '1') map.setVisual(0);
+			else if (input == '2') map.setVisual(1);
+			else if (input == '3') map.setVisual(2);
+			else if (input == 'l') map.showLine();
+			else if (input == 's') map.save();
+
+			System.out.println(e.getKeyCode());
+		    switch(e.getKeyCode()) { 
+		        case KeyEvent.VK_UP:
+		        		sendthread.send(SendThread.FORWARD);
+		            break;
+		        case KeyEvent.VK_DOWN:
+		        		sendthread.send(SendThread.BACKWARD);
+		            break;
+		        case KeyEvent.VK_LEFT:
+		        		sendthread.send(SendThread.LEFT);
+		            break;
+		        case KeyEvent.VK_RIGHT :
+		        		sendthread.send(SendThread.RIGHT);
+		            break;
+		    }
+		}
+	}
+
+	private ImageMap map;
+	private SendThread sendthread;
+	
+	public Map (DataInputStream input, final DataOutputStream output) throws IOException {
+		JFrame frame = new JFrame("Mapa MAC0318");
+		KeyboardEvent event = new KeyboardEvent(output);
+		sendthread = new SendThread(output);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        this.map = new ImageMap();
+		frame.add(this.map);
+		frame.setSize(800, 800);
+		frame.setVisible(true);
+		
+		frame.setFocusable(true);
+		frame.requestFocusInWindow();
+		
+		frame.addKeyListener(event);
+		String text = "1,2,3 - Change view mode.\n";
+		text += "s - Save image.\n";
+		text += "l - Show trace.\n";
+		JOptionPane.showMessageDialog(null, text);
+		
+		int bytes_valiable = -1;
+		
+		while(true) {
+			try {
+				bytes_valiable = input.available();
+			} catch (IOException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			}
+			if (bytes_valiable >= 0) {
+				if (input.readByte() != '@') continue;
+				int angle = input.readByte();
+				float x = input.readFloat();
+				int distance = input.readByte();
+				float y = input.readFloat();
+				System.out.println(x+" "+y);
+			}
+		}
+	}
+	
+    public void addPoint(Point3D p) {
+    		map.addPoint(p);
+	}
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+//		NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB); 
+//		NXTInfo[] nxtInfo = nxtComm.search("NXT8"); //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");
+//			System.exit(1);
+//		}
+//		if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
+//			System.err.println("Failed to open NXT");
+//			System.exit(1);
+//		}
+//		
+//		DataInputStream input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
+//		DataOutputStream output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
+		
+//		Map map = new Map(input, output);
+		
+		Map map = new Map(null, null);
+
+	}
+}

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

@@ -0,0 +1,89 @@
+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();
+		}
+		
+	}
+
+}

+ 48 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/27/e02acfa4e1b000171eb4aea94a5e3c6b

@@ -0,0 +1,48 @@
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+public class SendThread extends Thread{
+	
+	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;
+	
+	private int command;
+	private int before;
+	private boolean run;
+	private DataOutputStream output;
+	
+	public SendThread(DataOutputStream out) {
+		super();
+		command = -1;
+		before = command;
+		run = true;
+		output = out;
+	}
+	
+	@Override
+	public void run() {
+		while (run) {
+			if (before != command) {
+				try {
+					output.write(command);
+				} catch (IOException e) { }
+				before = command;
+			}
+			
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+	}
+	
+	public void send (int c) {
+		command = c;
+	}
+}

+ 185 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/29/10b4e4650db9001711c7a09600ea5d68

@@ -0,0 +1,185 @@
+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.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.SwingUtilities;
+
+import config.Map;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+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;
+
+	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);
+		// 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(this);
+		
+		if (result == false) {
+			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
+		}
+
+		//
+		// String text = "1,2,3 - Change view mode.\n";
+		// text += "s - Save image.\n";
+		// text += "l - Show trace.\n";
+		// text += "c - Clean map.\n";
+		// JOptionPane.showMessageDialog(null, text);
+	}
+
+	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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		if (robot == null)
+			return;
+		robot.stop();
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		//Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		System.err.println("Fechando...");
+		if (robot == null)
+			return;
+		robot.exit();
+
+	}
+
+	@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);
+		
+		// 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();
+		imap.addRead(p.getX()+dx, p.getY()+dy);
+		double expected = SonarModel();
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+}

+ 26 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/29/10dc8f6111b9001711c7a09600ea5d68

@@ -0,0 +1,26 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l : map.getLines()) {
+			System.out.println(l);
+			d = l.ptSegDist(p.getX() * 10, p.getY() * 10);
+			min = Math.min(min, d);
+		}
+		return min / 10.0;
+	}
+}

+ 26 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/29/b0aac23c12b9001711c7a09600ea5d68

@@ -0,0 +1,26 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l : map.getLines()) {
+			d = l.ptSegDist(p.getX(), p.getY());
+			min = Math.min(min, d);
+		}
+		System.out.println(Math.sqrt(min));
+		return Math.sqrt(min);
+	}
+}

+ 148 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2a/2031f4bed0b90017124d9f37712eb7c1

@@ -0,0 +1,148 @@
+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;
+		public double expected;
+
+		SonarRead(double distance, double ang, double expected) {
+			this.ang = ang;
+			this.distance = distance;
+			this.expected = expected;
+		}
+	}
+
+	@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 / 20.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];
+					double sin = Math.sin(-Math.toRadians(pose.getHeading() - 180));
+					double cos = Math.cos(-Math.toRadians(pose.getHeading() - 180));
+
+					double x1 = (l.x1 - pose.getX()) * d;
+					double y1 = (l.y1 - pose.getY()) * d;
+
+					double x2 = (l.x2 - pose.getX()) * d;
+					double y2 = (l.y2 - pose.getY()) * d;
+
+					double xx1 = x1 * cos - y1 * sin;
+					double yy1 = y1 * cos + x1 * sin;
+
+					double xx2 = x2 * cos - y2 * sin;
+					double yy2 = y2 * cos + x2 * sin;
+
+					g.drawLine((int) (w + xx1), (int) (h - yy1), (int) (w + xx2), (int) (h - yy2));
+				}
+			}
+
+			drawDots(g, w, h);
+			semaphore.release();
+		}
+	}
+
+	private void drawDots(Graphics g, int w, int h) {
+		int oval_size = 16;
+		int distance = h * 2 / 25;
+		double d = distance / 20.0;
+		double a = -oval_size / 4;
+		double x, y;
+
+		g.setColor(new Color(1f, 0f, 0f));
+		for (SonarRead r : lista_leituras) {
+			x = a + (d * r.distance) * Math.sin(Math.toRadians(r.ang));
+			y = a + (d * r.distance) * Math.cos(Math.toRadians(r.ang));
+			x = w - x;
+			y = h - y;
+			g.setColor(new Color(1f, 0f, 0f));
+			g.fillOval((int) (x - oval_size / 2.0), (int) (y - oval_size / 2.0), oval_size / 2, oval_size / 2);
+
+			x = a + (d * r.expected) * Math.sin(Math.toRadians(r.ang));
+			y = a + (d * r.expected) * Math.cos(Math.toRadians(r.ang));
+			x = w - x;
+			y = h - y;
+			g.setColor(new Color(0f, 0f, 1f));
+			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 setPose (Pose p) {
+		pose = p;
+	}
+
+	public void addRead(Pose p, double distance, double ang, double expected) {
+		if (semaphore.tryAcquire()) {
+			if (pose == null
+					|| !(p.getX() == pose.getX() && p.getY() == pose.getY() && p.getHeading() == pose.getHeading())
+					|| lista_leituras.size() >= 180) {
+				pose = new Pose(p.getX(), p.getY(), p.getHeading());
+				lista_leituras.clear();
+			}
+			lista_leituras.add(new SonarRead(distance, ang + 90, expected));
+			semaphore.release();
+		}
+		repaint();
+	}
+
+	public ScannerImage(LineMap map) {
+		this.map = map;
+		semaphore = new Semaphore(1);
+		lista_leituras = new ArrayList<SonarRead>();
+	}
+
+	public void clean() {
+		if (semaphore.tryAcquire()) {
+			lista_leituras.clear();
+			semaphore.release();
+		}
+		repaint();
+	}
+}

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

@@ -0,0 +1,129 @@
+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
+		
+	}
+
+}

+ 5 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2a/e02068fa1db80017145c9b6064c27648

@@ -0,0 +1,5 @@
+package robots;
+
+public interface RobotReturn {
+
+}

+ 220 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0680f0ecbb90017124d9f37712eb7c1

@@ -0,0 +1,220 @@
+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.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(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 (m):");
+		String ys = JOptionPane.showInputDialog("Enter y (m):");
+		String as = JOptionPane.showInputDialog("Enter heading (degress):");
+		float x  = Float.parseFloat(xs);
+		float y  = Float.parseFloat(ys);
+		float a  = Float.parseFloat(as);
+		robot.setPose(x, y, a);
+	}
+
+	@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);
+
+		// 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();
+		imap.addRead(p.getX() + dx, p.getY() + dy);
+
+		double expected = smodel.expectedSonarRead(p, data.getSensorAngle());
+
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		// Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+}

+ 113 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2b/d09491ff07b9001711c7a09600ea5d68

@@ -0,0 +1,113 @@
+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;
+    			
+    			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>();
+	}
+}

+ 60 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2d/b0888cb01ab80017145c9b6064c27648

@@ -0,0 +1,60 @@
+package robots;
+
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class VirtualRobot implements Robot {
+
+	public VirtualRobot(LineMap map) {
+		// TODO Auto-generated constructor stub
+	}
+
+	@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 void connect() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void stop() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void exit() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public Pose getData() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}

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

@@ -0,0 +1,279 @@
+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);
+			}
+		});
+	}
+}

+ 186 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2e/4015b9dc0db9001711c7a09600ea5d68

@@ -0,0 +1,186 @@
+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.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.SwingUtilities;
+
+import config.Map;
+import config.SonarModel;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+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;
+
+	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);
+		// 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(this);
+		
+		if (result == false) {
+			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
+		}
+
+		//
+		// String text = "1,2,3 - Change view mode.\n";
+		// text += "s - Save image.\n";
+		// text += "l - Show trace.\n";
+		// text += "c - Clean map.\n";
+		// JOptionPane.showMessageDialog(null, text);
+	}
+
+	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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		if (robot == null)
+			return;
+		robot.stop();
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		//Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		System.err.println("Fechando...");
+		if (robot == null)
+			return;
+		robot.exit();
+
+	}
+
+	@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);
+		
+		// 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();
+		imap.addRead(p.getX()+dx, p.getY()+dy);
+		double expected = SonarModel.expectedRead();
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+}

+ 24 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2e/80965eacc7b90017124d9f37712eb7c1

@@ -0,0 +1,24 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p, double angle) {
+		Pose tmppose = new Pose(p.getX(), p.getY(), p.getHeading());
+		float mindist = Float.POSITIVE_INFINITY;
+		for (int angulo=-cone/2; angulo <= cone/2; angulo++) {
+			tmppose.setHeading((float) (p.getHeading() - angulo + angle));
+			float dist = map.range(tmppose);
+			if (dist > 0 && dist < mindist) mindist = dist;
+		} 
+		return mindist;
+	}
+}

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

@@ -0,0 +1,276 @@
+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";
+	}
+
+}

+ 181 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2f/306eeab11eb80017145c9b6064c27648

@@ -0,0 +1,181 @@
+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 java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.bluetooth.BluetoothConnectionException;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.AncestorEvent;
+import javax.swing.event.AncestorListener;
+
+import config.Map;
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+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;
+
+	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);
+		ScannerImage scanner = new ScannerImage();
+		// 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);
+		
+		if (robot != null)
+			robot.connect(this);
+
+		//
+		// String text = "1,2,3 - Change view mode.\n";
+		// text += "s - Save image.\n";
+		// text += "l - Show trace.\n";
+		// text += "c - Clean map.\n";
+		// JOptionPane.showMessageDialog(null, text);
+	}
+
+	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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		if (robot == null)
+			return;
+		robot.stop();
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {
+	}
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		//Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		System.err.println("Fechando...");
+		if (robot == null)
+			return;
+		robot.exit();
+
+	}
+
+	@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) {
+		// TODO Auto-generated method stub
+		
+	}
+}

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

@@ -0,0 +1,297 @@
+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);
+			}
+		});
+	}
+}

+ 114 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/2f/80b91ae231b80017145c9b6064c27648

@@ -0,0 +1,114 @@
+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 = distance;
+    			//System.out.println(d);
+    			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/2;
+		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 += a*Math.sin(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>();
+	}
+}

+ 59 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/3/60f5422f19b80017145c9b6064c27648

@@ -0,0 +1,59 @@
+package robots;
+
+import lejos.robotics.navigation.Pose;
+
+public class BluetoothRobot implements Robot {
+	
+	BluetoothRobot (String name) {
+		
+	}
+
+	@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 void connect() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void stop() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void exit() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public Pose getData() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}

+ 64 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/3/f018d8e820b80017145c9b6064c27648

@@ -0,0 +1,64 @@
+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 void run() {
+			
+		}
+	}
+
+	public VirtualRobot(LineMap map) {
+		simthread = new Simulate();
+	}
+
+	@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() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void exit() {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

+ 120 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/30/0030ab1defb000171877feeee34c61ac

@@ -0,0 +1,120 @@
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+
+public class Map extends JPanel {
+	private final class KeyboardEvent implements KeyListener {
+		public void keyTyped(KeyEvent e) {
+		}
+
+		public void keyReleased(KeyEvent e) {
+		}
+
+		public void keyPressed(KeyEvent e) {
+			char input = e.getKeyChar();
+			if (input == '1') map.setVisual(0);
+			else if (input == '2') map.setVisual(1);
+			else if (input == '3') map.setVisual(2);
+			else if (input == 'l') map.showLine();
+			else if (input == 's') map.save();
+
+			System.out.println(e.getKeyCode());
+		    switch(e.getKeyCode()) { 
+		        case KeyEvent.VK_UP:
+		        		sendthread.send(SendThread.FORWARD);
+		            break;
+		        case KeyEvent.VK_DOWN:
+		        		sendthread.send(SendThread.BACKWARD);
+		            break;
+		        case KeyEvent.VK_LEFT:
+		        		sendthread.send(SendThread.LEFT);
+		            break;
+		        case KeyEvent.VK_RIGHT :
+		        		sendthread.send(SendThread.RIGHT);
+		            break;
+		    }
+		}
+	}
+
+	private ImageMap map;
+	private SendThread sendthread;
+	private DataOutputStream output;
+	
+	public Map (DataInputStream input, DataOutputStream output) throws IOException {
+		JFrame frame = new JFrame("Mapa MAC0318");
+		KeyboardEvent event = new KeyboardEvent();
+		output = this.output;
+		sendthread = new SendThread(output);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        this.map = new ImageMap();
+		frame.add(this.map);
+		frame.setSize(800, 800);
+		frame.setVisible(true);
+		
+		frame.setFocusable(true);
+		frame.requestFocusInWindow();
+		
+		frame.addKeyListener(event);
+		String text = "1,2,3 - Change view mode.\n";
+		text += "s - Save image.\n";
+		text += "l - Show trace.\n";
+		JOptionPane.showMessageDialog(null, text);
+		
+		int bytes_valiable = -1;
+		
+		while(true) {
+			try {
+				bytes_valiable = input.available();
+			} catch (IOException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			}
+			if (bytes_valiable >= 0) {
+				if (input.readByte() != '@') continue;
+				int angle = input.readByte();
+				float x = input.readFloat();
+				int distance = input.readByte();
+				float y = input.readFloat();
+				System.out.println(x+" "+y);
+			}
+		}
+	}
+	
+    public void addPoint(Point3D p) {
+    		map.addPoint(p);
+	}
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+		NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH); 
+		NXTInfo[] nxtInfo = nxtComm.search("NXT8"); //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");
+			System.exit(1);
+		}
+		if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
+			System.err.println("Failed to open NXT");
+			System.exit(1);
+		}
+		
+		DataInputStream input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
+		DataOutputStream output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
+		
+		Map map = new Map(input, output);
+		
+		Map map = new Map(null, null);
+
+	}
+}

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

@@ -0,0 +1,287 @@
+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);
+			}
+		});
+	}
+}

+ 16 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/30/2030788317b80017145c9b6064c27648

@@ -0,0 +1,16 @@
+
+public class Pose {
+	public double x, y, z;
+	
+	public Pose(double x, double y, double alpha) {
+		this.x = x;
+		this.y = y;
+		this.z = alpha; // em radianos
+	}
+	
+	public Pose() {
+		this.x = (int )(Math.random() * 100 - 50);
+		this.y = (int )(Math.random() * 100 - 50);
+		this.z = (int )(Math.random() * Math.PI * 2.0);
+	}
+}

+ 150 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/30/50641629d7b90017124d9f37712eb7c1

@@ -0,0 +1,150 @@
+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(50);
+				} catch (InterruptedException e) {
+				}
+			}
+		}
+
+	}
+
+	public VirtualRobot(LineMap map) {
+		pose = new Pose();
+		pose.setHeading(90);
+		this.map = map;
+	}
+
+	@Override
+	public void moveForward() {
+		move(5);
+	}
+
+	@Override
+	public void moveLeft() {
+		pose.rotateUpdate(45);
+	}
+
+	@Override
+	public void moveRight() {
+		pose.rotateUpdate(-45);
+	}
+
+	@Override
+	public void moveBackward() {
+		move(-5);
+	}
+
+	@Override
+	public boolean connect() {
+		return true;
+	}
+
+	@Override
+	public void stop() {
+	}
+
+	@Override
+	public void move(double x) {
+		double dx = Math.sin(Math.toRadians(pose.getHeading())) * x;
+		double dy = Math.cos(Math.toRadians(pose.getHeading())) * x;
+		pose.translate((float) dx, (float) -dy);
+	}
+
+	@Override
+	public void rotate(double x) {
+		pose.rotateUpdate((float)-x);
+	}
+
+	@Override
+	public ArrayList<DataPose> scann(int ini, int end, int interval) {
+		ArrayList<DataPose> result = new ArrayList<DataPose>();
+		int ang = 0;
+		for (ang  = ini ; ang <= end; ang += interval) {
+			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);
+	
+			result.add(data);
+		}
+		return result;
+	}
+
+	@Override
+	public void scann(RobotReturn r) {
+		rr = r;
+		simthread = new Simulate();
+		simthread.start();
+	}
+
+	@Override
+	public void stopScann() {
+		simthread.run = false;
+		try {
+			simthread.join();
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	@Override
+	public void disconnect() {
+
+	}
+
+	@Override
+	public void setPose(float x, float y, float a) {
+		pose.setHeading(a);
+		pose.setLocation(x, y);
+	}
+	
+	@Override
+	public String toString() {
+		return "Virtual Robot";
+	}
+
+}

+ 274 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/30/c0e5893e18b80017145c9b6064c27648

@@ -0,0 +1,274 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class MapImage extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener  {
+    private double zoom = 2.0; // pixel per cm
+    private double grid = 10.0; // cm
+    private double centerx = 0.0;
+    private double centery = 0.0; // cm
+    private Point mousePt;
+    private ArrayList<Pose> lista_pontos;
+    private ArrayList<Pose> lista_ultra;
+    private int visual_method = 0;
+    private boolean line = false;
+    
+    private LineMap map;
+    
+	public MapImage() {
+		super();
+		lista_pontos = new ArrayList<Pose>();
+		lista_ultra = new ArrayList<Pose>();
+		setBackground(Color.BLACK);
+		addMouseWheelListener(this);
+		addMouseListener(this);
+		addMouseMotionListener(this);
+	}
+	
+	public MapImage(LineMap map) {
+		this();
+		this.map = map;
+	}
+	
+    private void drawModel (Graphics g) {
+        int width = (int) (getWidth()+2*centerx);
+        int height = (int) (getHeight()+2*centery);
+        int count = 0;
+        int x_tmp = 0, y_tmp = 0;
+        
+	    	for (Pose p : lista_pontos) {
+			double hading = Math.toRadians(p.getHeading());
+				
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		
+			if (visual_method == 0) {
+				g.setColor(Color.getHSBColor((float) (hading/(2.0*Math.PI)), 1, 1));
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+			} else if (visual_method == 1) {
+	            g.setColor(Color.RED);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+	
+	           g.drawLine(
+	                width/2+(int)(p.getX()*zoom+zoom*Math.sin(hading)),
+	                height/2-(int)(p.getY()*zoom-zoom*Math.cos(hading)),
+	                width/2+(int)(p.getX()*zoom+0.6*zoom*Math.sin(Math.PI/8+hading)),
+	                height/2-(int)(p.getY()*zoom-0.6*zoom*Math.cos(Math.PI/8+hading))
+	            );
+			} else if (visual_method == 2) {
+				g.setColor(Color.RED);
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+	            g.setColor(Color.BLACK);
+	            g.drawLine(
+	                width/2+(int)(p.x*zoom),
+	                height/2-(int)(p.y*zoom), 
+	                width/2+(int)(p.x*zoom+Math.sin(p.z)*zoom),
+	                height/2-(int)(p.y*zoom-Math.cos(p.z)*zoom)
+	            );
+			}
+	
+		    	if (line && count != 0) {
+		    		g.setColor(Color.LIGHT_GRAY);
+		    		g.drawLine(x_tmp, y_tmp, x, y);
+		    	}
+	
+		    	x_tmp = x;
+		    	y_tmp = y;
+		    	count++;
+		}
+	    	
+	    	g.setColor(Color.RED);
+	    	for (Pose p : lista_ultra) {
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		g.fillRect(
+					x-(int)(zoom/2.0*1.0),
+					y-(int)(zoom/2.0*1.0),
+					(int)(zoom*1.0),
+					(int)(zoom*1.0)
+			);
+	    	}
+	    	
+	    	if (map != null) {
+	    		Line[] lines = map.getLines();
+	    		for (int i = 0; i < lines.length; i++) {
+	    			Line l = lines[i];
+	            g.drawLine(
+		                width/2+(int)(l.x1*zoom),
+		                height/2-(int)(l.y1*zoom), 
+		                width/2+(int)(l.x2*zoom),
+		                height/2-(int)(l.y2*zoom)
+		        );
+	    		}
+	    	}
+    }
+    
+    @Override
+    protected void paintComponent(Graphics g) {
+        int width = (int) (getWidth());
+        int height = (int) (getHeight());
+        int width2 = (int) (getWidth()+2*centerx);
+        int height2 = (int) (getHeight()+2*centery);
+        super.paintComponent(g);
+    
+        g.setColor(new Color(20, 20, 20));
+        
+        int initial_x = height2/2;
+        while (initial_x < width) {
+        	initial_x += grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        initial_x = height2/2;
+        while (initial_x > 0) {
+        	initial_x -= grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        int initial_y = width2/2;
+        while (initial_y < width) {
+        	initial_y += grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+        initial_y = width2/2;
+        while (initial_y > 0) {
+        	initial_y -= grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+
+        g.setColor(Color.ORANGE);
+        g.drawLine(width2/2, 0, width2/2, height);
+        g.drawLine(0, height2/2, width, height2/2);
+
+        drawModel(g);
+    }
+    
+    /**
+     * Adiciona um ponto ao mapa
+     * @param p ponto
+     */
+    public void addPoint(Pose p) {
+    		lista_pontos.add(p);
+    		repaint();
+	}
+
+    public void addPoint(double x, double y, double z) {
+    		lista_pontos.add(new Pose(x, y, z));
+    		repaint();
+	}
+    
+
+    public void addRead(double x, double y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+    public void showLine () {
+    		line = !line;
+    		repaint();
+    }
+
+    public void setVisual (int method) {
+    		visual_method = method;
+    		repaint();
+    }
+    
+    public void save () {
+	    	Integer name = new Integer((int) (Math.random()*1000000));
+	    	BufferedImage imagebuf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
+	    	Graphics g = imagebuf.createGraphics();
+	    	g.fillRect(0, 0, imagebuf.getWidth(), imagebuf.getHeight());
+	    	print(g);
+	    	try {
+			ImageIO.write(imagebuf, "png",  new File(name.toString()+".png"));
+			JOptionPane.showMessageDialog(null, "Image saved.");
+		} catch (IOException e) {
+			e.printStackTrace();
+			JOptionPane.showMessageDialog(null, "Image not saved.");
+		}
+    }
+    
+	public void clean() {
+		lista_pontos.clear();
+		lista_ultra.clear();
+		repaint();
+	}
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		centerx += e.getX() - mousePt.x;
+		centery += e.getY() - mousePt.y;
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseMoved(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseClicked(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mousePressed(MouseEvent e) {
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseReleased(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+	
+	@Override
+	public void mouseExited(MouseEvent e) {	
+	}
+	
+	@Override
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		if(e.getWheelRotation()<0){
+			if (zoom < 15.0)
+				zoom *= 1.1;
+			repaint();
+		}
+		//Zoom out
+		if(e.getWheelRotation()>0){
+			if (zoom > 1.0)
+				zoom /= 1.1;
+			repaint();
+		}
+	}
+}

+ 126 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/31/30b8c624e2b000171eb4aea94a5e3c6b

@@ -0,0 +1,126 @@
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.io.BufferedReader;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.pc.comm.NXTComm;
+import lejos.pc.comm.NXTCommException;
+import lejos.pc.comm.NXTCommFactory;
+import lejos.pc.comm.NXTInfo;
+
+public class Map extends JPanel {
+	private ImageMap map;
+	private SendThread sendthread;
+	
+	public Map (DataInputStream input, final DataOutputStream output) throws IOException {
+		JFrame frame = new JFrame("Mapa MAC0318");
+		sendthread = new SendThread(output);
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        frame.setLayout(new BorderLayout());
+        this.map = new ImageMap();
+		frame.add(this.map);
+		frame.setSize(800, 800);
+		frame.setVisible(true);
+		
+		frame.setFocusable(true);
+		frame.requestFocusInWindow();
+		
+		frame.addKeyListener(new KeyListener() {
+			@Override
+			public void keyTyped(KeyEvent e) {
+			}
+			@Override
+			public void keyReleased(KeyEvent e) {
+				
+			}
+			@Override
+			public void keyPressed(KeyEvent e) {
+				char input = e.getKeyChar();
+				if (input == '1') map.setVisual(0);
+				else if (input == '2') map.setVisual(1);
+				else if (input == '3') map.setVisual(2);
+				else if (input == 'l') map.showLine();
+				else if (input == 's') map.save();
+
+				try {
+					System.out.println(e.getKeyCode());
+				    switch(e.getKeyCode()) { 
+				        case KeyEvent.VK_UP:
+				        		output.write(SendThread.FORWARD);
+				            break;
+				        case KeyEvent.VK_DOWN:
+			        			output.write(SendThread.BACKWARD);
+				            break;
+				        case KeyEvent.VK_LEFT:
+				        		output.write(SendThread.LEFT);
+				            break;
+				        case KeyEvent.VK_RIGHT :
+				        		output.write(SendThread.RIGHT);
+				            break;
+				     }
+				    output.flush();
+
+				} catch (IOException e1) {
+					System.out.println(22222);
+				}
+			}
+		});
+		String text = "1,2,3 - Change view mode.\n";
+		text += "s - Save image.\n";
+		text += "l - Show trace.\n";
+		JOptionPane.showMessageDialog(null, text);
+		
+		int bytes_valiable = -1;
+		
+		while(true) {
+			try {
+				bytes_valiable = input.available();
+			} catch (IOException e1) {
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			}
+			if (bytes_valiable >= 0) {
+				if (input.readByte() != '@') continue;
+				int angle = input.readByte();
+				float x = input.readFloat();
+				int distance = input.readByte();
+				float y = input.readFloat();
+				System.out.println(x+" "+y);
+			}
+		}
+	}
+	
+    public void addPoint(Point3D p) {
+    		map.addPoint(p);
+	}
+
+	public static void main(String[] args) throws NXTCommException, IOException {
+//		NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB); 
+//		NXTInfo[] nxtInfo = nxtComm.search("NXT8"); //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");
+//			System.exit(1);
+//		}
+//		if (!nxtComm.open(nxtInfo[0])) { // the brick was found but a connection could not be establish
+//			System.err.println("Failed to open NXT");
+//			System.exit(1);
+//		}
+//		
+//		DataInputStream input = new DataInputStream(nxtComm.getInputStream()); // open data input stream 
+//		DataOutputStream output = new DataOutputStream(nxtComm.getOutputStream()); // open data output stream
+		
+//		Map map = new Map(input, output);
+		
+		Map map = new Map(null, null);
+
+	}
+}

+ 285 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/31/5006dba518b80017145c9b6064c27648

@@ -0,0 +1,285 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class MapImage extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener  {
+    private double zoom = 2.0; // pixel per cm
+    private double grid = 10.0; // cm
+    private double centerx = 0.0;
+    private double centery = 0.0; // cm
+    private Point mousePt;
+    private ArrayList<Pose> lista_pontos;
+    private ArrayList<Pose> lista_ultra;
+    private int visual_method = 0;
+    private boolean line = false;
+    
+    private LineMap map;
+    
+	public MapImage() {
+		super();
+		lista_pontos = new ArrayList<Pose>();
+		lista_ultra = new ArrayList<Pose>();
+		setBackground(Color.BLACK);
+		addMouseWheelListener(this);
+		addMouseListener(this);
+		addMouseMotionListener(this);
+	}
+	
+	public MapImage(LineMap map) {
+		this();
+		this.map = map;
+	}
+	
+    private void drawModel (Graphics g) {
+        int width = (int) (getWidth()+2*centerx);
+        int height = (int) (getHeight()+2*centery);
+        int count = 0;
+        int x_tmp = 0, y_tmp = 0;
+        
+	    	for (Pose p : lista_pontos) {
+			double hading = Math.toRadians(p.getHeading());
+				
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		
+			if (visual_method == 0) {
+				g.setColor(Color.getHSBColor((float) (hading/(2.0*Math.PI)), 1, 1));
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+			} else if (visual_method == 1) {
+	            g.setColor(Color.RED);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+	
+	           g.drawLine(
+	                width/2+(int)(p.getX()*zoom+zoom*Math.sin(hading)),
+	                height/2-(int)(p.getY()*zoom-zoom*Math.cos(hading)),
+	                width/2+(int)(p.getX()*zoom+0.6*zoom*Math.sin(Math.PI/8+hading)),
+	                height/2-(int)(p.getY()*zoom-0.6*zoom*Math.cos(Math.PI/8+hading))
+	            );
+			} else if (visual_method == 2) {
+				g.setColor(Color.RED);
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+	            g.setColor(Color.BLACK);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+			}
+	
+		    	if (line && count != 0) {
+		    		g.setColor(Color.LIGHT_GRAY);
+		    		g.drawLine(x_tmp, y_tmp, x, y);
+		    	}
+	
+		    	x_tmp = x;
+		    	y_tmp = y;
+		    	count++;
+		}
+	    	
+	    	g.setColor(Color.RED);
+	    	for (Pose p : lista_ultra) {
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		g.fillRect(
+					x-(int)(zoom/2.0*1.0),
+					y-(int)(zoom/2.0*1.0),
+					(int)(zoom*1.0),
+					(int)(zoom*1.0)
+			);
+	    	}
+	    	
+	    	if (map != null) {
+	    		Line[] lines = map.getLines();
+	    		for (int i = 0; i < lines.length; i++) {
+	    			Line l = lines[i];
+	            g.drawLine(
+		                width/2+(int)(l.x1*zoom),
+		                height/2-(int)(l.y1*zoom), 
+		                width/2+(int)(l.x2*zoom),
+		                height/2-(int)(l.y2*zoom)
+		        );
+	    		}
+	    	}
+    }
+    
+    @Override
+    protected void paintComponent(Graphics g) {
+        int width = (int) (getWidth());
+        int height = (int) (getHeight());
+        int width2 = (int) (getWidth()+2*centerx);
+        int height2 = (int) (getHeight()+2*centery);
+        super.paintComponent(g);
+    
+        g.setColor(new Color(20, 20, 20));
+        
+        int initial_x = height2/2;
+        while (initial_x < width) {
+        	initial_x += grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        initial_x = height2/2;
+        while (initial_x > 0) {
+        	initial_x -= grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        int initial_y = width2/2;
+        while (initial_y < width) {
+        	initial_y += grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+        initial_y = width2/2;
+        while (initial_y > 0) {
+        	initial_y -= grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+
+        g.setColor(Color.ORANGE);
+        g.drawLine(width2/2, 0, width2/2, height);
+        g.drawLine(0, height2/2, width, height2/2);
+
+        drawModel(g);
+    }
+    
+    /**
+     * Adiciona um ponto ao mapa
+     * @param p ponto
+     */
+    public void addPoint(Pose p) {
+    		lista_pontos.add(p);
+    		repaint();
+	}
+
+    public void addPoint(float x, float y, float z) {
+    		lista_pontos.add(new Pose(x, y, z));
+    		repaint();
+	}
+    
+
+    public void addRead(float x, float y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+
+    public void addPoint(double x, double y, double z) {
+    		addPoint((float)x, (float)y, (float)z);
+	}
+    
+
+    public void addRead(double x, double y) {
+    		addRead((float)z, (float)y);
+	}
+    
+    
+    public void showLine () {
+    		line = !line;
+    		repaint();
+    }
+
+    public void setVisual (int method) {
+    		visual_method = method;
+    		repaint();
+    }
+    
+    public void save () {
+	    	Integer name = new Integer((int) (Math.random()*1000000));
+	    	BufferedImage imagebuf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
+	    	Graphics g = imagebuf.createGraphics();
+	    	g.fillRect(0, 0, imagebuf.getWidth(), imagebuf.getHeight());
+	    	print(g);
+	    	try {
+			ImageIO.write(imagebuf, "png",  new File(name.toString()+".png"));
+			JOptionPane.showMessageDialog(null, "Image saved.");
+		} catch (IOException e) {
+			e.printStackTrace();
+			JOptionPane.showMessageDialog(null, "Image not saved.");
+		}
+    }
+    
+	public void clean() {
+		lista_pontos.clear();
+		lista_ultra.clear();
+		repaint();
+	}
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		centerx += e.getX() - mousePt.x;
+		centery += e.getY() - mousePt.y;
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseMoved(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseClicked(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mousePressed(MouseEvent e) {
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseReleased(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+	
+	@Override
+	public void mouseExited(MouseEvent e) {	
+	}
+	
+	@Override
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		if(e.getWheelRotation()<0){
+			if (zoom < 15.0)
+				zoom *= 1.1;
+			repaint();
+		}
+		//Zoom out
+		if(e.getWheelRotation()>0){
+			if (zoom > 1.0)
+				zoom /= 1.1;
+			repaint();
+		}
+	}
+}

+ 26 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/32/107c0d9713b9001711c7a09600ea5d68

@@ -0,0 +1,26 @@
+package config;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class Models {
+	private LineMap map;
+
+	public Models(LineMap map) {
+		this.map = map;
+	}
+
+	public double expectedSonarRead(Pose p) {
+		// o modelo apresentado aqui eh o mais burro
+		// ele pega a menor distancia do robo a um segmento
+		double min = Double.MAX_VALUE;
+		double d;
+		for (Line l : map.getLines()) {
+			d = l.ptSegDist(p.getX() * 10, p.getY() * 10);
+			min = Math.min(min, d);
+		}
+		//System.out.println(min);
+		return min / 10.0;
+	}
+}

+ 137 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/32/2023c245cbb90017124d9f37712eb7c1

@@ -0,0 +1,137 @@
+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) {
+		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) {
+		rr = r;
+		simthread.start();
+	}
+
+	@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();
+		}
+
+	}
+
+	@Override
+	public void setPose(float x, float y, float a) {
+		pose.setHeading(a);
+		pose.setLocation(x, y);
+	}
+
+}

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

@@ -0,0 +1,258 @@
+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);
+			}
+		});
+	}
+}

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

@@ -0,0 +1,233 @@
+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));
+	}
+
+}

+ 306 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/34/e02fcc20d3b90017124d9f37712eb7c1

@@ -0,0 +1,306 @@
+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 java.util.ArrayList;
+
+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() {
+		int interval;
+		try {
+			String rs = JOptionPane.showInputDialog("Interval (degress):");
+			interval = Integer.parseInt(rs);
+		} catch (Exception e) {
+			return;
+		}
+		ArrayList<DataPose> data = robot.scann(-90, 90, interval);
+		scanner.clean();
+		
+	}
+
+	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);
+			}
+		});
+	}
+}

+ 188 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/35/405ba1e50db9001711c7a09600ea5d68

@@ -0,0 +1,188 @@
+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.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.SwingUtilities;
+
+import config.Map;
+import config.SonarModel;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+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 SonarModel 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 = SonarModel(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(this);
+		
+		if (result == false) {
+			JOptionPane.showMessageDialog(null, "Não foi possível conectar ao robô");
+		}
+
+		//
+		// String text = "1,2,3 - Change view mode.\n";
+		// text += "s - Save image.\n";
+		// text += "l - Show trace.\n";
+		// text += "c - Clean map.\n";
+		// JOptionPane.showMessageDialog(null, text);
+	}
+
+	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 == 's')
+			imap.save();
+		else if (input == 'c')
+			imap.clean();
+		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;
+		}
+	}
+
+	@Override
+	public void keyReleased(KeyEvent arg0) {
+		if (robot == null)
+			return;
+		robot.stop();
+	}
+
+	@Override
+	public void keyTyped(KeyEvent arg0) {
+	}
+
+	public static void main(String[] args) {
+
+		LineMap map = Map.makeMap();
+		Robot robot = new VirtualRobot(map);
+		//Robot robot = new BluetoothRobot("NXJ8");
+
+		SwingUtilities.invokeLater(new Runnable() {
+			public void run() {
+				new MainProgram(map, robot);
+			}
+		});
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		System.err.println("Fechando...");
+		if (robot == null)
+			return;
+		robot.exit();
+
+	}
+
+	@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);
+		
+		// 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();
+		imap.addRead(p.getX()+dx, p.getY()+dy);
+		double expected = SonarModel.expectedRead();
+		scanner.addRead(p, data.getDistance(), data.getSensorAngle(), expected);
+	}
+}

+ 181 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/35/905643571eb80017145c9b6064c27648

@@ -0,0 +1,181 @@
+package robots;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+
+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;
+	
+	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;
+
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	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 class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	
+	public BluetoothRobot (String name) {
+		this.name = name;
+		data = new LinkedList<DataPose>();
+	}
+
+	@Override
+	public void moveForward() {
+		sendthread.send(FORWARD);
+	}
+
+	@Override
+	public void moveLeft() {
+		sendthread.send(LEFT);
+	}
+
+	@Override
+	public void moveRight() {
+		sendthread.send(RIGHT);
+		
+	}
+
+	@Override
+	public void moveBackward() {
+		sendthread.send(BACKWARD);
+	}
+
+	@Override
+	public boolean connect (RobotReturn r) {
+		rr = r;
+		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();
+		sendthread.start();
+		
+		return true;	
+	}
+
+	@Override
+	public void stop() {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void exit() {
+		sendthread.send(EXIT);
+		receivethread.run = false;
+		sendthread.send(EXIT);
+		try {
+			receivethread.join();
+			sendthread.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();
+		}
+	}
+
+}

+ 152 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/35/f09bc35fdfb90017124d9f37712eb7c1

@@ -0,0 +1,152 @@
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import lejos.nxt.Motor;
+import lejos.nxt.NXTRegulatedMotor;
+import lejos.nxt.SensorPort;
+import lejos.nxt.Sound;
+import lejos.nxt.UltrasonicSensor;
+import lejos.nxt.comm.BTConnection;
+import lejos.nxt.comm.Bluetooth;
+import lejos.robotics.navigation.DifferentialPilot;
+import lejos.robotics.navigation.Pose;
+import lejos.robotics.localization.*;
+
+class Scanner extends Thread {
+	DataOutputStream output;
+	OdometryPoseProvider provider;
+	boolean run;
+	public boolean scann;
+	
+	Scanner (DataOutputStream output, OdometryPoseProvider provider) {
+		super();
+		this.output = output;
+		this.provider = provider;
+		run = true;
+		scann = false;
+	}
+	
+	public void stop () {
+		run = false;
+	}
+	
+	public void run() {
+		NXTRegulatedMotor scannerm = Motor.A;
+		UltrasonicSensor sensor = new UltrasonicSensor(SensorPort.S1) ;
+		int increment = 5;
+		int position = 0;
+		
+		while (run) {
+			if (scann == false) {
+				scannerm.rotateTo(0);
+				continue;
+			}
+			if (position == 90 || position == -90)
+				increment *= -1;
+
+			scannerm.rotateTo(position);
+			scannerm.waitComplete();
+			
+			int distance = sensor.getDistance();
+						
+			Pose pose = provider.getPose();
+			float x = pose.getX();
+			float y = pose.getY();
+			float alpha = pose.getHeading();
+			
+			if (distance != 255) {
+				try {
+					output.write('@');
+					output.write(position);
+					output.writeFloat(alpha);
+					output.writeFloat(x);
+					output.write(distance);
+					output.writeFloat(y);
+					output.flush();
+				} catch (IOException e) {
+				}
+			}
+			
+			position += increment;
+		}
+		
+		scannerm.rotateTo(0);
+		scannerm.waitComplete();
+	}
+}
+
+public class Sonar {
+	
+	private static final byte FORWARD = 0;
+	private static final byte STOP = 1;
+	private static final byte EXIT = 2;
+	private static final byte LEFT = 3;
+	private static final byte RIGHT = 4;
+	private 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 void main(String[] args) throws Exception {
+		
+		BTConnection btc = Bluetooth.waitForConnection();
+		//USBConnection btc = USB.waitForConnection();
+		
+		DataInputStream input = btc.openDataInputStream();
+		DataOutputStream output = btc.openDataOutputStream();
+		
+		DifferentialPilot pilot = new DifferentialPilot(5.6f, 13.8f, Motor.B, Motor.C, false); 
+		OdometryPoseProvider provider = new OdometryPoseProvider(pilot);
+		pilot.setRotateSpeed(5);
+		pilot.setTravelSpeed(20);
+		
+		Scanner scan = new Scanner(output, provider);
+		scan.start();
+		int input_byte;
+		boolean run = true;
+		
+		Sound.twoBeeps();
+		
+		while (run) {
+			if (input.available() <= 0) {
+				Thread.yield();
+				continue;
+			}
+			input_byte = input.readByte();
+
+			System.out.println(input_byte);
+			
+			switch (input_byte) {
+				case FORWARD:
+					pilot.forward();
+					break;
+				case STOP:
+					pilot.stop();
+					break;
+				case EXIT:
+					run = false;
+					break;
+				case LEFT:
+					pilot.rotateLeft();
+					break;
+				case RIGHT:
+					pilot.rotateRight();
+					break;
+				case BACKWARD:
+					pilot.backward();
+					break;
+				case STOPSCANN:
+					pilot.scann = true;
+					break;
+			}
+		}
+		Sound.beep();
+		scan.stop();
+		scan.join();
+	}
+}

+ 285 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/36/f0945d7722b80017145c9b6064c27648

@@ -0,0 +1,285 @@
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.imageio.ImageIO;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import lejos.geom.Line;
+import lejos.robotics.mapping.LineMap;
+import lejos.robotics.navigation.Pose;
+
+public class MapImage extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener  {
+    private double zoom = 2.0; // pixel per cm
+    private double grid = 10.0; // cm
+    private double centerx = 0.0;
+    private double centery = 0.0; // cm
+    private Point mousePt;
+    private ArrayList<Pose> lista_pontos;
+    private ArrayList<Pose> lista_ultra;
+    private int visual_method = 0;
+    private boolean line = false;
+    
+    private LineMap map;
+    
+	public MapImage() {
+		super();
+		lista_pontos = new ArrayList<Pose>();
+		lista_ultra = new ArrayList<Pose>();
+		setBackground(Color.BLACK);
+		addMouseWheelListener(this);
+		addMouseListener(this);
+		addMouseMotionListener(this);
+	}
+	
+	public MapImage(LineMap map) {
+		this();
+		this.map = map;
+	}
+	
+    private void drawModel (Graphics g) {
+        int width = (int) (getWidth()+2*centerx);
+        int height = (int) (getHeight()+2*centery);
+        int count = 0;
+        int x_tmp = 0, y_tmp = 0;
+        
+	    	for (Pose p : lista_pontos) {
+			double hading = Math.toRadians(p.getHeading());
+				
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		
+			if (visual_method == 0) {
+				g.setColor(Color.getHSBColor((float) (hading/(2.0*Math.PI)), 1, 1));
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+			} else if (visual_method == 1) {
+	            g.setColor(Color.RED);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+	
+	           g.drawLine(
+	                width/2+(int)(p.getX()*zoom+zoom*Math.sin(hading)),
+	                height/2-(int)(p.getY()*zoom-zoom*Math.cos(hading)),
+	                width/2+(int)(p.getX()*zoom+0.6*zoom*Math.sin(Math.PI/8+hading)),
+	                height/2-(int)(p.getY()*zoom-0.6*zoom*Math.cos(Math.PI/8+hading))
+	            );
+			} else if (visual_method == 2) {
+				g.setColor(Color.RED);
+				g.fillOval(
+						x-(int)(zoom/2.0*1.5),
+						y-(int)(zoom/2.0*1.5),
+						(int)(zoom*1.5),
+						(int)(zoom*1.5)
+				);
+	            g.setColor(Color.BLACK);
+	            g.drawLine(
+	                width/2+(int)(p.getX()*zoom),
+	                height/2-(int)(p.getY()*zoom), 
+	                width/2+(int)(p.getX()*zoom+Math.sin(hading)*zoom),
+	                height/2-(int)(p.getY()*zoom-Math.cos(hading)*zoom)
+	            );
+			}
+	
+		    	if (line && count != 0) {
+		    		g.setColor(Color.LIGHT_GRAY);
+		    		g.drawLine(x_tmp, y_tmp, x, y);
+		    	}
+	
+		    	x_tmp = x;
+		    	y_tmp = y;
+		    	count++;
+		}
+	    	
+	    	g.setColor(Color.RED);
+	    	for (Pose p : lista_ultra) {
+	    		int x = width/2+(int)(p.getX()*zoom);
+	    		int y = height/2+(int)(p.getY()*zoom)*-1;
+	    		g.fillRect(
+					x-(int)(zoom/2.0*1.0),
+					y-(int)(zoom/2.0*1.0),
+					(int)(zoom*1.0),
+					(int)(zoom*1.0)
+			);
+	    	}
+	    	
+	    	if (map != null) {
+	    		Line[] lines = map.getLines();
+	    		for (int i = 0; i < lines.length; i++) {
+	    			Line l = lines[i];
+	            g.drawLine(
+		                width/2+(int)(l.x1*zoom*1000.0),
+		                height/2-(int)(l.y1*zoom*1000.0), 
+		                width/2+(int)(l.x2*zoom*1000.0),
+		                height/2-(int)(l.y2*zoom*1000.0)
+		        );
+	    		}
+	    	}
+    }
+    
+    @Override
+    protected void paintComponent(Graphics g) {
+        int width = (int) (getWidth());
+        int height = (int) (getHeight());
+        int width2 = (int) (getWidth()+2*centerx);
+        int height2 = (int) (getHeight()+2*centery);
+        super.paintComponent(g);
+    
+        g.setColor(new Color(20, 20, 20));
+        
+        int initial_x = height2/2;
+        while (initial_x < width) {
+        	initial_x += grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        initial_x = height2/2;
+        while (initial_x > 0) {
+        	initial_x -= grid*zoom;
+        	g.drawLine(0, initial_x, width, initial_x); 
+        }
+        int initial_y = width2/2;
+        while (initial_y < width) {
+        	initial_y += grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+        initial_y = width2/2;
+        while (initial_y > 0) {
+        	initial_y -= grid*zoom;
+            g.drawLine(initial_y, 0, initial_y, height);
+        }
+
+        g.setColor(Color.ORANGE);
+        g.drawLine(width2/2, 0, width2/2, height);
+        g.drawLine(0, height2/2, width, height2/2);
+
+        drawModel(g);
+    }
+    
+    /**
+     * Adiciona um ponto ao mapa
+     * @param p ponto
+     */
+    public void addPoint(Pose p) {
+    		lista_pontos.add(p);
+    		repaint();
+	}
+
+    public void addPoint(float x, float y, float z) {
+    		lista_pontos.add(new Pose(x, y, z));
+    		repaint();
+	}
+    
+
+    public void addRead(float x, float y) {
+    		lista_ultra.add(new Pose(x, y, 0));
+    		repaint();
+	}
+    
+
+    public void addPoint(double x, double y, double z) {
+    		addPoint((float)x, (float)y, (float)z);
+	}
+    
+
+    public void addRead(double x, double y) {
+    		addRead((float)x, (float)y);
+	}
+    
+    
+    public void showLine () {
+    		line = !line;
+    		repaint();
+    }
+
+    public void setVisual (int method) {
+    		visual_method = method;
+    		repaint();
+    }
+    
+    public void save () {
+	    	Integer name = new Integer((int) (Math.random()*1000000));
+	    	BufferedImage imagebuf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
+	    	Graphics g = imagebuf.createGraphics();
+	    	g.fillRect(0, 0, imagebuf.getWidth(), imagebuf.getHeight());
+	    	print(g);
+	    	try {
+			ImageIO.write(imagebuf, "png",  new File(name.toString()+".png"));
+			JOptionPane.showMessageDialog(null, "Image saved.");
+		} catch (IOException e) {
+			e.printStackTrace();
+			JOptionPane.showMessageDialog(null, "Image not saved.");
+		}
+    }
+    
+	public void clean() {
+		lista_pontos.clear();
+		lista_ultra.clear();
+		repaint();
+	}
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		centerx += e.getX() - mousePt.x;
+		centery += e.getY() - mousePt.y;
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseMoved(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseClicked(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mousePressed(MouseEvent e) {
+		mousePt = e.getPoint();
+		repaint();
+		
+	}
+	@Override
+	public void mouseReleased(MouseEvent e) {		
+	}
+	
+	@Override
+	public void mouseEntered(MouseEvent e) {
+	}
+	
+	@Override
+	public void mouseExited(MouseEvent e) {	
+	}
+	
+	@Override
+	public void mouseWheelMoved(MouseWheelEvent e) {
+		if(e.getWheelRotation()<0){
+			if (zoom < 15.0)
+				zoom *= 1.1;
+			repaint();
+		}
+		//Zoom out
+		if(e.getWheelRotation()>0){
+			if (zoom > 1.0)
+				zoom /= 1.1;
+			repaint();
+		}
+	}
+}

+ 176 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/37/20e590971cb80017145c9b6064c27648

@@ -0,0 +1,176 @@
+package robots;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+
+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;
+	
+	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;
+
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	private Receiver receivethread;
+	
+	private LinkedList<DataPose> data;
+	
+	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));
+						
+						data.add(d);
+						
+					} catch (IOException e1) {
+						continue;
+					}
+				}
+			}
+		}
+	}
+
+	private class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	
+	BluetoothRobot (String name) {
+		this.name = name;
+		data = new LinkedList<DataPose>();
+	}
+
+	@Override
+	public void moveForward() {
+		sendthread.send(FORWARD);
+	}
+
+	@Override
+	public void moveLeft() {
+		sendthread.send(LEFT);
+	}
+
+	@Override
+	public void moveRight() {
+		sendthread.send(RIGHT);
+		
+	}
+
+	@Override
+	public void moveBackward() {
+		sendthread.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();
+		sendthread.start();
+		
+		return true;	
+	}
+
+	@Override
+	public void stop() {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void exit() {
+		sendthread.send(EXIT);
+		input.close();
+		output.close();
+		
+	}
+
+	@Override
+	public DataPose getData() {
+		return data.pollFirst();
+	}
+
+}

+ 113 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/37/60acc8f807b9001711c7a09600ea5d68

@@ -0,0 +1,113 @@
+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*0.4;
+    			
+    			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>();
+	}
+}

+ 180 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/37/90dce55b1eb80017145c9b6064c27648

@@ -0,0 +1,180 @@
+package robots;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+
+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;
+	
+	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;
+
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	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 class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	
+	public BluetoothRobot (String name) {
+		this.name = name;
+	}
+
+	@Override
+	public void moveForward() {
+		sendthread.send(FORWARD);
+	}
+
+	@Override
+	public void moveLeft() {
+		sendthread.send(LEFT);
+	}
+
+	@Override
+	public void moveRight() {
+		sendthread.send(RIGHT);
+		
+	}
+
+	@Override
+	public void moveBackward() {
+		sendthread.send(BACKWARD);
+	}
+
+	@Override
+	public boolean connect (RobotReturn r) {
+		rr = r;
+		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();
+		sendthread.start();
+		
+		return true;	
+	}
+
+	@Override
+	public void stop() {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void exit() {
+		sendthread.send(EXIT);
+		receivethread.run = false;
+		sendthread.send(EXIT);
+		try {
+			receivethread.join();
+			sendthread.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();
+		}
+	}
+
+}

+ 179 - 0
.metadata/.plugins/org.eclipse.core.resources/.history/37/d010c503c2b90017124d9f37712eb7c1

@@ -0,0 +1,179 @@
+package robots;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+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;
+	
+	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;
+
+	private DataOutputStream output;
+	private DataInputStream input;
+	private Send sendthread;
+	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 class Send extends Thread {
+		private int before;
+		private int command;
+		private boolean run = true;
+		
+		@Override
+		public void run() {
+			before = -1;
+			command = STOP;
+			
+			while(run) {
+				if (before != command) {
+					try {
+						System.out.println("Send cmd");
+						output.write(command);
+						output.flush();
+						if (command == EXIT) run = false;
+					} catch (IOException e1) {
+						System.out.println("Erro send cmd");
+						before = -1;
+						send(command);
+					}
+					before = command;
+				}
+				
+				try {
+					Thread.sleep(50);
+				} catch (InterruptedException e) {
+
+				}
+			}
+		}
+		public void send(int cmd) {
+			command = cmd;
+		}
+	}
+	
+	
+	public BluetoothRobot (String name) {
+		this.name = name;
+	}
+
+	@Override
+	public void moveForward() {
+		sendthread.send(FORWARD);
+	}
+
+	@Override
+	public void moveLeft() {
+		sendthread.send(LEFT);
+	}
+
+	@Override
+	public void moveRight() {
+		sendthread.send(RIGHT);
+		
+	}
+
+	@Override
+	public void moveBackward() {
+		sendthread.send(BACKWARD);
+	}
+
+	@Override
+	public boolean connect (RobotReturn r) {
+		rr = r;
+		try {
+			nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
+			NXTInfo[] nxtInfo = nxtComm.search(); //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();
+		sendthread.start();
+		
+		return true;	
+	}
+
+	@Override
+	public void stop() {
+		sendthread.send(STOP);
+	}
+
+	@Override
+	public void exit() {
+		sendthread.send(EXIT);
+		receivethread.run = false;
+		sendthread.send(EXIT);
+		try {
+			receivethread.join();
+			sendthread.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();
+		}
+	}
+
+}

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно