1 // // // FGAIAircraft - FGAIBase-derived class creates an AI airplane
3 // Written by David Culp, started October 2003.
5 // Copyright (C) 2003 David P. Culp - davidculp2@comcast.net
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <simgear/route/waypoint.hxx>
26 #include <Main/fg_props.hxx>
27 #include <Main/globals.hxx>
28 #include <Main/viewer.hxx>
29 #include <Scenery/scenery.hxx>
30 #include <Scenery/tilemgr.hxx>
31 #include <Airports/dynamics.hxx>
38 # define finite _finite
39 #elif defined(__sun) || defined(sgi)
45 #include "AIAircraft.hxx"
46 #include "performancedata.hxx"
47 #include "performancedb.hxx"
49 //#include <Airports/trafficcontroller.hxx>
51 static string tempReg;
53 class AI_OutOfSight{};
56 FGAIAircraft::FGAIAircraft(FGAISchedule *ref) : FGAIBase(otAircraft) {
59 groundOffset = trafficRef->getGroundOffset();
60 setCallSign(trafficRef->getCallSign());
75 groundTargetSpeed = 0;
77 // set heading and altitude locks
81 headingChangeRate = 0.0;
86 _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
91 FGAIAircraft::~FGAIAircraft() {
94 controller->signOff(getID());
98 void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
102 FGAIBase::readFromScenario(scFileNode);
104 setPerformance(scFileNode->getStringValue("class", "jet_transport"));
105 setFlightPlan(scFileNode->getStringValue("flightplan"),
106 scFileNode->getBoolValue("repeat", false));
107 setCallSign(scFileNode->getStringValue("callsign"));
111 void FGAIAircraft::bind() {
114 props->tie("controls/gear/gear-down",
115 SGRawValueMethods<FGAIAircraft,bool>(*this,
116 &FGAIAircraft::_getGearDown));
117 props->tie("transponder-id",
118 SGRawValueMethods<FGAIAircraft,const char*>(*this,
119 &FGAIAircraft::_getTransponderCode));
123 void FGAIAircraft::unbind() {
126 props->untie("controls/gear/gear-down");
127 props->untie("transponder-id");
131 void FGAIAircraft::update(double dt) {
132 FGAIBase::update(dt);
137 void FGAIAircraft::setPerformance(const std::string& acclass) {
138 static PerformanceDB perfdb; //TODO make it a global service
139 setPerformance(perfdb.getDataFor(acclass));
143 void FGAIAircraft::setPerformance(PerformanceData *ps) {
148 void FGAIAircraft::Run(double dt) {
149 FGAIAircraft::dt = dt;
152 updatePrimaryTargetValues(); // target hdg, alt, speed
154 catch (AI_OutOfSight) {
157 catch (FP_Inactive) {
159 groundTargetSpeed = 0;
162 handleATCRequests(); // ATC also has a word to say
163 updateSecondaryTargetValues(); // target roll, vertical speed, pitch
165 UpdateRadar(manager);
169 void FGAIAircraft::checkVisibility()
171 double visibility_meters = fgGetDouble("/environment/visibility-m");
172 FGViewer* vw = globals->get_current_view();
173 invisible = (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters);
178 void FGAIAircraft::AccelTo(double speed) {
183 void FGAIAircraft::PitchTo(double angle) {
189 void FGAIAircraft::RollTo(double angle) {
195 void FGAIAircraft::YawTo(double angle) {
200 void FGAIAircraft::ClimbTo(double alt_ft ) {
201 tgt_altitude_ft = alt_ft;
206 void FGAIAircraft::TurnTo(double heading) {
207 tgt_heading = heading;
212 double FGAIAircraft::sign(double x) {
220 void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat) {
221 if (!flightplan.empty()) {
222 FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
223 fp->setRepeat(repeat);
229 void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
235 void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
237 // the one behind you
238 FGAIFlightPlan::waypoint* prev = 0;
240 FGAIFlightPlan::waypoint* curr = 0;
242 FGAIFlightPlan::waypoint* next = 0;
244 prev = fp->getPreviousWaypoint();
245 curr = fp->getCurrentWaypoint();
246 next = fp->getNextWaypoint();
250 ///////////////////////////////////////////////////////////////////////////
251 // Initialize the flightplan
252 //////////////////////////////////////////////////////////////////////////
254 handleFirstWaypoint();
256 } // end of initialization
257 if (! fpExecutable(now))
261 if (! leadPointReached(curr)) {
262 controlHeading(curr);
263 controlSpeed(curr, next);
265 if (curr->finished) //end of the flight plan
275 //TODO more intelligent method in AIFlightPlan, no need to send data it already has :-)
276 tgt_heading = fp->getBearing(curr, next);
280 //TODO let the fp handle this (loading of next leg)
281 fp->IncrementWaypoint( trafficRef != 0 );
282 if (!(fp->getNextWaypoint()) && trafficRef != 0)
283 if (!loadNextLeg()) {
288 prev = fp->getPreviousWaypoint();
289 curr = fp->getCurrentWaypoint();
290 next = fp->getNextWaypoint();
292 // Now that we have incremented the waypoints, excute some traffic manager specific code
294 //TODO isn't this best executed right at the beginning?
295 if (! aiTrafficVisible()) {
300 if (! handleAirportEndPoints(prev, now)) {
305 announcePositionToController();
310 fp->setLeadDistance(tgt_speed, tgt_heading, curr, next);
313 if (!(prev->on_ground)) // only update the tgt altitude from flightplan if not on the ground
315 tgt_altitude_ft = prev->altitude;
316 if (curr->crossat > -1000.0) {
318 tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
319 / 6076.0 / speed*60.0);
320 tgt_altitude_ft = curr->crossat;
325 tgt_speed = prev->speed;
326 hdg_lock = alt_lock = true;
327 no_roll = prev->on_ground;
332 void FGAIAircraft::initializeFlightPlan() {
336 bool FGAIAircraft::_getGearDown() const {
337 return _performance->gearExtensible(this);
341 const char * FGAIAircraft::_getTransponderCode() const {
342 return transponderCode.c_str();
346 bool FGAIAircraft::loadNextLeg() {
349 if ((leg = fp->getLeg()) == 10) {
350 if (!trafficRef->next()) {
353 setCallSign(trafficRef->getCallSign());
358 FGAirport *dep = trafficRef->getDepartureAirport();
359 FGAirport *arr = trafficRef->getArrivalAirport();
364 double cruiseAlt = trafficRef->getCruiseAlt() * 100;
371 trafficRef->getSpeed(),
375 trafficRef->getRadius(),
376 trafficRef->getFlightType(),
379 //cerr << "created leg " << leg << " for " << trafficRef->getCallSign() << endl;
385 // Note: This code is copied from David Luff's AILocalTraffic
386 // Warning - ground elev determination is CPU intensive
387 // Either this function or the logic of how often it is called
388 // will almost certainly change.
390 void FGAIAircraft::getGroundElev(double dt) {
393 // Update minimally every three secs, but add some randomness
394 // to prevent all AI objects doing this in synchrony
395 if (dt_elev_count < (3.0) + (rand() % 10))
400 // Only do the proper hitlist stuff if we are within visible range of the viewer.
402 double visibility_meters = fgGetDouble("/environment/visibility-m");
403 FGViewer* vw = globals->get_current_view();
405 if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) {
409 double range = 500.0;
410 if (!globals->get_tile_mgr()->scenery_available(pos, range)) {
411 // Try to shedule tiles for that position.
412 globals->get_tile_mgr()->update( pos, range );
416 if (getGroundElevationM(SGGeod::fromGeodM(pos, 20000), alt, 0))
417 tgt_altitude_ft = alt * SG_METER_TO_FEET;
422 void FGAIAircraft::doGroundAltitude() {
423 if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
424 altitude_ft = (tgt_altitude_ft + groundOffset);
426 altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
430 void FGAIAircraft::announcePositionToController() {
432 int leg = fp->getLeg();
434 // Note that leg has been incremented after creating the current leg, so we should use
435 // leg numbers here that are one higher than the number that is used to create the leg
438 case 2: // Startup and Push back
439 if (trafficRef->getDepartureAirport()->getDynamics())
440 controller = trafficRef->getDepartureAirport()->getDynamics()->getStartupController();
442 case 3: // Taxiing to runway
443 if (trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork()->exists())
444 controller = trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork();
446 case 4: //Take off tower controller
447 if (trafficRef->getDepartureAirport()->getDynamics()) {
448 controller = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
449 //if (trafficRef->getDepartureAirport()->getId() == "EHAM") {
450 //string trns = trafficRef->getCallSign() + " at runway " + fp->getRunway() +
451 // ". Ready for departure. " + trafficRef->getFlightType() + " to " +
452 // trafficRef->getArrivalAirport()->getId();
453 //fgSetString("/sim/messages/atc", trns.c_str());
454 // if (controller == 0) {
455 //cerr << "Error in assigning controller at " << trafficRef->getDepartureAirport()->getId() << endl;
459 cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
462 case 9: // Taxiing for parking
463 if (trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork()->exists())
464 controller = trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork();
471 if ((controller != prevController) && (prevController != 0)) {
472 prevController->signOff(getID());
474 prevController = controller;
476 controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->routeIndex,
477 _getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
478 trafficRef->getRadius(), leg, this);
483 // Process ATC instructions and report back
485 void FGAIAircraft::processATC(FGATCInstruction instruction) {
486 if (instruction.getCheckForCircularWait()) {
487 // This is not exactly an elegant solution,
488 // but at least it gives me a chance to check
489 // if circular waits are resolved.
490 // For now, just take the offending aircraft
493 // a more proper way should be - of course - to
494 // let an offending aircraft take an evasive action
495 // for instance taxi back a little bit.
497 //cerr << "Processing ATC instruction (not Implimented yet)" << endl;
498 if (instruction.getHoldPattern ()) {}
501 if (instruction.getHoldPosition ()) {
509 // cerr << trafficRef->getCallSign() << " Resuming Taxi." << endl;
512 // Change speed Instruction. This can only be excecuted when there is no
513 // Hold position instruction.
514 if (instruction.getChangeSpeed ()) {
516 //cerr << trafficRef->getCallSign() << " Changing Speed " << endl;
517 AccelTo(instruction.getSpeed());
519 if (fp) AccelTo(fp->getPreviousWaypoint()->speed);
522 if (instruction.getChangeHeading ()) {
524 TurnTo(instruction.getHeading());
530 if (instruction.getChangeAltitude()) {}
535 void FGAIAircraft::handleFirstWaypoint() {
536 bool eraseWaypoints; //TODO YAGNI
539 eraseWaypoints = true;
541 eraseWaypoints = false;
544 FGAIFlightPlan::waypoint* prev = 0; // the one behind you
545 FGAIFlightPlan::waypoint* curr = 0; // the one ahead
546 FGAIFlightPlan::waypoint* next = 0;// the next plus 1
551 //TODO fp should handle this
552 fp->IncrementWaypoint(eraseWaypoints);
553 if (!(fp->getNextWaypoint()) && trafficRef)
554 if (!loadNextLeg()) {
559 prev = fp->getPreviousWaypoint(); //first waypoint
560 curr = fp->getCurrentWaypoint(); //second waypoint
561 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
563 setLatitude(prev->latitude);
564 setLongitude(prev->longitude);
565 setSpeed(prev->speed);
566 setAltitude(prev->altitude);
568 if (prev->speed > 0.0)
569 setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
571 setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
573 // If next doesn't exist, as in incrementally created flightplans for
574 // AI/Trafficmanager created plans,
575 // Make sure lead distance is initialized otherwise
577 fp->setLeadDistance(speed, hdg, curr, next);
579 if (curr->crossat > -1000.0) //use a calculated descent/climb rate
582 tgt_vs = (curr->crossat - prev->altitude)
583 / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
584 / 6076.0 / prev->speed*60.0);
585 tgt_altitude_ft = curr->crossat;
588 tgt_altitude_ft = prev->altitude;
590 alt_lock = hdg_lock = true;
591 no_roll = prev->on_ground;
593 Transform(); // make sure aip is initialized.
594 getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value
597 // Make sure to announce the aircraft's position
598 announcePositionToController();
604 * Check Execution time (currently once every 100 ms)
605 * Add a bit of randomization to prevent the execution of all flight plans
606 * in synchrony, which can add significant periodic framerate flutter.
611 bool FGAIAircraft::fpExecutable(time_t now) {
612 double rand_exec_time = (rand() % 100) / 100;
613 return (dt_count > (0.1+rand_exec_time)) && (fp->isActive(now));
618 * Check to see if we've reached the lead point for our next turn
623 bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) {
624 double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
626 //cerr << "2" << endl;
627 double lead_dist = fp->getLeadDistance();
628 // experimental: Use fabs, because speed can be negative (I hope) during push_back.
630 if (lead_dist < fabs(2*speed)) {
631 //don't skip over the waypoint
632 lead_dist = fabs(2*speed);
633 //cerr << "Extending lead distance to " << lead_dist << endl;
636 //prev_dist_to_go = dist_to_go;
637 //if (dist_to_go < lead_dist)
638 // cerr << trafficRef->getCallSign() << " Distance : "
639 // << dist_to_go << ": Lead distance "
640 // << lead_dist << " " << curr->name
641 // << " Ground target speed " << groundTargetSpeed << endl;
643 return dist_to_go < lead_dist;
647 bool FGAIAircraft::aiTrafficVisible() {
648 SGGeod userPos(SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"),
649 fgGetDouble("/position/latitude-deg")));
651 return (SGGeodesy::distanceNm(userPos, pos) <= TRAFFICTOAIDISTTODIE);
656 * Handle release of parking gate, once were taxiing. Also ensure service time at the gate
657 * in the case of an arrival.
663 //TODO the trafficRef is the right place for the method
664 bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now) {
665 // prepare routing from one airport to another
666 FGAirport * dep = trafficRef->getDepartureAirport();
667 FGAirport * arr = trafficRef->getArrivalAirport();
672 // This waypoint marks the fact that the aircraft has passed the initial taxi
673 // departure waypoint, so it can release the parking.
674 //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
675 if (prev->name == "PushBackPoint") {
676 dep->getDynamics()->releaseParking(fp->getGate());
677 time_t holdUntil = now + 120;
678 fp->setTime(holdUntil);
679 //cerr << _getCallsign() << "Holding at pushback point" << endl;
682 // This is the last taxi waypoint, and marks the the end of the flight plan
683 // so, the schedule should update and wait for the next departure time.
684 if (prev->name == "END") {
685 time_t nextDeparture = trafficRef->getDepartureTime();
686 // make sure to wait at least 20 minutes at parking to prevent "nervous" taxi behavior
687 if (nextDeparture < (now+1200)) {
688 nextDeparture = now + 1200;
690 fp->setTime(nextDeparture); // should be "next departure"
698 * Check difference between target bearing and current heading and correct if necessary.
702 void FGAIAircraft::controlHeading(FGAIFlightPlan::waypoint* curr) {
703 double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
704 //cerr << "Bearing = " << calc_bearing << endl;
707 if (calc_bearing > 360)
711 if (finite(calc_bearing)) {
712 double hdg_error = calc_bearing - tgt_heading;
713 if (fabs(hdg_error) > 0.01) {
714 TurnTo( calc_bearing );
718 cerr << "calc_bearing is not a finite number : "
720 << "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
721 << "waypoint " << curr->latitude << ", " << curr->longitude << endl;
722 cerr << "waypoint name " << curr->name;
729 * Update the lead distance calculation if speed has changed sufficiently
730 * to prevent spinning (hopefully);
735 void FGAIAircraft::controlSpeed(FGAIFlightPlan::waypoint* curr, FGAIFlightPlan::waypoint* next) {
736 double speed_diff = speed - prevSpeed;
738 if (fabs(speed_diff) > 10) {
741 fp->setLeadDistance(speed, tgt_heading, curr, next);
748 * Update target values (heading, alt, speed) depending on flight plan or control properties
750 void FGAIAircraft::updatePrimaryTargetValues() {
751 if (fp) // AI object has a flightplan
753 //TODO make this a function of AIBase
754 time_t now = time(NULL) + fgGetLong("/sim/time/warp");
755 //cerr << "UpateTArgetValues() " << endl;
756 ProcessFlightPlan(dt, now);
758 // Do execute Ground elev for inactive aircraft, so they
759 // Are repositioned to the correct ground altitude when the user flies within visibility range.
760 // In addition, check whether we are out of user range, so this aircraft
763 Transform(); // make sure aip is initialized.
767 pos.setElevationFt(altitude_ft);
770 //cerr << trafficRef->getRegistration() << " Setting altitude to " << altitude_ft;
771 if (! aiTrafficVisible()) {
773 //cerr << trafficRef->getRegistration() << " is set to die " << endl;
774 throw AI_OutOfSight();
777 timeElapsed = now - fp->getStartTime();
778 if (! fp->isActive(now)) {
782 // no flight plan, update target heading, speed, and altitude
783 // from control properties. These default to the initial
784 // settings in the config file, but can be changed "on the
786 string lat_mode = props->getStringValue("controls/flight/lateral-mode");
787 if ( lat_mode == "roll" ) {
789 = props->getDoubleValue("controls/flight/target-roll" );
793 = props->getDoubleValue("controls/flight/target-hdg" );
798 = props->getStringValue("controls/flight/longitude-mode");
799 if ( lon_mode == "alt" ) {
800 double alt = props->getDoubleValue("controls/flight/target-alt" );
804 = props->getDoubleValue("controls/flight/target-pitch" );
808 AccelTo( props->getDoubleValue("controls/flight/target-spd" ) );
812 void FGAIAircraft::updatePosition() {
813 // convert speed to degrees per second
814 double speed_north_deg_sec = cos( hdg * SGD_DEGREES_TO_RADIANS )
815 * speed * 1.686 / ft_per_deg_lat;
816 double speed_east_deg_sec = sin( hdg * SGD_DEGREES_TO_RADIANS )
817 * speed * 1.686 / ft_per_deg_lon;
820 pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
821 pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
825 void FGAIAircraft::updateHeading() {
826 // adjust heading based on current bank angle
831 // double turnConstant;
833 // turnConstant = 0.0088362;
835 // turnConstant = 0.088362;
836 // If on ground, calculate heading change directly
838 double headingDiff = fabs(hdg-tgt_heading);
839 double bank_sense = 0.0;
841 double diff = fabs(hdg - tgt_heading);
843 diff = fabs(diff - 360);
845 double sum = hdg + diff;
848 if (fabs(sum - tgt_heading) < 1.0) {
849 bank_sense = 1.0; // right turn
851 bank_sense = -1.0; // left turn
853 if (headingDiff > 180)
854 headingDiff = fabs(headingDiff - 360);
855 double sum = hdg + headingDiff;
858 if (fabs(sum - tgt_heading) > 0.0001) {
864 //cerr << trafficRef->getCallSign() << " Heading "
865 // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << endl;
866 //if (headingDiff > 60) {
867 groundTargetSpeed = tgt_speed; // * cos(headingDiff * SG_DEGREES_TO_RADIANS);
868 //groundTargetSpeed = tgt_speed - tgt_speed * (headingDiff/180);
870 // groundTargetSpeed = tgt_speed;
872 if (sign(groundTargetSpeed) != sign(tgt_speed))
873 groundTargetSpeed = 0.21 * sign(tgt_speed); // to prevent speed getting stuck in 'negative' mode
875 if (headingDiff > 30.0) {
876 // invert if pushed backward
877 headingChangeRate += 10.0 * dt * sign(roll);
879 // Clamp the maximum steering rate to 30 degrees per second,
880 // But only do this when the heading error is decreasing.
881 if ((headingDiff < headingError)) {
882 if (headingChangeRate > 30)
883 headingChangeRate = 30;
884 else if (headingChangeRate < -30)
885 headingChangeRate = -30;
888 if (fabs(headingChangeRate) > headingDiff)
889 headingChangeRate = headingDiff*sign(roll);
891 headingChangeRate += dt * sign(roll);
894 hdg += headingChangeRate * dt * (fabs(speed) / 15);
895 headingError = headingDiff;
897 if (fabs(speed) > 1.0) {
898 turn_radius_ft = 0.088362 * speed * speed
899 / tan( fabs(roll) / SG_RADIANS_TO_DEGREES );
901 // Check if turn_radius_ft == 0; this might lead to a division by 0.
902 turn_radius_ft = 1.0;
904 double turn_circum_ft = SGD_2PI * turn_radius_ft;
905 double dist_covered_ft = speed * 1.686 * dt;
906 double alpha = dist_covered_ft / turn_circum_ft * 360.0;
907 hdg += alpha * sign(roll);
909 while ( hdg > 360.0 ) {
921 void FGAIAircraft::updateBankAngleTarget() {
922 // adjust target bank angle if heading lock engaged
924 double bank_sense = 0.0;
925 double diff = fabs(hdg - tgt_heading);
927 diff = fabs(diff - 360);
929 double sum = hdg + diff;
932 if (fabs(sum - tgt_heading) < 1.0) {
933 bank_sense = 1.0; // right turn
935 bank_sense = -1.0; // left turn
937 if (diff < _performance->maximumBankAngle()) {
938 tgt_roll = diff * bank_sense;
940 tgt_roll = _performance->maximumBankAngle() * bank_sense;
942 if ((fabs((double) spinCounter) > 1) && (diff > _performance->maximumBankAngle())) {
943 tgt_speed *= 0.999; // Ugly hack: If aircraft get stuck, they will continually spin around.
944 // The only way to resolve this is to make them slow down.
950 void FGAIAircraft::updateVerticalSpeedTarget() {
951 // adjust target Altitude, based on ground elevation when on ground
955 } else if (alt_lock) {
956 // find target vertical speed
958 if (altitude_ft < tgt_altitude_ft) {
959 tgt_vs = tgt_altitude_ft - altitude_ft;
960 if (tgt_vs > _performance->climbRate())
961 tgt_vs = _performance->climbRate();
963 tgt_vs = tgt_altitude_ft - altitude_ft;
964 if (tgt_vs < (-_performance->descentRate()))
965 tgt_vs = -_performance->descentRate();
968 double max_vs = 4*(tgt_altitude_ft - altitude_ft);
970 if (tgt_altitude_ft < altitude_ft)
972 if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
973 && (fabs(max_vs) < fabs(tgt_vs)))
976 if (fabs(tgt_vs) < fabs(min_vs))
983 void FGAIAircraft::updatePitchAngleTarget() {
984 // if on ground and above vRotate -> initial rotation
985 if (onGround() && (speed > _performance->vRotate()))
986 tgt_pitch = 8.0; // some rough B737 value
988 //TODO pitch angle on approach and landing
990 // match pitch angle to vertical speed
991 else if (tgt_vs > 0) {
992 tgt_pitch = tgt_vs * 0.005;
994 tgt_pitch = tgt_vs * 0.002;
998 string FGAIAircraft::atGate() {
1000 if (fp->getLeg() < 3) {
1002 if (fp->getGate() > 0) {
1004 trafficRef->getDepartureAirport()->getDynamics()->getParking(fp->getGate());
1005 tmp = park->getName();
1012 void FGAIAircraft::handleATCRequests() {
1013 //TODO implement NullController for having no ATC to save the conditionals
1015 controller->update(getID(),
1016 pos.getLatitudeDeg(),
1017 pos.getLongitudeDeg(),
1021 processATC(controller->getInstruction(getID()));
1025 void FGAIAircraft::updateActualState() {
1026 //update current state
1027 //TODO have a single tgt_speed and check speed limit on ground on setting tgt_speed
1031 speed = _performance->actualSpeed(this, groundTargetSpeed, dt);
1033 speed = _performance->actualSpeed(this, tgt_speed, dt);
1036 roll = _performance->actualBankAngle(this, tgt_roll, dt);
1038 // adjust altitude (meters) based on current vertical speed (fpm)
1039 altitude_ft += vs / 60.0 * dt;
1040 pos.setElevationFt(altitude_ft);
1042 vs = _performance->actualVerticalSpeed(this, tgt_vs, dt);
1043 pitch = _performance->actualPitch(this, tgt_pitch, dt);
1046 void FGAIAircraft::updateSecondaryTargetValues() {
1047 // derived target state values
1048 updateBankAngleTarget();
1049 updateVerticalSpeedTarget();
1050 updatePitchAngleTarget();
1052 //TODO calculate wind correction angle (tgt_yaw)