]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
Ground network distance tracking code. AIAircraft taxiing at airports
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 853cd90b3ab75f16b858a585e15f4a48963242d5..93f6f96be597ea8c1bd55152fed6b00703303c29 100644 (file)
@@ -58,7 +58,9 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
     // jet_fighter
     {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0},
     // tanker
-    {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0}
+    {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0},
+    // ufo (extreme accel/decel)
+    {30.0, 30.0, 6000.0, 6000.0, 150.0, 300.0, 430.0, 300.0, 130.0}
 };
 
 
@@ -72,6 +74,8 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) :
         groundOffset = 0;
 
     fp = 0;
+    controller = 0;
+    prevController = 0;
     dt_count = 0;
     dt_elev_count = 0;
     use_perf_vs = true;
@@ -105,7 +109,7 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
 
 
 bool FGAIAircraft::init() {
-    refuel_node = fgGetNode("systems/refuel/contact", true);
+    //refuel_node = fgGetNode("systems/refuel/contact", true);
     return FGAIBase::init();
 }
 
@@ -150,6 +154,8 @@ void FGAIAircraft::setPerformance(const std::string& acclass) {
     } else if (acclass == "tanker") {
         SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
         SetTanker(true);
+    } else if (acclass == "ufo") {
+        SetPerformance(&FGAIAircraft::settings[FGAIAircraft::UFO]);
     } else {
         SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
     }
@@ -165,7 +171,7 @@ void FGAIAircraft::SetPerformance(const PERF_STRUCT *ps) {
 void FGAIAircraft::Run(double dt) {
 
     FGAIAircraft::dt = dt;
-
+    
     if (fp) {
         time_t now = time(NULL) + fgGetLong("/sim/time/warp");
         ProcessFlightPlan(dt, now);
@@ -180,12 +186,53 @@ void FGAIAircraft::Run(double dt) {
                 doGroundAltitude();
                 //cerr << " Actual altitude " << altitude << endl;
                 // Transform();
-                pos.setelev(altitude * SG_FEET_TO_METER);
+                pos.setElevationFt(altitude_ft);
             }
             return;
         }
-    }
+    } else {
+        // no flight plan, update target heading, speed, and altitude
+        // from control properties.  These default to the initial
+        // settings in the config file, but can be changed "on the
+        // fly".
+        string lat_mode = props->getStringValue("controls/flight/lateral-mode");
+        if ( lat_mode == "roll" ) {
+            double angle
+                = props->getDoubleValue("controls/flight/target-roll" );
+            RollTo( angle );
+        } else {
+             double angle
+                = props->getDoubleValue("controls/flight/target-hdg" );
+            TurnTo( angle );
+        }
 
+        string lon_mode
+            = props->getStringValue("controls/flight/longitude-mode");
+        if ( lon_mode == "alt" ) {
+            double alt = props->getDoubleValue("controls/flight/target-alt" );
+            ClimbTo( alt );
+        } else {
+            double angle
+                = props->getDoubleValue("controls/flight/target-pitch" );
+            PitchTo( angle );
+        }
+
+        AccelTo( props->getDoubleValue("controls/flight/target-spd" ) );
+    }
+    if (controller)
+      {
+       controller->update(getID(), 
+                          pos.getLatitudeDeg(), 
+                          pos.getLongitudeDeg(),
+                          hdg,
+                          speed,
+                          altitude_ft);
+       //if (controller->hasInstruction(getID()))
+       //  {
+           processATC(controller->getInstruction(getID()));
+           //  }
+      }
+      
     double turn_radius_ft;
     double turn_circum_ft;
     double speed_north_deg_sec;
@@ -200,27 +247,47 @@ void FGAIAircraft::Run(double dt) {
     } else {
         speed_diff = groundTargetSpeed - speed;
     }
