📄 copilotagent.java.svn-base
字号:
package agents;
import interfaces.ClearanceDeliveryInterface;
import interfaces.CoPilotInterface;
import interfaces.GroundControllerInterface;
import interfaces.LocalControllerInterface;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Semaphore;
import world.Airport;
import world.Gate;
import world.Plane;
import world.RealPlane;
import world.Runway;
import world.TRACON;
import world.Taxiway;
import world.Tower;
import world.Waypoint;
import world.Weather;
import agents.PilotAgent.PilotState;
import base.Agent;
import base.World;
import base.WorldObject;
import base.WorldObjectState;
import base.WorldVector;
public class CoPilotAgent extends Agent implements CoPilotInterface {
final double departingVelocity = 10;
final double landingVelocity = 80;
final double taxiVelocity = 7;
Semaphore inc_velocity = new Semaphore(1, true);
//DATA
String flightNumber;
public Plane plane;
Airport airport;
String approach;
Weather weather;
TRACON departureTracon;
public enum PilotState {NO_ACTION, NEW_ARRIVAL, SENT_CHECKLIST, NEED_TO_ASK_TO_LAND, ASKED_TO_LAND, CLEAR_TO_LAND, NOT_CLEAR_TO_LAND, ECHO_LANDING,
GOT_LANDING_PATH, ECHO_LANDING_PATH, GOT_TAXI_LAND_PATH, ECHO_TAXI_LAND_PATH, LANDING, TAXIING, ARRIVED,
NEW_DEPARTURE, SENT_DEPARTURE_CHECKLIST, REQUESTED_DEPARTURE_CLEARANCE, CLEARED_FOR_DEPARTURE, ECHO_CLEARED_FOR_DEPARTURE,
GOT_WEATHER, ECHO_WEATHER, DEPARTURE_CHECKLIST_DONE, ASKED_FOR_PUSH_BACK, WAIT_PUSH_BACK, ECHO_PUSH_BACK, PUSH_BACK,
READY_FOR_TAXI, GOT_TAXI_PATH, ECHO_TAXI_PATH, DEPARTURE_TAXIING, HOLD_FOR_DEPARTURE, ECHO_HOLD_FOR_DEPARTURE,
GOT_DEPARTURE_TRACON, ECHO_DEPARTURE_TRACON, LC_CLEARED_FOR_DEPARTURE, TAKING_OFF, DEAD};
public PilotState pilotState;
public Runway landing, departing;
WorldVector runwayPosition;
Taxiway taxiway;
public Gate destinationGate;
public String destination;//???
public List<Taxiway> landingPath, taxiLandingPath, taxiDepartingPath; //what is landingPath used for?
List<Waypoint> departureProcedure;
public LocalControllerInterface localController;
public GroundControllerInterface groundController;
public ClearanceDeliveryInterface clearanceDelivery;
public static void main(String args[]){
Tower tower = new Tower();
List<WorldVector> vertices = new ArrayList<WorldVector>();
vertices.add(new WorldVector(50,90,0));
vertices.add(new WorldVector(50,110,0));
vertices.add(new WorldVector(150,90,0));
vertices.add(new WorldVector(150,110,0));
WorldObjectState runwayState = new WorldObjectState(new WorldVector(100,100,0),vertices);
Runway runway = new Runway("Runway2C",runwayState);
WorldObjectState planeState = new WorldObjectState(new WorldVector(100, 100, 0));
Plane myPlane = new RealPlane("747",planeState);
//LocalControllerInterface lc = new LocalController("lc",tower);
ClearanceDeliveryInterface cd = new ClearanceDeliveryAgent("cd", tower);
PilotAgent myPilot = new PilotAgent("Pilot",myPlane);
myPlane.ctrlAssumePilotRole(myPilot);
//myPilot.msgNewArrivingFlight("SWA111", runway, new Gate(new Taxiway()), lc);
//myPilot.pilotState = PilotState.ECHO_LANDING_PATH;
myPilot.msgNewDepartingFlight("SWA111", runway, new Gate(new Taxiway()), "Bora Bora", cd);
myPilot.pilotState = PilotAgent.PilotState.ECHO_DEPARTURE_TRACON;
World.startWorld();
myPilot.startThread();
}
public CoPilotAgent(Plane myPlane, Airport myAirport){
super();
plane = myPlane;
airport = myAirport;
pilotState = PilotState.NO_ACTION;
plane.ctrlAssumeCoPilotRole(this);
}
public CoPilotAgent(String name, Plane plane) {
super();
this.plane = plane;
flightNumber = name;
plane.ctrlAssumeCoPilotRole(this);
}
public CoPilotAgent(Plane myPlane, Airport myAirport, LocalControllerInterface lc,
GroundControllerInterface gc, ClearanceDeliveryInterface cd, String fn){
super();
plane = myPlane;
airport = myAirport;
pilotState = PilotState.NO_ACTION;
localController = lc; groundController = gc;
clearanceDelivery = cd;
flightNumber = fn;
}
// Pilot
public boolean heartBeat(){return true;}
// Non normative scenario
public void msgPilotIsDead() {
print("Pilot is now dead");
pilotState = PilotState.DEAD;
}
// Landing
public void msgNewArrivingFlight(String callNumber, Runway runway, Gate gate, LocalControllerInterface lc){
// print("Received msgNewArrivingaFlight");
flightNumber = callNumber;
landing = runway;
destinationGate = gate;
localController = lc;
//pilotState = PilotState.NEED_TO_ASK_TO_LAND;
//stateChanged();
}
public void msgArrivalChecklistSuccessful(){
print("Received msgArrivalChecklistSuccessful");
pilotState = PilotState.NEED_TO_ASK_TO_LAND;
stateChanged();
}
public void msgClearanceToLand(Runway runway){
print("Received msgClearanceToLand");
landing = runway;
pilotState = PilotState.CLEAR_TO_LAND;
stateChanged();
}
public void msgNotClearedToLand(){
print("Received msgNotClearedToLand");
pilotState = PilotState.NOT_CLEAR_TO_LAND;
stateChanged();
}
public void msgLandingPath(List<Taxiway> path, GroundControllerInterface gc){
print("Received msgLandingPath");
landingPath = path;
groundController = gc;
pilotState = PilotState.GOT_LANDING_PATH;
stateChanged();
}
public void msgTaxiLandingPath(List<Taxiway> taxiInstruction){
print("Received msgTaxiLandingPath");
taxiLandingPath = taxiInstruction;
pilotState = PilotState.GOT_TAXI_LAND_PATH;
stateChanged();
}
// Takeoff
public void msgNewDepartingFlight(String callNumber, Runway runway, Gate gate, String myDestination, ClearanceDeliveryInterface cd){
print("Received msgNewDepartingFlight");
flightNumber = callNumber;
runway.get_world_object_state();
departing = runway;
destinationGate = gate;
destination = myDestination;
clearanceDelivery = cd;
//pilotState = PilotState.NEW_DEPARTURE;
//pilotState = PilotState.GOT_TAXI_PATH;
//stateChanged();
}
public void msgClearanceGranted(List<Waypoint> procedure, GroundControllerInterface gc){
print("Received msgClearanceGranted");
departureProcedure = procedure;
groundController = gc;
pilotState = PilotState.CLEARED_FOR_DEPARTURE;
stateChanged();
}
public void msgSendWeather(Weather report){
print("Received msgSendWeather");
weather = report;
pilotState = PilotState.GOT_WEATHER;
stateChanged();
}
public void msgDepartureChecklistSuccessful(){
print("Received msgDepartureChecklistSuccessful");
pilotState = PilotState.DEPARTURE_CHECKLIST_DONE;
stateChanged();
}
public void msgGivePushBack(Runway takeoffRunway, Gate gate){
print("Received msgGivePushBack");
//departing = takeoffRunway;
destinationGate = gate;
pilotState = PilotState.WAIT_PUSH_BACK;
stateChanged();
}
public void msgWaitForTaxiway() {
print("Received msgWaitForTaxiway");
pilotState = PilotState.WAIT_PUSH_BACK;
stateChanged();
}
public void msgTaxiTakeoffPath(List<Taxiway> path, LocalControllerInterface lc){
print("Received msgTaxiTakeoffPath");
taxiDepartingPath = path;
localController = lc;
pilotState = PilotState.GOT_TAXI_PATH;
stateChanged();
}
public void msgPositionAndHold(){
print("Received msgPositionAndHold");
pilotState = PilotState.HOLD_FOR_DEPARTURE;
stateChanged();
}
public void msgClearedForTakeoff(Runway takeoffRunway){
print("Received msgClearedForTakeoff");
//departing = takeoffRunway;
pilotState = PilotState.GOT_DEPARTURE_TRACON;
//pilotState = PilotState.LC_CLEARED_FOR_DEPARTURE;
stateChanged();
}
public void msgContactDepartureControl(TRACON departureControl){
print("Received msgContactDepartureControl");
departureTracon = departureControl;
pilotState = PilotState.GOT_DEPARTURE_TRACON;
stateChanged();
}
@Override
protected boolean pickAndExecuteAnAction() {
//LANDING ARRIVAL
if(pilotState == PilotState.NEW_ARRIVAL){
DoSendArrivalChecklist();
return true;
}
else if(pilotState == PilotState.NEED_TO_ASK_TO_LAND){
DoAskToLand();
return true;
}
else if(pilotState == PilotState.CLEAR_TO_LAND){
DoEchoClearToLand();
return true;
}
else if(pilotState == PilotState.NOT_CLEAR_TO_LAND){
DoWaitToLand();
return true;
}
else if(pilotState==PilotState.GOT_LANDING_PATH){
DoEchoLandingPath();
return true;
}
else if(pilotState==PilotState.ECHO_LANDING_PATH){
DoLanding();
return true;
}
else if(pilotState==PilotState.GOT_TAXI_LAND_PATH){
DoEchoLandTaxiPath();
return true;
}
else if(pilotState==PilotState.ECHO_TAXI_LAND_PATH){
DoTaxiToGate();
return true;
}
//DEPARTING TAKE OFF
else if(pilotState==PilotState.NEW_DEPARTURE){
DoSendDepartureChecklist();
return true;
}
else if(pilotState==PilotState.SENT_DEPARTURE_CHECKLIST){
DoRequestClearanceForDeparture();
return true;
}
else if(pilotState==PilotState.CLEARED_FOR_DEPARTURE){
DoEchoDepartureClearance();
return true;
}
else if(pilotState==PilotState.GOT_WEATHER){
DoEchoWeather();
return true;
}
else if(pilotState==PilotState.DEPARTURE_CHECKLIST_DONE){
DoRequestPushBack();
return true;
}
else if(pilotState==PilotState.WAIT_PUSH_BACK){
DoEchoPushBack();
return true;
}
else if(pilotState==PilotState.ECHO_PUSH_BACK){
DoWaitForPushBack();
return true;
}
else if(pilotState==PilotState.GOT_TAXI_PATH){
DoEchoTaxiPath();
return true;
}
else if(pilotState==PilotState.ECHO_TAXI_PATH){
DoDepartureTaxiing();
return true;
}
else if(pilotState==PilotState.HOLD_FOR_DEPARTURE){
DoEchoHoldForDeparture();
return true;
}
else if(pilotState==PilotState.LC_CLEARED_FOR_DEPARTURE){
DoEchoClearedForLCDeparture();
return true;
}
else if(pilotState==PilotState.GOT_DEPARTURE_TRACON){
DoEchoDepartureTracon();
return true;
}
else if(pilotState == PilotState.ECHO_DEPARTURE_TRACON){
DoDeparture();
return true;
}
// Pilot dead scenario
else if(pilotState == PilotState.DEAD) {
DoDead();
return true;
}
return false;
}
// Non normative scenario
private void DoDead() {
stopThread();
}
//ACTIONS
//ARRIVALS
private void DoSendArrivalChecklist(){
pilotState = PilotState.SENT_CHECKLIST;
//print("Sending local controller msgNewArrivingFlight");
//localController.msgNewArrivingFlight(plane, flightNumber, landing, destinationGate);
stateChanged();
}
private void DoAskToLand(){
pilotState = PilotState.ASKED_TO_LAND;
approach = "visual";
print("Sending local controller msgRequestToLand");
localController.msgRequestToLand(flightNumber, approach, landing);
stateChanged();
}
private void DoEchoClearToLand(){
pilotState = PilotState.ECHO_LANDING;
print("Sending local controller msgConfirmClearanceToLand");
localController.msgConfirmClearanceToLand(flightNumber, landing);
stateChanged();
}
private void DoWaitToLand(){
//hover in sky for certain time
pilotState = PilotState.NEED_TO_ASK_TO_LAND;
stateChanged();
}
private void DoEchoLandingPath(){
pilotState = PilotState.ECHO_LANDING_PATH;
print("Sending local controller msgConfirmLandingPath");
localController.msgConfirmLandingPath(flightNumber, taxiLandingPath, groundController);
stateChanged();
}
private void DoLanding(){
pilotState = PilotState.LANDING;
//Landing procedure
ActionLanding();
print("Sending ground controller msgLeavingRunway");
groundController.msgLeavingRunway(flightNumber, landing, destinationGate);
stateChanged();
}
private void DoEchoLandTaxiPath() {
print("Sending ground controller msgConfirmTaxiLandingPath");
pilotState = PilotState.ECHO_TAXI_LAND_PATH;
groundController.msgConfirmTaxiLandingPath(flightNumber, new ArrayList<Taxiway>());
stateChanged();
}
private void DoTaxiToGate(){
pilotState = PilotState.TAXIING;
//Taxiing procedure
DoFollowTaxiways(taxiLandingPath);
pilotState = PilotState.ARRIVED;
stateChanged();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -