FGAIAircraft *FGAIAircraft::_self = NULL;
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
+ _self = this; // This needs to be the first entry.
manager = mgr;
- _self = this;
_type_str = "aircraft";
_otype = otAircraft;
fp = 0;
- fp_count = 0;
+ dt_count = 0;
use_perf_vs = true;
// set heading and altitude locks
FGAIAircraft::dt = dt;
- if (fp) ProcessFlightPlan();
+ if (fp) ProcessFlightPlan(dt);
double turn_radius_ft;
double turn_circum_ft;
fp = f;
}
-void FGAIAircraft::ProcessFlightPlan( void ) {
+void FGAIAircraft::ProcessFlightPlan( double dt ) {
FGAIFlightPlan::waypoint* prev = 0; // the one behind you
FGAIFlightPlan::waypoint* curr = 0; // the one ahead
FGAIFlightPlan::waypoint* next = 0; // the next plus 1
prev = fp->getPreviousWaypoint();
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- ++fp_count;
+ dt_count += dt;
if (!prev) { //beginning of flightplan, do this initialization once
fp->IncrementWaypoint();
return;
} // end of initialization
- // let's only process the flight plan every 11 time steps
- if (fp_count < 11) {
+ // let's only process the flight plan every 500 ms.
+ if (dt_count < 0.5) {
return;
} else {
- fp_count = 0;
+ while (dt_count > 0.5)
+ dt_count -= dt;
// 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);
//cout << "dist_to_go: " << dist_to_go << ", lead_dist: " << lead_dist << endl;
if ( dist_to_go < lead_dist ) {
- if (curr->name == "END") { //end of the flight plan, so terminate
+ if (curr->finished) { //end of the flight plan, so terminate
setDie(true);
return;
}
void YawTo(double angle);
void ClimbTo(double altitude);
void TurnTo(double heading);
- void ProcessFlightPlan( void );
+ void ProcessFlightPlan( double dt );
//double getHeading(double lat1, double lon1, double lat2, double lon2);
protected:
bool hdg_lock;
bool alt_lock;
FGAIFlightPlan *fp;
- int fp_count;
+ double dt_count;
double dt;
const PERF_STRUCT *performance;
inline bool FGAIAircraft::_getGearDown() {
return ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
- && (fgGetFloat("/orientation/pitch-deg") < 0.0)
&& (fgGetFloat("/velocities/airspeed-kt")
< _self->performance->land_speed*1.5));
}
for (i = 0; i < node->nChildren(); i++) {
//cout << "Reading waypoint " << i << endl;
waypoint* wpt = new waypoint;
- waypoints.push_back( wpt );
SGPropertyNode * wpt_node = node->getChild(i);
wpt->name = wpt_node->getStringValue("name", "END");
wpt->latitude = wpt_node->getDoubleValue("lat", 0);
wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
wpt->flaps_down= wpt_node->getBoolValue("flaps-down", false);
+
+ if (wpt->name == "END") wpt->finished = true;
+ else wpt->finished = false;
+
+ waypoints.push_back( wpt );
}
wpt_iterator = waypoints.begin();
if (!southerly && easterly) return 90.0 - angle;
if (southerly && !easterly) return 270.0 - angle;
if (!southerly && !easterly) return 270.0 + angle;
-}
+ // Omit a compiler warning.
+ return 0;
+}
double altitude;
double speed;
double crossat;
+ bool finished;
bool gear_down;
bool flaps_down;
} waypoint;