-    if (fabs(speed_diff) > 0.2) {
-        if (speed_diff > 0.0)
-            speed += performance->accel * dt;
-        if (speed_diff < 0.0) {
-            if (no_roll) { // was (!no_roll) but seems more logical this way (ground brakes).
-                speed -= performance->decel * dt * 3;
-            } else {
-                speed -= performance->decel * dt;
-            }
+
+    if (speed_diff > 0.0) {
+        speed += performance->accel * dt;
+       if (no_roll) { // apply overshoot correction
+         if ( speed > groundTargetSpeed ) speed = groundTargetSpeed;
+       }else {
+         if ( speed > tgt_speed ) speed = tgt_speed;
+       }
+    } else if (speed_diff < 0.0) {
+        if (no_roll) {
+            // on ground (aircraft can't roll)
+           // deceleration performance is better due to wheel brakes.
+            speed -= performance->decel * dt * 3;
+        } else {
+            speed -= performance->decel * dt;
         }
+       if (no_roll) { // apply overshoot correction
+        if (speed < groundTargetSpeed ) speed = groundTargetSpeed;
+       } else { 
+         if ( speed < tgt_speed ) speed = tgt_speed;
+       }
     }
-
+    
+    
     // convert speed to degrees per second
-    speed_north_deg_sec = cos( hdg / SG_RADIANS_TO_DEGREES )
+    speed_north_deg_sec = cos( hdg * SGD_DEGREES_TO_RADIANS )
                           * speed * 1.686 / ft_per_deg_lat;
-    speed_east_deg_sec  = sin( hdg / SG_RADIANS_TO_DEGREES )
+    speed_east_deg_sec  = sin( hdg * SGD_DEGREES_TO_RADIANS )
                           * speed * 1.686 / ft_per_deg_lon;
 
     // set new position
-    pos.setlat( pos.lat() + speed_north_deg_sec * dt);
-    pos.setlon( pos.lon() + speed_east_deg_sec * dt);
+    pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
+    pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt); 
+
+    /* printf("%.7f %0.4f %.7f %.5f %.7f %.7f %.8f %.8f %.9f %.9f\n",
+           dt, hdg, speed, ft_per_deg_lat,
+           cos( hdg * SGD_DEGREES_TO_RADIANS ),
+           speed * 1.686 / ft_per_deg_lat,
+           speed_north_deg_sec, speed_east_deg_sec,
+           pos.getLatitudeDeg(), pos.getLongitudeDeg()); */
+
     //if (!(finite(pos.lat()) && finite(pos.lon())))
     //  {
     //    cerr << "Position is not finite" << endl;
@@ -360,9 +427,8 @@ void FGAIAircraft::Run(double dt) {
     }
 
     // adjust altitude (meters) based on current vertical speed (fpm)
-    altitude += vs / 60.0 * dt;
-    pos.setelev(altitude * SG_FEET_TO_METER);
-    double altitude_ft = altitude;
+    altitude_ft += vs / 60.0 * dt;
+    pos.setElevationFt(altitude_ft);  
 
     // adjust target Altitude, based on ground elevation when on ground
     if (no_roll) {
@@ -371,23 +437,23 @@ void FGAIAircraft::Run(double dt) {
     } else {
         // find target vertical speed if altitude lock engaged
         if (alt_lock && use_perf_vs) {
-            if (altitude_ft < tgt_altitude) {
-                tgt_vs = tgt_altitude - altitude_ft;
+            if (altitude_ft < tgt_altitude_ft) {
+                tgt_vs = tgt_altitude_ft - altitude_ft;
                 if (tgt_vs > performance->climb_rate)
                     tgt_vs = performance->climb_rate;
             } else {
-                tgt_vs = tgt_altitude - altitude_ft;
+                tgt_vs = tgt_altitude_ft - altitude_ft;
                 if (tgt_vs  < (-performance->descent_rate))
                     tgt_vs = -performance->descent_rate;
             }
         }
 
         if (alt_lock && !use_perf_vs) {
-            double max_vs = 4*(tgt_altitude - altitude);
+            double max_vs = 4*(tgt_altitude_ft - altitude_ft);
             double min_vs = 100;
-            if (tgt_altitude < altitude)
+            if (tgt_altitude_ft < altitude_ft)
                 min_vs = -100.0;
-            if ((fabs(tgt_altitude - altitude) < 1500.0)
+            if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
                     && (fabs(max_vs) < fabs(tgt_vs)))
                 tgt_vs = max_vs;
 
@@ -399,12 +465,12 @@ void FGAIAircraft::Run(double dt) {
     double vs_diff = tgt_vs - vs;
     if (fabs(vs_diff) > 10.0) {
         if (vs_diff > 0.0) {
-            vs += 900.0 * dt;
+            vs += (performance->climb_rate / 3.0) * dt;
 
             if (vs > tgt_vs)
                 vs = tgt_vs;
         } else {
-            vs -= 400.0 * dt;
+            vs -= (performance->descent_rate / 3.0) * dt;
 
            if (vs < tgt_vs)
                vs = tgt_vs;
@@ -412,7 +478,7 @@ void FGAIAircraft::Run(double dt) {
     }
 
     // match pitch angle to vertical speed
-    if (vs > 0){
+    if (vs > 0) {
         pitch = vs * 0.005;
     } else {
         pitch = vs * 0.002;
@@ -430,10 +496,10 @@ void FGAIAircraft::Run(double dt) {
     if ( isTanker) {
         if ( (range_ft2 < 250.0 * 250.0) && (y_shift > 0.0)
                 && (elevation > 0.0) ) {
-            refuel_node->setBoolValue(true);
+            //refuel_node->setBoolValue(true);
             contact = true;
         } else {
-            refuel_node->setBoolValue(false);
+            //refuel_node->setBoolValue(false);
             contact = false;
         }
     } else {
@@ -464,8 +530,8 @@ void FGAIAircraft::YawTo(double angle) {
 }
 
 
-void FGAIAircraft::ClimbTo(double altitude) {
-    tgt_altitude = altitude;
+void FGAIAircraft::ClimbTo(double alt_ft ) {
+    tgt_altitude_ft = alt_ft;
     alt_lock = true;
 }
 
@@ -502,22 +568,11 @@ void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
 void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
     bool eraseWaypoints;
     if (trafficRef) {
-//      FGAirport *arr;
-//      FGAirport *dep;
         eraseWaypoints = true;
-//      cerr << trafficRef->getRegistration();
-//      cerr << "Departure airport " << endl;
-//      dep = trafficRef->getDepartureAirport();
-//      if (dep)
-//          cerr << dep->getId() << endl;
-//      cerr << "Arrival   airport " << endl;
-//      arr = trafficRef->getArrivalAirport();
-//      if (arr)
-//          cerr << arr->getId() <<endl << endl;;
     } else
         eraseWaypoints = false;
 
-    //cerr << "Processing Flightplan" << endl;
     FGAIFlightPlan::waypoint* prev = 0; // the one behind you
     FGAIFlightPlan::waypoint* curr = 0; // the one ahead
     FGAIFlightPlan::waypoint* next = 0; // the next plus 1
@@ -526,78 +581,71 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
     next = fp->getNextWaypoint();
     dt_count += dt;
 
-    if (!prev) {  //beginning of flightplan, do this initialization once
-        //setBank(0.0);
-        spinCounter = 0;
-        tempReg = "";
-        //prev_dist_to_go = HUGE;
-        //cerr << "Before increment " << curr-> name << endl;
-        fp->IncrementWaypoint(eraseWaypoints);
-        //prev = fp->getPreviousWaypoint(); //first waypoint
-        //curr = fp->getCurrentWaypoint();  //second waypoint
-        //next = fp->getNextWaypoint();     //third waypoint (might not exist!)
-        //cerr << "After increment " << prev-> name << endl;
-        if (!(fp->getNextWaypoint()) && trafficRef)
-            loadNextLeg();
-
-        //cerr << "After load " << prev-> name << endl;
-        prev = fp->getPreviousWaypoint(); //first waypoint
-        curr = fp->getCurrentWaypoint();  //second waypoint
-        next = fp->getNextWaypoint();     //third waypoint (might not exist!)
-        //cerr << "After load " << prev-> name << endl;
-        setLatitude(prev->latitude);
-        setLongitude(prev->longitude);
-        setSpeed(prev->speed);
-        setAltitude(prev->altitude);
-
-        if (prev->speed > 0.0)
-            setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
-        else
-            setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
-
-        // If next doesn't exist, as in incrementally created flightplans for
-        // AI/Trafficmanager created plans,
-        // Make sure lead distance is initialized otherwise
-        if (next)
-            fp->setLeadDistance(speed, hdg, curr, next);
-
-        if (curr->crossat > -1000.0) { //use a calculated descent/climb rate
-            use_perf_vs = false;
-            tgt_vs = (curr->crossat - prev->altitude)
-                    / (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)
-                    / 6076.0 / prev->speed*60.0);
-            tgt_altitude = curr->crossat;
-        } else {
-            use_perf_vs = true;
-            tgt_altitude = prev->altitude;
-        }
-        alt_lock = hdg_lock = true;
-        no_roll = prev->on_ground;
-        if (no_roll) {
-            Transform();         // make sure aip is initialized.
-            getGroundElev(60.1); // make sure it's exectuted first time around, so force a large dt value
-            //getGroundElev(60.1); // Need to do this twice.
-            //cerr << trafficRef->getRegistration() << " Setting altitude to " << tgt_altitude << endl;
-            doGroundAltitude(); //(tgt_altitude);
-        }
-        prevSpeed = 0;
-        //cout << "First waypoint:  " << prev->name << endl;
-        //cout << "  Target speed:    " << tgt_speed << endl;
-        //cout << "  Target altitude: " << tgt_altitude << endl;
-        //cout << "  Target heading:  " << tgt_heading << endl << endl;
-        //cerr << "Done Flightplan init" << endl;
-        return;
+    ///////////////////////////////////////////////////////////////////////////
+    // Initialize the flightplan
+    //////////////////////////////////////////////////////////////////////////
+    if (!prev) {
+
+      spinCounter = 0;
+      tempReg = "";
+      fp->IncrementWaypoint(eraseWaypoints);
+      if (!(fp->getNextWaypoint()) && trafficRef)
+       loadNextLeg();
+      
+      prev = fp->getPreviousWaypoint(); //first waypoint
+      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);
+      
+      if (prev->speed > 0.0)
+       setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
+      else
+       setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
+      
+      // If next doesn't exist, as in incrementally created flightplans for
+      // AI/Trafficmanager created plans,
+      // Make sure lead distance is initialized otherwise
+      if (next)
+       fp->setLeadDistance(speed, hdg, curr, next);
+      
+      if (curr->crossat > -1000.0) { //use a calculated descent/climb rate
+       use_perf_vs = false;
+       tgt_vs = (curr->crossat - prev->altitude)
+         / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
+            / 6076.0 / prev->speed*60.0);
+       tgt_altitude_ft = curr->crossat;
+      } else {
+       use_perf_vs = true;
+       tgt_altitude_ft = prev->altitude;
+      }
+      alt_lock = hdg_lock = true;
+      no_roll = prev->on_ground;
+      if (no_roll) {
+       Transform();         // make sure aip is initialized.
+       getGroundElev(60.1); // make sure it's exectuted first time around, so force a large dt value
+       doGroundAltitude(); 
+      }
+      // Make sure to announce the aircraft's position 
+      announcePositionToController();
+      prevSpeed = 0;
+      return;
     } // end of initialization
-
-    // let's only process the flight plan every 100 ms.
+    
+    ///////////////////////////////////////////////////////////////////////////
+    // Check Execution time (currently once every 100 ms
+    ///////////////////////////////////////////////////////////////////////////
     if ((dt_count < 0.1) || (now < fp->getStartTime())) {
-        //cerr  << "done fp dt" << endl;
-        return;
+      //cerr  << "done fp dt" << endl;
+      return;
     } else {
-        dt_count = 0;
+      dt_count = 0;
     }
     // check to see if we've reached the lead point for our next turn
-    double dist_to_go = fp->getDistanceToGo(pos.lat(), pos.lon(), curr);
+    double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
 
     //cerr << "2" << endl;
     double lead_dist = fp->getLeadDistance();
@@ -608,45 +656,18 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         lead_dist = fabs(2*speed);  //don't skip over the waypoint
         //cerr << "Extending lead distance to " << lead_dist << endl;
     }
-//  FGAirport * apt = trafficRef->getDepartureAirport();
-//  if ((dist_to_go > prev_dist_to_go) && trafficRef && apt) {
-//      if (apt->getId() == string("EHAM"))
-//          cerr << "Alert: " << trafficRef->getRegistration() << " is moving away from waypoint " << curr->name  << endl
-//               << "Target heading : " << tgt_heading << "act heading " << hdg << " Tgt speed : " << tgt_speed << endl
-//               << "Lead distance : " << lead_dist  << endl
-//               << "Distance to go: " << dist_to_go << endl;
-//  }
-
-    prev_dist_to_go = dist_to_go;
-    //cerr << "2" << endl;
-    //if (no_roll)
-    //  lead_dist = 10.0;
-    //cout << "Leg : " << (fp->getLeg()-1) << ". dist_to_go: " << dist_to_go << ",  lead_dist: "
-    //     << lead_dist << ", tgt_speed " << tgt_speed << ", tgt_heading " << tgt_heading
-    //     << " speed " << speed << " hdg " << hdg << ". Altitude "  << altitude << " TAget alt :"
-    //     << tgt_altitude << endl;
+
+    //prev_dist_to_go = dist_to_go;
 
     if ( dist_to_go < lead_dist ) {
-        //prev_dist_to_go = HUGE;
-        // For traffic manager generated aircraft:
-        // check if the aircraft flies of of user range. And adjust the
-        // Current waypoint's elevation according to Terrain Elevation
         if (curr->finished) {  //end of the flight plan
             if (fp->getRepeat())
                 fp->restart();
             else
                 setDie(true);
-
-            //cerr << "Done die end of fp" << endl;
             return;
         }
 
-        // we've reached the lead-point for the waypoint ahead
-        //cerr << "4" << endl;
-        //cerr << "Situation after lead point" << endl;
-        //cerr << "Prviious: " << prev->name << endl;
-        //cerr << "Current : " << curr->name << endl;
-        //cerr << "Next    : " << next->name << endl;
         if (next) {
             tgt_heading = fp->getBearing(curr, next);
             spinCounter = 0;
@@ -661,67 +682,41 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         next = fp->getNextWaypoint();
 
         // Now that we have incremented the waypoints, excute some traffic manager specific code
-        // based on the name of the waypoint we just passed.
         if (trafficRef) {
             double userLatitude  = fgGetDouble("/position/latitude-deg");
             double userLongitude = fgGetDouble("/position/longitude-deg");
             double course, distance;
-            SGWayPoint current (pos.lon(), pos.lat(), 0);
+            SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
             SGWayPoint user (userLongitude, userLatitude, 0);
             user.CourseAndDistance(current, &course, &distance);
             if ((distance * SG_METER_TO_NM) > TRAFFICTOAIDIST) {
                 setDie(true);
-                //cerr << "done fp die out of range" << endl;
                 return;
             }
 
             FGAirport * dep = trafficRef->getDepartureAirport();
             FGAirport * arr = trafficRef->getArrivalAirport();
-            // At parking the beginning of the airport
             if (!( dep && arr)) {
                 setDie(true);
                 return;
             }
-
-            //if ((dep->getId() == string("EHAM") || (arr->getId() == string("EHAM")))) {
-            //    cerr << trafficRef->getRegistration()
-            //         << " Enroute from " << dep->getId()
-            //         << " to "           << arr->getId()
-            //         << " just crossed " << prev->name
-            //         << " Assigned rwy     " << fp->getRunwayId()
-            //         << " " << fp->getRunway() << endl;
-            // }
-            //if ((dep->getId() == string("EHAM")) && (prev->name == "park2")) {
-            //    cerr << "Schiphol ground "
-            //         << trafficRef->getCallSign();
-            //    if (trafficRef->getHeavy())
-            //        cerr << "Heavy";
-            //    cerr << ", is type "
-            //         << trafficRef->getAircraft()
-            //         << " ready to go. IFR to "
-            //         << arr->getId() <<endl;
-            // }
-
+           // This waypoint marks the fact that the aircraft has passed the initial taxi
+           // departure waypoint, so it can release the parking.
             if (prev->name == "park2")
                 dep->getDynamics()->releaseParking(fp->getGate());
-
-            // Some debug messages, specific to testing the Logical networks.
-            // if ((arr->getId() == string("EHAM")) && (prev->name  == "Center")) {
-            //     cerr << "Schiphol ground "
-            //          << trafficRef->getRegistration() << " "
-            //          << trafficRef->getCallSign();
-            //     if (trafficRef->getHeavy())
-            //         cerr << "Heavy";
-            //     cerr << ", arriving from " << dep->getName() ;
-            //     cerr << " landed runway "
-            //          << fp->getRunway()
-            //          << " request taxi to gate "
-            //          << arr->getDynamics()->getParkingName(fp->getGate())
-            //          << endl;
-            // }
-            if (prev->name == "END")
-                fp->setTime(trafficRef->getDepartureTime());
-            //cerr << "5" << endl;
+           // 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") {
+             // make sure to wait at least 20 minutes at parking to prevent "nervous" taxi behavior
+             // delayed aircraft. 
+             time_t nextDeparture = trafficRef->getDepartureTime();
+             if (nextDeparture < (now+1200)) {
+               nextDeparture = now + 1200; 
+             }
+             fp->setTime(trafficRef->getDepartureTime());
+           }
+           announcePositionToController();
+            
         }
 
         if (next) {
@@ -732,19 +727,19 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
 
         //cerr << "5.1" << endl;
         if (!(prev->on_ground)) { // only update the tgt altitude from flightplan if not on the ground
-            tgt_altitude = prev->altitude;
+            tgt_altitude_ft = prev->altitude;
             if (curr->crossat > -1000.0) {
                 //cerr << "5.1a" << endl;
                 use_perf_vs = false;
-                tgt_vs = (curr->crossat - altitude) / (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)
+                tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
                         / 6076.0 / speed*60.0);
                 //cerr << "5.1b" << endl;
-                tgt_altitude = curr->crossat;
+                tgt_altitude_ft = curr->crossat;
             } else {
                 //cerr << "5.1c" << endl;
                 use_perf_vs = true;
                 //cerr << "5.1d" << endl;
-                //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+                //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
             }
         }
         //cerr << "6" << endl;
@@ -753,11 +748,11 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         no_roll = prev->on_ground;
         //cout << "Crossing waypoint: " << prev->name << endl;
         //cout << "  Target speed:    " << tgt_speed << endl;
-        //cout << "  Target altitude: " << tgt_altitude << endl;
+        //cout << "  Target altitude: " << tgt_altitude_ft << endl;
         //cout << "  Target heading:  " << tgt_heading << endl << endl;
 
     } else {
-        double calc_bearing = fp->getBearing(pos.lat(), pos.lon(), curr);
+        double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
         //cerr << "Bearing = " << calc_bearing << endl;
         if (speed < 0) {
             calc_bearing +=180;
@@ -774,10 +769,10 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         } else {
             cerr << "calc_bearing is not a finite number : "
                  << "Speed " << speed
-                 << "pos : " << pos.lat() << ", " << pos.lon()
+                 << "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
                  << "waypoint " << curr->latitude << ", " << curr->longitude << endl;
             cerr << "waypoint name " << curr->name;
-            exit(1);  // FIXME 
+            exit(1);  // FIXME
         }
 
         double speed_diff = speed - prevSpeed;
@@ -792,6 +787,11 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
     }
 }
 
+void FGAIAircraft::initializeFlightPlan() 
+{
+
+}
+
 
 bool FGAIAircraft::_getGearDown() const {
     return ((props->getFloatValue("position/altitude-agl-ft") < 900.0)
@@ -863,16 +863,16 @@ void FGAIAircraft::loadNextLeg() {
         //        //cerr << "25.1a" << endl;
         //        use_perf_vs = false;
         //
-        //        tgt_vs = (curr->crossat - altitude)/
+        //        tgt_vs = (curr->crossat - altitude_ft)/
         //          (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)/6076.0/speed*60.0);
         //        //cerr << "25.1b" << endl;
-        //        tgt_altitude = curr->crossat;
+        //        tgt_altitude_ft = curr->crossat;
         //} else {
         //        //cerr << "25.1c" << endl;
         //        use_perf_vs = true;
         //        //cerr << "25.1d" << endl;
-        //        tgt_altitude = prev->altitude;
-        //        //cerr << "Setting target altitude : " <<tgt_altitude << endl;
+        //        tgt_altitude_ft = prev->altitude;
+        //        //cerr << "Setting target altitude : " <<tgt_altitude_ft << endl;
         // }
         //cerr << "26" << endl;
         //tgt_speed = prev->speed;
@@ -909,12 +909,6 @@ void FGAIAircraft::getGroundElev(double dt) {
     else
        dt_elev_count = 0;
 
-    // It would be nice if we could set the correct tile center here in order to get a correct
-    // answer with one call to the function, but what I tried in the two commented-out lines
-    // below only intermittently worked, and I haven't quite groked why yet.
-    //SGBucket buck(pos.lon(), pos.lat());
-    //aip.getSGLocation()->set_tile_center(Point3D(buck.get_center_lon(), buck.get_center_lat(), 0.0));
-
     // Only do the proper hitlist stuff if we are within visible range of the viewer.
     if (!invisible) {
         double visibility_meters = fgGetDouble("/environment/visibility-m");
@@ -922,9 +916,7 @@ void FGAIAircraft::getGroundElev(double dt) {
         FGViewer* vw = globals->get_current_view();
         double course, distance;
 
-        //Point3D currView(vw->getLongitude_deg(),
-        //                 vw->getLatitude_deg(), 0.0);
-        SGWayPoint current (pos.lon(), pos.lat(), 0);
+        SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
         SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
         view.CourseAndDistance(current, &course, &distance);
         if(distance > visibility_meters) {
@@ -934,21 +926,21 @@ void FGAIAircraft::getGroundElev(double dt) {
 
         // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
         double range = 500.0;
-        if (!globals->get_tile_mgr()->scenery_available(pos.lat(), pos.lon(), range)) {
+        if (!globals->get_tile_mgr()->scenery_available(pos.getLatitudeDeg(), pos.getLongitudeDeg(), range)) {
             // Try to shedule tiles for that position.
             globals->get_tile_mgr()->update( aip.getSGLocation(), range );
         }
 
         // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
         double alt;
-        if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(), 20000.0, alt))
-            tgt_altitude = alt * SG_METER_TO_FEET;
+        if (globals->get_scenery()->get_elevation_m(pos.getLatitudeDeg(), pos.getLongitudeDeg(), 20000.0, alt, 0))
+            tgt_altitude_ft = alt * SG_METER_TO_FEET;
 
-        //cerr << "Target altitude : " << tgt_altitude << endl;
+        //cerr << "Target altitude : " << tgt_altitude_ft << endl;
         // if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(),
         //                                            20000.0, alt))
-        //    tgt_altitude = alt * SG_METER_TO_FEET;
-        //cerr << "Target altitude : " << tgt_altitude << endl;
+        //    tgt_altitude_ft = alt * SG_METER_TO_FEET;
+        //cerr << "Target altitude : " << tgt_altitude_ft << endl;
     }
 }
 
@@ -964,9 +956,88 @@ void FGAIAircraft::setTACANChannelID(const string& id) {
 
 
 void FGAIAircraft::doGroundAltitude() {
-   if (fabs(altitude - (tgt_altitude+groundOffset)) > 1000.0)
-       altitude = (tgt_altitude + groundOffset);
+   if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
+       altitude_ft = (tgt_altitude_ft + groundOffset);
    else
-      altitude += 0.1 * ((tgt_altitude+groundOffset) - altitude);
+      altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
+}
+
+
+void FGAIAircraft::announcePositionToController() 
+{
+  if (trafficRef) {
+    //FGTaxiRoute *taxiRoute = fp->getTaxiRoute();
+    
+    int leg = fp->getLeg();
+    
+    // For starters, I'll only do this for departure and arrival taxi. The mechanism
+    // could be extended to include any controller however. 
+    //int node, currentTaxiSegment;
+    //if (taxiRoute->next(&node, &currentTaxiSegment)) {
+    if (fp->getCurrentWaypoint()->routeIndex != 0) {
+      //char buffer[10];
+      //snprintf (buffer, 10, "%d", node);
+      switch (leg) {
+      case 3:
+       cerr << trafficRef->getRegistration() 
+            << " taxiing to runway at segment " 
+            << fp->getCurrentWaypoint()->routeIndex
+            << endl;
+       //cerr << "Match check between taxisegment and taxiroute : " << node << " " 
+       //     << fp->getCurrentWaypoint()->name << endl;
+       if (trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork()->exists())
+         controller = trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork();
+       break;
+      case 9:
+       cerr << trafficRef->getRegistration() 
+            << " taxiing to parking at segment " 
+            << fp->getCurrentWaypoint()->routeIndex
+            << endl;
+       if (trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork()->exists())
+         controller = trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork();
+       break;
+      default: 
+       controller = 0;
+       break;
+      }
+    } else {
+      //fp->deleteTaxiRoute();
+      controller = 0;
+    }
+    if ((controller != prevController) && (prevController != 0)) {
+      prevController->signOff(getID());
+      cerr << trafficRef->getRegistration() 
+          << " signing off " << endl;
+    }
+    prevController = controller;
+    if (controller) {
+      controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->routeIndex,
+                                  _getLatitude(), _getLongitude(), hdg, speed, altitude_ft, 
+                                  trafficRef->getRadius());
+    }
+  }
 }
 
+
+void FGAIAircraft::processATC(FGATCInstruction instruction)
+{
+  //cerr << "Processing ATC instruction (not Implimented yet)" << endl;
+  if (instruction.getHoldPattern   ()) {
+  }
+  if (instruction.getHoldPosition  ()) {
+  }
+  if (instruction.getChangeSpeed   ()) {
+    AccelTo(instruction.getSpeed());
+  }else {
+    if (fp) AccelTo(fp->getPreviousWaypoint()->speed);
+  }
+  if (instruction.getChangeHeading ()) { 
+    hdg_lock = false;
+    TurnTo(instruction.getHeading());
+  } else {
+    if (fp) {hdg_lock = true;}
+  }
+  if (instruction.getChangeAltitude()) { 
+  }
+
+}