new additions

This commit is contained in:
cs-powell
2024-10-05 10:05:35 -04:00
parent 21404bcc07
commit 8253861a80
2 changed files with 11528 additions and 27 deletions

View File

@@ -63,12 +63,7 @@ public class Main
xpc.sendDATA(data); xpc.sendDATA(data);
System.out.println("Trying something new!!"); System.out.println("Trying something new!!");
JFrame frame = new JFrame(); JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(300,100)); frame.setPreferredSize(new Dimension(300,100));
@@ -199,10 +194,10 @@ 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);
float[] value = xpc.getDREF(dref); float[] value = xpc.getDREF(dref);
float[] value2 = xpc.getDREF(dref2); float[] value2 = xpc.getDREF(dref2);
float[] valueHDG = xpc.getDREF(drefHDG); float[] valueHDG = xpc.getDREF(drefHDG);
@@ -220,25 +215,25 @@ public class Main
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);
one.setText(String.valueOf(ctrl1[0])); one.setText(String.valueOf(ctrl1[0]));
if(ctrl1[0] >= 0 ){ if(ctrl1[0] >= 0 ) {
one.setForeground(Color.green); one.setForeground(Color.green);
} else { } else {
one.setForeground(Color.red); one.setForeground(Color.red);
} }
two.setText(String.valueOf(ctrl1[1])); two.setText(String.valueOf(ctrl1[1]));
if(ctrl1[1] >= 0 ){ if(ctrl1[1] >= 0 ) {
two.setForeground(Color.green); two.setForeground(Color.green);
} else { } else {
two.setForeground(Color.red); two.setForeground(Color.red);
} }
three.setText(String.valueOf(ctrl1[2])); three.setText(String.valueOf(ctrl1[2]));
if(ctrl1[2] >= 0 ){ if(ctrl1[2] >= 0 ) {
three.setForeground(Color.green); three.setForeground(Color.green);
} else { } else {
three.setForeground(Color.red); three.setForeground(Color.red);
} }
four.setText(String.valueOf(ctrl1[3])); four.setText(String.valueOf(ctrl1[3]));
if(ctrl1[3] >= 0 ){ if(ctrl1[3] >= 0 ) {
four.setForeground(Color.green); four.setForeground(Color.green);
} else { } else {
four.setForeground(Color.red); four.setForeground(Color.red);
@@ -249,14 +244,10 @@ public class Main
yoke.setX(ctrl1[1]); yoke.setX(ctrl1[1]);
yoke.setY(ctrl1[0]); yoke.setY(ctrl1[0]);
yoke.repaint(); yoke.repaint();
axis.setXBound(grid.getWidth()); axis.setXBound(grid.getWidth());
axis.setYBound(grid.getHeight()); axis.setYBound(grid.getHeight());
axis.repaint(); axis.repaint();
//Writing Data to a File //Writing Data to a File
try { try {
bw.write(log + "\n"); bw.write(log + "\n");
@@ -264,7 +255,6 @@ public class Main
} catch (IOException e) { } catch (IOException e) {
System.out.println("Log Data Failed"); System.out.println("Log Data Failed");
} }
/* /*
* Flight Controls * Flight Controls
*/ */
@@ -286,13 +276,17 @@ public class Main
// xpc.sendCTRL(pitchDown); // xpc.sendCTRL(pitchDown);
// } // }
if(valueAltitude[0] > 1000f && !switchTrack){ if(valueAltitude[0] > 1000f && !switchTrack){
System.out.println("In switch"); System.out.println("In switch");
takeoff = false; takeoff = false;
cruise = true; cruise = true;
switchTrack = true; switchTrack = true;
} }
//Control Profiles
if(takeoff) { if(takeoff) {
float[] fullThrottle = {-998.0f, -998.0f, -998.0f, 1f}; float[] fullThrottle = {-998.0f, -998.0f, -998.0f, 1f};
if(!throttleFull) { if(!throttleFull) {
@@ -347,7 +341,7 @@ public class Main
if(cruise) { if(cruise) {
//Basic Autopilot For Roll (based on bank angle) //Basic Autopilot For Roll (based on bank angle)
float[] rollRight = {-998.0f, ctrl1[1] + 0.01f}; float[] rollRight = {-998.0f, ctrl1[1] + 0.01f};
float[] rollLeft = {-998.0f, ctrl1[1] - 0.01f}; float[] rollLeft = {-998.0f, ctrl1[1] - 0.01f};
if(value2[0] < 0) { if(value2[0] < 0) {
@@ -357,7 +351,7 @@ public class Main
} }
} else if(value2[0] > 0) { } else if(value2[0] > 0) {
if(ctrl1[1] > -0.15f){ if(ctrl1[1] > -0.15f) {
xpc.sendCTRL(rollLeft); xpc.sendCTRL(rollLeft);
} }
} }
@@ -388,9 +382,6 @@ public class Main
} }
} }
// System.out.println("Setting controls"); // System.out.println("Setting controls");
// float[] ctrl = new float[4]; // float[] ctrl = new float[4];
// ctrl[3] = 0.8F; // ctrl[3] = 0.8F;
@@ -422,13 +413,12 @@ public class Main
// } // }
} }
class axis extends JComponent { class axis extends JComponent {
int xBound = 0; int xBound = 0;
int yBound = 0; int yBound = 0;
axis(int currentX, int currentY){ axis(int currentX, int currentY) {
xBound = currentX; xBound = currentX;
yBound = currentY; yBound = currentY;
} }
@@ -448,7 +438,6 @@ class axis extends JComponent {
public void setYBound(int newY){ public void setYBound(int newY){
this.yBound = newY; this.yBound = newY;
} }
} }
@@ -461,7 +450,10 @@ class yokePosition extends JComponent {
float y = 0; float y = 0;
int yBound = 0; int yBound = 0;
yokePosition(int currentX, int currentY){ int width = 50;
int height = 50;
yokePosition(int currentX, int currentY) {
xBound = currentX; xBound = currentX;
yBound = currentY; yBound = currentY;
} }
@@ -475,10 +467,11 @@ class yokePosition extends JComponent {
{ {
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.red); g2.setColor(Color.red);
int currX = (int)(x*xBound) + xBound/2; int currX = (int)(x*xBound) + xBound/2 - width/2;
int currY = (int)(y*yBound) + yBound/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, 50, 50); // g2.drawOval(currX, currY, width, height);
g2.fillOval(currX, currY, width, height);
} }
public void setX(float newX){ public void setX(float newX){

File diff suppressed because it is too large Load Diff