Some small updates that hopefully solve the segmentation fault at the end of the flightplan.
This commit is contained in:
parent
3ef1c6f540
commit
009fa7371d
4 changed files with 21 additions and 14 deletions
|
@ -52,12 +52,12 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
|
||||||
FGAIAircraft *FGAIAircraft::_self = NULL;
|
FGAIAircraft *FGAIAircraft::_self = NULL;
|
||||||
|
|
||||||
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
|
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
|
||||||
|
_self = this; // This needs to be the first entry.
|
||||||
manager = mgr;
|
manager = mgr;
|
||||||
_self = this;
|
|
||||||
_type_str = "aircraft";
|
_type_str = "aircraft";
|
||||||
_otype = otAircraft;
|
_otype = otAircraft;
|
||||||
fp = 0;
|
fp = 0;
|
||||||
fp_count = 0;
|
dt_count = 0;
|
||||||
use_perf_vs = true;
|
use_perf_vs = true;
|
||||||
|
|
||||||
// set heading and altitude locks
|
// set heading and altitude locks
|
||||||
|
@ -113,7 +113,7 @@ void FGAIAircraft::Run(double dt) {
|
||||||
|
|
||||||
FGAIAircraft::dt = dt;
|
FGAIAircraft::dt = dt;
|
||||||
|
|
||||||
if (fp) ProcessFlightPlan();
|
if (fp) ProcessFlightPlan(dt);
|
||||||
|
|
||||||
double turn_radius_ft;
|
double turn_radius_ft;
|
||||||
double turn_circum_ft;
|
double turn_circum_ft;
|
||||||
|
@ -336,14 +336,14 @@ void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
|
||||||
fp = f;
|
fp = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIAircraft::ProcessFlightPlan( void ) {
|
void FGAIAircraft::ProcessFlightPlan( double dt ) {
|
||||||
FGAIFlightPlan::waypoint* prev = 0; // the one behind you
|
FGAIFlightPlan::waypoint* prev = 0; // the one behind you
|
||||||
FGAIFlightPlan::waypoint* curr = 0; // the one ahead
|
FGAIFlightPlan::waypoint* curr = 0; // the one ahead
|
||||||
FGAIFlightPlan::waypoint* next = 0; // the next plus 1
|
FGAIFlightPlan::waypoint* next = 0; // the next plus 1
|
||||||
prev = fp->getPreviousWaypoint();
|
prev = fp->getPreviousWaypoint();
|
||||||
curr = fp->getCurrentWaypoint();
|
curr = fp->getCurrentWaypoint();
|
||||||
next = fp->getNextWaypoint();
|
next = fp->getNextWaypoint();
|
||||||
++fp_count;
|
dt_count += dt;
|
||||||
|
|
||||||
if (!prev) { //beginning of flightplan, do this initialization once
|
if (!prev) { //beginning of flightplan, do this initialization once
|
||||||
fp->IncrementWaypoint();
|
fp->IncrementWaypoint();
|
||||||
|
@ -375,11 +375,12 @@ void FGAIAircraft::ProcessFlightPlan( void ) {
|
||||||
return;
|
return;
|
||||||
} // end of initialization
|
} // end of initialization
|
||||||
|
|
||||||
// let's only process the flight plan every 11 time steps
|
// let's only process the flight plan every 500 ms.
|
||||||
if (fp_count < 11) {
|
if (dt_count < 0.5) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} 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
|
// 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.lat(), pos.lon(), curr);
|
||||||
|
@ -388,7 +389,7 @@ void FGAIAircraft::ProcessFlightPlan( void ) {
|
||||||
//cout << "dist_to_go: " << dist_to_go << ", lead_dist: " << lead_dist << endl;
|
//cout << "dist_to_go: " << dist_to_go << ", lead_dist: " << lead_dist << endl;
|
||||||
|
|
||||||
if ( dist_to_go < lead_dist ) {
|
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);
|
setDie(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
void YawTo(double angle);
|
void YawTo(double angle);
|
||||||
void ClimbTo(double altitude);
|
void ClimbTo(double altitude);
|
||||||
void TurnTo(double heading);
|
void TurnTo(double heading);
|
||||||
void ProcessFlightPlan( void );
|
void ProcessFlightPlan( double dt );
|
||||||
//double getHeading(double lat1, double lon1, double lat2, double lon2);
|
//double getHeading(double lat1, double lon1, double lat2, double lon2);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
bool hdg_lock;
|
bool hdg_lock;
|
||||||
bool alt_lock;
|
bool alt_lock;
|
||||||
FGAIFlightPlan *fp;
|
FGAIFlightPlan *fp;
|
||||||
int fp_count;
|
double dt_count;
|
||||||
double dt;
|
double dt;
|
||||||
|
|
||||||
const PERF_STRUCT *performance;
|
const PERF_STRUCT *performance;
|
||||||
|
@ -91,7 +91,6 @@ private:
|
||||||
|
|
||||||
inline bool FGAIAircraft::_getGearDown() {
|
inline bool FGAIAircraft::_getGearDown() {
|
||||||
return ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
|
return ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
|
||||||
&& (fgGetFloat("/orientation/pitch-deg") < 0.0)
|
|
||||||
&& (fgGetFloat("/velocities/airspeed-kt")
|
&& (fgGetFloat("/velocities/airspeed-kt")
|
||||||
< _self->performance->land_speed*1.5));
|
< _self->performance->land_speed*1.5));
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
|
||||||
for (i = 0; i < node->nChildren(); i++) {
|
for (i = 0; i < node->nChildren(); i++) {
|
||||||
//cout << "Reading waypoint " << i << endl;
|
//cout << "Reading waypoint " << i << endl;
|
||||||
waypoint* wpt = new waypoint;
|
waypoint* wpt = new waypoint;
|
||||||
waypoints.push_back( wpt );
|
|
||||||
SGPropertyNode * wpt_node = node->getChild(i);
|
SGPropertyNode * wpt_node = node->getChild(i);
|
||||||
wpt->name = wpt_node->getStringValue("name", "END");
|
wpt->name = wpt_node->getStringValue("name", "END");
|
||||||
wpt->latitude = wpt_node->getDoubleValue("lat", 0);
|
wpt->latitude = wpt_node->getDoubleValue("lat", 0);
|
||||||
|
@ -60,6 +59,11 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
|
||||||
wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
|
wpt->crossat = wpt_node->getDoubleValue("crossat", -10000);
|
||||||
wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
|
wpt->gear_down = wpt_node->getBoolValue("gear-down", false);
|
||||||
wpt->flaps_down= wpt_node->getBoolValue("flaps-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();
|
wpt_iterator = waypoints.begin();
|
||||||
|
@ -163,6 +167,8 @@ double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp){
|
||||||
if (!southerly && easterly) return 90.0 - angle;
|
if (!southerly && easterly) return 90.0 - angle;
|
||||||
if (southerly && !easterly) return 270.0 - angle;
|
if (southerly && !easterly) return 270.0 - angle;
|
||||||
if (!southerly && !easterly) return 270.0 + angle;
|
if (!southerly && !easterly) return 270.0 + angle;
|
||||||
|
|
||||||
|
// Omit a compiler warning.
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
double altitude;
|
double altitude;
|
||||||
double speed;
|
double speed;
|
||||||
double crossat;
|
double crossat;
|
||||||
|
bool finished;
|
||||||
bool gear_down;
|
bool gear_down;
|
||||||
bool flaps_down;
|
bool flaps_down;
|
||||||
} waypoint;
|
} waypoint;
|
||||||
|
|
Loading…
Add table
Reference in a new issue