void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
// the one behind you
- FGAIFlightPlan::waypoint* prev = 0;
+ FGAIWaypoint* prev = 0;
// the one ahead
- FGAIFlightPlan::waypoint* curr = 0;
+ FGAIWaypoint* curr = 0;
// the next plus 1
- FGAIFlightPlan::waypoint* next = 0;
+ FGAIWaypoint* next = 0;
prev = fp->getPreviousWaypoint();
curr = fp->getCurrentWaypoint();
<< endl;
} */
} else {
- if (curr->finished) //end of the flight plan
+ if (curr->isFinished()) //end of the flight plan
{
if (fp->getRepeat())
fp->restart();
fp->setLeadDistance(tgt_speed, tgt_heading, curr, next);
}
- if (!(prev->on_ground)) // only update the tgt altitude from flightplan if not on the ground
+ if (!(prev->getOn_ground())) // only update the tgt altitude from flightplan if not on the ground
{
- tgt_altitude_ft = prev->altitude;
- if (curr->crossat > -1000.0) {
+ tgt_altitude_ft = prev->getAltitude();
+ if (curr->getCrossat() > -1000.0) {
use_perf_vs = false;
- tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
+ tgt_vs = (curr->getCrossat() - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
/ 6076.0 / speed*60.0);
checkTcas();
- tgt_altitude_ft = curr->crossat;
+ tgt_altitude_ft = curr->getCrossat();
} else {
use_perf_vs = true;
}
}
- AccelTo(prev->speed);
+ AccelTo(prev->getSpeed());
hdg_lock = alt_lock = true;
- no_roll = prev->on_ground;
+ no_roll = prev->getOn_ground();
}
}
return transponderCode.c_str();
}
+// NOTE: Check whether the new (delayed leg increment code has any effect on this code.
+// Probably not, because it should only be executed after we have already passed the leg incrementing waypoint.
bool FGAIAircraft::loadNextLeg(double distance) {
fp->create (this,
dep,
arr,
- leg,
+ leg+1,
cruiseAlt,
trafficRef->getSpeed(),
_getLatitude(),
// Note that leg has been incremented after creating the current leg, so we should use
// leg numbers here that are one higher than the number that is used to create the leg
- //
+ // NOTE: As of July, 30, 2011, the post-creation leg updating is no longer happening.
+ // Leg numbers are updated only once the aircraft passes the last waypoint created for that legm so I should probably just use
+ // the original leg numbers here!
switch (leg) {
- case 2: // Startup and Push back
+ case 1: // Startup and Push back
if (trafficRef->getDepartureAirport()->getDynamics())
controller = trafficRef->getDepartureAirport()->getDynamics()->getStartupController();
break;
- case 3: // Taxiing to runway
+ case 2: // Taxiing to runway
if (trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork()->exists())
controller = trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork();
break;
- case 4: //Take off tower controller
+ case 3: //Take off tower controller
if (trafficRef->getDepartureAirport()->getDynamics()) {
controller = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
} else {
cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
}
break;
- case 7:
+ case 6:
if (trafficRef->getDepartureAirport()->getDynamics()) {
controller = trafficRef->getArrivalAirport()->getDynamics()->getApproachController();
}
break;
- case 9: // Taxiing for parking
+ case 8: // Taxiing for parking
if (trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork()->exists())
controller = trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork();
break;
}
prevController = controller;
if (controller) {
- controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->routeIndex,
+ controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
_getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
trafficRef->getRadius(), leg, this);
}
//cerr << trafficRef->getCallSign() << " Changing Speed " << endl;
AccelTo(instruction.getSpeed());
} else {
- if (fp) AccelTo(fp->getPreviousWaypoint()->speed);
+ if (fp) AccelTo(fp->getPreviousWaypoint()->getSpeed());
}
}
if (instruction.getChangeHeading ()) {
eraseWaypoints = false;
}
- FGAIFlightPlan::waypoint* prev = 0; // the one behind you
- FGAIFlightPlan::waypoint* curr = 0; // the one ahead
- FGAIFlightPlan::waypoint* next = 0;// the next plus 1
+ FGAIWaypoint* prev = 0; // the one behind you
+ FGAIWaypoint* curr = 0; // the one ahead
+ FGAIWaypoint* next = 0;// the next plus 1
spinCounter = 0;
tempReg = "";
curr = fp->getCurrentWaypoint(); //second waypoint
next = fp->getNextWaypoint(); //third waypoint (might not exist!)
- setLatitude(prev->latitude);
- setLongitude(prev->longitude);
- setSpeed(prev->speed);
- setAltitude(prev->altitude);
+ setLatitude(prev->getLatitude());
+ setLongitude(prev->getLongitude());
+ setSpeed(prev->getSpeed());
+ setAltitude(prev->getAltitude());
- if (prev->speed > 0.0)
- setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
+ if (prev->getSpeed() > 0.0)
+ setHeading(fp->getBearing(prev->getLatitude(), prev->getLongitude(), curr));
else
- setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
+ setHeading(fp->getBearing(curr->getLatitude(), curr->getLongitude(), prev));
// If next doesn't exist, as in incrementally created flightplans for
// AI/Trafficmanager created plans,
if (next)
fp->setLeadDistance(speed, hdg, curr, next);
- if (curr->crossat > -1000.0) //use a calculated descent/climb rate
+ if (curr->getCrossat() > -1000.0) //use a calculated descent/climb rate
{
use_perf_vs = false;
- tgt_vs = (curr->crossat - prev->altitude)
+ tgt_vs = (curr->getCrossat() - prev->getAltitude())
/ (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
- / 6076.0 / prev->speed*60.0);
+ / 6076.0 / prev->getSpeed()*60.0);
checkTcas();
- tgt_altitude_ft = curr->crossat;
+ tgt_altitude_ft = curr->getCrossat();
} else {
use_perf_vs = true;
- tgt_altitude_ft = prev->altitude;
+ tgt_altitude_ft = prev->getAltitude();
}
alt_lock = hdg_lock = true;
- no_roll = prev->on_ground;
+ no_roll = prev->getOn_ground();
if (no_roll) {
Transform(); // make sure aip is initialized.
getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value
* @param curr
* @return
*/
-bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) {
+bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr) {
double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
//cerr << "2" << endl;
double lead_dist = fp->getLeadDistance();
// experimental: Use fabs, because speed can be negative (I hope) during push_back.
- if ((dist_to_go < fabs(10.0* speed)) && (speed < 0) && (tgt_speed < 0) && fp->getCurrentWaypoint()->name == string("PushBackPoint")) {
+ if ((dist_to_go < fabs(10.0* speed)) && (speed < 0) && (tgt_speed < 0) && fp->getCurrentWaypoint()->contains("PushBackPoint")) {
tgt_speed = -(dist_to_go / 10.0);
if (tgt_speed > -0.5) {
tgt_speed = -0.5;
}
- if (fp->getPreviousWaypoint()->speed < tgt_speed) {
- fp->getPreviousWaypoint()->speed = tgt_speed;
+ if (fp->getPreviousWaypoint()->getSpeed() < tgt_speed) {
+ fp->getPreviousWaypoint()->setSpeed(tgt_speed);
}
}
if (lead_dist < fabs(2*speed)) {
*/
//TODO the trafficRef is the right place for the method
-bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now) {
+bool FGAIAircraft::handleAirportEndPoints(FGAIWaypoint* prev, time_t now) {
// prepare routing from one airport to another
FGAirport * dep = trafficRef->getDepartureAirport();
FGAirport * arr = trafficRef->getArrivalAirport();
// This waypoint marks the fact that the aircraft has passed the initial taxi
// departure waypoint, so it can release the parking.
//cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
- if (prev->name == "PushBackPoint") {
+ if (prev->contains("PushBackPoint")) {
dep->getDynamics()->releaseParking(fp->getGate());
AccelTo(0.0);
setTaxiClearanceRequest(true);
}
+ if (prev->contains("legend")) {
+ fp->incrementLeg();
+ }
// This is the last taxi waypoint, and marks the the end of the flight plan
// so, the schedule should update and wait for the next departure time.
- if (prev->name == "END") {
+ if (prev->contains("END")) {
time_t nextDeparture = trafficRef->getDepartureTime();
// make sure to wait at least 20 minutes at parking to prevent "nervous" taxi behavior
if (nextDeparture < (now+1200)) {
*
* @param curr
*/
-void FGAIAircraft::controlHeading(FGAIFlightPlan::waypoint* curr) {
+void FGAIAircraft::controlHeading(FGAIWaypoint* curr) {
double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
//cerr << "Bearing = " << calc_bearing << endl;
if (speed < 0) {
cerr << "calc_bearing is not a finite number : "
<< "Speed " << speed
<< "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
- << "waypoint " << curr->latitude << ", " << curr->longitude << endl;
- cerr << "waypoint name " << curr->name;
+ << "waypoint " << curr->getLatitude() << ", " << curr->getLongitude() << endl;
+ cerr << "waypoint name " << curr->getName();
exit(1); // FIXME
}
}
* @param curr
* @param next
*/
-void FGAIAircraft::controlSpeed(FGAIFlightPlan::waypoint* curr, FGAIFlightPlan::waypoint* next) {
+void FGAIAircraft::controlSpeed(FGAIWaypoint* curr, FGAIWaypoint* next) {
double speed_diff = speed - prevSpeed;
if (fabs(speed_diff) > 10) {
bool FGAIAircraft::reachedEndOfCruise(double &distance) {
- FGAIFlightPlan::waypoint* curr = fp->getCurrentWaypoint();
- if (curr->name == "BOD") {
+ FGAIWaypoint* curr = fp->getCurrentWaypoint();
+ if (curr->getName() == string("BOD")) {
double dist = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
double descentSpeed = (getPerformance()->vDescent() * SG_NM_TO_METER) / 3600.0; // convert from kts to meter/s
double descentRate = (getPerformance()->descentRate() * SG_FEET_TO_METER) / 60.0; // convert from feet/min to meter/s
void FGAIAircraft::resetPositionFromFlightPlan()
{
// the one behind you
- FGAIFlightPlan::waypoint* prev = 0;
+ FGAIWaypoint* prev = 0;
// the one ahead
- FGAIFlightPlan::waypoint* curr = 0;
+ FGAIWaypoint* curr = 0;
// the next plus 1
- FGAIFlightPlan::waypoint* next = 0;
+ FGAIWaypoint* next = 0;
prev = fp->getPreviousWaypoint();
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- setLatitude(prev->latitude);
- setLongitude(prev->longitude);
+ setLatitude(prev->getLatitude());
+ setLongitude(prev->getLongitude());
double tgt_heading = fp->getBearing(curr, next);
setHeading(tgt_heading);
- setAltitude(prev->altitude);
- setSpeed(prev->speed);
+ setAltitude(prev->getAltitude());
+ setSpeed(prev->getSpeed());
}
double FGAIAircraft::getBearing(double crse)
}
time_t FGAIAircraft::checkForArrivalTime(string wptName) {
- FGAIFlightPlan::waypoint* curr = 0;
+ FGAIWaypoint* curr = 0;
curr = fp->getCurrentWaypoint();
double tracklength = fp->checkTrackLength(wptName);
//subclasses to override specific behaviour
bool fpExecutable(time_t now);
void handleFirstWaypoint(void);
- bool leadPointReached(FGAIFlightPlan::waypoint* curr);
- bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
+ bool leadPointReached(FGAIWaypoint* curr);
+ bool handleAirportEndPoints(FGAIWaypoint* prev, time_t now);
bool reachedEndOfCruise(double&);
bool aiTrafficVisible(void);
- void controlHeading(FGAIFlightPlan::waypoint* curr);
- void controlSpeed(FGAIFlightPlan::waypoint* curr,
- FGAIFlightPlan::waypoint* next);
+ void controlHeading(FGAIWaypoint* curr);
+ void controlSpeed(FGAIWaypoint* curr,
+ FGAIWaypoint* next);
void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
using std::cerr;
+FGAIWaypoint::FGAIWaypoint() {
+ latitude = 0;
+ longitude = 0;
+ altitude = 0;
+ speed = 0;
+ crossat = 0;
+ finished = 0;
+ gear_down = 0;
+ flaps_down = 0;
+ on_ground = 0;
+ routeIndex = 0;
+ time_sec = 0;
+ trackLength = 0;
+}
+
+bool FGAIWaypoint::contains(string target) {
+ size_t found = name.find(target);
+ if (found == string::npos)
+ return false;
+ else
+ return true;
+}
+
FGAIFlightPlan::FGAIFlightPlan()
{
rwy = 0;
SGPropertyNode * node = root.getNode("flightplan");
for (i = 0; i < node->nChildren(); i++) {
//cout << "Reading waypoint " << i << endl;
- waypoint* wpt = new waypoint;
+ FGAIWaypoint* wpt = new FGAIWaypoint;
SGPropertyNode * wpt_node = node->getChild(i);
- wpt->name = wpt_node->getStringValue("name", "END");
- wpt->latitude = wpt_node->getDoubleValue("lat", 0);
- wpt->longitude = wpt_node->getDoubleValue("lon", 0);
- wpt->altitude = wpt_node->getDoubleValue("alt", 0);
- wpt->speed = wpt_node->getDoubleValue("ktas", 0);
- wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
- wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
- wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
- wpt->on_ground = wpt_node->getBoolValue("on-ground", false);
- wpt->time_sec = wpt_node->getDoubleValue("time-sec", 0);
- wpt->time = wpt_node->getStringValue("time", "");
-
- if (wpt->name == "END") wpt->finished = true;
- else wpt->finished = false;
+ wpt->setName (wpt_node->getStringValue("name", "END" ));
+ wpt->setLatitude (wpt_node->getDoubleValue("lat", 0 ));
+ wpt->setLongitude (wpt_node->getDoubleValue("lon", 0 ));
+ wpt->setAltitude (wpt_node->getDoubleValue("alt", 0 ));
+ wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0 ));
+ wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000 ));
+ wpt->setGear_down (wpt_node->getBoolValue("gear-down", false ));
+ wpt->setFlaps_down (wpt_node->getBoolValue("flaps-down", false ));
+ wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false ));
+ wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0 ));
+ wpt->setTime (wpt_node->getStringValue("time", "" ));
+
+ if (wpt->getName() == "END") wpt->setFinished(true);
+ else wpt->setFinished(false);
waypoints.push_back( wpt );
}
//waypoints.push_back( init_waypoint );
for (int i = 0; i < node->nChildren(); i++) {
//cout << "Reading waypoint " << i << endl;
- waypoint* wpt = new waypoint;
+ FGAIWaypoint* wpt = new FGAIWaypoint;
SGPropertyNode * wpt_node = node->getChild(i);
- wpt->name = wpt_node->getStringValue("name", "END");
- wpt->latitude = wpt_node->getDoubleValue("lat", 0);
- wpt->longitude = wpt_node->getDoubleValue("lon", 0);
- wpt->altitude = wpt_node->getDoubleValue("alt", 0);
- wpt->speed = wpt_node->getDoubleValue("ktas", 0);
- //wpt->speed = speed;
- wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
- wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
- wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
+ wpt->setName (wpt_node->getStringValue("name", "END" ));
+ wpt->setLatitude (wpt_node->getDoubleValue("lat", 0 ));
+ wpt->setLongitude (wpt_node->getDoubleValue("lon", 0 ));
+ wpt->setAltitude (wpt_node->getDoubleValue("alt", 0 ));
+ wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0 ));
+ wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000 ));
+ wpt->setGear_down (wpt_node->getBoolValue("gear-down", false ));
+ wpt->setFlaps_down (wpt_node->getBoolValue("flaps-down", false ));
- if (wpt->name == "END") wpt->finished = true;
- else wpt->finished = false;
+ if (wpt->getName() == "END") wpt->setFinished(true);
+ else wpt->setFinished(false);
waypoints.push_back(wpt);
} // of node loop
wpt_iterator = waypoints.begin();
}
-FGAIFlightPlan::waypoint* const
-FGAIFlightPlan::getPreviousWaypoint( void ) const
+FGAIWaypoint* const FGAIFlightPlan::getPreviousWaypoint( void ) const
{
if (wpt_iterator == waypoints.begin()) {
return 0;
}
}
-FGAIFlightPlan::waypoint* const
-FGAIFlightPlan::getCurrentWaypoint( void ) const
+FGAIWaypoint* const FGAIFlightPlan::getCurrentWaypoint( void ) const
{
return *wpt_iterator;
}
-FGAIFlightPlan::waypoint* const
-FGAIFlightPlan::getNextWaypoint( void ) const
+FGAIWaypoint* const FGAIFlightPlan::getNextWaypoint( void ) const
{
wpt_vector_iterator i = waypoints.end();
i--; // end() points to one element after the last one.
// gives distance in feet from a position to a waypoint
-double FGAIFlightPlan::getDistanceToGo(double lat, double lon, waypoint* wp) const{
+double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const{
return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat),
- SGGeod::fromDeg(wp->longitude, wp->latitude));
+ SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
}
// sets distance in feet from a lead point to the current waypoint
void FGAIFlightPlan::setLeadDistance(double speed, double bearing,
- waypoint* current, waypoint* next){
+ FGAIWaypoint* current, FGAIWaypoint* next){
double turn_radius;
// Handle Ground steering
// At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn
}
-double FGAIFlightPlan::getBearing(waypoint* first, waypoint* second) const{
- return getBearing(first->latitude, first->longitude, second);
+double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const{
+ return getBearing(first->getLatitude(), first->getLongitude(), second);
}
-double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp) const{
+double FGAIFlightPlan::getBearing(double lat, double lon, FGAIWaypoint* wp) const{
return SGGeodesy::courseDeg(SGGeod::fromDeg(lon, lat),
- SGGeod::fromDeg(wp->longitude, wp->latitude));
+ SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
}
void FGAIFlightPlan::deleteWaypoints()
return;
else
{
- waypoint *wpt = new waypoint;
+ FGAIWaypoint *wpt = new FGAIWaypoint;
wpt_vector_iterator i = waypoints.end();
i--;
- wpt->name = (*i)->name;
- wpt->latitude = (*i)->latitude;
- wpt->longitude = (*i)->longitude;
- wpt->altitude = (*i)->altitude;
- wpt->speed = (*i)->speed;
- wpt->crossat = (*i)->crossat;
- wpt->gear_down = (*i)->gear_down;
- wpt->flaps_down= (*i)->flaps_down;
- wpt->finished = false;
- wpt->on_ground = (*i)->on_ground;
+ wpt->setName ( (*i)->getName() );
+ wpt->setLatitude ( (*i)->getLatitude() );
+ wpt->setLongitude ( (*i)->getLongitude() );
+ wpt->setAltitude ( (*i)->getAltitude() );
+ wpt->setSpeed ( (*i)->getSpeed() );
+ wpt->setCrossat ( (*i)->getCrossat() );
+ wpt->setGear_down ( (*i)->getGear_down() );
+ wpt->setFlaps_down ( (*i)->getFlaps_down() );
+ wpt->setFinished ( false );
+ wpt->setOn_ground ( (*i)->getOn_ground() );
//cerr << "Recycling waypoint " << wpt->name << endl;
deleteWaypoints();
waypoints.push_back(wpt);
int FGAIFlightPlan::getRouteIndex(int i) {
if ((i > 0) && (i < (int)waypoints.size())) {
- return waypoints[i]->routeIndex;
+ return waypoints[i]->getRouteIndex();
}
else
return 0;
wpt_vector_iterator wptvec = waypoints.begin();
wptvec++;
wptvec++;
- while ((wptvec != waypoints.end()) && ((*wptvec)->name != wptName)) {
- trackDistance += (*wptvec)->trackLength;
+ while ((wptvec != waypoints.end()) && (!((*wptvec)->contains(wptName)))) {
+ trackDistance += (*wptvec)->getTrackLength();
wptvec++;
}
if (wptvec == waypoints.end()) {
class FGAirport;
class SGGeod;
-class FGAIFlightPlan {
-
-public:
-
- typedef struct {
+class FGAIWaypoint {
+private:
std::string name;
double latitude;
double longitude;
bool on_ground;
int routeIndex; // For AI/ATC purposes;
double time_sec;
- double trackLength; // distance from previous waypoint (for AI purposes);
+ double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
std::string time;
- } waypoint;
+public:
+ FGAIWaypoint();
+ ~FGAIWaypoint() {};
+ void setName (std::string nam) { name = nam; };
+ void setLatitude (double lat) { latitude = lat; };
+ void setLongitude (double lon) { longitude = lon; };
+ void setAltitude (double alt) { altitude = alt; };
+ void setSpeed (double spd) { speed = spd; };
+ void setCrossat (double val) { crossat = val; };
+ void setFinished (bool fin) { finished = fin; };
+ void setGear_down (bool grd) { gear_down = grd; };
+ void setFlaps_down (bool fld) { flaps_down = fld; };
+ void setOn_ground (bool grn) { on_ground = grn; };
+ void setRouteIndex (int rte) { routeIndex = rte; };
+ void setTime_sec (double ts ) { time_sec = ts; };
+ void setTrackLength (double tl ) { trackLength = tl; };
+ void setTime (std::string tme) { time = tme; };
+
+ bool contains(std::string name);
+
+ std::string getName () { return name; };
+ double getLatitude () { return latitude; };
+ double getLongitude () { return longitude; };
+ double getAltitude () { return altitude; };
+ double getSpeed () { return speed; };
+
+ double getCrossat () { return crossat; };
+ bool getGear_down () { return gear_down; };
+ bool getFlaps_down () { return flaps_down; };
+ bool getOn_ground () { return on_ground; };
+ int getRouteIndex () { return routeIndex; };
+ bool isFinished () { return finished; };
+ double getTime_sec () { return time_sec; };
+ double getTrackLength() { return trackLength; };
+ std::string getTime () { return time; };
+
+ };
+
+
+class FGAIFlightPlan {
+
+public:
+
FGAIFlightPlan();
FGAIFlightPlan(const std::string& filename);
FGAIFlightPlan(FGAIAircraft *,
const std::string& airline);
~FGAIFlightPlan();
- waypoint* const getPreviousWaypoint( void ) const;
- waypoint* const getCurrentWaypoint( void ) const;
- waypoint* const getNextWaypoint( void ) const;
+ FGAIWaypoint* const getPreviousWaypoint( void ) const;
+ FGAIWaypoint* const getCurrentWaypoint( void ) const;
+ FGAIWaypoint* const getNextWaypoint( void ) const;
void IncrementWaypoint( bool erase );
void DecrementWaypoint( bool erase );
- double getDistanceToGo(double lat, double lon, waypoint* wp) const;
+ double getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const;
int getLeg () const { return leg;};
- void setLeadDistance(double speed, double bearing, waypoint* current, waypoint* next);
+ void setLeadDistance(double speed, double bearing, FGAIWaypoint* current, FGAIWaypoint* next);
void setLeadDistance(double distance_ft);
double getLeadDistance( void ) const {return lead_distance;}
- double getBearing(waypoint* previous, waypoint* next) const;
- double getBearing(double lat, double lon, waypoint* next) const;
+ double getBearing(FGAIWaypoint* previous, FGAIWaypoint* next) const;
+ double getBearing(double lat, double lon, FGAIWaypoint* next) const;
double checkTrackLength(std::string wptName);
time_t getStartTime() const { return start_time; }
time_t getArrivalTime() const { return arrivalTime; }
std::string getRunway() { return activeRunway; }
bool isActive(time_t time) {return time >= this->getStartTime();}
+ void incrementLeg() { leg++;};
+
void setRunway(std::string rwy) { activeRunway = rwy; };
std::string getRunwayClassFromTrafficType(std::string fltType);
- void addWaypoint(waypoint* wpt) { waypoints.push_back(wpt); };
+ void addWaypoint(FGAIWaypoint* wpt) { waypoints.push_back(wpt); };
void setName(std::string n) { name = n; };
std::string getName() { return name; };
void setSID(FGAIFlightPlan* fp) { sid = fp;};
FGAIFlightPlan* getSID() { return sid; };
+ FGAIWaypoint *getWayPoint(int i) { return waypoints[i]; };
+ FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
private:
FGRunway* rwy;
FGAIFlightPlan *sid;
- typedef std::vector <waypoint*> wpt_vector_type;
+ typedef std::vector <FGAIWaypoint*> wpt_vector_type;
typedef wpt_vector_type::const_iterator wpt_vector_iterator;
double getTurnRadius(double, bool);
- waypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
- waypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
- waypoint* cloneWithPos(FGAIAircraft *, waypoint* aWpt, const std::string& aName, const SGGeod& aPos);
- waypoint* clone(waypoint* aWpt);
+ FGAIWaypoint* createOnGround(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
+ FGAIWaypoint* createInAir(FGAIAircraft *, const std::string& aName, const SGGeod& aPos, double aElev, double aSpeed);
+ FGAIWaypoint* cloneWithPos(FGAIAircraft *, FGAIWaypoint* aWpt, const std::string& aName, const SGGeod& aPos);
+ FGAIWaypoint* clone(FGAIWaypoint* aWpt);
//void createCruiseFallback(bool, FGAirport*, FGAirport*, double, double, double, double);
wpt_vector_iterator getFirstWayPoint() { return waypoints.begin(); };
wpt_vector_iterator getLastWayPoint() { return waypoints.end(); };
bool isValidPlan() { return isValid; };
-};
+};
#endif // _FG_AIFLIGHTPLAN_HXX
# include <config.h>
#endif
+
#include "AIFlightPlan.hxx"
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/props/props.hxx>
" this is probably an internal program error");
}
wpt_iterator = waypoints.begin() + currWpt;
- leg++;
+ //don't increment leg right away, but only once we pass the actual last waypoint that was created.
+ // to do so, mark the last waypoint with a special status flag
+ if (retVal) {
+ waypoints.back()->setName( waypoints.back()->getName() + string("legend"));
+ // "It's pronounced Leg-end" (Roger Glover (Deep Purple): come Hell or High Water DvD, 1993)
+ }
+
+
+ //leg++;
return retVal;
}
-FGAIFlightPlan::waypoint *
- FGAIFlightPlan::createOnGround(FGAIAircraft * ac,
+FGAIWaypoint * FGAIFlightPlan::createOnGround(FGAIAircraft * ac,
const std::string & aName,
const SGGeod & aPos, double aElev,
double aSpeed)
{
- waypoint *wpt = new waypoint;
- wpt->name = aName;
- wpt->longitude = aPos.getLongitudeDeg();
- wpt->latitude = aPos.getLatitudeDeg();
- wpt->altitude = aElev;
- wpt->speed = aSpeed;
- wpt->crossat = -10000.1;
- wpt->gear_down = true;
- wpt->flaps_down = true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = 0;
+ FGAIWaypoint *wpt = new FGAIWaypoint;
+ wpt->setName (aName );
+ wpt->setLongitude (aPos.getLongitudeDeg() );
+ wpt->setLatitude (aPos.getLatitudeDeg() );
+ wpt->setAltitude (aElev );
+ wpt->setSpeed (aSpeed );
+ wpt->setCrossat (-10000.1 );
+ wpt->setGear_down (true );
+ wpt->setFlaps_down (true );
+ wpt->setFinished (false );
+ wpt->setOn_ground (true );
+ wpt->setRouteIndex (0 );
return wpt;
}
-FGAIFlightPlan::waypoint *
- FGAIFlightPlan::createInAir(FGAIAircraft * ac,
+FGAIWaypoint * FGAIFlightPlan::createInAir(FGAIAircraft * ac,
const std::string & aName,
const SGGeod & aPos, double aElev,
double aSpeed)
{
- waypoint *wpt = new waypoint;
- wpt->name = aName;
- wpt->longitude = aPos.getLongitudeDeg();
- wpt->latitude = aPos.getLatitudeDeg();
- wpt->altitude = aElev;
- wpt->speed = aSpeed;
- wpt->crossat = -10000.1;
- wpt->gear_down = false;
- wpt->flaps_down = false;
- wpt->finished = false;
- wpt->on_ground = false;
- wpt->routeIndex = 0;
+ FGAIWaypoint * wpt = createOnGround(ac, aName, aPos, aElev, aSpeed);
+ wpt->setGear_down (false );
+ wpt->setFlaps_down (false );
+ wpt->setOn_ground (false );
return wpt;
}
-FGAIFlightPlan::waypoint *
- FGAIFlightPlan::cloneWithPos(FGAIAircraft * ac, waypoint * aWpt,
- const std::string & aName,
- const SGGeod & aPos)
+FGAIWaypoint * FGAIFlightPlan::clone(FGAIWaypoint * aWpt)
{
- waypoint *wpt = new waypoint;
- wpt->name = aName;
- wpt->longitude = aPos.getLongitudeDeg();
- wpt->latitude = aPos.getLatitudeDeg();
-
- wpt->altitude = aWpt->altitude;
- wpt->speed = aWpt->speed;
- wpt->crossat = aWpt->crossat;
- wpt->gear_down = aWpt->gear_down;
- wpt->flaps_down = aWpt->flaps_down;
- wpt->finished = aWpt->finished;
- wpt->on_ground = aWpt->on_ground;
- wpt->routeIndex = 0;
+ FGAIWaypoint *wpt = new FGAIWaypoint;
+ wpt->setName ( aWpt->getName () );
+ wpt->setLongitude ( aWpt->getLongitude() );
+ wpt->setLatitude ( aWpt->getLatitude() );
+ wpt->setAltitude ( aWpt->getAltitude() );
+ wpt->setSpeed ( aWpt->getSpeed() );
+ wpt->setCrossat ( aWpt->getCrossat() );
+ wpt->setGear_down ( aWpt->getGear_down() );
+ wpt->setFlaps_down ( aWpt->getFlaps_down() );
+ wpt->setFinished ( aWpt->isFinished() );
+ wpt->setOn_ground ( aWpt->getOn_ground() );
+ wpt->setRouteIndex ( 0 );
return wpt;
}
-FGAIFlightPlan::waypoint * FGAIFlightPlan::clone(waypoint * aWpt)
+
+FGAIWaypoint * FGAIFlightPlan::cloneWithPos(FGAIAircraft * ac, FGAIWaypoint * aWpt,
+ const std::string & aName,
+ const SGGeod & aPos)
{
- waypoint *wpt = new waypoint;
- wpt->name = aWpt->name;
- wpt->longitude = aWpt->longitude;
- wpt->latitude = aWpt->latitude;
-
- wpt->altitude = aWpt->altitude;
- wpt->speed = aWpt->speed;
- wpt->crossat = aWpt->crossat;
- wpt->gear_down = aWpt->gear_down;
- wpt->flaps_down = aWpt->flaps_down;
- wpt->finished = aWpt->finished;
- wpt->on_ground = aWpt->on_ground;
- wpt->routeIndex = 0;
+ FGAIWaypoint *wpt = clone(aWpt);
+ wpt->setName ( aName );
+ wpt->setLongitude ( aPos.getLongitudeDeg () );
+ wpt->setLatitude ( aPos.getLatitudeDeg () );
return wpt;
}
+
void FGAIFlightPlan::createDefaultTakeoffTaxi(FGAIAircraft * ac,
FGAirport * aAirport,
FGRunway * aRunway)
SGGeod runwayTakeoff = aRunway->pointOnCenterline(5.0);
double airportElev = aAirport->getElevation();
- waypoint *wpt;
+ FGAIWaypoint *wpt;
wpt =
createOnGround(ac, "Airport Center", aAirport->geod(), airportElev,
ac->getPerformance()->vTaxi());
snprintf(buffer, 10, "%d", node);
FGTaxiNode *tn =
apt->getDynamics()->getGroundNetwork()->findNode(node);
- waypoint *wpt =
+ FGAIWaypoint *wpt =
createOnGround(ac, buffer, tn->getGeod(), apt->getElevation(),
ac->getPerformance()->vTaxi());
- wpt->routeIndex = route;
+ wpt->setRouteIndex(route);
waypoints.push_back(wpt);
}
return true;
FGAirport * aAirport)
{
SGGeod lastWptPos =
- SGGeod::fromDeg(waypoints.back()->longitude,
- waypoints.back()->latitude);
+ SGGeod::fromDeg(waypoints.back()->getLongitude(),
+ waypoints.back()->getLatitude());
double airportElev = aAirport->getElevation();
- waypoint *wpt;
+ FGAIWaypoint *wpt;
wpt =
createOnGround(ac, "Runway Exit", lastWptPos, airportElev,
ac->getPerformance()->vTaxi());
acType, airline);
SGGeod lastWptPos =
- SGGeod::fromDeg(waypoints.back()->longitude,
- waypoints.back()->latitude);
+ SGGeod::fromDeg(waypoints.back()->getLongitude(),
+ waypoints.back()->getLatitude());
FGGroundNetwork *gn = apt->getDynamics()->getGroundNetwork();
// Find a route from runway end to parking/gate.
char buffer[10];
snprintf(buffer, 10, "%d", node);
FGTaxiNode *tn = gn->findNode(node);
- waypoint *wpt =
+ FGAIWaypoint *wpt =
createOnGround(ac, buffer, tn->getGeod(), apt->getElevation(),
ac->getPerformance()->vTaxi());
- wpt->routeIndex = route;
+ wpt->setRouteIndex(route);
waypoints.push_back(wpt);
}
return true;
(vRotateMetric * vRotateMetric -
vTaxiMetric * vTaxiMetric) / (2 * accelMetric);
//cerr << "Using " << accelDistance << " " << accelMetric << " " << vRotateMetric << endl;
- waypoint *wpt;
+ FGAIWaypoint *wpt;
// Get the current active runway, based on code from David Luff
// This should actually be unified and extended to include
// Preferential runway use schema's
wpt =
createOnGround(ac, "rotate", accelPoint, airportElev + 1000,
vTakeoff * 1.1);
- wpt->on_ground = false;
+ wpt->setOn_ground(false);
waypoints.push_back(wpt);
wpt = cloneWithPos(ac, wpt, "3000 ft", rwy->end());
- wpt->altitude = airportElev + 3000;
+ wpt->setAltitude(airportElev + 3000);
waypoints.push_back(wpt);
// Finally, add two more waypoints, so that aircraft will remain under
// Tower control until they have reached the 3000 ft climb point
SGGeod pt = rwy->pointOnCenterline(5000 + rwy->lengthM() * 0.5);
wpt = cloneWithPos(ac, wpt, "5000 ft", pt);
- wpt->altitude = airportElev + 5000;
+ wpt->setAltitude(airportElev + 5000);
waypoints.push_back(wpt);
return true;
}
FGAirport * apt, double speed, double alt,
const string & fltType)
{
- waypoint *wpt;
+ FGAIWaypoint *wpt;
// bool planLoaded = false;
string fPLName;
double vClimb = ac->getPerformance()->vClimb();
} else {
SGGeod climb1 = rwy->pointOnCenterline(10 * SG_NM_TO_METER);
wpt = createInAir(ac, "10000ft climb", climb1, vClimb, 10000);
- wpt->gear_down = true;
- wpt->flaps_down = true;
+ wpt->setGear_down(true);
+ wpt->setFlaps_down(true);
waypoints.push_back(wpt);
SGGeod climb2 = rwy->pointOnCenterline(20 * SG_NM_TO_METER);
wpt = cloneWithPos(ac, wpt, "18000ft climb", climb2);
- wpt->altitude = 18000;
+ wpt->setAltitude(18000);
waypoints.push_back(wpt);
}
return true;
double requiredDistance)
{
bool reposition = false;
- waypoint *wpt;
+ FGAIWaypoint *wpt;
double vDescent = ac->getPerformance()->vDescent();
double vApproach = ac->getPerformance()->vApproach();
SGGeodesy::direct(origin, azimuth, currentDist, result, dummyAz2);
snprintf(buffer, 16, "descent%03d", i);
wpt = createInAir(ac, buffer, result, currentAltitude, vDescent);
- wpt->crossat = currentAltitude;
- wpt->trackLength = (newDistance / nPoints);
+ wpt->setCrossat(currentAltitude);
+ wpt->setTrackLength((newDistance / nPoints));
waypoints.push_back(wpt);
//cerr << "Track Length : " << wpt->trackLength;
//cerr << " Position : " << result.getLatitudeDeg() << " " << result.getLongitudeDeg() << " " << currentAltitude << endl;
initialTurnRadius, result, dummyAz2);
snprintf(buffer, 16, "turn%03d", i);
wpt = createInAir(ac, buffer, result, currentAltitude, vDescent);
- wpt->crossat = currentAltitude;
- wpt->trackLength = trackLength;
+ wpt->setCrossat(currentAltitude);
+ wpt->setTrackLength(trackLength);
//cerr << "Track Length : " << wpt->trackLength;
waypoints.push_back(wpt);
//cerr << " Position : " << result.getLatitudeDeg() << " " << result.getLongitudeDeg() << " " << currentAltitude << endl;
snprintf(buffer, 16, "final%03d", i);
result = rwy->pointOnCenterline((-distanceOut) + currentDist);
wpt = createInAir(ac, buffer, result, currentAltitude, vApproach);
- wpt->crossat = currentAltitude;
- wpt->trackLength = (distanceOut / nPoints);
+ wpt->setCrossat(currentAltitude);
+ wpt->setTrackLength((distanceOut / nPoints));
// account for the extra distance due to an extended downwind leg
if (i == 1) {
- wpt->trackLength += distanceCovered;
+ wpt->setTrackLength(wpt->getTrackLength() + distanceCovered);
}
//cerr << "Track Length : " << wpt->trackLength;
waypoints.push_back(wpt);
//rwy = apt->getRunwayByIdent(activeRunway);
- waypoint *wpt;
+ FGAIWaypoint *wpt;
double aptElev = apt->getElevation();
SGGeod coord;
snprintf(buffer, 12, "wpt%d", i);
coord = rwy->pointOnCenterline(rwy->lengthM() * (i / 10.0));
wpt = createOnGround(ac, buffer, coord, aptElev, (vTouchdown / i));
- wpt->crossat = apt->getElevation();
+ wpt->setCrossat(apt->getElevation());
waypoints.push_back(wpt);
}
bool FGAIFlightPlan::createParking(FGAIAircraft * ac, FGAirport * apt,
double radius)
{
- waypoint *wpt;
+ FGAIWaypoint *wpt;
double aptElev = apt->getElevation();
double lat = 0.0, lat2 = 0.0;
double lon = 0.0, lon2 = 0.0;
double alt, const string& fltType)
{
double vCruise = ac->getPerformance()->vCruise();
- waypoint *wpt;
+ FGAIWaypoint *wpt;
wpt = createInAir(ac, "Cruise", SGGeod::fromDeg(longitude, latitude), alt, vCruise);
waypoints.push_back(wpt);
return false;
char buffer[10];
snprintf (buffer, 10, "%d", gateId);
+ SGGeod coord = coord.fromDeg(lon, lat);
//FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
- waypoint *wpt;
- wpt = new waypoint;
- wpt->name = string(buffer); // fixme: should be the name of the taxiway
- wpt->latitude = lat;
- wpt->longitude = lon;
- // Elevation is currently disregarded when on_ground is true
- // because the AIModel obtains a periodic ground elevation estimate.
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiBackward;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = -1;
+ FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
+ wpt->setRouteIndex(-1);
waypoints.push_back(wpt);
}
//cerr << "Success : GateId = " << gateId << endl;
pushBackRoute = parking->getPushBackRoute();
- if ((pushBackNode > 0) && (pushBackRoute == 0)) {
+ if ((pushBackNode > 0) && (pushBackRoute == 0)) { // Load the already established route for this gate
int node, rte;
FGTaxiRoute route;
//cerr << "Creating push-back for " << gateId << " (" << parking->getName() << ") using push-back point " << pushBackNode << endl;
SG_LOG(SG_GENERAL, SG_WARN, "Using " << pushBackNode);
}
pushBackRoute->first();
- waypoint *wpt;
while(pushBackRoute->next(&node, &rte))
{
//FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findSegment(node)->getEnd();
snprintf (buffer, 10, "%d", node);
FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
//ids.pop_back();
- wpt = new waypoint;
- wpt->name = string(buffer); // fixme: should be the name of the taxiway
- wpt->latitude = tn->getLatitude();
- wpt->longitude = tn->getLongitude();
- // Elevation is currently disregarded when on_ground is true
- // because the AIModel obtains a periodic ground elevation estimate.
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiBackward;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = rte;
+ //wpt = new waypoint;
+ SGGeod coord = coord.fromDeg(tn->getLongitude(), tn->getLatitude());
+ FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiBackward);
+
+ wpt->setRouteIndex(rte);
waypoints.push_back(wpt);
}
// some special considerations for the last point:
- wpt->name = string("PushBackPoint");
- wpt->speed = vTaxi;
- //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) {
- // cerr << "Waypoint Name: " << (*i)->name << endl;
- //}
- } else {
- /*
- string rwyClass = getRunwayClassFromTrafficType(fltType);
-
- // Only set this if it hasn't been set by ATC already.
- if (activeRunway.empty()) {
- //cerr << "Getting runway for " << ac->getTrafficRef()->getCallSign() << " at " << apt->getId() << endl;
- double depHeading = ac->getTrafficRef()->getCourse();
- dep->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
- depHeading);
- }
- rwy = dep->getRunwayByIdent(activeRunway);
- SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0);
-
- FGGroundNetwork *gn = dep->getDynamics()->getGroundNetwork();
- if (!gn->exists()) {
- createDefaultTakeoffTaxi(ac, dep, rwy);
- return true;
- }
- int runwayId = gn->findNearestNode(runwayTakeoff);
- int node = 0;
- // Find out which node to start from
- FGParking *park = dep->getDynamics()->getParking(gateId);
- if (park) {
- node = park->getPushBackPoint();
- }
-
- if (node == -1) {
- node = gateId;
- }
- // HAndle case where parking doens't have a node
- if ((node == 0) && park) {
- if (firstFlight) {
- node = gateId;
- } else {
- node = gateId;
- }
- }
- //delete taxiRoute;
- //taxiRoute = new FGTaxiRoute;
- FGTaxiRoute tr = gn->findShortestRoute(node, runwayId);
- int route;
- FGTaxiNode *tn;
- waypoint *wpt;
- int nr = 0;
- cerr << "Creating taxiroute from gate: " << gateId << " at " << dep->getId() << endl;
- while (tr.next(&node, &route) && (nr++ < 3)) {
- char buffer[10];
- snprintf(buffer, 10, "%d", node);
- tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
- wpt = createOnGround(ac, buffer, tn->getGeod(), dep->getElevation(),
- vTaxiReduced);
- wpt->routeIndex = route;
- waypoints.push_back(wpt);
- }
- wpt->name = "PushBackPoint";
- lastNodeVisited = tn->getIndex();
- //FGTaxiNode *firstNode = findNode(gateId);
- //FGTaxiNode *lastNode = findNode(runwayId);
- //cerr << "Creating direct forward departure route fragment" << endl;
- */
+ waypoints.back()->setName(string("PushBackPoint"));
+ waypoints.back()->setSpeed(vTaxi);
+ } else { // In case of a push forward departure...
double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
- waypoint *wpt;
- geo_direct_wgs_84 ( 0, lat, lon, heading,
- 2, &lat2, &lon2, &az2 );
- wpt = new waypoint;
- wpt->name = "park2";
- wpt->latitude = lat2;
- wpt->longitude = lon2;
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiReduced;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = 0;
- waypoints.push_back(wpt);
-
- geo_direct_wgs_84 ( 0, lat, lon, heading,
- 4, &lat2, &lon2, &az2 );
- wpt = new waypoint;
- wpt->name = "name";
- wpt->latitude = lat2;
- wpt->longitude = lon2;
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiReduced;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = 0;
- waypoints.push_back(wpt);
//cerr << "Creating final push forward point for gate " << gateId << endl;
FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(gateId);
SG_LOG(SG_GENERAL, SG_ALERT, "No valid taxinode found");
exit(1);
}
- wpt = new waypoint;
- wpt->name = "PushBackPoint";
- wpt->latitude = tn->getLatitude();
- wpt->longitude = tn->getLongitude();
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiReduced;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = (*ts)->getIndex();
- waypoints.push_back(wpt);
+ double distance = (*ts)->getLength();
+ cerr << "Length of push forward route = " << distance << " and heading is " << heading << endl;
+ lat2 = tn->getLatitude();
+ lon2 = tn->getLongitude();
+
+ for (int i = 1; i < 10; i++) {
+ geo_direct_wgs_84 ( 0, lat, lon, heading,
+ ((i / 10.0) * distance), &lat2, &lon2, &az2 );
+ char buffer[16];
+ snprintf(buffer, 16, "pushback-%02d", i);
+ SGGeod coord = coord.fromDeg(lon2, lat2);
+ cerr << i << endl;
+ FGAIWaypoint *wpt = createOnGround(ac, string(buffer), coord, dep->getElevation(), vTaxiReduced);
+
+ wpt->setRouteIndex((*ts)->getIndex());
+ waypoints.push_back(wpt);
+ }
+ cerr << "Done " << endl;
+ waypoints.back()->setName(string("PushBackPoint"));
+ cerr << "Done assinging new name" << endl;
}
-
}
return true;
}
heading += 180.0;
if (heading > 360)
- heading -= 360;
- waypoint *wpt = new waypoint;
- wpt->name = "park";
- wpt->latitude = lat;
- wpt->longitude = lon;
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiBackward;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
+ heading -= 360;
+
+ SGGeod coord = coord.fromDeg(lon, lat);
+ FGAIWaypoint *wpt = createOnGround(ac, string("park"), coord, dep->getElevation(), vTaxiBackward);
waypoints.push_back(wpt);
geo_direct_wgs_84 ( 0, lat, lon, heading,
10,
&lat2, &lon2, &az2 );
- wpt = new waypoint;
- wpt->name = "park2";
- wpt->latitude = lat2;
- wpt->longitude = lon2;
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiBackward;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = 0;
+ coord = coord.fromDeg(lon2, lat2);
+ wpt = createOnGround(ac, string("park2"), coord, dep->getElevation(), vTaxiBackward);
+
waypoints.push_back(wpt);
+
geo_direct_wgs_84 ( 0, lat, lon, heading,
2.2*radius,
&lat2, &lon2, &az2 );
- wpt = new waypoint;
- wpt->name = "taxiStart";
- wpt->latitude = lat2;
- wpt->longitude = lon2;
- wpt->altitude = dep->getElevation();
- wpt->speed = vTaxiReduced;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- wpt->routeIndex = 0;
+ coord = coord.fromDeg(lon2, lat2);
+ wpt = createOnGround(ac, string("taxiStart"), coord, dep->getElevation(), vTaxiReduced);
waypoints.push_back(wpt);
+
}
} else {
- if (prev->altitude == 0 || curr->altitude == 0) return false;
+ if (prev->getAltitude() == 0 || curr->getAltitude() == 0) return false;
static double distance;
static double d_alt;
if (_new_waypoint){
//cout << "new waypoint, calculating pitch " << endl;
- curr_alt = curr->altitude;
- prev_alt = prev->altitude;
+ curr_alt = curr->getAltitude();
+ prev_alt = prev->getAltitude();
//cout << "prev_alt" <<prev_alt << endl;
d_alt = (curr_alt - prev_alt) * SG_METER_TO_FEET;
//_elevation = prev->altitude;
- distance = SGGeodesy::distanceM(SGGeod::fromDeg(prev->longitude, prev->latitude),
- SGGeod::fromDeg(curr->longitude, curr->latitude));
+ distance = SGGeodesy::distanceM(SGGeod::fromDeg(prev->getLongitude(), prev->getLatitude()),
+ SGGeod::fromDeg(curr->getLongitude(), curr->getLatitude()));
_pitch = atan2(d_alt, distance * SG_METER_TO_FEET) * SG_RADIANS_TO_DEGREES;
//cout << "new waypoint, calculating pitch " << _pitch <<
// " " << _pitch_offset << " " << _elevation <<endl;
}
double distance_to_go = SGGeodesy::distanceM(SGGeod::fromDeg(pos.getLongitudeDeg(), pos.getLatitudeDeg()),
- SGGeod::fromDeg(curr->longitude, curr->latitude));
+ SGGeod::fromDeg(curr->getLongitude(), curr->getLatitude()));
/*cout << "tunnel " << _tunnel
<< " distance prev & curr " << prev->name << " " << curr->name << " " << distance * SG_METER_TO_FEET
double count = 0;
string parent_next_name =_selected_ac->getStringValue("waypoint/name-next");
- while(fp->getNextWaypoint() != 0 && fp->getNextWaypoint()->name != "END" && count < 5){
+ while(fp->getNextWaypoint() != 0 && fp->getNextWaypoint()->getName() != "END" && count < 5){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<<" advancing waypoint to: " << parent_next_name);
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " not setting waypoint already at: " << fp->getNextWaypoint()->name);
+ << " not setting waypoint already at: " << fp->getNextWaypoint()->getName());
return;
}
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " waypoint set to: " << fp->getNextWaypoint()->name);
+ << " waypoint set to: " << fp->getNextWaypoint()->getName());
return;
}
}// end while loop
- while(fp->getPreviousWaypoint() != 0 && fp->getPreviousWaypoint()->name != "END"
+ while(fp->getPreviousWaypoint() != 0 && fp->getPreviousWaypoint()->getName() != "END"
&& count > -10){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " retreating waypoint to: " << parent_next_name
- << " at: " << fp->getNextWaypoint()->name);
+ << " at: " << fp->getNextWaypoint()->getName());
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " not setting waypoint already at:" << fp->getNextWaypoint()->name );
+ << " not setting waypoint already at:" << fp->getNextWaypoint()->getName() );
return;
}
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " waypoint set to: " << fp->getNextWaypoint()->name);
+ << " waypoint set to: " << fp->getNextWaypoint()->getName());
return;
}
}
if(_parent == ""){
- AccelTo(prev->speed);
+ AccelTo(prev->getSpeed());
_dt_count = 0;
return;
}
bool parent_waiting = _selected_ac->getBoolValue("waypoint/waiting");
//bool parent_restart = _selected_ac->getBoolValue("controls/restart");
- if (parent_next_name == "END" && fp->getNextWaypoint()->name != "END" ){
+ if (parent_next_name == "END" && fp->getNextWaypoint()->getName() != "END" ){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " setting END: getting new waypoints ");
AdvanceFP();
AdvanceFP();
setWPNames();
_waiting = true;
- } else if (parent_next_name != "WAIT" && fp->getNextWaypoint()->name == "WAIT"){
+ } else if (parent_next_name != "WAIT" && fp->getNextWaypoint()->getName() == "WAIT"){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " wait done: getting new waypoints ");
_waiting = false;
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name == "WAITUNTIL" || next->name == "WAIT"
- || next->name == "END"){
+ if (next->getName() == "WAITUNTIL" || next->getName() == "WAIT"
+ || next->getName() == "END"){
} else {
prev = curr;
fp->IncrementWaypoint(false);
void FGAIShip::setWPNames() {
if (prev != 0)
- setPrevName(prev->name);
+ setPrevName(prev->getName());
else
setPrevName("");
if (curr != 0)
- setCurrName(curr->name);
+ setCurrName(curr->getName());
else{
setCurrName("");
SG_LOG(SG_GENERAL, SG_ALERT, "AIShip: current wp name error" );
}
if (next != 0)
- setNextName(next->name);
+ setNextName(next->getName());
else
setNextName("");
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->name);
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->name);
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->name);
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: prev wp name " << prev->getName());
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: current wp name " << curr->getName());
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: next wp name " << next->getName());
}
// check to see if we've reached the point for our next turn
// if the range to the waypoint is less than the calculated turn
// radius we can start the turn to the next leg
- _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
+ _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->getLatitude(), curr->getLongitude());
_range_rate = (_wp_range - _old_range) / _dt_count;
double sp_turn_radius_nm = _sp_turn_radius_ft / 6076.1155;
// we need to try to identify a _missed waypoint
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name == "WAITUNTIL" || next->name == "WAIT"
- || next->name == "END" || next->name == "TUNNEL")
+ if (next->getName() == "WAITUNTIL" || next->getName() == "WAIT"
+ || next->getName() == "END" || next->getName() == "TUNNEL")
return;
prev = curr;
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
setWPNames();
- _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
+ _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->getLatitude(), curr->getLongitude());
_old_range = _wp_range;
_range_rate = 0;
_new_waypoint = true;
_missed_count = 0;
_lead_angle = 0;
- AccelTo(prev->speed);
+ AccelTo(prev->getSpeed());
} else if (_restart){
SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " Flightplan restarting ");
_missed_count = 0;
} else if (_next_name == "WAIT") {
- if (_wait_count < next->time_sec) {
+ if (_wait_count < next->getTime_sec()) {
SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " waiting ");
setSpeed(0);
_waiting = true;
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name == "WAITUNTIL" || next->name == "WAIT"
- || next->name == "END" || next->name == "TUNNEL")
+ if (next->getName() == "WAITUNTIL" || next->getName() == "WAIT"
+ || next->getName() == "END" || next->getName() == "TUNNEL")
return;
prev = curr;
} else if (_next_name == "WAITUNTIL") {
time_sec = getDaySeconds();
- until_time_sec = processTimeString(next->time);
- _until_time = next->time;
- setUntilTime(next->time);
+ until_time_sec = processTimeString(next->getTime());
+ _until_time = next->getTime();
+ setUntilTime(next->getTime());
if (until_time_sec > time_sec) {
SG_LOG(SG_GENERAL, SG_INFO, "AIShip: " << _name << " "
- << curr->name << " waiting until: "
+ << curr->getName() << " waiting until: "
<< _until_time << " " << until_time_sec << " now " << time_sec );
setSpeed(0);
_lead_angle = 0;
setUntilTime("");
fp->IncrementWaypoint(false);
- while (next->name == "WAITUNTIL") {
+ while (next->getName() == "WAITUNTIL") {
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
}
- if (next->name == "WAIT")
+ if (next->getName() == "WAIT")
return;
prev = curr;
_missed_count = 0;
_range_rate = 0;
_lead_angle = 0;
- _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
+ _wp_range = getRange(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->getLatitude(), curr->getLongitude());
_old_range = _wp_range;
setWPPos();
object_type type = getType();
if (type != 10)
- AccelTo(prev->speed);
+ AccelTo(prev->getSpeed());
- _curr_alt = curr->altitude;
- _prev_alt = prev->altitude;
+ _curr_alt = curr->getAltitude();
+ _prev_alt = prev->getAltitude();
} else {
_new_waypoint = false;
}
// now revise the required course for the next way point
- _course = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->latitude, curr->longitude);
+ _course = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr->getLatitude(), curr->getLongitude());
if (finite(_course))
TurnTo(_course);
curr = fp->getCurrentWaypoint(); //second waypoint
next = fp->getNextWaypoint(); //third waypoint (might not exist!)
- while (curr->name == "WAIT" || curr->name == "WAITUNTIL") { // don't wait when initialising
+ while (curr->getName() == "WAIT" || curr->getName() == "WAITUNTIL") { // don't wait when initialising
SG_LOG(SG_GENERAL, SG_DEBUG, "AIShip: " << _name << " re-initializing waypoints ");
fp->IncrementWaypoint(false);
curr = fp->getCurrentWaypoint();
}
} else {
- setLatitude(prev->latitude);
- setLongitude(prev->longitude);
- setSpeed(prev->speed);
+ setLatitude(prev->getLatitude());
+ setLongitude(prev->getLongitude());
+ setSpeed(prev->getSpeed());
}
setWPNames();
- setHeading(getCourse(prev->latitude, prev->longitude, curr->latitude, curr->longitude));
- _wp_range = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
+ setHeading(getCourse(prev->getLatitude(), prev->getLongitude(), curr->getLatitude(), curr->getLongitude()));
+ _wp_range = getRange(prev->getLatitude(), prev->getLongitude(), curr->getLatitude(), curr->getLongitude());
_old_range = _wp_range;
_range_rate = 0;
_hdg_lock = true;
while ( elapsed_sec < day_sec ) {
- if (next->name == "END" || fp->getNextWaypoint() == 0) {
+ if (next->getName() == "END" || fp->getNextWaypoint() == 0) {
if (_repeat ) {
//cout << _name << ": " << "restarting flightplan" << endl;
return false;
}
- } else if (next->name == "WAIT") {
+ } else if (next->getName() == "WAIT") {
//cout << _name << ": begin WAIT: " << prev->name << " ";
//cout << curr->name << " " << next->name << endl;
- elapsed_sec += next->time_sec;
+ elapsed_sec += next->getTime_sec();
if ( elapsed_sec >= day_sec)
continue;
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name != "WAITUNTIL" && next->name != "WAIT"
- && next->name != "END") {
+ if (next->getName() != "WAITUNTIL" && next->getName() != "WAIT"
+ && next->getName() != "END") {
prev = curr;
fp->IncrementWaypoint(false);
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
}
- } else if (next->name == "WAITUNTIL") {
- double until_sec = processTimeString(next->time);
+ } else if (next->getName() == "WAITUNTIL") {
+ double until_sec = processTimeString(next->getTime());
if (until_sec > _start_sec && start_sec < 0)
until_sec -= _day;
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name != "WAITUNTIL" && next->name != "WAIT") {
+ if (next->getName() != "WAITUNTIL" && next->getName() != "WAIT") {
prev = curr;
fp->IncrementWaypoint(false);
curr = fp->getCurrentWaypoint();
//cout << prev->name << " " << curr->name << " " << next->name << endl;
} else {
- distance_nm = getRange(prev->latitude, prev->longitude, curr->latitude, curr->longitude);
- elapsed_sec += distance_nm * 60 * 60 / prev->speed;
+ distance_nm = getRange(prev->getLatitude(), prev->getLongitude(), curr->getLatitude(), curr->getLongitude());
+ elapsed_sec += distance_nm * 60 * 60 / prev->getSpeed();
if (elapsed_sec >= day_sec)
continue;
//cout << " time diff " << time_diff << endl;
- if (next->name == "WAIT" ){
+ if (next->getName() == "WAIT" ){
setSpeed(0);
- lat = curr->latitude;
- lon = curr->longitude;
+ lat = curr->getLatitude();
+ lon = curr->getLongitude();
_wait_count= time_diff;
_waiting = true;
- } else if (next->name == "WAITUNTIL") {
+ } else if (next->getName() == "WAITUNTIL") {
setSpeed(0);
- lat = curr->latitude;
- lon = curr->longitude;
+ lat = curr->getLatitude();
+ lon = curr->getLongitude();
_waiting = true;
} else {
- setSpeed(prev->speed);
+ setSpeed(prev->getSpeed());
distance_nm = speed * time_diff / (60 * 60);
- double brg = getCourse(curr->latitude, curr->longitude, prev->latitude, prev->longitude);
+ double brg = getCourse(curr->getLatitude(), curr->getLongitude(), prev->getLatitude(), prev->getLongitude());
//cout << " brg " << brg << " from " << curr->name << " to " << prev->name << " "
// << " lat " << curr->latitude << " lon " << curr->longitude
// << " distance m " << distance_nm * SG_NM_TO_METER << endl;
- lat = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
+ lat = geo_direct_wgs_84 (curr->getLatitude(), curr->getLongitude(), brg,
distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
- lon = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
+ lon = geo_direct_wgs_84 (curr->getLatitude(), curr->getLongitude(), brg,
distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
- recip = geo_direct_wgs_84 (curr->latitude, curr->longitude, brg,
+ recip = geo_direct_wgs_84 (curr->getLatitude(), curr->getLongitude(), brg,
distance_nm * SG_NM_TO_METER, &lat, &lon, &recip );
}
void FGAIShip::setWPPos() {
- if (curr->name == "END" || curr->name == "WAIT"
- || curr->name == "WAITUNTIL" || curr->name == "TUNNEL"){
+ if (curr->getName() == "END" || curr->getName() == "WAIT"
+ || curr->getName() == "WAITUNTIL" || curr->getName() == "TUNNEL"){
//cout << curr->name << " returning" << endl;
return;
}
double elevation_m = 0;
- wppos.setLatitudeDeg(curr->latitude);
- wppos.setLongitudeDeg(curr->longitude);
+ wppos.setLatitudeDeg(curr->getLatitude());
+ wppos.setLongitudeDeg(curr->getLongitude());
wppos.setElevationM(0);
- if (curr->on_ground){
+ if (curr->getOn_ground()){
if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(wppos, 3000),
elevation_m, &_material, 0)){
//cout << curr->name << " setting measured elev " << elevation_m << endl;
} else {
- wppos.setElevationM(curr->altitude);
+ wppos.setElevationM(curr->getAltitude());
//cout << curr->name << " setting FP elev " << elevation_m << endl;
}
- curr->altitude = wppos.getElevationM();
+ curr->setAltitude(wppos.getElevationM());
}
void FGAIShip::setXTrackError() {
- double course = getCourse(prev->latitude, prev->longitude,
- curr->latitude, curr->longitude);
+ double course = getCourse(prev->getLatitude(), prev->getLongitude(),
+ curr->getLatitude(), curr->getLongitude());
double brg = getCourse(pos.getLatitudeDeg(), pos.getLongitudeDeg(),
- curr->latitude, curr->longitude);
+ curr->getLatitude(), curr->getLongitude());
double xtrack_error_nm = sin((course - brg)* SG_DEGREES_TO_RADIANS) * _wp_range;
double factor = -0.0045 * speed + 1;
double limit = _lead_angle_limit * factor;
double _missed_range, _tow_angle, _wait_count, _missed_count,_wp_range;
double _dt_count, _next_run;
- FGAIFlightPlan::waypoint* prev; // the one behind you
- FGAIFlightPlan::waypoint* curr; // the one ahead
- FGAIFlightPlan::waypoint* next; // the next plus 1
+ FGAIWaypoint* prev; // the one behind you
+ FGAIWaypoint* curr; // the one ahead
+ FGAIWaypoint* next; // the next plus 1
protected:
FGATCManager::FGATCManager() {
+ controller = 0;
+ prevController = 0;
networkVisible = false;
}
int stationFreq = apt->getDynamics()->getTowerFrequency(2);
//cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
- leg = 4;
+ leg = 3;
string fltType = "ga";
fp->setRunway(runway);
fp->createTakeOff(&ai_ac, false, apt, 0, fltType);
} else {
controller = apt->getDynamics()->getStartupController();
- int stationFreq = apt->getDynamics()->getGroundFrequency(2);
+ int stationFreq = apt->getDynamics()->getGroundFrequency(1);
//cerr << "Setting radio frequency to : " << stationFreq << endl;
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
- leg = 2;
+ leg = 1;
//double, lat, lon, head; // Unused variables;
//int getId = apt->getDynamics()->getParking(gateId, &lat, &lon, &head);
FGParking* parking = dcs->getParking(park_index);
fltType,
aircraftType,
airline);
- }
+
+ }
+ fp->getLastWaypoint()->setName( fp->getLastWaypoint()->getName() + string("legend"));
} else {
controller = 0;
}
ai_ac.SetFlightPlan(fp);
}
if (controller) {
- controller->announcePosition(ai_ac.getID(), fp, fp->getCurrentWaypoint()->routeIndex,
+ controller->announcePosition(ai_ac.getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
ai_ac._getLatitude(), ai_ac._getLongitude(), heading, speed, altitude,
aircraftRadius, leg, &ai_ac);
FGAIFlightPlan *fp = ai_ac.GetFlightPlan();
/* test code : find out how the routing develops */
- //if (fp) {
- // int size = fp->getNrOfWayPoints();
+ if (fp) {
+ int size = fp->getNrOfWayPoints();
// //cerr << "Setting pos" << pos << " ";
// //cerr << "setting intentions " ;
- // for (int i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
// int val = fp->getRouteIndex(i);
- // cerr << val << " ";
+ cerr << fp->getWayPoint(i)->getName() << " ";
//if ((val) && (val != pos)) {
//intentions.push_back(val);
//cerr << "[done ] " << endl;
//}
- // }
- //}
- //cerr << "[done ] " << endl;
+ }
+ }
+ cerr << "[done ] " << endl;
+ if (fp) {
+ cerr << "Currently at leg : " << fp->getLeg() << endl;
+ }
double longitude = fgGetDouble("/position/longitude-deg");
double latitude = fgGetDouble("/position/latitude-deg");
double heading = fgGetDouble("/orientation/heading-deg");
controller = ai_ac.getATCController();
currentATCDialog->update(time);
if (controller) {
-
+ cerr << "name of previous waypoint : " << fp->getPreviousWaypoint()->getName() << endl;
//cerr << "Running FGATCManager::update()" << endl;
+ cerr << "Currently under control of " << controller->getName() << endl;
controller->updateAircraftInformation(ai_ac.getID(),
latitude,
longitude,
networkVisible = !networkVisible;
trans_num->setIntValue(-1);
}
+ if ((controller != prevController) && (prevController)) {
+ prevController->render(false);
+ }
controller->render(networkVisible);
//cerr << "Adding groundnetWork to the scenegraph::update" << endl;
+ prevController = controller;
}
//globals->get_scenery()->get_scene_graph()->addChild(node);
}
private:
AtcVec activeStations;
FGAIAircraft ai_ac;
- FGATCController *controller; // The ATC controller that is responsible for the user's aircraft.
+ FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft.
//FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog();
bool networkVisible;
sender = rec->getAircraft()->getTrafficRef()->getCallSign();
//cerr << "transmitting for: " << sender << "Leg = " << rec->getLeg() << endl;
switch (rec->getLeg()) {
+ case 1:
case 2:
- case 3:
freqId = rec->getNextFrequency();
stationFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getGroundFrequency(rec->getLeg() + freqId);
taxiFreq =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
- getDynamics()->getGroundFrequency(3);
+ getDynamics()->getGroundFrequency(2);
receiver =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getName() + "-Ground";
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getDynamics()->getAtisSequence();
break;
- case 4:
+ case 3:
receiver =
rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
getName() + "-Tower";
* class FGTowerController
*
**************************************************************************/
-FGTowerController::FGTowerController():
+FGTowerController::FGTowerController(FGAirportDynamics *par) :
FGATCController()
{
+ parent = par;
}
//
//cerr << "FGTowerController::render function not yet implemented" << endl;
}
+string FGTowerController::getName() {
+ return string(parent->getId() + "-tower");
+}
+
+
/***************************************************************************
* class FGStartupController
}
}
+string FGStartupController::getName() {
+ return string(parent->getId() + "-startup");
+}
+
+
/***************************************************************************
* class FGApproachController
*
**************************************************************************/
-FGApproachController::FGApproachController():
+FGApproachController::FGApproachController(FGAirportDynamics *par):
FGATCController()
{
+ parent = par;
}
//
void FGApproachController::render(bool visible) {
//cerr << "FGApproachController::render function not yet implemented" << endl;
}
+
+
+
+string FGApproachController::getName() {
+ return string(parent->getId() + "-approach");
+}
void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir, bool audible);
string getGateName(FGAIAircraft *aircraft);
virtual void render(bool) = 0;
+ virtual string getName() = 0;
+
private:
private:
TrafficVector activeTraffic;
ActiveRunwayVec activeRunways;
+ FGAirportDynamics *parent;
public:
- FGTowerController();
+ FGTowerController(FGAirportDynamics *parent);
virtual ~FGTowerController() {};
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon,
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
+ virtual string getName();
bool hasActiveTraffic() { return activeTraffic.size() != 0; };
TrafficVector &getActiveTraffic() { return activeTraffic; };
};
private:
TrafficVector activeTraffic;
//ActiveRunwayVec activeRunways;
-FGAirportDynamics *parent;
+ FGAirportDynamics *parent;
public:
FGStartupController(FGAirportDynamics *parent);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
+ virtual string getName();
bool hasActiveTraffic() { return activeTraffic.size() != 0; };
TrafficVector &getActiveTraffic() { return activeTraffic; };
private:
TrafficVector activeTraffic;
ActiveRunwayVec activeRunways;
+ FGAirportDynamics *parent;
public:
- FGApproachController();
- virtual ~FGApproachController() {};
+ FGApproachController(FGAirportDynamics * parent);
+ virtual ~FGApproachController() { };
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
+ virtual string getName();
ActiveRunway* getRunway(string name);
FGAirportDynamics::FGAirportDynamics(FGAirport * ap):
_ap(ap), rwyPrefs(ap), SIDs(ap),
+ startupController (this),
+ towerController (this),
+ approachController (this),
atisSequenceIndex(-1),
- atisSequenceTimeStamp(0.0),
- startupController(this)
+ atisSequenceTimeStamp(0.0)
+
{
lastUpdate = 0;
}
int FGAirportDynamics::getGroundFrequency(unsigned leg)
{
//return freqGround.size() ? freqGround[0] : 0; };
+ cerr << "Getting frequency for : " << leg << endl;
int groundFreq = 0;
- if (leg < 2) {
+ if (leg < 1) {
SG_LOG(SG_ATC, SG_ALERT,
- "Leg value is smaller than two at " << SG_ORIGIN);
+ "Leg value is smaller than one at " << SG_ORIGIN);
}
if (freqGround.size() == 0) {
return 0;
}
- if ((freqGround.size() > leg - 1) && (leg > 1)) {
- groundFreq = freqGround[leg - 1];
- }
- if ((freqGround.size() < leg - 1) && (leg > 1)) {
+
+ if ((freqGround.size() < leg) && (leg > 0)) {
groundFreq =
(freqGround.size() <
(leg - 1)) ? freqGround[freqGround.size() -
- 1] : freqGround[leg - 2];
+ 1] : freqGround[leg - 1];
}
- if ((freqGround.size() >= leg - 1) && (leg > 1)) {
- groundFreq = freqGround[leg - 2];
+ if ((freqGround.size() >= leg) && (leg > 0)) {
+ groundFreq = freqGround[leg - 1];
}
return groundFreq;
}
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
+#include <ATC/atc_mgr.hxx>
+
#include <Scenery/scenery.hxx>
#include "groundnetwork.hxx"
}
}
+
void FGGroundNetwork::signOff(int id)
{
TrafficVectorIterator i = activeTraffic.begin();
int state = i->getState();
if ((state >= minState) && (state <= maxState) && available) {
if ((msgDir == ATC_AIR_TO_GROUND) && isUserAircraft(i->getAircraft())) {
-
//cerr << "Checking state " << state << " for " << i->getAircraft()->getCallSign() << endl;
static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
int n = trans_num->getIntValue();
trans_num->setIntValue(-1);
// PopupCallback(n);
cerr << "Selected transmission message " << n << endl;
+ FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc");
+ atc->getATCDialog()->removeEntry(1);
} else {
//cerr << "creating message for " << i->getAircraft()->getCallSign() << endl;
transmit(&(*i), msgId, msgDir, false);
return false;
}
}
- //cerr << "Transmitting startup msg" << endl;
transmit(&(*i), msgId, msgDir, true);
i->updateState();
lastTransmission = now;
current->setState(0);
current->setHoldPosition(false);
}
-
- /*if ((state == 1) && (available)) {
- //cerr << "ACKNOWLEDGE HOLD" << endl;
- transmit(&(*current), MSG_ACKNOWLEDGE_HOLD_POSITION, ATC_AIR_TO_GROUND, true);
- current->setState(0);
- current->setHoldPosition(true);
- lastTransmission = now;
- available = false;
-
- }
- if ((state == 2) && (available)) {
- //cerr << "ACKNOWLEDGE RESUME" << endl;
- transmit(&(*current), MSG_ACKNOWLEDGE_RESUME_TAXI, ATC_AIR_TO_GROUND, true);
- current->setState(0);
- current->setHoldPosition(false);
- lastTransmission = now;
- available = false;
- }*/
}
/**
}
globals->get_scenery()->get_scene_graph()->addChild(group);
}
-}
\ No newline at end of file
+}
+
+string FGGroundNetwork::getName() {
+ return string(parent->getId() + "-ground");
+}
AtcMsgDir msgDir);
bool checkForCircularWaits(int id);
virtual void render(bool);
+ virtual string getName();
};
fp->setName(name);
SGPropertyNode * wpts_node = fpl_node->getNode("wpts");
for (int j = 0; j < wpts_node->nChildren(); j++) {
- FGAIFlightPlan::waypoint* wpt = new FGAIFlightPlan::waypoint;
+ FGAIWaypoint* wpt = new FGAIWaypoint;
SGPropertyNode * wpt_node = wpts_node->getChild(j);
//cerr << "Reading waypoint " << j << wpt_node->getStringValue("name", "END") << endl;
- wpt->name = wpt_node->getStringValue("name", "END");
- wpt->latitude = wpt_node->getDoubleValue("lat", 0);
- wpt->longitude = wpt_node->getDoubleValue("lon", 0);
- wpt->altitude = wpt_node->getDoubleValue("alt", 0);
- wpt->speed = wpt_node->getDoubleValue("ktas", 0);
- wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
- wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
- wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
- wpt->on_ground = wpt_node->getBoolValue("on-ground", false);
- wpt->time_sec = wpt_node->getDoubleValue("time-sec", 0);
- wpt->time = wpt_node->getStringValue("time", "");
-
- if (wpt->name == "END") wpt->finished = true;
- else wpt->finished = false;
+ wpt->setName (wpt_node->getStringValue("name", "END"));
+ wpt->setLatitude (wpt_node->getDoubleValue("lat", 0));
+ wpt->setLongitude (wpt_node->getDoubleValue("lon", 0));
+ wpt->setAltitude (wpt_node->getDoubleValue("alt", 0));
+ wpt->setSpeed (wpt_node->getDoubleValue("ktas", 0));
+ wpt->setCrossat (wpt_node->getDoubleValue("crossat", -10000));
+ wpt->setGear_down (wpt_node->getBoolValue("gear-down", false));
+ wpt->setFlaps_down (wpt_node->getBoolValue("flaps-down", false));
+ wpt->setOn_ground (wpt_node->getBoolValue("on-ground", false));
+ wpt->setTime_sec (wpt_node->getDoubleValue("time-sec", 0));
+ wpt->setTime (wpt_node->getStringValue("time", ""));
+
+ if (wpt->contains("END"))
+ wpt->setFinished(true);
+ else
+ wpt->setFinished(false);
//
fp->addWaypoint( wpt );