diff --git a/src/com/muhavision/control/DroneController.java b/src/com/muhavision/control/DroneController.java index a24b3c2..942c6e0 100644 --- a/src/com/muhavision/control/DroneController.java +++ b/src/com/muhavision/control/DroneController.java @@ -21,6 +21,8 @@ public class DroneController { ARDrone drone = null; NavData data = null; + + BufferedImage quadImage = null; public DroneController(final VisualRenderer visual) { System.out.println("Drone controller loading..."); @@ -33,16 +35,7 @@ public DroneController(final VisualRenderer visual) { @Override public void imageReceived(BufferedImage image) { - QuadrantFlowSpeed speed = null; - EulerAngles angle = null; - - if (visual.global_main.flightMode.getMode() == FlightMode.eMode.MUHA_MODE) - speed = calc.getFlowData(image); - else if (visual.global_main.flightMode.getMode() == FlightMode.eMode.TAG_MODE) - angle = MarkerControl - .getControlDataAndPictureDataBasedOnNavData(data); - - visual.reloadDatas(image, speed, data, angle); + quadImage = image; } }); @@ -53,6 +46,39 @@ public void navDataReceived(NavData fdata) { data = fdata; } }); + + Thread t = new Thread(){ + + public void run(){ + while(true){ + + long millis = System.currentTimeMillis(); + + QuadrantFlowSpeed speed = null; + EulerAngles angle = null; + + if(visual.global_main.flightMode!=null) + if (visual.global_main.flightMode.getMode() == FlightMode.eMode.MUHA_MODE) + speed = calc.getFlowData(quadImage); + else if (visual.global_main.flightMode.getMode() == FlightMode.eMode.TAG_MODE) + angle = MarkerControl + .getControlDataAndPictureDataBasedOnNavData(data); + + visual.reloadDatas(quadImage, speed, data, angle); + + millis = System.currentTimeMillis() - millis; + + try { + Thread.sleep(70-millis); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + } + + }; + t.start(); } catch (UnknownHostException e) { e.printStackTrace(); diff --git a/src/com/muhavision/control/FlightMode.java b/src/com/muhavision/control/FlightMode.java index 2627a99..38453b5 100644 --- a/src/com/muhavision/control/FlightMode.java +++ b/src/com/muhavision/control/FlightMode.java @@ -35,7 +35,6 @@ public eMode getMode() { public void setMode(eMode mode) { this.mode = mode; - mode.toString(); } } diff --git a/src/com/muhavision/control/MarkerControl.java b/src/com/muhavision/control/MarkerControl.java index 78b669e..d290f44 100644 --- a/src/com/muhavision/control/MarkerControl.java +++ b/src/com/muhavision/control/MarkerControl.java @@ -11,21 +11,22 @@ public class MarkerControl { public static EulerAngles getControlDataAndPictureDataBasedOnNavData( NavData nav) { - if (nav.isVisionEnabled()) { - List tags = nav.getVisionTags(); - if (!tags.isEmpty()) { - VisionTag tag = tags.get(0); - if (tag != null) { - EulerAngles angles = new EulerAngles(); - Point point = tag.getPosition(); - angles.picX = point.getX(); - angles.picY = point.getY(); - angles.dist = tag.getDistance(); - angles.hasAngles = true; - return angles; + if(nav!=null) + if (nav.isVisionEnabled()) { + List tags = nav.getVisionTags(); + if (!tags.isEmpty()) { + VisionTag tag = tags.get(0); + if (tag != null) { + EulerAngles angles = new EulerAngles(); + Point point = tag.getPosition(); + angles.picX = point.getX(); + angles.picY = point.getY(); + angles.dist = tag.getDistance(); + angles.hasAngles = true; + return angles; + } } } - } return new EulerAngles(); } diff --git a/src/com/muhavision/cv/OpticalFlowCalculator.java b/src/com/muhavision/cv/OpticalFlowCalculator.java index 0a69535..705c84f 100644 --- a/src/com/muhavision/cv/OpticalFlowCalculator.java +++ b/src/com/muhavision/cv/OpticalFlowCalculator.java @@ -37,13 +37,9 @@ public BufferedImage Equalize(BufferedImage bufferedimg) { IplImage srcimg = AbstractIplImage.create(iploriginal.width(), iploriginal.height(), IPL_DEPTH_8U, 1); - // IplImage destimg = IplImage.create(iploriginal.width(), - // iploriginal.height(), IPL_DEPTH_8U, 1); cvCvtColor(iploriginal, srcimg, CV_BGR2GRAY); - // cvEqualizeHist( srcimg, destimg ); - BufferedImage eqimg = srcimg.getBufferedImage(); return eqimg; diff --git a/src/com/muhavision/cv/image/VisualRenderer.java b/src/com/muhavision/cv/image/VisualRenderer.java index 835f95c..5f864de 100644 --- a/src/com/muhavision/cv/image/VisualRenderer.java +++ b/src/com/muhavision/cv/image/VisualRenderer.java @@ -57,7 +57,7 @@ public void paintComponent(Graphics g_panel) { g.drawString("Mark. dist.: " + angles.dist, 250, 38); g.fillRect(angles.picX, angles.picY, 4, 4); } - + g.drawString("Roll: " + (int) global_main.roll, 30, 30); g.drawString("Pitch: " + (int) global_main.pitch, 30, 38); g.drawString("Yaw: " + (int) global_main.yaw, 30, 46);