6 #include "performancedata.hxx"
7 #include "AIAircraft.hxx"
9 PerformanceData::PerformanceData(double acceleration,
21 _acceleration(acceleration),
22 _deceleration(deceleration),
23 _climbRate(climbRate),
24 _descentRate(descentRate),
30 _vApproach(vApproach),
31 _vTouchdown(vTouchdown),
34 _rollrate = 9.0; // degrees per second
35 _maxbank = 30.0; // passenger friendly bank angle
38 // read perf data from file
39 PerformanceData::PerformanceData( const std::string& filename)
42 PerformanceData::~PerformanceData()
45 double PerformanceData::actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt) {
46 // if (tgt_speed > _vTaxi & ac->onGround()) // maximum taxi speed on ground
47 // tgt_speed = _vTaxi;
48 // bad idea for a take off roll :-)
50 double speed = ac->getSpeed();
51 double speed_diff = tgt_speed - speed;
53 if (speed_diff > 0.0) // need to accelerate
55 speed += _acceleration * dt;
56 if ( speed > tgt_speed )
59 } else if (speed_diff < 0.0) { // decelerate
61 // deceleration performance is better due to wheel brakes.
62 speed -= 3 * _deceleration * dt;
64 speed -= _deceleration * dt;
67 if ( speed < tgt_speed )
75 double PerformanceData::actualBankAngle(FGAIAircraft* ac, double tgt_roll, double dt) {
76 // check maximum bank angle
77 if (fabs(tgt_roll) > _maxbank)
78 tgt_roll = _maxbank * tgt_roll/fabs(tgt_roll);
80 double roll = ac->getRoll();
81 double bank_diff = tgt_roll - roll;
83 if (fabs(bank_diff) > 0.2) {
84 if (bank_diff > 0.0) {
85 roll += _rollrate * dt;
89 else if (bank_diff < 0.0) {
90 roll -= _rollrate * dt;
95 //while (roll > 180) roll -= 360;
96 //while (roll < 180) roll += 360;
102 double PerformanceData::actualPitch(FGAIAircraft* ac, double tgt_pitch, double dt) {
103 double pitch = ac->getPitch();
104 double pdiff = tgt_pitch - pitch;
106 if (pdiff > 0.0) { // nose up
107 pitch += 0.005*_climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs
109 if (pitch > tgt_pitch)
112 } else if (pdiff < 0.0) { // nose down
113 pitch -= 0.002*_descentRate * dt / 3.0;
115 if (pitch < tgt_pitch)
122 double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, double dt) {
123 if (ac->onGround()) {
124 //FIXME: return a value here
126 return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
129 double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
130 double vs = ac->getVerticalSpeed();
131 double vs_diff = tgt_vs - vs;
133 if (fabs(vs_diff) > 10.0) {
135 vs += _climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs to attain climb rate from level flight
140 } else if (vs_diff < 0.0) {
141 vs -= _descentRate * dt / 3.0;
151 bool PerformanceData::gearExtensible(const FGAIAircraft* ac) {
152 return (ac->altitudeAGL() < 900.0)
153 && (ac->airspeed() < _vTouchdown * 1.25);