documents reformatted
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
package ModelFiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// import ModelFiles.ActionType;
|
||||
@@ -6,12 +7,12 @@ import java.io.IOException;
|
||||
|
||||
public class Model {
|
||||
|
||||
private MindQueue q; //Queue for actions
|
||||
private MindQueue q; // Queue for actions
|
||||
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;
|
||||
|
||||
//Constructors
|
||||
// Constructors
|
||||
public Model() {
|
||||
q = new MindQueue();
|
||||
modelActive = false;
|
||||
@@ -20,62 +21,61 @@ public class Model {
|
||||
public Model(XPlaneConnect xpc) {
|
||||
q = new MindQueue();
|
||||
modelActive = false;
|
||||
this.xpc = xpc;
|
||||
this.xpc = xpc;
|
||||
}
|
||||
|
||||
|
||||
/*Getters*/
|
||||
/* Getters */
|
||||
public MindQueue getQueue() {
|
||||
return q;
|
||||
}
|
||||
|
||||
/*Setters*/
|
||||
/* Setters */
|
||||
|
||||
/*
|
||||
* Setup Methods
|
||||
* Printing, Empty check, Activation/Deactivation of Model, etc.
|
||||
*/
|
||||
*/
|
||||
public void activateModel() {
|
||||
modelActive = true;
|
||||
}
|
||||
|
||||
public void establishConnection(XPlaneConnect newXPC){
|
||||
public void establishConnection(XPlaneConnect newXPC) {
|
||||
this.xpc = newXPC;
|
||||
}
|
||||
|
||||
public void deactivateModel(){
|
||||
public void deactivateModel() {
|
||||
modelActive = false;
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
public boolean isEmpty() {
|
||||
return q.isEmpty();
|
||||
}
|
||||
|
||||
public void push(Action a){
|
||||
public void push(Action a) {
|
||||
q.push(a);
|
||||
}
|
||||
|
||||
public boolean isActive(){
|
||||
public boolean isActive() {
|
||||
return modelActive;
|
||||
}
|
||||
|
||||
public void printModelQueue(){
|
||||
public void printModelQueue() {
|
||||
System.out.println(q.printQueue());
|
||||
}
|
||||
|
||||
public int getModelQueueLength(){
|
||||
public int getModelQueueLength() {
|
||||
return q.queueLength();
|
||||
}
|
||||
|
||||
public void createAction(ActionType actionType, MotorType motorType, int delay,String target) {
|
||||
|
||||
public void createAction(ActionType actionType, MotorType motorType, int delay, String target) {
|
||||
Action newAction = null;
|
||||
switch(actionType) {
|
||||
switch (actionType) {
|
||||
case VISION:
|
||||
newAction = new Vision(delay,target);
|
||||
newAction = new Vision(delay, target);
|
||||
this.push(newAction);
|
||||
break;
|
||||
case MOTOR:
|
||||
newAction = new Motor(motorType,delay,target);
|
||||
newAction = new Motor(motorType, delay, target);
|
||||
this.push(newAction);
|
||||
break;
|
||||
|
||||
@@ -83,13 +83,13 @@ public class Model {
|
||||
newAction = new Delay(delay);
|
||||
this.push(newAction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Processing Methods
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
* Process the next event in the model queue
|
||||
@@ -99,30 +99,30 @@ public class Model {
|
||||
Action temp = q.pop();
|
||||
// System.out.println("Type of Action: " + temp.getType());
|
||||
|
||||
if(temp.getType() == ActionType.VISION){ // Vision Action (Get Data)
|
||||
handelVisionAction(temp, returnArray);
|
||||
} else if (temp.getType() == ActionType.MOTOR){ //Motor Action (Act Upon Data)
|
||||
if (temp.getType() == ActionType.VISION) { // Vision Action (Get Data)
|
||||
handelVisionAction(temp, returnArray);
|
||||
} else if (temp.getType() == ActionType.MOTOR) { // Motor Action (Act Upon Data)
|
||||
handleMotorAction(temp);
|
||||
} else if (temp.getType() == ActionType.DELAY){//Pure Delays (Do nothing)
|
||||
handleDelayAction(temp);
|
||||
} else if (temp.getType() == ActionType.DELAY) {// Pure Delays (Do nothing)
|
||||
handleDelayAction(temp);
|
||||
}
|
||||
// q.push(temp);
|
||||
return returnArray;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Next Helpers */
|
||||
private void handelVisionAction(Action temp, float[] returnArray) {
|
||||
Vision tempV = (Vision) temp;
|
||||
initiateDelay(tempV.getDelay());
|
||||
String dref = tempV.getTarget();
|
||||
try {
|
||||
returnArray = xpc.getDREF(dref);
|
||||
storedVision = returnArray.clone();
|
||||
// System.out.println(returnArray[0]);
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
Vision tempV = (Vision) temp;
|
||||
initiateDelay(tempV.getDelay());
|
||||
String dref = tempV.getTarget();
|
||||
try {
|
||||
returnArray = xpc.getDREF(dref);
|
||||
storedVision = returnArray.clone();
|
||||
// System.out.println(returnArray[0]);
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMotorAction(Action temp) {
|
||||
@@ -135,50 +135,51 @@ public class Model {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
switch(motorType){
|
||||
case PITCHUP:
|
||||
float[] pitchUp = {currentControls[0] + 0.01f};
|
||||
if(storedVision[0] > 80) {
|
||||
if(currentControls[0] < 0.2f) {
|
||||
System.out.println("Pitching Up");
|
||||
xpc.sendCTRL(pitchUp);
|
||||
}
|
||||
|
||||
switch (motorType) {
|
||||
case PITCHUP:
|
||||
float[] pitchUp = { currentControls[0] + 0.01f };
|
||||
if (storedVision[0] > 80) {
|
||||
if (currentControls[0] < 0.2f) {
|
||||
System.out.println("Pitching Up");
|
||||
xpc.sendCTRL(pitchUp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case PITCHDOWN:
|
||||
float[] pitchDown = {currentControls[0] - 0.01f};
|
||||
if(storedVision[0] < 80) {
|
||||
if(currentControls[0] > -0.2f) {
|
||||
// System.out.println("Sending Pitch Down");
|
||||
System.out.println("Pitching Down");
|
||||
xpc.sendCTRL(pitchDown);
|
||||
}
|
||||
case PITCHDOWN:
|
||||
float[] pitchDown = { currentControls[0] - 0.01f };
|
||||
if (storedVision[0] < 80) {
|
||||
if (currentControls[0] > -0.2f) {
|
||||
// System.out.println("Sending Pitch Down");
|
||||
System.out.println("Pitching Down");
|
||||
xpc.sendCTRL(pitchDown);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDelayAction(Action temp){
|
||||
private void handleDelayAction(Action temp) {
|
||||
Delay tempD = (Delay) temp;
|
||||
initiateDelay(tempD.getDelay());
|
||||
}
|
||||
|
||||
public static void initiateDelay(int delay){
|
||||
public static void initiateDelay(int delay) {
|
||||
try {
|
||||
Thread.sleep(delay); // Using the action's Built in Delay
|
||||
Thread.sleep(delay); // Using the action's Built in Delay
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user