Data logging toggle switch
This commit is contained in:
6
Java/ProjectModels/.vscode/settings.json
vendored
Normal file
6
Java/ProjectModels/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar",
|
||||||
|
"/Users/flyingtopher/Desktop/Code Citadel/flatlaf-3.5.2.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package ModelFiles;
|
package ModelFiles;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
// import ModelFiles.ActionType;
|
// import ModelFiles.ActionType;
|
||||||
@@ -11,17 +14,22 @@ public class Model {
|
|||||||
boolean modelActive; // On/Off Switch for the model execution
|
boolean modelActive; // On/Off Switch for the model execution
|
||||||
XPlaneConnect xpc; // Allows connection to the simulator
|
XPlaneConnect xpc; // Allows connection to the simulator
|
||||||
float[] storedVision;
|
float[] storedVision;
|
||||||
|
boolean logCreated;
|
||||||
|
boolean logAllowed;
|
||||||
|
File dataLogFile = null;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
public Model() {
|
public Model() {
|
||||||
q = new MindQueue();
|
q = new MindQueue();
|
||||||
modelActive = false;
|
modelActive = false;
|
||||||
|
logCreated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model(XPlaneConnect xpc) {
|
public Model(XPlaneConnect xpc) {
|
||||||
q = new MindQueue();
|
q = new MindQueue();
|
||||||
modelActive = false;
|
modelActive = false;
|
||||||
this.xpc = xpc;
|
this.xpc = xpc;
|
||||||
|
logCreated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters */
|
/* Getters */
|
||||||
@@ -183,14 +191,58 @@ public class Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float[] getCurrentControls(){
|
public float[] getCurrentControls() throws IOException{
|
||||||
float [] returnArray = null;
|
float [] returnArray = null;
|
||||||
try {
|
try {
|
||||||
returnArray = xpc.getCTRL(0);
|
returnArray = xpc.getCTRL(0);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
throw e;
|
||||||
}
|
}
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void startLog(){
|
||||||
|
logAllowed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopLog(){
|
||||||
|
logAllowed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean logPermission(){
|
||||||
|
return logAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void logData() {
|
||||||
|
if(logAllowed) {
|
||||||
|
logProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void logProcess(){
|
||||||
|
if(!logCreated) {
|
||||||
|
dataLogFile = new File("./dataLog/" + java.time.LocalDateTime.now());
|
||||||
|
logCreated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String log = null;
|
||||||
|
try {
|
||||||
|
float[] ctrl1 = this.getCurrentControls();
|
||||||
|
log = String.format("[Elevator: %2f] [Roll: %2f] [Yaw: %2f] [Throttle:%2f] [Flaps: %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);
|
||||||
|
br.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("No data to log");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
|
|
||||||
import ModelFiles.Model;
|
import ModelFiles.Model;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// FlatLightLaf.setup();
|
||||||
|
|
||||||
// Encapsulation (or lack thereof) Test
|
// Encapsulation (or lack thereof) Test
|
||||||
Model m = new Model();
|
Model m = new Model();
|
||||||
testprocess1 tp1 = new testprocess1(m, null);
|
testprocess1 tp1 = new testprocess1(m, null);
|
||||||
|
|||||||
@@ -205,7 +205,6 @@ public class Main
|
|||||||
BufferedWriter bw = new BufferedWriter(fw);
|
BufferedWriter bw = new BufferedWriter(fw);
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
//THE GETTERS
|
//THE GETTERS
|
||||||
double[] posi1 = xpc.getPOSI(aircraft); // FIXME: change this to 64-bit double
|
double[] posi1 = xpc.getPOSI(aircraft); // FIXME: change this to 64-bit double
|
||||||
float[] ctrl1 = xpc.getCTRL(aircraft);
|
float[] ctrl1 = xpc.getCTRL(aircraft);
|
||||||
@@ -221,7 +220,6 @@ public class Main
|
|||||||
*/
|
*/
|
||||||
// System.out.format("\r[Elevator: %2f] [Roll: %2f] [Yaw: %2f] ---- [Throttle:%2f] ---- [Flaps: %2f] -- [Data Ref: %2f] -- [T/O: %b ][Cruise: %b ]",
|
// System.out.format("\r[Elevator: %2f] [Roll: %2f] [Yaw: %2f] ---- [Throttle:%2f] ---- [Flaps: %2f] -- [Data Ref: %2f] -- [T/O: %b ][Cruise: %b ]",
|
||||||
// ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5], valueAltitude[0], takeoff, cruise);
|
// ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5], valueAltitude[0], takeoff, cruise);
|
||||||
|
|
||||||
String log = String.format("[Elevator: %2f] [Roll: %2f] [Yaw: %2f] [Throttle:%2f] [Flaps: %2f] [Data Ref: %2f] [T/O: %b ][Cruise: %b ]",
|
String log = String.format("[Elevator: %2f] [Roll: %2f] [Yaw: %2f] [Throttle:%2f] [Flaps: %2f] [Data Ref: %2f] [T/O: %b ][Cruise: %b ]",
|
||||||
ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5], valueAltitude[0], takeoff, cruise);
|
ctrl1[0], ctrl1[1], ctrl1[2], ctrl1[3], ctrl1[5], valueAltitude[0], takeoff, cruise);
|
||||||
|
|
||||||
|
|||||||
@@ -3,29 +3,42 @@ package Visualizer;
|
|||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import ModelFiles.*;
|
import ModelFiles.*;
|
||||||
|
|
||||||
public class visualizer {
|
public class visualizer {
|
||||||
|
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
|
JPanel frameBottom = new JPanel();
|
||||||
JPanel display = new JPanel();
|
JPanel display = new JPanel();
|
||||||
JPanel visualizer = new JPanel();
|
JPanel visualizer = new JPanel();
|
||||||
JPanel yokeGrid = new JPanel();
|
JPanel yokeGrid = new JPanel();
|
||||||
axis axis = new axis(0,0);
|
axis axis = new axis(0,0);
|
||||||
rudderPosition rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
rudderPosition rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
||||||
yokePosition yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight());
|
yokePosition yoke = new yokePosition(yokeGrid.getWidth(), yokeGrid.getHeight());
|
||||||
|
JLabel one = new JLabel();
|
||||||
|
JLabel two = new JLabel();
|
||||||
|
JLabel three = new JLabel();
|
||||||
|
JLabel four = new JLabel();
|
||||||
|
Model m;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public visualizer(Model m){
|
public visualizer(Model m){
|
||||||
|
this.m = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void initializeDisplay() {
|
public void initializeDisplay() {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||||
|
} catch(Exception ignored){}
|
||||||
|
|
||||||
frame.setPreferredSize(new Dimension(1700,270));
|
frame.setPreferredSize(new Dimension(1700,270));
|
||||||
frame.setLayout(new GridLayout(1,2));
|
frame.setLayout(new BorderLayout());
|
||||||
|
frameBottom.setLayout(new GridLayout(1,2));
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
@@ -50,19 +63,19 @@ public class visualizer {
|
|||||||
titleFour.setFont(fontTitles);
|
titleFour.setFont(fontTitles);
|
||||||
titleFour.setHorizontalAlignment(SwingConstants.CENTER);
|
titleFour.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
titleFour.setVerticalAlignment(SwingConstants.BOTTOM);
|
titleFour.setVerticalAlignment(SwingConstants.BOTTOM);
|
||||||
JLabel one = new JLabel();
|
one = new JLabel();
|
||||||
one.setFont(fontData);
|
one.setFont(fontData);
|
||||||
one.setHorizontalAlignment(SwingConstants.CENTER);
|
one.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
one.setVerticalAlignment(SwingConstants.TOP);
|
one.setVerticalAlignment(SwingConstants.TOP);
|
||||||
JLabel two = new JLabel();
|
two = new JLabel();
|
||||||
two.setFont(fontData);
|
two.setFont(fontData);
|
||||||
two.setHorizontalAlignment(SwingConstants.CENTER);
|
two.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
two.setVerticalAlignment(SwingConstants.TOP);
|
two.setVerticalAlignment(SwingConstants.TOP);
|
||||||
JLabel three = new JLabel();
|
three = new JLabel();
|
||||||
three.setFont(fontData);
|
three.setFont(fontData);
|
||||||
three.setHorizontalAlignment(SwingConstants.CENTER);
|
three.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
three.setVerticalAlignment(SwingConstants.TOP);
|
three.setVerticalAlignment(SwingConstants.TOP);
|
||||||
JLabel four = new JLabel();
|
four = new JLabel();
|
||||||
four.setFont(fontData);
|
four.setFont(fontData);
|
||||||
four.setHorizontalAlignment(SwingConstants.CENTER);
|
four.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
four.setVerticalAlignment(SwingConstants.TOP);
|
four.setVerticalAlignment(SwingConstants.TOP);
|
||||||
@@ -112,13 +125,86 @@ public class visualizer {
|
|||||||
rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
rudderGrid = new rudderPosition(yokeGrid.getWidth(), 0);
|
||||||
visualizer.add(rudderGrid);
|
visualizer.add(rudderGrid);
|
||||||
|
|
||||||
frame.add(display); // Left Side
|
JToolBar tool = new JToolBar("Toolbar");
|
||||||
frame.add(visualizer); // Right Side
|
JButton b1 = new JButton("Data Log Toggle");
|
||||||
|
ActionListener press = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(m.logPermission() == false){
|
||||||
|
m.startLog();
|
||||||
|
JOptionPane.showMessageDialog(frame,"Data Logging Enabled");
|
||||||
|
tool.setBackground(Color.green);
|
||||||
|
} else {
|
||||||
|
m.stopLog();
|
||||||
|
JOptionPane.showMessageDialog(frame,"Data Logging Disabled");
|
||||||
|
tool.setBackground(Color.white);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
b1.addActionListener(press);
|
||||||
|
JButton b2 = new JButton("button 2");
|
||||||
|
tool.setBackground(Color.red);
|
||||||
|
tool.setOrientation(1);
|
||||||
|
tool.add(b1);
|
||||||
|
tool.add(b2);
|
||||||
|
frame.add(tool,BorderLayout.WEST);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JPanel buttonBar = new JPanel();
|
||||||
|
buttonBar.setLayout(new GridLayout(2,1));
|
||||||
|
JToolBar tool2 = new JToolBar("Toolbar");
|
||||||
|
JButton b3 = new JButton("button 2");
|
||||||
|
JButton b4 = new JButton("button 2");
|
||||||
|
tool2.add(b3);
|
||||||
|
tool2.add(b4);
|
||||||
|
|
||||||
|
JToolBar tool3 = new JToolBar("Toolbar");
|
||||||
|
JButton b5 = new JButton("button 3");
|
||||||
|
JButton b6 = new JButton("button 3");
|
||||||
|
tool3.add(b5);
|
||||||
|
tool3.add(b6);
|
||||||
|
buttonBar.add(tool2);
|
||||||
|
buttonBar.add(tool3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
frameBottom.add(display); // Left Side
|
||||||
|
frameBottom.add(visualizer); // Right Side
|
||||||
|
frame.add(frameBottom,BorderLayout.CENTER);
|
||||||
|
frame.add(buttonBar, BorderLayout.SOUTH);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateVisualizer(float[] ctrl1){
|
public void updateVisualizer(float[] ctrl1){
|
||||||
|
one.setText(String.valueOf(ctrl1[0]));
|
||||||
|
if(ctrl1[0] >= 0 ) {
|
||||||
|
one.setForeground(Color.green);
|
||||||
|
} else {
|
||||||
|
one.setForeground(Color.red);
|
||||||
|
}
|
||||||
|
two.setText(String.valueOf(ctrl1[1]));
|
||||||
|
if(ctrl1[1] >= 0 ) {
|
||||||
|
two.setForeground(Color.green);
|
||||||
|
} else {
|
||||||
|
two.setForeground(Color.red);
|
||||||
|
}
|
||||||
|
three.setText(String.valueOf(ctrl1[2]));
|
||||||
|
if(ctrl1[2] >= 0 ) {
|
||||||
|
three.setForeground(Color.green);
|
||||||
|
} else {
|
||||||
|
three.setForeground(Color.red);
|
||||||
|
}
|
||||||
|
four.setText(String.valueOf(ctrl1[3]));
|
||||||
|
if(ctrl1[3] >= 0 ) {
|
||||||
|
four.setForeground(Color.green);
|
||||||
|
} else {
|
||||||
|
four.setForeground(Color.red);
|
||||||
|
}
|
||||||
|
|
||||||
yoke.setXBound(yokeGrid.getWidth());
|
yoke.setXBound(yokeGrid.getWidth());
|
||||||
yoke.setYBound(yokeGrid.getHeight());
|
yoke.setYBound(yokeGrid.getHeight());
|
||||||
yoke.setX(ctrl1[1]);
|
yoke.setX(ctrl1[1]);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class testprocess1 extends testprocess {
|
|||||||
// m.createAction(ActionType.MOTOR, MotorType.PITCHDOWN, 0, null);
|
// m.createAction(ActionType.MOTOR, MotorType.PITCHDOWN, 0, null);
|
||||||
}
|
}
|
||||||
// m.printModelQueue();
|
// m.printModelQueue();
|
||||||
|
m.logData();
|
||||||
vis1.updateVisualizer(m.getCurrentControls());
|
vis1.updateVisualizer(m.getCurrentControls());
|
||||||
}
|
}
|
||||||
} catch (SocketException ex) {
|
} catch (SocketException ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user