From 18744b6489d9d9639472d82c42e8ae914af143c5 Mon Sep 17 00:00:00 2001 From: Pylo Date: Thu, 20 Aug 2015 21:41:01 +0200 Subject: [PATCH] First working commit ready to be released --- src/com/sourcegasm/riftvision/Main.java | 5 +- .../riftvision/control/MainController.java | 112 +++++++++++++++--- .../riftvision/render/RenderManager.java | 8 +- .../riftvision/sensors/JoyStickSensors.java | 6 +- 4 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src/com/sourcegasm/riftvision/Main.java b/src/com/sourcegasm/riftvision/Main.java index 7221954..d66d33c 100644 --- a/src/com/sourcegasm/riftvision/Main.java +++ b/src/com/sourcegasm/riftvision/Main.java @@ -20,10 +20,11 @@ public static void main(String[] args) throws IOException { joystickSensors.startReceiving(); mainController.droneController = droneController; mainController.oculusSensors = oculusSensors; + mainController.joyStickSensors = joystickSensors; RenderRiftWindow frame = new RenderRiftWindow(mainController); - - //frame.showFrame(); + frame.showFrame(); + new RenderManager(droneController, frame); } } \ No newline at end of file diff --git a/src/com/sourcegasm/riftvision/control/MainController.java b/src/com/sourcegasm/riftvision/control/MainController.java index 3223e4d..b7f65ae 100644 --- a/src/com/sourcegasm/riftvision/control/MainController.java +++ b/src/com/sourcegasm/riftvision/control/MainController.java @@ -1,6 +1,7 @@ package com.sourcegasm.riftvision.control; import com.sourcegasm.riftvision.helper.ControlModes; +import com.sourcegasm.riftvision.sensors.JoyStickSensors; import com.sourcegasm.riftvision.sensors.OculusSensors; import java.io.IOException; @@ -9,7 +10,10 @@ * Created by klemen on 19.8.2015. ^selfish */ public class MainController { + public OculusSensors oculusSensors; + public JoyStickSensors joyStickSensors; + private Thread thread; public DroneController droneController; private HeightController heightController = new HeightController(); @@ -19,25 +23,13 @@ public class MainController { public void startController() { - /*heightController = new HeightController(); - yawController.setZero(droneController, oculusSensors);*/ - heightController = new HeightController(); yawController.setZero(droneController, oculusSensors); - contiune = true; - thread = new Thread(new Runnable() { - @Override - public void run() { - while (contiune) { - oculusOnlyControllerLiteration(); - } - } - }); - thread.start(); - /*switch (controlMode) { + switch (controlMode) { case OculusOnly: + contiune = true; thread = new Thread(new Runnable() { @Override public void run() { @@ -49,13 +41,103 @@ public void run() { thread.start(); break; + case OculusYaw: + + contiune = true; + thread = new Thread(new Runnable() { + @Override + public void run() { + while (contiune) { + oculusYawControllerLiteration(); + } + } + }); + thread.start(); + + break; + + case OculusYawPitch: + + contiune = true; + thread = new Thread(new Runnable() { + @Override + public void run() { + while (contiune) { + oculusYawPitchControllerLiteration(); + } + } + }); + thread.start(); + break; + case JoystickOnly: + + contiune = true; + thread = new Thread(new Runnable() { + @Override + public void run() { + while (contiune) { + joysitckOnlyControllerLiteration(); + } + } + }); + thread.start(); + break; - }*/ + } } + + private void joysitckOnlyControllerLiteration() { + + try { + droneController.getDrone().move((float)joyStickSensors.getRawRool(), (float)joyStickSensors.getRawPitch(), (float)joyStickSensors.getRawHeight(), (float)joyStickSensors.getRawYaw()); + } catch (IOException e) { + e.printStackTrace(); + } + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + private void oculusYawControllerLiteration() { + + double yaw = yawController.getYawMove(droneController, oculusSensors); + try { + droneController.getDrone().move((float)joyStickSensors.getRawRool(), (float)joyStickSensors.getRawPitch(), (float)joyStickSensors.getRawHeight(), (float)yaw); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void oculusYawPitchControllerLiteration() { + + float pitch = (float) (ExpoController.getExpo(oculusSensors.getSmoothedPitch()) / 90.0); + double yaw = yawController.getYawMove(droneController, oculusSensors); + try { + droneController.getDrone().move((float)joyStickSensors.getRawRool(), (float)pitch, (float)joyStickSensors.getRawHeight(), (float)yaw); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + Thread.sleep(50); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + private void oculusOnlyControllerLiteration() { float roll = (float) (ExpoController.getExpo(oculusSensors.getSmoothedRool()) / 90.0); diff --git a/src/com/sourcegasm/riftvision/render/RenderManager.java b/src/com/sourcegasm/riftvision/render/RenderManager.java index 882900a..3ab9e89 100644 --- a/src/com/sourcegasm/riftvision/render/RenderManager.java +++ b/src/com/sourcegasm/riftvision/render/RenderManager.java @@ -1,17 +1,21 @@ package com.sourcegasm.riftvision.render; +import java.awt.image.BufferedImage; +import java.awt.image.RescaleOp; + +import com.codeminders.ardrone.util.BufferedImageVideoListener; import com.sourcegasm.riftvision.control.DroneController; public class RenderManager { public RenderManager(DroneController controller, final RenderRiftWindow frame) { - /*controller.getDrone().addImageListener(new BufferedImageVideoListener() { + controller.getDrone().addImageListener(new BufferedImageVideoListener() { @Override public void imageReceived(BufferedImage image) { RescaleOp rescaleOp = new RescaleOp(1.2f, 15, null); rescaleOp.filter(image, image); frame.updateFrame(image, controller.getNavData()); } - });*/ + }); } } diff --git a/src/com/sourcegasm/riftvision/sensors/JoyStickSensors.java b/src/com/sourcegasm/riftvision/sensors/JoyStickSensors.java index 9e0047d..99f4eed 100644 --- a/src/com/sourcegasm/riftvision/sensors/JoyStickSensors.java +++ b/src/com/sourcegasm/riftvision/sensors/JoyStickSensors.java @@ -47,7 +47,7 @@ public void run() { rawPitch = (float) (ExpoController.getJoyStickExpo(Integer.parseInt(mami_array[3].trim()))); rawRoll = (float) (ExpoController.getJoyStickExpo(Integer.parseInt(mami_array[2].trim()))); rawYaw = (float) (ExpoController.getJoyStickExpo((Integer.parseInt(mami_array[0].trim())))); - rawHeight = (float) (ExpoController.getJoyStickExpo((Integer.parseInt(mami_array[1].trim())))); + rawHeight = (float) ((Integer.parseInt(mami_array[1].trim()))) / -300.0f; } } @@ -133,5 +133,9 @@ public double getRawPitch() { public double getRawYaw() { return rawYaw; } + + public double getRawHeight(){ + return rawHeight; + } }