Document atc_mgr, remove method from SchedFlight
This commit is contained in:
parent
84c075a20f
commit
86dae35b37
4 changed files with 109 additions and 58 deletions
|
@ -41,6 +41,9 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
/**
|
||||
Constructer, initializes values to private boolean and FGATCController instances
|
||||
*/
|
||||
FGATCManager::FGATCManager() :
|
||||
controller(NULL),
|
||||
prevController(NULL),
|
||||
|
@ -49,47 +52,59 @@ FGATCManager::FGATCManager() :
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Default destructor
|
||||
*/
|
||||
FGATCManager::~FGATCManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
Sets up ATC subsystem parts depending on other subsystems
|
||||
Override of SGSubsystem::postinit()
|
||||
Will set private boolean flag "initSucceeded" to true upon conclusion
|
||||
*/
|
||||
void FGATCManager::postinit()
|
||||
{
|
||||
int leg = 0;
|
||||
|
||||
trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
|
||||
|
||||
// find a reasonable controller for our user's aircraft..
|
||||
// Let's start by working out the following three scenarios:
|
||||
// Starting on ground at a parking position
|
||||
// Starting on ground at the runway.
|
||||
// Starting in the Air
|
||||
// Assign a controller to the user's aircraft.
|
||||
// Three scenarios are considered:
|
||||
// - Starting on ground at a parking position
|
||||
// - Starting on ground at the runway.
|
||||
// - Starting in the air
|
||||
bool onGround = fgGetBool("/sim/presets/onground");
|
||||
string runway = fgGetString("/sim/atc/runway");
|
||||
string curAirport = fgGetString("/sim/presets/airport-id");
|
||||
string destination = fgGetString("/autopilot/route-manager/destination/airport");
|
||||
string parking = fgGetString("/sim/presets/parkpos");
|
||||
destination = fgGetString("/autopilot/route-manager/destination/airport");
|
||||
|
||||
FGAIManager* aiManager = globals->get_subsystem<FGAIManager>();
|
||||
FGAIAircraft* userAircraft = aiManager->getUserAircraft();
|
||||
|
||||
string callsign = userAircraft->getCallSign();
|
||||
string callsign = userAircraft->getCallSign();
|
||||
|
||||
double aircraftRadius = 40; // note that this is currently hardcoded to a one-size-fits all JumboJet value. Should change later;
|
||||
double aircraftRadius = 40; // note that this is currently hardcoded to a one-size-fits all JumboJet value. Should change later.
|
||||
|
||||
// In case a destination is not set yet, make it equal to the current airport
|
||||
if (destination == "") {
|
||||
destination = curAirport;
|
||||
}
|
||||
// In case a destination is not set yet, make it equal to the current airport
|
||||
if (destination == "") {
|
||||
destination = curAirport;
|
||||
}
|
||||
|
||||
// NEXT UP: Create a traffic Schedule and fill that with appropriate information. This we can use to flight planning.
|
||||
// NEXT UP: Create a traffic schedule and fill that with appropriate information. This we can use for flight planning.
|
||||
// Note that these are currently only defaults.
|
||||
FGAISchedule *trafficRef = new FGAISchedule;
|
||||
trafficRef->setFlightType("gate");
|
||||
|
||||
|
||||
FGScheduledFlight* flight = createScheduledFlightWithInfo(curAirport, destination, "IFR", callsign);
|
||||
FGScheduledFlight* userAircraftScheduledFlight = new FGScheduledFlight;
|
||||
userAircraftScheduledFlight->setDepartureAirport(curAirport);
|
||||
userAircraftScheduledFlight->setArrivalAirport(destination);
|
||||
userAircraftScheduledFlight->initializeAirports();
|
||||
userAircraftScheduledFlight->setFlightRules("IFR");
|
||||
userAircraftScheduledFlight->setCallSign(callsign);
|
||||
|
||||
trafficRef->assign(flight);
|
||||
trafficRef->assign(userAircraftScheduledFlight);
|
||||
std::unique_ptr<FGAIFlightPlan> fp ;
|
||||
userAircraft->setTrafficRef(trafficRef);
|
||||
|
||||
|
@ -135,7 +150,7 @@ void FGATCManager::postinit()
|
|||
int stationFreq = dcs->getGroundFrequency(1);
|
||||
if (stationFreq > 0)
|
||||
{
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Setting radio frequency to : " << stationFreq);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Setting radio frequency to : " << stationFreq);
|
||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||
}
|
||||
leg = 1;
|
||||
|
@ -206,15 +221,27 @@ void FGATCManager::postinit()
|
|||
initSucceeded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
Shutdown method
|
||||
Clears activeStations vector in preparation for clean shutdown
|
||||
Override of SGSubsystem::shutdown()
|
||||
*/
|
||||
void FGATCManager::shutdown()
|
||||
{
|
||||
activeStations.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
Adds FGATCController instance to std::vector activeStations.
|
||||
FGATCController is a basic class for every controller
|
||||
*/
|
||||
void FGATCManager::addController(FGATCController *controller) {
|
||||
activeStations.push_back(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
Searches for and removes FGATCController instance from std::vector activeStations
|
||||
*/
|
||||
void FGATCManager::removeController(FGATCController *controller)
|
||||
{
|
||||
AtcVecIterator it;
|
||||
|
@ -224,74 +251,106 @@ void FGATCManager::removeController(FGATCController *controller)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Update the subsystem.
|
||||
FlightGear invokes this method every time the subsystem should
|
||||
update its state.
|
||||
|
||||
@param time The delta time, in seconds, since the last
|
||||
update. On first update, delta time will be 0.
|
||||
*/
|
||||
void FGATCManager::update ( double time ) {
|
||||
SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time);
|
||||
// Test code: let my virtual co-pilot handle ATC:
|
||||
|
||||
SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time);
|
||||
|
||||
// Test code: let my virtual co-pilot handle ATC
|
||||
FGAIManager* aiManager = globals->get_subsystem<FGAIManager>();
|
||||
FGAIAircraft* ai_ac = aiManager->getUserAircraft();
|
||||
FGAIFlightPlan *fp = ai_ac->GetFlightPlan();
|
||||
FGAIAircraft* user_ai_ac = aiManager->getUserAircraft();
|
||||
FGAIFlightPlan *fp = user_ai_ac->GetFlightPlan();
|
||||
|
||||
|
||||
/* test code : find out how the routing develops */
|
||||
if (fp) {
|
||||
int size = fp->getNrOfWayPoints();
|
||||
//SG_LOG(SG_ATC, SG_DEBUG, "Setting pos" << pos << " ");
|
||||
//SG_LOG(SG_ATC, SG_DEBUG, "Setting intentions");
|
||||
//SG_LOG(SG_ATC, SG_DEBUG, "Setting pos" << pos << " ");
|
||||
//SG_LOG(SG_ATC, SG_DEBUG, "Setting intentions");
|
||||
// This indicates that we have run out of waypoints: Im future versions, the
|
||||
// user should be able to select a new route, but for now just shut down the
|
||||
// system.
|
||||
if (size < 3) {
|
||||
SG_LOG(SG_ATC, SG_INFO, "Shutting down the atc_mgr - ran out of waypoints");
|
||||
SG_LOG(SG_ATC, SG_INFO, "Shutting down the atc_mgr - ran out of waypoints");
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
// Test code: Print how far we're progressing along the taxi route.
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Size of waypoint cue " << size);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Size of waypoint cue " << size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int val = fp->getRouteIndex(i);
|
||||
SG_LOG(SG_ATC, SG_BULK, fp->getWayPoint(i)->getName() << " ");
|
||||
SG_LOG(SG_ATC, SG_BULK, fp->getWayPoint(i)->getName() << " ");
|
||||
//if ((val) && (val != pos)) {
|
||||
// intentions.push_back(val);
|
||||
SG_LOG(SG_ATC, SG_BULK, "[done ]");
|
||||
SG_LOG(SG_ATC, SG_BULK, "[done ]");
|
||||
//}
|
||||
}
|
||||
SG_LOG(SG_ATC, SG_BULK, "[done ]");
|
||||
SG_LOG(SG_ATC, SG_BULK, "[done ]");
|
||||
#endif
|
||||
}
|
||||
if (fp) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Currently at leg : " << fp->getLeg());
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Currently at leg : " << fp->getLeg());
|
||||
}
|
||||
|
||||
controller = ai_ac->getATCController();
|
||||
FGATCDialogNew::instance()->update(time);
|
||||
if (controller) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "name of previous waypoint : " << fp->getPreviousWaypoint()->getName());
|
||||
// Call getATCController method; returns what FGATCController presently controls the user aircraft
|
||||
// - e.g. FGStartupController
|
||||
controller = user_ai_ac->getATCController();
|
||||
|
||||
// Update the ATC dialog
|
||||
FGATCDialogNew::instance()->update(time);
|
||||
|
||||
// Controller manager - if controller is set, then will update controller
|
||||
if (controller) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "name of previous waypoint : " << fp->getPreviousWaypoint()->getName());
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Currently under control of " << controller->getName());
|
||||
|
||||
// update aircraft information (simulates transponder)
|
||||
|
||||
controller->updateAircraftInformation(user_ai_ac->getID(),
|
||||
user_ai_ac->_getLatitude(),
|
||||
user_ai_ac->_getLongitude(),
|
||||
user_ai_ac->_getHeading(),
|
||||
user_ai_ac->getSpeed(),
|
||||
user_ai_ac->getAltitude(), time);
|
||||
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Currently under control of " << controller->getName());
|
||||
controller->updateAircraftInformation(ai_ac->getID(),
|
||||
ai_ac->_getLatitude(),
|
||||
ai_ac->_getLongitude(),
|
||||
ai_ac->_getHeading(),
|
||||
ai_ac->getSpeed(),
|
||||
ai_ac->getAltitude(), time);
|
||||
//string airport = fgGetString("/sim/presets/airport-id");
|
||||
//FGAirport *apt = FGAirport::findByIdent(airport);
|
||||
// AT this stage we should update the flightplan, so that waypoint incrementing is conducted as well as leg loading.
|
||||
|
||||
// Ground network visibility:
|
||||
// a) check to see if the message to toggle visibility was called
|
||||
// b) if so, toggle network visibility and reset the transmission
|
||||
// c) therafter disable rendering for the old controller (TODO: should this be earlier?)
|
||||
// d) and render if enabled for the new controller
|
||||
int n = trans_num->getIntValue();
|
||||
|
||||
if (n == 1) {
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Toggling ground network visibility " << networkVisible);
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Toggling ground network visibility " << networkVisible);
|
||||
networkVisible = !networkVisible;
|
||||
trans_num->setIntValue(-1);
|
||||
}
|
||||
|
||||
// stop rendering the old controller's groundnetwork
|
||||
if ((controller != prevController) && (prevController)) {
|
||||
prevController->render(false);
|
||||
}
|
||||
|
||||
// render the path for the present controller if the ground network is set to visible
|
||||
controller->render(networkVisible);
|
||||
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Adding groundnetWork to the scenegraph::update");
|
||||
SG_LOG(SG_ATC, SG_DEBUG, "Adding ground network to the scenegraph::update");
|
||||
|
||||
// reset previous controller for next update() iteration
|
||||
prevController = controller;
|
||||
}
|
||||
|
||||
// update the active ATC stations
|
||||
for (AtcVecIterator atc = activeStations.begin(); atc != activeStations.end(); atc++) {
|
||||
(*atc)->update(time);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
* Written by Durk Talsma. Started August 1, 2010; based on earlier work
|
||||
* by David C. Luff
|
||||
*
|
||||
* Updated by Jonathan Redpath. Started June 12, 2019. Documenting and extending
|
||||
* functionality of the ATC subsystem
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
|
@ -21,7 +24,7 @@
|
|||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* The ATC Manager interfaces the users aircraft with the AI traffic system
|
||||
* The ATC Manager interfaces the users aircraft within the AI traffic system
|
||||
* and also monitors the ongoing AI traffic patterns for potential conflicts
|
||||
* and interferes where necessary.
|
||||
*************************************************************************/
|
||||
|
@ -47,7 +50,9 @@ private:
|
|||
bool networkVisible;
|
||||
bool initSucceeded;
|
||||
SGPropertyNode_ptr trans_num;
|
||||
|
||||
string destination;
|
||||
// SGSharedPtr<FGScheduledFlight> userAircraftScheduledFlight;
|
||||
|
||||
public:
|
||||
FGATCManager();
|
||||
~FGATCManager();
|
||||
|
|
|
@ -290,17 +290,6 @@ bool FGScheduledFlight::initializeAirports()
|
|||
return true;
|
||||
}
|
||||
|
||||
// Function to create a new instance of FGScheduledFlight for use with the ATC code
|
||||
FGScheduledFlight* createScheduledFlightWithInfo(string departure, string destination, string FlightRules, string callsign){
|
||||
FGScheduledFlight *flight = new FGScheduledFlight;
|
||||
flight->setDepartureAirport(departure);
|
||||
flight->setArrivalAirport(destination);
|
||||
flight->initializeAirports();
|
||||
flight->setFlightRules(FlightRules);
|
||||
flight->setCallSign(callsign);
|
||||
return flight;
|
||||
}
|
||||
|
||||
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b)
|
||||
{
|
||||
return (*a) < (*b);
|
||||
|
|
|
@ -117,8 +117,6 @@ typedef std::vector<FGScheduledFlight*>::iterator FGScheduledFlightVecIterator;
|
|||
|
||||
typedef std::map < std::string, FGScheduledFlightVec > FGScheduledFlightMap;
|
||||
|
||||
FGScheduledFlight* createScheduledFlightWithInfo(string curAirport, string destination, string FlightRules, string callsign);
|
||||
|
||||
bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue