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/math/point3d.hxx>
26 #include <simgear/route/waypoint.hxx>
27 #include <Main/fg_props.hxx>
28 #include <Main/globals.hxx>
29 #include <Main/viewer.hxx>
30 #include <Scenery/scenery.hxx>
31 #include <Scenery/tilemgr.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("callsign",
117 SGRawValueMethods<FGAIAircraft,const char *>(*this,
118 &FGAIAircraft::_getCallSign));
119 //props->setStringValue("callsign", callsign.c_str());
123 void FGAIAircraft::unbind() {
126 props->untie("controls/gear/gear-down");
127 props->untie("callsign");
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) {
161 handleATCRequests(); // ATC also has a word to say
162 updateSecondaryTargetValues(); // target roll, vertical speed, pitch
164 UpdateRadar(manager);
169 void FGAIAircraft::AccelTo(double speed) {
174 void FGAIAircraft::PitchTo(double angle) {
180 void FGAIAircraft::RollTo(double angle) {
186 void FGAIAircraft::YawTo(double angle) {
191 void FGAIAircraft::ClimbTo(double alt_ft ) {
192 tgt_altitude_ft = alt_ft;
197 void FGAIAircraft::TurnTo(double heading) {
198 tgt_heading = heading;
203 double FGAIAircraft::sign(double x) {
211 void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat) {
212 if (!flightplan.empty()) {
213 FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
214 fp->setRepeat(repeat);
220 void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
226 void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
228 // the one behind you
229 FGAIFlightPlan::waypoint* prev = 0;
231 FGAIFlightPlan::waypoint* curr = 0;
233 FGAIFlightPlan::waypoint* next = 0;
235 prev = fp->getPreviousWaypoint();
236 curr = fp->getCurrentWaypoint();
237 next = fp->getNextWaypoint();
241 ///////////////////////////////////////////////////////////////////////////
242 // Initialize the flightplan
243 //////////////////////////////////////////////////////////////////////////
245 handleFirstWaypoint();
247 } // end of initialization
248 if (! fpExecutable(now))
252 if (! leadPointReached(curr)) {
253 controlHeading(curr);
254 controlSpeed(curr, next);
256 if (curr->finished) //end of the flight plan
266 //TODO more intelligent method in AIFlightPlan, no need to send data it already has :-)
267 tgt_heading = fp->getBearing(curr, next);
271 //TODO let the fp handle this (loading of next leg)
272 fp->IncrementWaypoint((bool) trafficRef);
273 if (!(fp->getNextWaypoint()) && trafficRef)
276 prev = fp->getPreviousWaypoint();
277 curr = fp->getCurrentWaypoint();
278 next = fp->getNextWaypoint();
280 // Now that we have incremented the waypoints, excute some traffic manager specific code
282 //TODO isn't this best executed right at the beginning?
283 if (! aiTrafficVisible()) {
288 if (! handleAirportEndPoints(prev, now)) {
293 announcePositionToController();
298 fp->setLeadDistance(speed, tgt_heading, curr, next);
301 if (!(prev->on_ground)) // only update the tgt altitude from flightplan if not on the ground
303 tgt_altitude_ft = prev->altitude;
304 if (curr->crossat > -1000.0) {
306 tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
307 / 6076.0 / speed*60.0);
308 tgt_altitude_ft = curr->crossat;
313 tgt_speed = prev->speed;
314 hdg_lock = alt_lock = true;
315 no_roll = prev->on_ground;
320 void FGAIAircraft::initializeFlightPlan() {
324 bool FGAIAircraft::_getGearDown() const {
325 return _performance->gearExtensible(this);
328 const char * FGAIAircraft::_getCallSign() const {
329 return callsign.c_str();
333 void FGAIAircraft::loadNextLeg() {
336 if ((leg = fp->getLeg()) == 10) {
338 setCallSign(trafficRef->getCallSign());
339 //props->setStringValue("callsign", callsign.c_str());
344 FGAirport *dep = trafficRef->getDepartureAirport();
345 FGAirport *arr = trafficRef->getArrivalAirport();
350 double cruiseAlt = trafficRef->getCruiseAlt() * 100;
355 cruiseAlt, //(trafficRef->getCruiseAlt() * 100), // convert from FL to feet
356 trafficRef->getSpeed(),
360 trafficRef->getRadius(),
361 trafficRef->getFlightType(),
368 // Note: This code is copied from David Luff's AILocalTraffic
369 // Warning - ground elev determination is CPU intensive
370 // Either this function or the logic of how often it is called
371 // will almost certainly change.
373 void FGAIAircraft::getGroundElev(double dt) {
376 // Update minimally every three secs, but add some randomness
377 // to prevent all IA objects doing this in synchrony
378 if (dt_elev_count < (3.0) + (rand() % 10))
383 // Only do the proper hitlist stuff if we are within visible range of the viewer.
385 double visibility_meters = fgGetDouble("/environment/visibility-m");
387 FGViewer* vw = globals->get_current_view();
388 double course, distance;
390 SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
391 SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
392 view.CourseAndDistance(current, &course, &distance);
393 if (distance > visibility_meters) {
394 //aip.getSGLocation()->set_cur_elev_m(aptElev);
398 // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
399 double range = 500.0;
400 if (!globals->get_tile_mgr()->scenery_available(pos.getLatitudeDeg(), pos.getLongitudeDeg(), range)) {
401 // Try to shedule tiles for that position.
402 globals->get_tile_mgr()->update( aip.getSGLocation(), range );
405 // FIXME: make sure the pos.lat/pos.lon values are in degrees ...
407 if (globals->get_scenery()->get_elevation_m(pos.getLatitudeDeg(), pos.getLongitudeDeg(), 20000.0, alt, 0))
408 tgt_altitude_ft = alt * SG_METER_TO_FEET;
413 void FGAIAircraft::setCallSign(const string& s) {
418 void FGAIAircraft::doGroundAltitude() {
419 if (fabs(altitude_ft - (tgt_altitude_ft+groundOffset)) > 1000.0)
420 altitude_ft = (tgt_altitude_ft + groundOffset);
422 altitude_ft += 0.1 * ((tgt_altitude_ft+groundOffset) - altitude_ft);
426 void FGAIAircraft::announcePositionToController() {
428 int leg = fp->getLeg();
430 // Note that leg was been incremented after creating the current leg, so we should use
431 // leg numbers here that are one higher than the number that is used to create the leg
434 case 3: // Taxiing to runway
435 if (trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork()->exists())
436 controller = trafficRef->getDepartureAirport()->getDynamics()->getGroundNetwork();
438 case 4: //Take off tower controller
439 if (trafficRef->getDepartureAirport()->getDynamics()) {
440 controller = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
441 //if (trafficRef->getDepartureAirport()->getId() == "EHAM") {
442 //cerr << trafficRef->getCallSign() << " at runway " << fp->getRunway() << "Ready for departure "
443 // << trafficRef->getFlightType() << " to " << trafficRef->getArrivalAirport()->getId() << endl;
444 // if (controller == 0) {
445 //cerr << "Error in assigning controller at " << trafficRef->getDepartureAirport()->getId() << endl;
449 cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
452 case 9: // Taxiing for parking
453 if (trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork()->exists())
454 controller = trafficRef->getArrivalAirport()->getDynamics()->getGroundNetwork();
461 if ((controller != prevController) && (prevController != 0)) {
462 prevController->signOff(getID());
463 string callsign = trafficRef->getCallSign();
464 if ( trafficRef->getHeavy())
468 //cerr << callsign << " ready to taxi to runway " << fp->getRunway() << endl;
471 //cerr << callsign << " at runway " << fp->getRunway() << "Ready for take-off. "
472 // << trafficRef->getFlightRules() << " to " << trafficRef->getArrivalAirport()->getId()
473 // << "(" << trafficRef->getArrivalAirport()->getName() << ")."<< endl;
477 prevController = controller;
479 controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->routeIndex,
480 _getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
481 trafficRef->getRadius(), leg, trafficRef->getCallSign());
487 void FGAIAircraft::processATC(FGATCInstruction instruction) {
488 if (instruction.getCheckForCircularWait()) {
489 // This is not exactly an elegant solution,
490 // but at least it gives me a chance to check
491 // if circular waits are resolved.
492 // For now, just take the offending aircraft
495 // a more proper way should be - of course - to
496 // let an offending aircraft take an evasive action
497 // for instance taxi back a little bit.
499 //cerr << "Processing ATC instruction (not Implimented yet)" << endl;
500 if (instruction.getHoldPattern ()) {}
503 if (instruction.getHoldPosition ()) {
511 // cerr << trafficRef->getCallSign() << " Resuming Taxi " << endl;
514 // Change speed Instruction. This can only be excecuted when there is no
515 // Hold position instruction.
516 if (instruction.getChangeSpeed ()) {
518 //cerr << trafficRef->getCallSign() << " Changing Speed " << endl;
519 AccelTo(instruction.getSpeed());
521 if (fp) AccelTo(fp->getPreviousWaypoint()->speed);
524 if (instruction.getChangeHeading ()) {
526 TurnTo(instruction.getHeading());
532 if (instruction.getChangeAltitude()) {}
537 void FGAIAircraft::handleFirstWaypoint() {
538 bool eraseWaypoints; //TODO YAGNI
540 eraseWaypoints = true;
542 eraseWaypoints = false;
545 FGAIFlightPlan::waypoint* prev = 0; // the one behind you
546 FGAIFlightPlan::waypoint* curr = 0; // the one ahead
547 FGAIFlightPlan::waypoint* next = 0;// the next plus 1
552 //TODO fp should handle this
553 fp->IncrementWaypoint(eraseWaypoints);
554 if (!(fp->getNextWaypoint()) && trafficRef)
557 prev = fp->getPreviousWaypoint(); //first waypoint
558 curr = fp->getCurrentWaypoint(); //second waypoint
559 next = fp->getNextWaypoint(); //third waypoint (might not exist!)
561 setLatitude(prev->latitude);
562 setLongitude(prev->longitude);
563 setSpeed(prev->speed);
564 setAltitude(prev->altitude);
566 if (prev->speed > 0.0)
567 setHeading(fp->getBearing(prev->latitude, prev->longitude, curr));
569 setHeading(fp->getBearing(curr->latitude, curr->longitude, prev));
571 // If next doesn't exist, as in incrementally created flightplans for
572 // AI/Trafficmanager created plans,
573 // Make sure lead distance is initialized otherwise
575 fp->setLeadDistance(speed, hdg, curr, next);
577 if (curr->crossat > -1000.0) //use a calculated descent/climb rate
580 tgt_vs = (curr->crossat - prev->altitude)
581 / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
582 / 6076.0 / prev->speed*60.0);
583 tgt_altitude_ft = curr->crossat;
586 tgt_altitude_ft = prev->altitude;
588 alt_lock = hdg_lock = true;
589 no_roll = prev->on_ground;
591 Transform(); // make sure aip is initialized.
592 getGroundElev(60.1); // make sure it's executed first time around, so force a large dt value
595 // Make sure to announce the aircraft's position
596 announcePositionToController();
602 * Check Execution time (currently once every 100 ms)
603 * Add a bit of randomization to prevent the execution of all flight plans
604 * in synchrony, which can add significant periodic framerate flutter.
609 bool FGAIAircraft::fpExecutable(time_t now) {
610 double rand_exec_time = (rand() % 100) / 100;
611 return (dt_count > (0.1+rand_exec_time)) && (fp->isActive(now));
616 * Check to see if we've reached the lead point for our next turn
621 bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) {
622 double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
624 //cerr << "2" << endl;
625 double lead_dist = fp->getLeadDistance();
626 //cerr << " Distance : " << dist_to_go << ": Lead distance " << lead_dist << endl;
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 return dist_to_go < lead_dist;
640 bool FGAIAircraft::aiTrafficVisible() {
641 double userLatitude = fgGetDouble("/position/latitude-deg");
642 double userLongitude = fgGetDouble("/position/longitude-deg");
643 double course, distance;
645 SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
646 SGWayPoint user (userLongitude, userLatitude, 0);
648 user.CourseAndDistance(current, &course, &distance);
650 return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDIST);
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 if (prev->name == "park2") {
674 dep->getDynamics()->releaseParking(fp->getGate());
677 // This is the last taxi waypoint, and marks the the end of the flight plan
678 // so, the schedule should update and wait for the next departure time.
679 if (prev->name == "END") {
680 time_t nextDeparture = trafficRef->getDepartureTime();
681 // make sure to wait at least 20 minutes at parking to prevent "nervous" taxi behavior
682 if (nextDeparture < (now+1200)) {
683 nextDeparture = now + 1200;
685 fp->setTime(nextDeparture); // should be "next departure"
693 * Check difference between target bearing and current heading and correct if necessary.
697 void FGAIAircraft::controlHeading(FGAIFlightPlan::waypoint* curr) {
698 double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
699 //cerr << "Bearing = " << calc_bearing << endl;
702 if (calc_bearing > 360)
706 if (finite(calc_bearing)) {
707 double hdg_error = calc_bearing - tgt_heading;
708 if (fabs(hdg_error) > 1.0) {
709 TurnTo( calc_bearing );
713 cerr << "calc_bearing is not a finite number : "
715 << "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
716 << "waypoint " << curr->latitude << ", " << curr->longitude << endl;
717 cerr << "waypoint name " << curr->name;
724 * Update the lead distance calculation if speed has changed sufficiently
725 * to prevent spinning (hopefully);
730 void FGAIAircraft::controlSpeed(FGAIFlightPlan::waypoint* curr, FGAIFlightPlan::waypoint* next) {
731 double speed_diff = speed - prevSpeed;
733 if (fabs(speed_diff) > 10) {
735 fp->setLeadDistance(speed, tgt_heading, curr, next);
741 * Update target values (heading, alt, speed) depending on flight plan or control properties
743 void FGAIAircraft::updatePrimaryTargetValues() {
744 if (fp) // AI object has a flightplan
746 //TODO make this a function of AIBase
747 time_t now = time(NULL) + fgGetLong("/sim/time/warp");
748 //cerr << "UpateTArgetValues() " << endl;
749 ProcessFlightPlan(dt, now);
750 if (! fp->isActive(now)) {
751 // Do execute Ground elev for inactive aircraft, so they
752 // Are repositioned to the correct ground altitude when the user flies within visibility range.
753 // In addition, check whether we are out of user range, so this aircraft
756 Transform(); // make sure aip is initialized.
758 //cerr << trafficRef->getRegistration() << " Setting altitude to " << altitude_ft;
759 if (! aiTrafficVisible()) {
761 throw AI_OutOfSight();
766 pos.setElevationFt(altitude_ft);
773 // no flight plan, update target heading, speed, and altitude
774 // from control properties. These default to the initial
775 // settings in the config file, but can be changed "on the
777 string lat_mode = props->getStringValue("controls/flight/lateral-mode");
778 if ( lat_mode == "roll" ) {
780 = props->getDoubleValue("controls/flight/target-roll" );
784 = props->getDoubleValue("controls/flight/target-hdg" );
789 = props->getStringValue("controls/flight/longitude-mode");
790 if ( lon_mode == "alt" ) {
791 double alt = props->getDoubleValue("controls/flight/target-alt" );
795 = props->getDoubleValue("controls/flight/target-pitch" );
799 AccelTo( props->getDoubleValue("controls/flight/target-spd" ) );
803 void FGAIAircraft::updatePosition() {
804 // convert speed to degrees per second
805 double speed_north_deg_sec = cos( hdg * SGD_DEGREES_TO_RADIANS )
806 * speed * 1.686 / ft_per_deg_lat;
807 double speed_east_deg_sec = sin( hdg * SGD_DEGREES_TO_RADIANS )
808 * speed * 1.686 / ft_per_deg_lon;
811 pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
812 pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
816 void FGAIAircraft::updateHeading() {
817 // adjust heading based on current bank angle
822 // double turnConstant;
824 // turnConstant = 0.0088362;
826 // turnConstant = 0.088362;
827 // If on ground, calculate heading change directly
829 double headingDiff = fabs(hdg-tgt_heading);
831 if (headingDiff > 180)
832 headingDiff = fabs(headingDiff - 360);
834 groundTargetSpeed = tgt_speed - (tgt_speed * (headingDiff/45));
835 if (sign(groundTargetSpeed) != sign(tgt_speed))
836 groundTargetSpeed = 0.21 * sign(tgt_speed); // to prevent speed getting stuck in 'negative' mode
838 if (headingDiff > 30.0) {
839 // invert if pushed backward
840 headingChangeRate += dt * sign(roll);
842 if (headingChangeRate > 30)
843 headingChangeRate = 30;
844 else if (headingChangeRate < -30)
845 headingChangeRate = -30;
848 if (fabs(headingChangeRate) > headingDiff)
849 headingChangeRate = headingDiff*sign(roll);
851 headingChangeRate += dt * sign(roll);
853 hdg += headingChangeRate * dt;
855 if (fabs(speed) > 1.0) {
856 turn_radius_ft = 0.088362 * speed * speed
857 / tan( fabs(roll) / SG_RADIANS_TO_DEGREES );
859 // Check if turn_radius_ft == 0; this might lead to a division by 0.
860 turn_radius_ft = 1.0;
862 double turn_circum_ft = SGD_2PI * turn_radius_ft;
863 double dist_covered_ft = speed * 1.686 * dt;
864 double alpha = dist_covered_ft / turn_circum_ft * 360.0;
865 hdg += alpha * sign(roll);
867 while ( hdg > 360.0 ) {
879 void FGAIAircraft::updateBankAngleTarget() {
880 // adjust target bank angle if heading lock engaged
882 double bank_sense = 0.0;
883 double diff = fabs(hdg - tgt_heading);
885 diff = fabs(diff - 360);
887 double sum = hdg + diff;
890 if (fabs(sum - tgt_heading) < 1.0) {
891 bank_sense = 1.0; // right turn
893 bank_sense = -1.0; // left turn
895 if (diff < _performance->maximumBankAngle()) {
896 tgt_roll = diff * bank_sense;
898 tgt_roll = _performance->maximumBankAngle() * bank_sense;
900 if ((fabs((double) spinCounter) > 1) && (diff > _performance->maximumBankAngle())) {
901 tgt_speed *= 0.999; // Ugly hack: If aircraft get stuck, they will continually spin around.
902 // The only way to resolve this is to make them slow down.
908 void FGAIAircraft::updateVerticalSpeedTarget() {
909 // adjust target Altitude, based on ground elevation when on ground
913 } else if (alt_lock) {
914 // find target vertical speed
916 if (altitude_ft < tgt_altitude_ft) {
917 tgt_vs = tgt_altitude_ft - altitude_ft;
918 if (tgt_vs > _performance->climbRate())
919 tgt_vs = _performance->climbRate();
921 tgt_vs = tgt_altitude_ft - altitude_ft;
922 if (tgt_vs < (-_performance->descentRate()))
923 tgt_vs = -_performance->descentRate();
926 double max_vs = 4*(tgt_altitude_ft - altitude_ft);
928 if (tgt_altitude_ft < altitude_ft)
930 if ((fabs(tgt_altitude_ft - altitude_ft) < 1500.0)
931 && (fabs(max_vs) < fabs(tgt_vs)))
934 if (fabs(tgt_vs) < fabs(min_vs))
941 void FGAIAircraft::updatePitchAngleTarget() {
942 // if on ground and above vRotate -> initial rotation
943 if (onGround() && (speed > _performance->vRotate()))
944 tgt_pitch = 8.0; // some rough B737 value
946 //TODO pitch angle on approach and landing
948 // match pitch angle to vertical speed
949 else if (tgt_vs > 0) {
950 tgt_pitch = tgt_vs * 0.005;
952 tgt_pitch = tgt_vs * 0.002;
956 void FGAIAircraft::handleATCRequests() {
957 //TODO implement NullController for having no ATC to save the conditionals
959 controller->update(getID(),
960 pos.getLatitudeDeg(),
961 pos.getLongitudeDeg(),
965 processATC(controller->getInstruction(getID()));
969 void FGAIAircraft::updateActualState() {
970 //update current state
971 //TODO have a single tgt_speed and check speed limit on ground on setting tgt_speed
975 speed = _performance->actualSpeed(this, groundTargetSpeed, dt);
977 speed = _performance->actualSpeed(this, tgt_speed, dt);
980 roll = _performance->actualBankAngle(this, tgt_roll, dt);
982 // adjust altitude (meters) based on current vertical speed (fpm)
983 altitude_ft += vs / 60.0 * dt;
984 pos.setElevationFt(altitude_ft);
986 vs = _performance->actualVerticalSpeed(this, tgt_vs, dt);
987 pitch = _performance->actualPitch(this, tgt_pitch, dt);
990 void FGAIAircraft::updateSecondaryTargetValues() {
991 // derived target state values
992 updateBankAngleTarget();
993 updateVerticalSpeedTarget();
994 updatePitchAngleTarget();
996 //TODO calculate wind correction angle (tgt_yaw)