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) {
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 speed -= BRAKE_SETTING * _deceleration * dt;
71 speed -= _deceleration * dt;
74 if ( speed < tgt_speed )
82 double PerformanceData::actualBankAngle(FGAIAircraft* ac, double tgt_roll, double dt) {
83 // check maximum bank angle
84 if (fabs(tgt_roll) > _maxbank)
85 tgt_roll = _maxbank * tgt_roll/fabs(tgt_roll);
87 double roll = ac->getRoll();
88 double bank_diff = tgt_roll - roll;
90 if (fabs(bank_diff) > 0.2) {
91 if (bank_diff > 0.0) {
92 roll += _rollrate * dt;
96 else if (bank_diff < 0.0) {
97 roll -= _rollrate * dt;
102 //while (roll > 180) roll -= 360;
103 //while (roll < 180) roll += 360;
109 double PerformanceData::actualPitch(FGAIAircraft* ac, double tgt_pitch, double dt) {
110 double pitch = ac->getPitch();
111 double pdiff = tgt_pitch - pitch;
113 if (pdiff > 0.0) { // nose up
114 pitch += 0.005*_climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs
116 if (pitch > tgt_pitch)
118 } else if (pdiff < 0.0) { // nose down
119 pitch -= 0.002*_descentRate * dt / 3.0;
121 if (pitch < tgt_pitch)
128 double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, double dt) {
129 if (ac->onGround()) {
130 //FIXME: a return sensible value here
131 return 0.0; // 0 for now to avoid compiler errors
133 return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
136 double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
137 double vs = ac->getVerticalSpeed();
138 double vs_diff = tgt_vs - vs;
140 if (fabs(vs_diff) > .001) {
142 vs += _climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs to attain climb rate from level flight
146 } else if (vs_diff < 0.0) {
147 vs -= _descentRate * dt / 3.0;
157 bool PerformanceData::gearExtensible(const FGAIAircraft* ac) {
158 return (ac->altitudeAGL() < 900.0)
159 && (ac->airspeed() < _vTouchdown * 1.25);