diff --git a/Java/ProjectModels/CognitiveModel/ModelFiles/Action.java b/Java/ProjectModels/CognitiveModel/ModelFiles/Action.java index b96df3b..94ecb79 100644 --- a/Java/ProjectModels/CognitiveModel/ModelFiles/Action.java +++ b/Java/ProjectModels/CognitiveModel/ModelFiles/Action.java @@ -32,5 +32,4 @@ public abstract class Action { public String getTarget() { return targetDREF; } - } diff --git a/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java b/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java index 58b5513..2fc67a0 100644 --- a/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java +++ b/Java/ProjectModels/CognitiveModel/ModelFiles/Model.java @@ -78,7 +78,6 @@ public class Model { newAction = new Motor(motorType, delay, target); this.push(newAction); break; - case DELAY: newAction = new Delay(delay); this.push(newAction); @@ -108,7 +107,6 @@ public class Model { } // q.push(temp); return returnArray; - } /* Next Helpers */ @@ -137,7 +135,6 @@ public class Model { } try { - switch (motorType) { case PITCHUP: float[] pitchUp = { currentControls[0] + 0.01f }; @@ -147,7 +144,6 @@ public class Model { xpc.sendCTRL(pitchUp); } } - break; case PITCHDOWN: float[] pitchDown = { currentControls[0] - 0.01f }; @@ -161,7 +157,6 @@ public class Model { break; } - } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -182,4 +177,15 @@ public class Model { } } + + public float[] getCurrentControls(){ + float [] returnArray = null; + try { + returnArray = xpc.getCTRL(0); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return returnArray; + } } diff --git a/Java/ProjectModels/CognitiveModel/ModelFiles/MotorType.java b/Java/ProjectModels/CognitiveModel/ModelFiles/MotorType.java index ff46913..7d90a2c 100644 --- a/Java/ProjectModels/CognitiveModel/ModelFiles/MotorType.java +++ b/Java/ProjectModels/CognitiveModel/ModelFiles/MotorType.java @@ -2,5 +2,7 @@ package ModelFiles; public enum MotorType { PITCHUP, - PITCHDOWN -} + PITCHDOWN, + THROTTLEUP, + THROTTLEDOWN +} \ No newline at end of file diff --git a/Java/ProjectModels/Main.java b/Java/ProjectModels/Main.java index 5a44558..43df077 100644 --- a/Java/ProjectModels/Main.java +++ b/Java/ProjectModels/Main.java @@ -23,58 +23,10 @@ import ModelFiles.Vision; import ModelFiles.XPlaneConnect; public class Main { - public static void main(String[] args) { // Encapsulation (or lack thereof) Test Model m = new Model(); testprocess1 tp1 = new testprocess1(m, null); tp1.runProcess(); - - // MindQueue q = m.getQueue(); - // Action a = new Vision(); - // System.out.println(q.pop()); - // q.push(a); - // MindQueue q2 = m.getQueue(); - // System.out.println(q2.pop()); - - // // Using actions - // try (XPlaneConnect xpc = new XPlaneConnect()) { - // Action b = new Vision(10, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"); - // Action d = new Delay(20); - // // Ensure connection established. - // m = new Model(xpc); - // m.activateModel(); - // 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(); - // // m.deactivateModel(); - // 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); - // // } - // } else { - // // System.out.println("no dice"); - // // System.out.println(xpc.getDREF(null)"); - // } - // 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) { - // System.out.println("Unable to set up the connection. (Error message was '" + ex.getMessage() + "'.)"); - // } catch (IOException ex) { - // System.out.println( - // "Something went wrong with one of the commands. (Error message was '" + ex.getMessage() + "'.)"); - // } - // System.out.println("Exiting"); } } diff --git a/Java/ProjectModels/Visualizer/assets/Rudder Pedals.png b/Java/ProjectModels/Visualizer/assets/Rudder Pedals.png new file mode 100644 index 0000000..0db4762 Binary files /dev/null and b/Java/ProjectModels/Visualizer/assets/Rudder Pedals.png differ diff --git a/Java/ProjectModels/Visualizer/assets/Yoke Symbol.png b/Java/ProjectModels/Visualizer/assets/Yoke Symbol.png new file mode 100644 index 0000000..cc7e4c9 Binary files /dev/null and b/Java/ProjectModels/Visualizer/assets/Yoke Symbol.png differ diff --git a/Java/ProjectModels/Visualizer/axis.java b/Java/ProjectModels/Visualizer/axis.java new file mode 100644 index 0000000..4130e54 --- /dev/null +++ b/Java/ProjectModels/Visualizer/axis.java @@ -0,0 +1,58 @@ +package Visualizer; + + +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JComponent; + + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.OverlayLayout; +import javax.swing.SwingConstants; +import javax.swing.border.Border; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.SocketException; +import java.util.Arrays; +import javax.swing.*; +import javax.swing.border.Border; +import javax.imageio.ImageIO; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.*; + +import ModelFiles.*; + + +public class axis extends JComponent { + + int xBound = 0; + int yBound = 0; + + axis(int currentX, int currentY) { + xBound = currentX; + yBound = currentY; + } + + public void paint(Graphics g) + { + Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.green); + g2.drawLine(xBound/2, 0, xBound/2, yBound); + g2.drawLine(0, yBound/2, xBound, yBound/2); + } + + public void setXBound(int newX){ + this.xBound = newX; + } + + public void setYBound(int newY){ + this.yBound = newY; + } +} diff --git a/Java/ProjectModels/Visualizer/rudderPosition.java b/Java/ProjectModels/Visualizer/rudderPosition.java new file mode 100644 index 0000000..83e3bf5 --- /dev/null +++ b/Java/ProjectModels/Visualizer/rudderPosition.java @@ -0,0 +1,75 @@ +package Visualizer; + +import javax.imageio.ImageIO; +import javax.swing.JComponent; + + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.OverlayLayout; +import javax.swing.SwingConstants; +import javax.swing.border.Border; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.SocketException; +import java.util.Arrays; +import javax.swing.*; +import javax.swing.border.Border; +import javax.imageio.ImageIO; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.*; + +import ModelFiles.*; + +public class rudderPosition extends JComponent { + + int xBound = 0; + int yBound = 0; + + float rudderTravel = 0; + + rudderPosition(int currentXBound, int currentYBound) { + xBound = currentXBound; + yBound = currentYBound; + } + + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + int spacer = 10; + g.setColor(Color.gray); + g2.fillRect(0, spacer, xBound, yBound - spacer); + + g2.setColor(Color.red); + int width = (int) (xBound/2 * rudderTravel); + //g2.drawRect(xBound/2, 0 +spacer, width, yBound); + g2.fillRect(xBound/2, 0 + spacer, width, yBound); + + g.drawString("Yaw Left",0, yBound/2); + int textWidth = g.getFontMetrics().stringWidth("Roll Right"); + g.drawString("Yaw Right", xBound - textWidth, yBound/2); + // try { + // final BufferedImage image = ImageIO.read(new File("/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/Java/ProjectModels/Visualizer/assets/Rudder Pedals.png")); + // Image scaledImage = image.getScaledInstance(xBound, yBound, Image.SCALE_DEFAULT); + // g.drawImage(scaledImage, 0, 0, getFocusCycleRootAncestor()); + // } catch (IOException e) { + // System.out.print("Rudder Image Failed"); + // } + } + + public void setX(float newX) { + this.rudderTravel = newX; + } + + public void setXBound(int newX) { + this.xBound = newX; + } + + public void setYBound(int newY) { + this.yBound = newY; + } + +} \ No newline at end of file diff --git a/Java/ProjectModels/Visualizer/visualizer.java b/Java/ProjectModels/Visualizer/visualizer.java new file mode 100644 index 0000000..22c32b3 --- /dev/null +++ b/Java/ProjectModels/Visualizer/visualizer.java @@ -0,0 +1,162 @@ +package Visualizer; + +import javax.swing.border.Border; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.SocketException; +import java.util.Arrays; +import javax.swing.*; +import javax.swing.border.Border; +import javax.imageio.ImageIO; + +import java.awt.image.BufferedImage; +import java.awt.*; + +import ModelFiles.*; + +public class visualizer { + + JFrame frame = new JFrame(); + JPanel display = new JPanel(); + JPanel visualizer = new JPanel(); + JPanel yokeGrid = new JPanel(); + axis axis = new axis(0,0); + rudderPosition rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0); + yokePosition yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight()); + + + + public visualizer(Model m){ + + } + + + public void initializeDisplay() { + frame.setPreferredSize(new Dimension(1700,270)); + frame.setLayout(new GridLayout(1,2)); + frame.setVisible(true); + + + display.setPreferredSize(new Dimension(100,100)); + display.setLayout(new GridLayout(2,4)); + + Font fontTitles = new Font("Impact", 1,40); + Font fontData = new Font("Monospaced", 1,30); + JLabel titleOne = new JLabel("Elevator"); + titleOne.setFont(fontTitles); + titleOne.setHorizontalAlignment(SwingConstants.CENTER); + titleOne.setVerticalAlignment(SwingConstants.BOTTOM); + JLabel titleTwo = new JLabel("Roll"); + titleTwo.setFont(fontTitles); + titleTwo.setHorizontalAlignment(SwingConstants.CENTER); + titleTwo.setVerticalAlignment(SwingConstants.BOTTOM); + JLabel titleThree = new JLabel("Yaw"); + titleThree.setFont(fontTitles); + titleThree.setHorizontalAlignment(SwingConstants.CENTER); + titleThree.setVerticalAlignment(SwingConstants.BOTTOM); + JLabel titleFour = new JLabel("Throttle"); + titleFour.setFont(fontTitles); + titleFour.setHorizontalAlignment(SwingConstants.CENTER); + titleFour.setVerticalAlignment(SwingConstants.BOTTOM); + JLabel one = new JLabel(); + one.setFont(fontData); + one.setHorizontalAlignment(SwingConstants.CENTER); + one.setVerticalAlignment(SwingConstants.TOP); + JLabel two = new JLabel(); + two.setFont(fontData); + two.setHorizontalAlignment(SwingConstants.CENTER); + two.setVerticalAlignment(SwingConstants.TOP); + JLabel three = new JLabel(); + three.setFont(fontData); + three.setHorizontalAlignment(SwingConstants.CENTER); + three.setVerticalAlignment(SwingConstants.TOP); + JLabel four = new JLabel(); + four.setFont(fontData); + four.setHorizontalAlignment(SwingConstants.CENTER); + four.setVerticalAlignment(SwingConstants.TOP); + + one.setText("Test"); + two.setText("Test"); + three.setText("Test"); + four.setText("Test"); + display.add(titleOne); + display.add(titleTwo); + display.add(titleThree); + display.add(titleFour); + display.add(one); + display.add(two); + display.add(three); + display.add(four); + + + visualizer.setLayout(new GridLayout(2,1)); + + + //Col 1 of Visualizer + + yokeGrid.setMinimumSize(new Dimension(100,100)); + //grid.setOpaque(true); + // grid.setLayout(null); + yokeGrid.setBackground(Color.black); + yokeGrid.setVisible(true); + Integer layer1 = 0; + Integer layer2 = 1; + // grid.setLayout(new GridLayout(1,1)); + yokeGrid.setLayout(new OverlayLayout(yokeGrid)); + + yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight()); + // yaw yaw = new yaw(grid.getWidth(), grid.getHeight()); + axis = new axis(yokeGrid.getWidth(), yokeGrid.getHeight()); + + // grid.setLayer(axis, layer1); + yokeGrid.add(axis); + yokeGrid.add(yoke); + // grid.add(yaw); + // grid.setLayer(yoke, layer2); + + Border greenLine = BorderFactory.createLineBorder(Color.green); + yokeGrid.setBorder(greenLine); + visualizer.add(yokeGrid); + //Row 2 of Visualizer + //Rudder Vizualizer + rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0); + visualizer.add(rudderGrid); + + frame.add(display); // Left Side + frame.add(visualizer); // Right Side + frame.pack(); + } + + + public void updateVisualizer(float[] ctrl1){ + yoke.setXBound(yokeGrid.getWidth()); + yoke.setYBound(yokeGrid.getHeight()); + yoke.setX(ctrl1[1]); + yoke.setY(ctrl1[0]); + yoke.repaint(); + + rudderGrid.setXBound(yokeGrid.getWidth()); + rudderGrid.setYBound(yokeGrid.getHeight()); + rudderGrid.setX(ctrl1[2]); + rudderGrid.repaint(); + + + + // yaw.setYBound(grid.getHeight()); + // yaw.setYBound(grid.getHeight()); + // yaw.setX(ctrl1[2]); + // yaw.repaint(); + + axis.setXBound(yokeGrid.getWidth()); + axis.setYBound(yokeGrid.getHeight()); + axis.repaint(); + } + +} + + + + + diff --git a/Java/ProjectModels/Visualizer/yokePosition.java b/Java/ProjectModels/Visualizer/yokePosition.java new file mode 100644 index 0000000..29baf3c --- /dev/null +++ b/Java/ProjectModels/Visualizer/yokePosition.java @@ -0,0 +1,96 @@ +package Visualizer; + +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JComponent; + + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.OverlayLayout; +import javax.swing.SwingConstants; +import javax.swing.border.Border; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.SocketException; +import java.util.Arrays; +import javax.swing.*; +import javax.swing.border.Border; +import javax.imageio.ImageIO; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.awt.*; + +import ModelFiles.*; + +class yokePosition extends JComponent { + float x = 0; + int xBound = 0; + float y = 0; + int yBound = 0; + + int width = 50; + int height = 50; + + yokePosition(int currentX, int currentY) { + xBound = currentX; + yBound = currentY; + } + + yokePosition() { + + } + + public void paint(Graphics g) + { + Graphics2D g2 = (Graphics2D) g; + + // try { + // final BufferedImage image = ImageIO.read(new File("/Users/flyingtopher/Desktop/Code Citadel/School/2. Research/Fork Clone/XPlaneConnectCSP/Java/ProjectModels/Visualizer/assets/Yoke Symbol.png")); + // Image scaledImage = image.getScaledInstance(xBound, yBound, Image.SCALE_DEFAULT); + + // g.drawImage(scaledImage, 0, 0, getFocusCycleRootAncestor()); + // } catch (IOException e){ + // System.out.print("Rudder Image Failed"); + // } + + g2.setColor(Color.red); + int currX = (int)(x*xBound) + xBound/2 - width/2; + int currY = (int)(y*yBound) + yBound/2 - height/2; + System.out.println("CurrX, CurrY: " + currX +", " + currY); + // g2.drawOval(currX, currY, width, height); + + g2.fillOval(currX, currY, width, height); + g.setColor(Color.green); + int height = g.getFontMetrics().getHeight(); + g.drawString("Nose Down", (xBound/2) + 5, height); + g.drawString("Nose Up", (xBound/2) + 5, yBound - height/2); + g.drawString("Roll Left",0, yBound/2); + int width = g.getFontMetrics().stringWidth("Roll Right"); + g.drawString("Roll Right", xBound - width, yBound/2); + + + + + } + + public void setX(float newX){ + this.x = newX; + } + + public void setXBound(int newX){ + this.xBound = newX; + } + + public void setY(float newY){ + this.y = newY; + } + public void setYBound(int newY){ + this.yBound = newY; + } +} \ No newline at end of file diff --git a/Java/ProjectModels/testprocess.java b/Java/ProjectModels/testprocess.java new file mode 100644 index 0000000..c46ab97 --- /dev/null +++ b/Java/ProjectModels/testprocess.java @@ -0,0 +1,19 @@ +import ModelFiles.Model; +import ModelFiles.XPlaneConnect; + +public abstract class testprocess { + + + Model m = new Model(); + + public testprocess(Model inputM, XPlaneConnect xpc) { + m = inputM; + m.establishConnection(xpc); + } + + + public void runProcess() { + + } + +} diff --git a/Java/ProjectModels/testprocess1.java b/Java/ProjectModels/testprocess1.java index ef11730..204cc23 100644 --- a/Java/ProjectModels/testprocess1.java +++ b/Java/ProjectModels/testprocess1.java @@ -1,58 +1,36 @@ import java.io.IOException; import java.net.SocketException; -import ModelFiles.Model; -import ModelFiles.XPlaneConnect; - import ModelFiles.*; -import ModelFiles.Action; -import ModelFiles.ActionType; -import ModelFiles.Delay; -import ModelFiles.MindQueue; -import ModelFiles.Model; -import ModelFiles.Vision; -import ModelFiles.XPlaneConnect; +import Visualizer.visualizer; -public class testprocess1 { - - Model m = new Model(); +public class testprocess1 extends testprocess { public testprocess1(Model inputM, XPlaneConnect xpc) { - m = inputM; - m.establishConnection(xpc); + super(inputM, xpc); + } + @Override public void runProcess() { try (XPlaneConnect xpc = new XPlaneConnect()) { - Action b = new Vision(10, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot"); - Action d = new Delay(20); // Ensure connection established. m = new Model(xpc); m.activateModel(); 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(); - // m.deactivateModel(); + visualizer vis1 = new visualizer(m); + vis1.initializeDisplay(); 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); - // } - } else { - // System.out.println("no dice"); - // System.out.println(xpc.getDREF(null)"); - } 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.createAction(ActionType.MOTOR, MotorType.PITCHUP, 0, null); + // m.createAction(ActionType.MOTOR, MotorType.PITCHDOWN, 0, null); } - // m.printModelQueue(); + vis1.updateVisualizer(m.getCurrentControls()); } } catch (SocketException ex) { System.out.println("Unable to set up the connection. (Error message was '" + ex.getMessage() + "'.)"); @@ -62,5 +40,4 @@ public class testprocess1 { } System.out.println("Exiting"); } - -} +} \ No newline at end of file diff --git a/Java/ProjectModels/testprocess2.java b/Java/ProjectModels/testprocess2.java new file mode 100644 index 0000000..aa6e063 --- /dev/null +++ b/Java/ProjectModels/testprocess2.java @@ -0,0 +1,15 @@ +import ModelFiles.XPlaneConnect; +import ModelFiles.*; + +public class testprocess2 extends testprocess { + + public testprocess2(Model m, XPlaneConnect xpc){ + super(m, xpc); + } + + @Override + public void runProcess() { + + } + +}