-// FGAIAircraft - FGAIBase-derived class creates an AI airplane
+// // FGAIAircraft - FGAIBase-derived class creates an AI airplane
//
// Written by David Culp, started October 2003.
//
handleATCRequests(); // ATC also has a word to say
updateSecondaryTargetValues(); // target roll, vertical speed, pitch
updateActualState();
- UpdateRadar(manager);
+ // We currently have one situation in which an AIAircraft object is used that is not attached to the
+ // AI manager. In this particular case, the AIAircraft is used to shadow the user's aircraft's behavior in the AI world.
+ // Since we perhaps don't want a radar entry of our own aircraft, the following conditional should probably be adequate
+ // enough
+ if (manager)
+ UpdateRadar(manager);
checkVisibility();
}
if (! leadPointReached(curr)) {
controlHeading(curr);
controlSpeed(curr, next);
+ if (speed < 0) {
+ cerr << getCallSign()
+ << ": verifying lead distance to waypoint : "
+ << fp->getCurrentWaypoint()->name << " "
+ << fp->getLeadDistance() << ". Distance to go "
+ << (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr))
+ << ". Target speed = "
+ << tgt_speed
+ << ". Current speed = "
+ << speed
+ << ". Minimum Bearing " << minBearing
+ << endl;
+ }
} else {
if (curr->finished) //end of the flight plan
{
use_perf_vs = false;
tgt_vs = (curr->crossat - altitude_ft) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
/ 6076.0 / speed*60.0);
+ checkTcas();
tgt_altitude_ft = curr->crossat;
} else {
use_perf_vs = true;
}
}
+void FGAIAircraft::checkTcas(void)
+{
+ if (props->getIntValue("tcas/threat-level",0)==3)
+ {
+ int RASense = props->getIntValue("tcas/ra-sense",0);
+ if ((RASense>0)&&(tgt_vs<4000))
+ // upward RA: climb!
+ tgt_vs = 4000;
+ else
+ if (RASense<0)
+ {
+ // downward RA: descend!
+ if (altitude_ft < 1000)
+ {
+ // too low: level off
+ if (tgt_vs>0)
+ tgt_vs = 0;
+ }
+ else
+ {
+ if (tgt_vs >- 4000)
+ tgt_vs = -4000;
+ }
+ }
+ }
+}
void FGAIAircraft::initializeFlightPlan() {
}
tgt_vs = (curr->crossat - prev->altitude)
/ (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
/ 6076.0 / prev->speed*60.0);
+ checkTcas();
tgt_altitude_ft = curr->crossat;
} else {
use_perf_vs = true;
//cerr << "2" << endl;
double lead_dist = fp->getLeadDistance();
// experimental: Use fabs, because speed can be negative (I hope) during push_back.
-
+ if ((dist_to_go < fabs(10.0* speed)) && (speed < 0) && (tgt_speed < 0) && fp->getCurrentWaypoint()->name == string("PushBackPoint")) {
+ tgt_speed = -(dist_to_go / 10.0);
+ if (tgt_speed > -0.5) {
+ tgt_speed = -0.5;
+ }
+ if (fp->getPreviousWaypoint()->speed < tgt_speed) {
+ fp->getPreviousWaypoint()->speed = tgt_speed;
+ }
+ }
if (lead_dist < fabs(2*speed)) {
//don't skip over the waypoint
lead_dist = fabs(2*speed);
bank_sense = 1.0;
}
//if (trafficRef)
- //cerr << trafficRef->getCallSign() << " Heading "
- // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << endl;
+ // cerr << trafficRef->getCallSign() << " Heading "
+ // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << endl;
//if (headingDiff > 60) {
groundTargetSpeed = tgt_speed; // * cos(headingDiff * SG_DEGREES_TO_RADIANS);
//groundTargetSpeed = tgt_speed - tgt_speed * (headingDiff/180);
//}
if (sign(groundTargetSpeed) != sign(tgt_speed))
groundTargetSpeed = 0.21 * sign(tgt_speed); // to prevent speed getting stuck in 'negative' mode
-
- if (headingDiff > 30.0) {
- // invert if pushed backward
- headingChangeRate += 10.0 * dt * sign(roll);
-
- // Clamp the maximum steering rate to 30 degrees per second,
- // But only do this when the heading error is decreasing.
- if ((headingDiff < headingError)) {
- if (headingChangeRate > 30)
- headingChangeRate = 30;
- else if (headingChangeRate < -30)
- headingChangeRate = -30;
+
+ // Only update the target values when we're not moving because otherwise we might introduce an enormous target change rate while waiting a the gate, or holding.
+ if (speed != 0) {
+ if (headingDiff > 30.0) {
+ // invert if pushed backward
+ headingChangeRate += 10.0 * dt * sign(roll);
+
+ // Clamp the maximum steering rate to 30 degrees per second,
+ // But only do this when the heading error is decreasing.
+ if ((headingDiff < headingError)) {
+ if (headingChangeRate > 30)
+ headingChangeRate = 30;
+ else if (headingChangeRate < -30)
+ headingChangeRate = -30;
+ }
+ } else {
+ if (speed != 0) {
+ if (fabs(headingChangeRate) > headingDiff)
+ headingChangeRate = headingDiff*sign(roll);
+ else
+ headingChangeRate += dt * sign(roll);
+ }
}
- } else {
- if (fabs(headingChangeRate) > headingDiff)
- headingChangeRate = headingDiff*sign(roll);
- else
- headingChangeRate += dt * sign(roll);
}
-
- hdg += headingChangeRate * dt * (fabs(speed) / 15);
+ if (trafficRef)
+ //cerr << trafficRef->getCallSign() << " Heading "
+ // << hdg << ". Target " << tgt_heading << ". Diff " << fabs(sum - tgt_heading) << ". Speed " << speed << "Heading change rate : " << headingChangeRate << " bacnk sence " << bank_sense << endl;
+ hdg += headingChangeRate * dt * sqrt(fabs(speed) / 15);
headingError = headingDiff;
} else {
if (fabs(speed) > 1.0) {
}
} //else
// tgt_vs = 0.0;
+ checkTcas();
}
void FGAIAircraft::updatePitchAngleTarget() {
void FGAIAircraft::handleATCRequests() {
//TODO implement NullController for having no ATC to save the conditionals
if (controller) {
- controller->update(getID(),
- pos.getLatitudeDeg(),
- pos.getLongitudeDeg(),
- hdg,
- speed,
- altitude_ft, dt);
+ controller->updateAircraftInformation(getID(),
+ pos.getLatitudeDeg(),
+ pos.getLongitudeDeg(),
+ hdg,
+ speed,
+ altitude_ft, dt);
processATC(controller->getInstruction(getID()));
}
}
cerr << "Checking arrival time: ete " << ete << ". Time to go : " << secondsToGo << ". Track length = " << tracklength << endl;
}
return (ete - secondsToGo); // Positive when we're too slow...
-}
\ No newline at end of file
+}