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;
85 _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
90 FGAIAircraft::~FGAIAircraft() {
93 controller->signOff(getID());
97 void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
101 FGAIBase::readFromScenario(scFileNode);
103 setPerformance(scFileNode->getStringValue("class", "jet_transport"));
104 setFlightPlan(scFileNode->getStringValue("flightplan"),
105 scFileNode->getBoolValue("repeat", false));
106 setCallSign(scFileNode->getStringValue("callsign"));
110 void FGAIAircraft::bind() {
113 props->tie("controls/gear/gear-down",
114 SGRawValueMethods<FGAIAircraft,bool>(*this,
115 &FGAIAircraft::_getGearDown));
116 props->tie("transponder-id",
117 SGRawValueMethods<FGAIAircraft,const char*>(*this,
118 &FGAIAircraft::_getTransponderCode));
122 void FGAIAircraft::unbind() {
125 props->untie("controls/gear/gear-down");
126 props->untie("transponder-id");
130 void FGAIAircraft::update(double dt) {
131 FGAIBase::update(dt);
136 void FGAIAircraft::setPerformance(const std::string& acclass) {
137 static PerformanceDB perfdb; //TODO make it a global service
138 setPerformance(perfdb.getDataFor(acclass));
142 void FGAIAircraft::setPerformance(PerformanceData *ps) {
147 void FGAIAircraft::Run(double dt) {
148 FGAIAircraft::dt = dt;
151 updatePrimaryTargetValues(); // target hdg, alt, speed
153 catch (AI_OutOfSight) {
156 catch (FP_Inactive) {
158 groundTargetSpeed = 0;
161 handleATCRequests(); // ATC also has a word to say
162 updateSecondaryTargetValues(); // target roll, vertical speed, pitch
164 UpdateRadar(manager);
168 void FGAIAircraft::checkVisibility()
170 double visibility_meters = fgGetDouble("/environment/visibility-m");
171 FGViewer* vw = globals->get_current_view();
172 invisible = (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters);
177 void FGAIAircraft::AccelTo(double speed) {
182 void FGAIAircraft::PitchTo(double angle) {
188 void FGAIAircraft::RollTo(double angle) {
194 void FGAIAircraft::YawTo(double angle) {
199 void FGAIAircraft::ClimbTo(double alt_ft ) {
200 tgt_altitude_ft = alt_ft;
205 void FGAIAircraft::TurnTo(double heading) {
206 tgt_heading = heading;
211 double FGAIAircraft::sign(double x) {
219 void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat) {
220 if (!flightplan.empty()) {
221 FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
222 fp->setRepeat(repeat);
228 void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
234 void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
236 // the one behind you
237 FGAIFlightPlan::waypoint* prev = 0;
239 FGAIFlightPlan::waypoint* curr = 0;
241 FGAIFlightPlan::waypoint* next = 0;
243 prev = fp->getPreviousWaypoint();
244 curr = fp->getCurrentWaypoint();
245 next = fp->getNextWaypoint();
249 ///////////////////////////////////////////////////////////////////////////
250 // Initialize the flightplan
251 //////////////////////////////////////////////////////////////////////////
253 handleFirstWaypoint();
255 } // end of initialization
256 if (! fpExecutable(now))
260 if (! leadPointReached(curr)) {
261 controlHeading(curr);
262 controlSpeed(curr, next);
264 if (curr->finished) //end of the flight plan
274 //TODO more intelligent method in AIFlightPlan, no need to send data it already has :-)
275 tgt_heading = fp->getBearing(curr, next);
279 //TODO let the fp handle this (loading of next leg)
280 fp->IncrementWaypoint( trafficRef != 0 );
281 if (!(fp->getNextWaypoint()) && trafficRef != 0)
282 if (!loadNextLeg()) {
287 prev = fp->getPreviousWaypoint();
288 curr = fp->getCurrentWaypoint();
289 next = fp->getNextWaypoint();
291 // Now that we have incremented the waypoints, excute some traffic manager specific code
293 //TODO isn't this best executed right at the beginning?
294 if (! aiTrafficVisible()) {
299 if (! handleAirportEndPoints(prev, now)) {
304 announcePositionToController();
309 fp->setLeadDistance(tgt_speed, tgt_heading, curr, next);
312 if (!(prev->on_ground)) // only update the tgt altitude from flightplan if not on the ground
314 tgt_altitude_ft = prev->altitude;
315 if (curr->crossat > -1000.0) {
317 tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
318 / 6076.0 / speed*60.0);
319 tgt_altitude_ft = curr->crossat;
324 tgt_speed = prev->speed;
325 hdg_lock = alt_lock = true;
326 no_roll = prev->on_ground;
331 void FGAIAircraft::initializeFlightPlan() {
335 bool FGAIAircraft::_getGearDown() const {
336 return _performance->gearExtensible(this);
340 const char * FGAIAircraft::_getTransponderCode() const {
341 return transponderCode.c_str();
345 bool FGAIAircraft::loadNextLeg() {
348 if ((leg = fp->getLeg()) == 10) {
349 if (!trafficRef->next()) {
352 setCallSign(trafficRef->getCallSign());
357 FGAirport *dep = trafficRef->getDepartureAirport();
358 FGAirport *arr = trafficRef->getArrivalAirport();
363 double cruiseAlt = trafficRef->getCruiseAlt() * 100;
370 trafficRef->getSpeed(),
374 trafficRef->getRadius(),
375 trafficRef->getFlightType(),
378 //cerr << "created leg " << leg << " for " << trafficRef->getCallSign() << endl;
384 // Note: This code is copied from David Luff's AILocalTraffic
385 // Warning - ground elev determination is CPU intensive
386 // Either this function or the logic of how often it is called
387 // will almost certainly change.
389 void FGAIAircraft::getGroundElev(double dt) {
392 // Update minimally every three secs, but add some randomness
393 // to prevent all AI objects doing this in synchrony
394 if (dt_elev_count < (3.0) + (rand() % 10))
399 // Only do the proper hitlist stuff if we are within visible range of the viewer.
401 double visibility_meters = fgGetDouble("/environment/visibility-m");
402 FGViewer* vw = globals->get_current_view();
404 if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) {
408 double range = 500.0;
409 if (!globals->get_tile_mgr()->scenery_available(pos, range)) {
410 // Try to shedule tiles for that position.
411 globals->get_tile_mgr()->update( pos, range );
415 if (getGroundElevationM(SGGeod::fromGeodM(pos, 20000), alt, 0))
416 tgt_altitude_ft = alt * SG_METER_TO_FEET;
421 void FGAIAircraft::doGroundAltitude() {
422 if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
423 altitude_ft = (tgt_altitude_ft + groundOffset);
425 altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
429 void FGAIAircraft::announcePositionToController() {
431 int leg = fp->getLeg();
433 // Note that leg has been incremented after creating the current leg, so we should use
434 // leg numbers here that are one higher than the number that is used to create the leg
437 case 2: // Startup and Push back
438 if (trafficRef->getDepartureAirport()->getDynamics())
439 controller = trafficRef->getDepartureAirport()->getDynamics()->getStartupController();
441 case 3: // Taxiing to runway
442 if (trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork()->exists())
443 controller = trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork();
445 case 4: //Take off tower controller
446 if (trafficRef->getDepartureAirport()->getDynamics()) {
447 controller = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
448 //if (trafficRef->getDepartureAirport()->getId() == "EHAM") {
449 //string trns = trafficRef->getCallSign() + " at runway " + fp->getRunway() +
450 // ". Ready for departure. " + trafficRef->getFlightType() + " to " +
451 // trafficRef->getArrivalAirport()->getId();
452 //fgSetString("/sim/messages/atc", trns.c_str());
453 // if (controller == 0) {
454 //cerr << "Error in assigning controller at " << trafficRef->getDepartureAirport()->getId() << endl;
458 cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
461 case 9: // Taxiing for parking
462 if (trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork()->exists())
463 controller = trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork();
470 if ((controller != prevController) && (prevController != 0)) {
471 prevController->signOff(getID());
473 prevController = controller;
475 controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->routeIndex,
476 _getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
477 trafficRef->getRadius(), leg, this);
482 // Process ATC instructions and report back
484 void FGAIAircraft::processATC(FGATCInstruction instruction) {
485 if (instruction.getCheckForCircularWait()) {
486 // This is not exactly an elegant solution,
487 // but at least it gives me a chance to check
488 // if circular waits are resolved.
489 // For now, just take the offending aircraft
492 // a more proper way should be - of course - to
493 // let an offending aircraft take an evasive action
494 // for instance taxi back a little bit.
496 //cerr << "Processing ATC instruction (not Implimented yet)" << endl;
497 if (instruction.getHoldPattern ()) {}
500 if (instruction.getHoldPosition ()) {
508 // cerr << trafficRef->getCallSign() << " Resuming Taxi." << endl;
511 // Change speed Instruction. This can only be excecuted when there is no
512 // Hold position instruction.
513 if (instruction.getChangeSpeed ()) {
515 //cerr << trafficRef->getCallSign() << " Changing Speed " << endl;
516 AccelTo(instruction.getSpeed());
518 if (fp) AccelTo(fp->getPreviousWaypoint()->speed);
521 if (instruction.getChangeHeading ()) {
523 TurnTo(instruction.getHeading());
529 if (instruction.getChangeAltitude()) {}
534 void FGAIAircraft::handleFirstWaypoint() {
535 bool eraseWaypoints; //TODO YAGNI
538 eraseWaypoints = true;
540 eraseWaypoints = false;
543 FGAIFlightPlan::waypoint* prev = 0; // the one behind you
544 FGAIFlightPlan::waypoint* curr = 0; // the one ahead
545 FGAIFlightPlan::waypoint* next = 0;// the next plus 1
550 //TODO fp should handle this
551 fp->IncrementWaypoint(eraseWaypoints);
552 if (!(fp->getNextWaypoint()) && trafficRef)
553 if (!loadNextLeg()) {
558 prev = fp->getPreviousWaypoint(); //first waypoint
559 curr = fp->getCurrentWaypoint(); //second waypoint
560 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
562 setLatitude(prev->latitude);
563 setLongitude(prev->longitude);
564 setSpeed(prev->speed);
565 setAltitude(prev->altitude);
567 if (prev->speed > 0.0)
568 setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
570 setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
572 // If next doesn't exist, as in incrementally created flightplans for
573 // AI/Trafficmanager created plans,
574 // Make sure lead distance is initialized otherwise
576 fp->setLeadDistance(speed, hdg, curr, next);
578 if (curr->crossat > -1000.0) //use a calculated descent/climb rate
581 tgt_vs = (curr->crossat - prev->altitude)
582 / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
583 / 6076.0 / prev->speed*60.0);
584 tgt_altitude_ft = curr->crossat;
587 tgt_altitude_ft = prev->altitude;
589 alt_lock = hdg_lock = true;
590 no_roll = prev->on_ground;
592 Transform(); // make sure aip is initialized.
593 getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value
596 // Make sure to announce the aircraft's position
597 announcePositionToController();
603 * Check Execution time (currently once every 100 ms)
604 * Add a bit of randomization to prevent the execution of all flight plans
605 * in synchrony, which can add significant periodic framerate flutter.
610 bool FGAIAircraft::fpExecutable(time_t now) {
611 double rand_exec_time = (rand() % 100) / 100;
612 return (dt_count > (0.1+rand_exec_time)) && (fp->isActive(now));
617 * Check to see if we've reached the lead point for our next turn
622 bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) {
623 double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
625 //cerr << "2" << endl;
626 double lead_dist = fp->getLeadDistance();
627 // experimental: Use fabs, because speed can be negative (I hope) during push_back.
629 if (lead_dist < fabs(2*speed)) {
630 //don't skip over the waypoint
631 lead_dist = fabs(2*speed);
632 //cerr << "Extending lead distance to " << lead_dist << endl;
635 //prev_dist_to_go = dist_to_go;
636 //if (dist_to_go < lead_dist)
637 // cerr << trafficRef->getCallSign() << " Distance : "
638 // << dist_to_go << ": Lead distance "
639 // << lead_dist << " " << curr->name
640 // << " Ground target speed " << groundTargetSpeed << endl;
642 return dist_to_go < lead_dist;
646 bool FGAIAircraft::aiTrafficVisible() {
647 SGGeod userPos(SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"),
648 fgGetDouble("/position/latitude-deg")));
650 return (SGGeodesy::distanceNm(userPos, pos) <= TRAFFICTOAIDISTTODIE);
655 * Handle release of parking gate, once were taxiing. Also ensure service time at the gate
656 * in the case of an arrival.
662 //TODO the trafficRef is the right place for the method
663 bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now) {
664 // prepare routing from one airport to another
665 FGAirport * dep = trafficRef->getDepartureAirport();
666 FGAirport * arr = trafficRef->getArrivalAirport();
671 // This waypoint marks the fact that the aircraft has passed the initial taxi
672 // departure waypoint, so it can release the parking.
673 //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
674 if (prev->name == "PushBackPoint") {
675 dep->getDynamics()->releaseParking(fp->getGate());
676 time_t holdUntil = now + 120;
677 fp->setTime(holdUntil);
678 //cerr << _getCallsign() << "Holding at pushback point" << endl;
681 // This is the last taxi waypoint, and marks the the end of the flight plan
682 // so, the schedule should update and wait for the next departure time.
683 if (prev->name == "END") {
684 time_t nextDeparture = trafficRef->getDepartureTime();
685 // make sure to wait at least 20 minutes at parking to prevent "nervous" taxi behavior
686 if (nextDeparture < (now+1200)) {
687 nextDeparture = now + 1200;
689 fp->setTime(nextDeparture); // should be "next departure"
697 * Check difference between target bearing and current heading and correct if necessary.
701 void FGAIAircraft::controlHeading(FGAIFlightPlan::waypoint* curr) {
702 double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
703 //cerr << "Bearing = " << calc_bearing << endl;
706 if (calc_bearing > 360)
710 if (finite(calc_bearing)) {
711 double hdg_error = calc_bearing - tgt_heading;
712 if (fabs(hdg_error) > 0.01) {
713 TurnTo( calc_bearing );
717 cerr << "calc_bearing is not a finite number : "
719 << "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
720 << "waypoint " << curr->latitude << ", " << curr->longitude << endl;
721 cerr << "waypoint name " << curr->name;
728 * Update the lead distance calculation if speed has changed sufficiently
729 * to prevent spinning (hopefully);
734 void FGAIAircraft::controlSpeed(FGAIFlightPlan::waypoint* curr, FGAIFlightPlan::waypoint* next) {
735 double speed_diff = speed - prevSpeed;
737 if (fabs(speed_diff) > 10) {
740 fp->setLeadDistance(speed, tgt_heading, curr, next);
747 * Update target values (heading, alt, speed) depending on flight plan or control properties
749 void FGAIAircraft::updatePrimaryTargetValues() {
750 if (fp) // AI object has a flightplan
752 //TODO make this a function of AIBase
753 time_t now = time(NULL) + fgGetLong("/sim/time/warp");
754 //cerr << "UpateTArgetValues() " << endl;
755 ProcessFlightPlan(dt, now);
757 // Do execute Ground elev for inactive aircraft, so they
758 // Are repositioned to the correct ground altitude when the user flies within visibility range.
759 // In addition, check whether we are out of user range, so this aircraft
762 Transform(); // make sure aip is initialized.
766 pos.setElevationFt(altitude_ft);
769 //cerr << trafficRef->getRegistration() << " Setting altitude to " << altitude_ft;
770 if (! aiTrafficVisible()) {
772 //cerr << trafficRef->getRegistration() << " is set to die " << endl;
773 throw AI_OutOfSight();
776 timeElapsed = now - fp->getStartTime();
777 if (! fp->isActive(now)) {
781 // no flight plan, update target heading, speed, and altitude
782 // from control properties. These default to the initial
783 // settings in the config file, but can be changed "on the
785 string lat_mode = props->getStringValue("controls/flight/lateral-mode");
786 if ( lat_mode == "roll" ) {
788 = props->getDoubleValue("controls/flight/target-roll" );
792 = props->getDoubleValue("controls/flight/target-hdg" );
797 = props->getStringValue("controls/flight/longitude-mode");
798 if ( lon_mode == "alt" ) {
799 double alt = props->getDoubleValue("controls/flight/target-alt" );
803 = props->getDoubleValue("controls/flight/target-pitch" );
807 AccelTo( props->getDoubleValue("controls/flight/target-spd" ) );
811 void FGAIAircraft::updatePosition() {
812 // convert speed to degrees per second
813 double speed_north_deg_sec = cos( hdg * SGD_DEGREES_TO_RADIANS )
814 * speed * 1.686 / ft_per_deg_lat;
815 double speed_east_deg_sec = sin( hdg * SGD_DEGREES_TO_RADIANS )
816 * speed * 1.686 / ft_per_deg_lon;
819 pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
820 pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
824 void FGAIAircraft::updateHeading() {
825 // adjust heading based on current bank angle
830 // double turnConstant;
832 // turnConstant = 0.0088362;
834 // turnConstant = 0.088362;
835 // If on ground, calculate heading change directly
837 double headingDiff = fabs(hdg-tgt_heading);
838 double bank_sense = 0.0;
840 double diff = fabs(hdg - tgt_heading);
842 diff = fabs(diff - 360);
844 double sum = hdg + diff;
847 if (fabs(sum - tgt_heading) < 1.0) {
848 bank_sense = 1.0; // right turn
850 bank_sense = -1.0; // left turn
852 if (headingDiff > 180)
853 headingDiff = fabs(headingDiff - 360);
854 double sum = hdg + headingDiff;
857 if (fabs(sum - tgt_heading) > 0.0001) {
863 //cerr << trafficRef->getCallSign() << " Heading "
864 // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << endl;
865 //if (headingDiff > 60) {
866 groundTargetSpeed = tgt_speed; // * cos(headingDiff * SG_DEGREES_TO_RADIANS);
867 //groundTargetSpeed = tgt_speed - tgt_speed * (headingDiff/180);
869 // groundTargetSpeed = tgt_speed;
871 if (sign(groundTargetSpeed) != sign(tgt_speed))
872 groundTargetSpeed = 0.21 * sign(tgt_speed); // to prevent speed getting stuck in 'negative' mode
874 if (headingDiff > 30.0) {
875 // invert if pushed backward
876 headingChangeRate += 10.0 * dt * sign(roll);
878 // Clamp the maximum steering rate to 30 degrees per second,
879 // But only do this when the heading error is decreasing.
880 if ((headingDiff < headingError)) {
881 if (headingChangeRate > 30)
882 headingChangeRate = 30;
883 else if (headingChangeRate < -30)
884 headingChangeRate = -30;
887 if (fabs(headingChangeRate) > headingDiff)
888 headingChangeRate = headingDiff*sign(roll);
890 headingChangeRate += dt * sign(roll);
893 hdg += headingChangeRate * dt * (fabs(speed) / 15);
894 headingError = headingDiff;
896 if (fabs(speed) > 1.0) {
897 turn_radius_ft = 0.088362 * speed * speed
898 / tan( fabs(roll) / SG_RADIANS_TO_DEGREES );
900 // Check if turn_radius_ft == 0; this might lead to a division by 0.
901 turn_radius_ft = 1.0;
903 double turn_circum_ft = SGD_2PI * turn_radius_ft;
904 double dist_covered_ft = speed * 1.686 * dt;
905 double alpha = dist_covered_ft / turn_circum_ft * 360.0;
906 hdg += alpha * sign(roll);
908 while ( hdg > 360.0 ) {
920 void FGAIAircraft::updateBankAngleTarget() {
921 // adjust target bank angle if heading lock engaged
923 double bank_sense = 0.0;
924 double diff = fabs(hdg - tgt_heading);
926 diff = fabs(diff - 360);
928 double sum = hdg + diff;
931 if (fabs(sum - tgt_heading) < 1.0) {
932 bank_sense = 1.0; // right turn
934 bank_sense = -1.0; // left turn
936 if (diff < _performance->maximumBankAngle()) {
937 tgt_roll = diff * bank_sense;
939 tgt_roll = _performance->maximumBankAngle() * bank_sense;
941 if ((fabs((double) spinCounter) > 1) && (diff > _performance->maximumBankAngle())) {
942 tgt_speed *= 0.999; // Ugly hack: If aircraft get stuck, they will continually spin around.
943 // The only way to resolve this is to make them slow down.
949 void FGAIAircraft::updateVerticalSpeedTarget() {
950 // adjust target Altitude, based on ground elevation when on ground
954 } else if (alt_lock) {
955 // find target vertical speed
957 if (altitude_ft < tgt_altitude_ft) {
958 tgt_vs = tgt_altitude_ft - altitude_ft;
959 if (tgt_vs > _performance->climbRate())
960 tgt_vs = _performance->climbRate();
962 tgt_vs = tgt_altitude_ft - altitude_ft;
963 if (tgt_vs < (-_performance->descentRate()))
964 tgt_vs = -_performance->descentRate();
967 double max_vs = 4*(tgt_altitude_ft - altitude_ft);
969 if (tgt_altitude_ft < altitude_ft)
971 if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
972 && (fabs(max_vs) < fabs(tgt_vs)))
975 if (fabs(tgt_vs) < fabs(min_vs))
982 void FGAIAircraft::updatePitchAngleTarget() {
983 // if on ground and above vRotate -> initial rotation
984 if (onGround() && (speed > _performance->vRotate()))
985 tgt_pitch = 8.0; // some rough B737 value
987 //TODO pitch angle on approach and landing
989 // match pitch angle to vertical speed
990 else if (tgt_vs > 0) {
991 tgt_pitch = tgt_vs * 0.005;
993 tgt_pitch = tgt_vs * 0.002;
997 string FGAIAircraft::atGate() {
999 if (fp->getLeg() < 3) {
1001 if (fp->getGate() > 0) {
1003 trafficRef->getDepartureAirport()->getDynamics()->getParking(fp->getGate());
1004 tmp = park->getName();
1011 void FGAIAircraft::handleATCRequests() {
1012 //TODO implement NullController for having no ATC to save the conditionals
1014 controller->update(getID(),
1015 pos.getLatitudeDeg(),
1016 pos.getLongitudeDeg(),
1020 processATC(controller->getInstruction(getID()));
1024 void FGAIAircraft::updateActualState() {
1025 //update current state
1026 //TODO have a single tgt_speed and check speed limit on ground on setting tgt_speed
1030 speed = _performance->actualSpeed(this, groundTargetSpeed, dt);
1032 speed = _performance->actualSpeed(this, tgt_speed, dt);
1035 roll = _performance->actualBankAngle(this, tgt_roll, dt);
1037 // adjust altitude (meters) based on current vertical speed (fpm)
1038 altitude_ft += vs / 60.0 * dt;
1039 pos.setElevationFt(altitude_ft);
1041 vs = _performance->actualVerticalSpeed(this, tgt_vs, dt);
1042 pitch = _performance->actualPitch(this, tgt_pitch, dt);
1045 void FGAIAircraft::updateSecondaryTargetValues() {
1046 // derived target state values
1047 updateBankAngleTarget();
1048 updateVerticalSpeedTarget();
1049 updatePitchAngleTarget();
1051 //TODO calculate wind correction angle (tgt_yaw)