6 #include "performancedata.hxx"
7 #include "AIAircraft.hxx"
10 // For now, make this a define
11 // Later on, additional class variables can simulate settings such as braking power
12 // also, the performance parameters can be tweaked a little to add some personality
14 #define BRAKE_SETTING 1.6
16 PerformanceData::PerformanceData(double acceleration,
28 _acceleration(acceleration),
29 _deceleration(deceleration),
30 _climbRate(climbRate),
31 _descentRate(descentRate),
37 _vApproach(vApproach),
38 _vTouchdown(vTouchdown),
41 _rollrate = 9.0; // degrees per second
42 _maxbank = 30.0; // passenger friendly bank angle
45 // read perf data from file
46 PerformanceData::PerformanceData( const std::string& filename)
49 PerformanceData::~PerformanceData()
52 double PerformanceData::actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt, bool maxBrakes) {
53 // if (tgt_speed > _vTaxi & ac->onGround()) // maximum taxi speed on ground
54 // tgt_speed = _vTaxi;
55 // bad idea for a take off roll :-)
57 double speed = ac->getSpeed();
58 double speed_diff = tgt_speed - speed;
60 if (speed_diff > 0.0) // need to accelerate
62 speed += _acceleration * dt;
63 if ( speed > tgt_speed )
66 } else if (speed_diff < 0.0) { // decelerate
68 // deceleration performance is better due to wheel brakes.
69 double brakePower = 0;
73 brakePower = BRAKE_SETTING;
75 speed -= brakePower * _deceleration * dt;
77 speed -= _deceleration * dt;
80 if ( speed < tgt_speed )
88 double PerformanceData::actualBankAngle(FGAIAircraft* ac, double tgt_roll, double dt) {
89 // check maximum bank angle
90 if (fabs(tgt_roll) > _maxbank)
91 tgt_roll = _maxbank * tgt_roll/fabs(tgt_roll);
93 double roll = ac->getRoll();
94 double bank_diff = tgt_roll - roll;
96 if (fabs(bank_diff) > 0.2) {
97 if (bank_diff > 0.0) {
98 roll += _rollrate * dt;
102 else if (bank_diff < 0.0) {
103 roll -= _rollrate * dt;
108 //while (roll > 180) roll -= 360;
109 //while (roll < 180) roll += 360;
115 double PerformanceData::actualPitch(FGAIAircraft* ac, double tgt_pitch, double dt) {
116 double pitch = ac->getPitch();
117 double pdiff = tgt_pitch - pitch;
119 if (pdiff > 0.0) { // nose up
120 pitch += 0.005*_climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs
122 if (pitch > tgt_pitch)
124 } else if (pdiff < 0.0) { // nose down
125 pitch -= 0.002*_descentRate * dt / 3.0;
127 if (pitch < tgt_pitch)
134 double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, double dt) {
135 if (ac->onGround()) {
136 //FIXME: a return sensible value here
137 return 0.0; // 0 for now to avoid compiler errors
139 return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
142 double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
143 double vs = ac->getVerticalSpeed();
144 double vs_diff = tgt_vs - vs;
146 if (fabs(vs_diff) > .001) {
148 vs += _climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs to attain climb rate from level flight
152 } else if (vs_diff < 0.0) {
153 vs -= _descentRate * dt / 3.0;
163 bool PerformanceData::gearExtensible(const FGAIAircraft* ac) {
164 return (ac->altitudeAGL() < 900.0)
165 && (ac->airspeed() < _vTouchdown * 1.25);