From 1ea3927d71bb16767408e31fd225f3b18a415bea Mon Sep 17 00:00:00 2001 From: cs-powell <142438185+cs-powell@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:57:19 -0500 Subject: [PATCH] final update commit (backlog 1) --- .../CognitiveModel/ModelFiles/Model.java | 27 +++++++++++++------ .../CognitiveModel/ModelFiles/Motor.java | 12 +++++---- Java/ProjectModels/Main.java | 22 ++++++++------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java b/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java index 45fa179..4866c84 100644 --- a/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java +++ b/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java @@ -67,7 +67,7 @@ public class Model { return q.queueLength(); } - public void createAction(ActionType actionType,int delay,String target) { + public void createAction(ActionType actionType, MotorType motorType, int delay,String target) { Action newAction = null; switch(actionType) { case VISION: @@ -75,7 +75,7 @@ public class Model { this.push(newAction); break; case MOTOR: - newAction = new Motor(delay,target); + newAction = new Motor(motorType,delay,target); this.push(newAction); break; @@ -129,25 +129,36 @@ public class Model { Motor tempM = (Motor) temp; MotorType motorType = tempM.getMotorType(); float[] currentControls = null; + try { + currentControls = xpc.getCTRL(0); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } try { switch(motorType){ case PITCHUP: float[] pitchUp = {currentControls[0] + 0.01f}; - if(storedVision[0] > 90) { - if(currentControls[0] < 0.1f) { + if(storedVision[0] > 80) { + if(currentControls[0] < 0.2f) { + System.out.println("Pitching Up"); xpc.sendCTRL(pitchUp); } } - System.out.println("Pitching Up"); + + break; case PITCHDOWN: float[] pitchDown = {currentControls[0] - 0.01f}; - if(storedVision[0] < 50) { - if(currentControls[0] > 0.1f) { + if(storedVision[0] < 80) { + if(currentControls[0] > -0.2f) { + // System.out.println("Sending Pitch Down"); + System.out.println("Pitching Down"); xpc.sendCTRL(pitchDown); } } - System.out.println("Pitching Down"); + + break; } } catch (IOException e) { diff --git a/Java/ProjectModels/CognitiveModel/ModelFiles/Motor.java b/Java/ProjectModels/CognitiveModel/ModelFiles/Motor.java index 53345f9..9a2cdaa 100644 --- a/Java/ProjectModels/CognitiveModel/ModelFiles/Motor.java +++ b/Java/ProjectModels/CognitiveModel/ModelFiles/Motor.java @@ -7,17 +7,19 @@ public class Motor extends Action { float[] control; MotorType motorType; - public Motor() { + public Motor(MotorType motorType) { super(ActionType.MOTOR,1000); + this.motorType = motorType; } -public Motor(int delay) { - super(ActionType.MOTOR,delay); -} +// public Motor(int delay) { +// super(ActionType.MOTOR,delay); +// } -public Motor(int delay, String target) { +public Motor(MotorType motorType,int delay, String target) { super(ActionType.MOTOR,delay,target); + this.motorType = motorType; } diff --git a/Java/ProjectModels/Main.java b/Java/ProjectModels/Main.java index 559bfd4..e9e7fb3 100644 --- a/Java/ProjectModels/Main.java +++ b/Java/ProjectModels/Main.java @@ -41,8 +41,8 @@ public class Main { // Ensure connection established. m = new Model(xpc); m.activateModel(); - m.createAction(ActionType.VISION, 0, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"); - m.createAction(ActionType.MOTOR, 0, null); + m.createAction(ActionType.VISION, null, 0, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"); + m.createAction(ActionType.MOTOR, MotorType.PITCHUP, 0, null); // m.push(b); // m.push(d); m.printModelQueue(); @@ -50,17 +50,21 @@ public class Main { while(m.isActive() && !m.isEmpty()) { float[] array = m.next(); if(array != null) { - System.out.println(array[0]); - if(array[0] > 80.0f) { - m.push(d); - } + // System.out.println(array[0]); + // if(array[0] > 80.0f) { + // m.push(d); + // } } else { // System.out.println("no dice"); // System.out.println(xpc.getDREF(null)"); } - - // m.createAction(ActionType.MOTOR, 0, null); - m.printModelQueue(); + if(m.getModelQueueLength() < 5){ + m.createAction(ActionType.VISION, null, 0, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"); + m.createAction(ActionType.MOTOR, MotorType.PITCHUP, 0, null); + m.createAction(ActionType.MOTOR, MotorType.PITCHDOWN, 0, null); + } + + // m.printModelQueue(); } } catch (SocketException ex)