New visualization for model queue and delay events between looking at compass and looking at airspeed
This commit is contained in:
@@ -33,7 +33,7 @@ public class MindQueue {
|
||||
return q.isEmpty();
|
||||
}
|
||||
|
||||
public String printQueue() {
|
||||
public String queueToString() {
|
||||
String queueTrace = "Next to Execute ==> ";
|
||||
|
||||
for (Action action : q) {
|
||||
@@ -47,6 +47,7 @@ public class MindQueue {
|
||||
queueTrace += "[D]";
|
||||
}
|
||||
}
|
||||
queueTrace += "\n";
|
||||
return queueTrace;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ public class Model {
|
||||
private MindQueue q; // Queue for actions
|
||||
boolean modelActive; // On/Off Switch for the model execution
|
||||
XPlaneConnect xpc; // Allows connection to the simulator
|
||||
float[] storedVision;
|
||||
String storedVisionTarget;
|
||||
float[] storedVisionResult;
|
||||
boolean logCreated;
|
||||
boolean logAllowed;
|
||||
File dataLogFile = null;
|
||||
@@ -68,7 +69,7 @@ public class Model {
|
||||
}
|
||||
|
||||
public void printModelQueue() {
|
||||
System.out.println(q.printQueue());
|
||||
System.out.println(q.queueToString());
|
||||
}
|
||||
|
||||
public int getModelQueueLength() {
|
||||
@@ -124,7 +125,8 @@ public class Model {
|
||||
String dref = tempV.getTarget();
|
||||
try {
|
||||
returnArray = xpc.getDREF(dref);
|
||||
storedVision = returnArray.clone();
|
||||
storedVisionTarget = dref;
|
||||
storedVisionResult = returnArray.clone();
|
||||
// System.out.println(returnArray[0]);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -146,7 +148,7 @@ public class Model {
|
||||
switch (motorType) {
|
||||
case PITCHUP:
|
||||
float[] pitchUp = { currentControls[0] + 0.01f };
|
||||
if (storedVision[0] > 80) {
|
||||
if (storedVisionResult[0] > 80) {
|
||||
if (currentControls[0] < 0.2f) {
|
||||
System.out.println("Pitching Up");
|
||||
xpc.sendCTRL(pitchUp);
|
||||
@@ -155,7 +157,7 @@ public class Model {
|
||||
break;
|
||||
case PITCHDOWN:
|
||||
float[] pitchDown = { currentControls[0] - 0.01f };
|
||||
if (storedVision[0] < 80) {
|
||||
if (storedVisionResult[0] < 80) {
|
||||
if (currentControls[0] > -0.2f) {
|
||||
// System.out.println("Sending Pitch Down");
|
||||
System.out.println("Pitching Down");
|
||||
@@ -179,6 +181,7 @@ public class Model {
|
||||
private void handleDelayAction(Action temp) {
|
||||
Delay tempD = (Delay) temp;
|
||||
initiateDelay(tempD.getDelay());
|
||||
storedVisionTarget = "INTERRUPTION: DELAY";
|
||||
}
|
||||
|
||||
public static void initiateDelay(int delay) {
|
||||
@@ -197,26 +200,27 @@ public class Model {
|
||||
returnArray = xpc.getCTRL(0);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw e;
|
||||
while(returnArray == null) {
|
||||
System.out.println("Waiting for reconnect");
|
||||
returnArray = xpc.getCTRL(0);
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
|
||||
public void startLog(){
|
||||
public void startLog() {
|
||||
logAllowed = true;
|
||||
}
|
||||
|
||||
public void stopLog(){
|
||||
public void stopLog() {
|
||||
logAllowed = false;
|
||||
logCreated = false;
|
||||
}
|
||||
|
||||
public boolean logPermission(){
|
||||
public boolean logPermission() {
|
||||
return logAllowed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void logData() {
|
||||
if(logAllowed) {
|
||||
logProcess();
|
||||
@@ -226,15 +230,31 @@ public class Model {
|
||||
|
||||
private void logProcess(){
|
||||
if(!logCreated) {
|
||||
dataLogFile = new File("./dataLog/" + java.time.LocalDateTime.now());
|
||||
dataLogFile = new File("./dataLog/" + java.time.LocalDateTime.now() + ".csv");
|
||||
logCreated = true;
|
||||
}
|
||||
try {
|
||||
float[] ctrl1 = this.getCurrentControls();
|
||||
String setup = "Elevator, Roll, Yaw, Throttle, Flaps\n";
|
||||
FileWriter fw = new FileWriter(dataLogFile, true);
|
||||
BufferedWriter br = new BufferedWriter(fw);
|
||||
br.write(setup);
|
||||
br.flush();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
String log = null;
|
||||
try {
|
||||
float[] ctrl1 = this.getCurrentControls();
|
||||
|
||||
|
||||
//Labled Format
|
||||
log = String.format("[Elevator: %2f] [Roll: %2f] [Yaw: %2f] [Throttle:%2f] [Flaps: %2f] \n",
|
||||
ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5]);
|
||||
//CSV Format
|
||||
log = String.format("%2f, %2f, %2f, %2f, %2f\n",
|
||||
ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5]);
|
||||
|
||||
FileWriter fw = new FileWriter(dataLogFile, true);
|
||||
BufferedWriter br = new BufferedWriter(fw);
|
||||
br.write(log);
|
||||
@@ -245,4 +265,13 @@ public class Model {
|
||||
System.out.println("No data to log");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public float[] getStoredVisionResult() {
|
||||
return storedVisionResult;
|
||||
}
|
||||
|
||||
public String getStoredVisionTarget() {
|
||||
return storedVisionTarget;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
//import CognitiveModel.ModelFiles.*;
|
||||
import CognitiveModel.ModelFiles.*;
|
||||
|
||||
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();
|
||||
Model m = new Model();
|
||||
testprocess1 tp1 = new testprocess1(m, null);
|
||||
tp1.runProcess();
|
||||
// testprocess2 tp2 = new testprocess2(m, null);
|
||||
// tp2.runProcess();
|
||||
|
||||
for (int i = 1; i<10; i++) {
|
||||
if (i%2 == 0) {
|
||||
int t = 0;
|
||||
} else if(i == 9) {
|
||||
System.out.println("Breaking now");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for (int i = 1; i<10; i++) {
|
||||
// if (i%2 == 0) {
|
||||
// int t = 0;
|
||||
// } else if(i == 9) {
|
||||
// System.out.println("Breaking now");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import CognitiveModel.ModelFiles.*;
|
||||
|
||||
@@ -12,7 +13,11 @@ public class visualizer {
|
||||
|
||||
JFrame frame = new JFrame();
|
||||
JPanel frameBottom = new JPanel();
|
||||
JPanel display = new JPanel();
|
||||
JPanel controlDisplay = new JPanel();
|
||||
JPanel modelDisplay = new JPanel();
|
||||
JTextArea modelQueue = new JTextArea();
|
||||
JTextArea modelVision = new JTextArea();
|
||||
JPanel mainDisplay = new JPanel();
|
||||
JPanel visualizer = new JPanel();
|
||||
JPanel yokeGrid = new JPanel();
|
||||
axis axis = new axis(0,0);
|
||||
@@ -42,8 +47,9 @@ public class visualizer {
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
display.setPreferredSize(new Dimension(100,100));
|
||||
display.setLayout(new GridLayout(2,4));
|
||||
controlDisplay.setPreferredSize(new Dimension(100,100));
|
||||
|
||||
controlDisplay.setLayout(new GridLayout(2,4));
|
||||
|
||||
Font fontTitles = new Font("Impact", 1,40);
|
||||
Font fontData = new Font("Monospaced", 1,30);
|
||||
@@ -84,14 +90,14 @@ public class visualizer {
|
||||
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);
|
||||
controlDisplay.add(titleOne);
|
||||
controlDisplay.add(titleTwo);
|
||||
controlDisplay.add(titleThree);
|
||||
controlDisplay.add(titleFour);
|
||||
controlDisplay.add(one);
|
||||
controlDisplay.add(two);
|
||||
controlDisplay.add(three);
|
||||
controlDisplay.add(four);
|
||||
|
||||
|
||||
visualizer.setLayout(new GridLayout(2,1));
|
||||
@@ -171,9 +177,27 @@ public class visualizer {
|
||||
buttonBar.add(tool2);
|
||||
buttonBar.add(tool3);
|
||||
|
||||
modelQueue.setRows(3);
|
||||
modelQueue.setPreferredSize(new Dimension(250, mainDisplay.getWidth()));
|
||||
|
||||
|
||||
frameBottom.add(display); // Left Side
|
||||
modelVision.setRows(1);
|
||||
Font font = new Font("Verdana", Font.BOLD, 12);
|
||||
modelVision.setFont(font);
|
||||
modelVision.setBackground(Color.PINK);
|
||||
modelVision.setPreferredSize(new Dimension(250, mainDisplay.getWidth()));
|
||||
|
||||
modelDisplay.setLayout(new GridLayout(2,1));
|
||||
modelDisplay.add(modelQueue);
|
||||
modelDisplay.add(modelVision);
|
||||
|
||||
|
||||
mainDisplay.setLayout(new BorderLayout());
|
||||
mainDisplay.add(controlDisplay,BorderLayout.CENTER);
|
||||
mainDisplay.add(modelDisplay,BorderLayout.SOUTH);
|
||||
|
||||
|
||||
frameBottom.add(mainDisplay); // Left Side
|
||||
frameBottom.add(visualizer); // Right Side
|
||||
frame.add(frameBottom,BorderLayout.CENTER);
|
||||
frame.add(buttonBar, BorderLayout.SOUTH);
|
||||
@@ -181,7 +205,9 @@ public class visualizer {
|
||||
}
|
||||
|
||||
|
||||
public void updateVisualizer(float[] ctrl1){
|
||||
public void updateVisualizer(Model m) throws IOException {
|
||||
float[] ctrl1 = m.getCurrentControls();
|
||||
|
||||
one.setText(String.valueOf(ctrl1[0]));
|
||||
if(ctrl1[0] >= 0 ) {
|
||||
one.setForeground(Color.green);
|
||||
@@ -219,6 +245,14 @@ public class visualizer {
|
||||
rudderGrid.repaint();
|
||||
|
||||
|
||||
modelQueue.setText(m.getQueue().queueToString());
|
||||
modelQueue.setPreferredSize(new Dimension(mainDisplay.getWidth(),100));
|
||||
|
||||
modelVision.setPreferredSize(new Dimension(mainDisplay.getWidth(),100));
|
||||
|
||||
modelVision.setText("We just looked at: " + m.getStoredVisionTarget() +"\n" +
|
||||
"Result: " + m.getStoredVisionResult()[0]);
|
||||
|
||||
|
||||
// yaw.setYBound(grid.getHeight());
|
||||
// yaw.setYBound(grid.getHeight());
|
||||
|
||||
@@ -38,7 +38,8 @@ class yokePosition extends JComponent {
|
||||
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);
|
||||
|
||||
// System.out.println("CurrX, CurrY: " + currX +", " + currY);
|
||||
// g2.drawOval(currX, currY, width, height);
|
||||
|
||||
g2.fillOval(currX, currY, width, height);
|
||||
|
||||
@@ -12,15 +12,22 @@ public class testprocess1 extends testprocess {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void innerProcess(visualizer vis1){
|
||||
public void innerProcess(visualizer vis1) {
|
||||
float[] array = m.next();
|
||||
double r = Math.random();
|
||||
if (m.getModelQueueLength() < 5) {
|
||||
if (r > 0.5) {
|
||||
// m.createAction(ActionType.DELAY, null, 200, null);
|
||||
m.createAction(ActionType.DELAY, null, 200, null);
|
||||
m.createAction(ActionType.VISION, null, 0, "sim/cockpit2/gauges/indicators/compass_heading_deg_mag");
|
||||
} else {
|
||||
m.createAction(ActionType.VISION, null, 0, "sim/cockpit2/gauges/indicators/airspeed_kts_pilot");
|
||||
}
|
||||
}
|
||||
// m.printModelQueue();
|
||||
m.logData();
|
||||
try {
|
||||
vis1.updateVisualizer(m.getCurrentControls());
|
||||
vis1.updateVisualizer(m);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user