1 #include "performancedata.hxx"
2 #include "AIAircraft.hxx"
4 PerformanceData::PerformanceData(double acceleration,
16 _acceleration(acceleration),
17 _deceleration(deceleration),
18 _climbRate(climbRate),
19 _descentRate(descentRate),
25 _vApproach(vApproach),
26 _vTouchdown(vTouchdown),
29 _rollrate = 9.0; // degrees per second
30 _maxbank = 30.0; // passenger friendly bank angle
33 // read perf data from file
34 PerformanceData::PerformanceData( const std::string& filename)
37 PerformanceData::~PerformanceData()
40 double PerformanceData::actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt) {
41 // if (tgt_speed > _vTaxi & ac->onGround()) // maximum taxi speed on ground
42 // tgt_speed = _vTaxi;
43 // bad idea for a take off roll :-)
45 double speed = ac->getSpeed();
46 double speed_diff = tgt_speed - speed;
48 if (speed_diff > 0.0) // need to accelerate
50 speed += _acceleration * dt;
51 if ( speed > tgt_speed )
54 } else if (speed_diff < 0.0) { // decelerate
56 // deceleration performance is better due to wheel brakes.
57 speed -= 3 * _deceleration * dt;
59 speed -= _deceleration * dt;
62 if ( speed < tgt_speed )
70 double PerformanceData::actualBankAngle(FGAIAircraft* ac, double tgt_roll, double dt) {
71 // check maximum bank angle
72 if (fabs(tgt_roll) > _maxbank)
73 tgt_roll = _maxbank * tgt_roll/fabs(tgt_roll);
75 double roll = ac->getRoll();
76 double bank_diff = tgt_roll - roll;
78 if (fabs(bank_diff) > 0.2) {
79 if (bank_diff > 0.0) {
80 roll += _rollrate * dt;
84 else if (bank_diff < 0.0) {
85 roll -= _rollrate * dt;
90 //while (roll > 180) roll -= 360;
91 //while (roll < 180) roll += 360;
97 double PerformanceData::actualPitch(FGAIAircraft* ac, double tgt_pitch, double dt) {
98 double pitch = ac->getPitch();
99 double pdiff = tgt_pitch - pitch;
101 if (pdiff > 0.0) { // nose up
102 pitch += 0.005*_climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs
104 if (pitch > tgt_pitch)
107 } else if (pdiff < 0.0) { // nose down
108 pitch -= 0.002*_descentRate * dt / 3.0;
110 if (pitch < tgt_pitch)
117 double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, double dt) {
118 if (ac->onGround()) {
120 return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
123 double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
124 double vs = ac->getVerticalSpeed();
125 double vs_diff = tgt_vs - vs;
127 if (fabs(vs_diff) > 10.0) {
129 vs += _climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs to attain climb rate from level flight
134 } else if (vs_diff < 0.0) {
135 vs -= _descentRate * dt / 3.0;
145 bool PerformanceData::gearExtensible(const FGAIAircraft* ac) {
146 return (ac->altitudeAGL() < 900.0)
147 && (ac->airspeed() < _vTouchdown * 1.25);