1
0
Fork 0

AIFlightPlan: Maintenance

virtual dtor
ensure members are initialized
double constants with double types
variable scope conflict fixed
This commit is contained in:
Scott Giese 2022-01-15 20:09:28 -06:00
parent 1816e3e551
commit 42ee4822c7
3 changed files with 48 additions and 69 deletions

View file

@ -534,7 +534,6 @@ void FGAIFlightPlan::addWaypoint(FGAIWaypoint* wpt)
pushBackWaypoint(wpt); pushBackWaypoint(wpt);
} }
void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt) void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt)
{ {
size_t pos = wpt_iterator - waypoints.begin(); size_t pos = wpt_iterator - waypoints.begin();

View file

@ -16,8 +16,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef _FG_AIFLIGHTPLAN_HXX #pragma once
#define _FG_AIFLIGHTPLAN_HXX
#include <vector> #include <vector>
#include <string> #include <string>
@ -41,23 +40,25 @@ private:
bool finished; bool finished;
bool gear_down; bool gear_down;
double flaps; double flaps;
double spoilers; double spoilers = 0.0;
double speedbrakes; double speedbrakes = 0.0;
bool on_ground; bool on_ground;
int routeIndex; // For AI/ATC purposes; int routeIndex; // For AI/ATC purposes;
double time_sec; double time_sec;
double trackLength; // distance from previous FGAIWaypoint (for AI purposes); double trackLength; // distance from previous FGAIWaypoint (for AI purposes);
std::string time; std::string time;
bool beacon_light;
bool landing_light; bool beacon_light = false;
bool nav_light; bool landing_light = false;
bool strobe_light; bool nav_light = false;
bool taxi_light; bool strobe_light = false;
bool cabin_light; bool taxi_light = false;
bool cabin_light = false;
public: public:
FGAIWaypoint(); FGAIWaypoint();
~FGAIWaypoint() {}; virtual ~FGAIWaypoint() {};
void setName (const std::string& nam) { name = nam; }; void setName (const std::string& nam) { name = nam; };
void setLatitude (double lat); void setLatitude (double lat);
void setLongitude (double lon); void setLongitude (double lon);
@ -82,6 +83,7 @@ public:
nav_light = nav; nav_light = nav;
strobe_light = strobe; strobe_light = strobe;
taxi_light = taxi; }; taxi_light = taxi; };
// beacon cabin ldg nav strobe taxi // beacon cabin ldg nav strobe taxi
void setPowerDownLights() { setLights(false, true, false, false, false, false); }; void setPowerDownLights() { setLights(false, true, false, false, false, false); };
void setGroundLights() { setLights(true, true, false, true, false, true ); }; void setGroundLights() { setLights(true, true, false, true, false, true ); };
@ -122,7 +124,6 @@ public:
bool getNavLight() { return nav_light; }; bool getNavLight() { return nav_light; };
bool getStrobeLight() { return strobe_light;}; bool getStrobeLight() { return strobe_light;};
bool getTaxiLight() { return taxi_light; }; bool getTaxiLight() { return taxi_light; };
}; };
@ -147,7 +148,7 @@ public:
const std::string& fltType, const std::string& fltType,
const std::string& acType, const std::string& acType,
const std::string& airline); const std::string& airline);
~FGAIFlightPlan(); virtual ~FGAIFlightPlan();
/** /**
@brief create a neatrly empty FlightPlan for the user aircraft, based @brief create a neatrly empty FlightPlan for the user aircraft, based
@ -194,7 +195,6 @@ public:
} }
void setTime(time_t st) { start_time = st; } void setTime(time_t st) { start_time = st; }
double getLeadInAngle() const { return leadInAngle; } double getLeadInAngle() const { return leadInAngle; }
const std::string& getRunway() const; const std::string& getRunway() const;
@ -316,4 +316,3 @@ private:
bool isValidPlan() { return isValid; }; bool isValidPlan() { return isValid; };
}; };
#endif // _FG_AIFLIGHTPLAN_HXX

View file

@ -220,7 +220,6 @@ FGAIWaypoint * FGAIFlightPlan::cloneWithPos(FGAIAircraft * ac, FGAIWaypoint * aW
} }
void FGAIFlightPlan::createDefaultTakeoffTaxi(FGAIAircraft * ac, void FGAIFlightPlan::createDefaultTakeoffTaxi(FGAIAircraft * ac,
FGAirport * aAirport, FGAirport * aAirport,
FGRunway * aRunway) FGRunway * aRunway)
@ -634,8 +633,6 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
double speed, double alt, double speed, double alt,
const string & fltType) const string & fltType)
{ {
FGAIWaypoint *wpt;
// string fPLName;
double vClimb = ac->getPerformance()->vClimb(); double vClimb = ac->getPerformance()->vClimb();
if (firstFlight) { if (firstFlight) {
@ -644,11 +641,10 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
heading); heading);
} }
if (sid) { if (sid) {
for (wpt_vector_iterator i = sid->getFirstWayPoint(); for (wpt_vector_iterator i = sid->getFirstWayPoint(); i != sid->getLastWayPoint(); ++i) {
i != sid->getLastWayPoint(); i++) {
pushBackWaypoint(clone(*(i))); pushBackWaypoint(clone(*(i)));
//cerr << " Cloning waypoint " << endl;
} }
} else { } else {
if (!apt->hasRunwayWithIdent(activeRunway)) if (!apt->hasRunwayWithIdent(activeRunway))
@ -664,13 +660,14 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
double course = SGGeodesy::courseDeg(cur, arrival->geod()); double course = SGGeodesy::courseDeg(cur, arrival->geod());
SGGeod climb1 = SGGeodesy::direct(cur, course, 10 * SG_NM_TO_METER); SGGeod climb1 = SGGeodesy::direct(cur, course, 10 * SG_NM_TO_METER);
wpt = createInAir(ac, "10000ft climb", climb1, 10000, vClimb); FGAIWaypoint *wpt = createInAir(ac, "10000ft climb", climb1, 10000, vClimb);
pushBackWaypoint(wpt); pushBackWaypoint(wpt);
SGGeod climb2 = SGGeodesy::direct(cur, course, 20 * SG_NM_TO_METER); SGGeod climb2 = SGGeodesy::direct(cur, course, 20 * SG_NM_TO_METER);
wpt = createInAir(ac, "18000ft climb", climb2, 18000, vClimb); wpt = createInAir(ac, "18000ft climb", climb2, 18000, vClimb);
pushBackWaypoint(wpt); pushBackWaypoint(wpt);
} }
return true; return true;
} }
@ -769,6 +766,7 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
// lon = initialTarget.getLongitudeDeg(); // lon = initialTarget.getLongitudeDeg();
//cerr << "Initial Target point (" << lat << ", " << lon << ")." << endl; //cerr << "Initial Target point (" << lat << ", " << lon << ")." << endl;
#if 0
double ratio = initialTurnRadius / distance; double ratio = initialTurnRadius / distance;
if (ratio > 1.0) if (ratio > 1.0)
ratio = 1.0; ratio = 1.0;
@ -779,13 +777,17 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
double newDistance = double newDistance =
cos(newHeading * SG_DEGREES_TO_RADIANS) * distance; cos(newHeading * SG_DEGREES_TO_RADIANS) * distance;
//cerr << "new distance " << newDistance << ". additional Heading " << newHeading << endl; //cerr << "new distance " << newDistance << ". additional Heading " << newHeading << endl;
#endif
double side = azimuth - rwy->headingDeg(); double side = azimuth - rwy->headingDeg();
if (side < 0.0)
side += 360.0;
double lateralOffset = initialTurnRadius; double lateralOffset = initialTurnRadius;
if (side < 0) if (side < 180.0) {
side += 360; lateralOffset *= -1.0;
if (side < 180) {
lateralOffset *= -1;
} }
// Calculate the ETA at final, based on remaining distance, and approach speed. // Calculate the ETA at final, based on remaining distance, and approach speed.
// distance should really consist of flying time to terniary target, plus circle // distance should really consist of flying time to terniary target, plus circle
// but the distance to secondary target should work as a reasonable approximation // but the distance to secondary target should work as a reasonable approximation
@ -809,25 +811,16 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
if (reposition == false) { if (reposition == false) {
newEta = newEta =
apt->getDynamics()->getApproachController()->getRunway(rwy-> apt->getDynamics()->getApproachController()->getRunway(rwy->name())->requestTimeSlot(eta);
name
())->
requestTimeSlot(eta);
} else { } else {
newEta = eta; newEta = eta;
} }
//if ((eta < (previousArrivalTime+60)) && (reposition == false)) {
arrivalTime = newEta; arrivalTime = newEta;
time_t additionalTimeNeeded = newEta - eta; time_t additionalTimeNeeded = newEta - eta;
double distanceCovered = double distanceCovered =
((vApproach * SG_NM_TO_METER) / 3600.0) * additionalTimeNeeded; ((vApproach * SG_NM_TO_METER) / 3600.0) * additionalTimeNeeded;
distanceOut += distanceCovered; distanceOut += distanceCovered;
//apt->getDynamics()->getApproachController()->getRunway(rwy->name())->setEstApproachTime(eta+additionalTimeNeeded);
//cerr << "Adding additional distance: " << distanceCovered << " to allow " << additionalTimeNeeded << " seconds of flying time" << endl << endl;
//} else {
//apt->getDynamics()->getApproachController()->getRunway(rwy->name())->setEstApproachTime(eta);
//}
//cerr << "Timing information : Previous eta: " << previousArrivalTime << ". Current ETA : " << eta << endl;
SGGeod secondaryTarget = SGGeod secondaryTarget =
rwy->pointOffCenterline(-distanceOut, lateralOffset); rwy->pointOffCenterline(-distanceOut, lateralOffset);
@ -835,22 +828,16 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
distance = SGGeodesy::distanceM(origin, secondaryTarget); distance = SGGeodesy::distanceM(origin, secondaryTarget);
azimuth = SGGeodesy::courseDeg(origin, secondaryTarget); azimuth = SGGeodesy::courseDeg(origin, secondaryTarget);
double ratio = initialTurnRadius / distance;
// lat = secondaryTarget.getLatitudeDeg();
// lon = secondaryTarget.getLongitudeDeg();
//cerr << "Secondary Target point (" << lat << ", " << lon << ")." << endl;
//cerr << "Distance : " << distance << endl;
//cerr << "Azimuth : " << azimuth << endl;
ratio = initialTurnRadius / distance;
if (ratio > 1.0) if (ratio > 1.0)
ratio = 1.0; ratio = 1.0;
if (ratio < -1.0) if (ratio < -1.0)
ratio = -1.0; ratio = -1.0;
newHeading = asin(ratio) * SG_RADIANS_TO_DEGREES;
newDistance = cos(newHeading * SG_DEGREES_TO_RADIANS) * distance; double newHeading = asin(ratio) * SG_RADIANS_TO_DEGREES;
double newDistance = cos(newHeading * SG_DEGREES_TO_RADIANS) * distance;
//cerr << "new distance realative to secondary target: " << newDistance << ". additional Heading " << newHeading << endl; //cerr << "new distance realative to secondary target: " << newDistance << ". additional Heading " << newHeading << endl;
if (side < 180) { if (side < 180) {
azimuth += newHeading; azimuth += newHeading;
} else { } else {
@ -858,14 +845,12 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
} }
SGGeod tertiaryTarget; SGGeod tertiaryTarget;
SGGeodesy::direct(origin, azimuth, SGGeodesy::direct(origin, azimuth, newDistance, tertiaryTarget, dummyAz2);
newDistance, tertiaryTarget, dummyAz2);
// lat = tertiaryTarget.getLatitudeDeg(); // lat = tertiaryTarget.getLatitudeDeg();
// lon = tertiaryTarget.getLongitudeDeg(); // lon = tertiaryTarget.getLongitudeDeg();
//cerr << "tertiary Target point (" << lat << ", " << lon << ")." << endl; //cerr << "tertiary Target point (" << lat << ", " << lon << ")." << endl;
for (int i = 1; i < nPoints; i++) { for (int i = 1; i < nPoints; i++) {
SGGeod result; SGGeod result;
double currentDist = i * (newDistance / nPoints); double currentDist = i * (newDistance / nPoints);
@ -904,7 +889,6 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
if (endval < startval) { if (endval < startval) {
endval += 360; endval += 360;
} }
} }
//cerr << "creating circle between " << startval << " and " << endval << " using " << increment << endl; //cerr << "creating circle between " << startval << " and " << endval << " using " << increment << endl;
@ -943,30 +927,27 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
IncrementWaypoint(true); IncrementWaypoint(true);
if (reposition) { if (reposition) {
double tempDistance; double tempDistance = SGGeodesy::distanceM(current, initialTarget);
//double minDistance = HUGE_VAL; time_t eta2 =
//string wptName;
tempDistance = SGGeodesy::distanceM(current, initialTarget);
time_t eta =
tempDistance / ((vDescent * SG_NM_TO_METER) / 3600.0) + now; tempDistance / ((vDescent * SG_NM_TO_METER) / 3600.0) + now;
time_t newEta = time_t newEta2 =
apt->getDynamics()->getApproachController()->getRunway(rwy-> apt->getDynamics()->getApproachController()->getRunway(rwy->name())->requestTimeSlot(eta2);
name arrivalTime = newEta2;
())-> double newDistance2 =
requestTimeSlot(eta); ((vDescent * SG_NM_TO_METER) / 3600.0) * (newEta2 - now);
arrivalTime = newEta;
double newDistance =
((vDescent * SG_NM_TO_METER) / 3600.0) * (newEta - now);
//cerr << "Repositioning information : eta" << eta << ". New ETA " << newEta << ". Diff = " << (newEta - eta) << ". Distance = " << tempDistance << ". New distance = " << newDistance << endl;
IncrementWaypoint(true); // remove waypoint BOD2 IncrementWaypoint(true); // remove waypoint BOD2
while (checkTrackLength("final001") > newDistance) {
while (checkTrackLength("final001") > newDistance2) {
IncrementWaypoint(true); IncrementWaypoint(true);
} }
//cerr << "Repositioning to waypoint " << (*waypoints.begin())->name << endl;
ac->resetPositionFromFlightPlan(); ac->resetPositionFromFlightPlan();
} }
SG_LOG(SG_AI, SG_BULK, "Setting Node " << waypoints[1]->getName() << " to a leg end"); SG_LOG(SG_AI, SG_BULK, "Setting Node " << waypoints[1]->getName() << " to a leg end");
waypoints[1]->setName( (waypoints[1]->getName() + string("legend"))); waypoints[1]->setName( (waypoints[1]->getName() + string("legend")));
return true; return true;
} }