]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/performancedata.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / AIModel / performancedata.cxx
1 #include "performancedata.hxx"
2 #include "AIAircraft.hxx"
3
4 PerformanceData::PerformanceData(double acceleration,
5                                  double deceleration,
6                                  double climbRate,
7                                  double descentRate,
8                                  double vRotate,
9                                  double vTakeOff,
10                                  double vClimb,
11                                  double vCruise,
12                                  double vDescent,
13                                  double vApproach,
14                                  double vTouchdown,
15                                  double vTaxi) :
16     _acceleration(acceleration),
17     _deceleration(deceleration),
18     _climbRate(climbRate),
19     _descentRate(descentRate),
20     _vRotate(vRotate),
21     _vTakeOff(vTakeOff),
22     _vClimb(vClimb),
23     _vCruise(vCruise),
24     _vDescent(vDescent),
25     _vApproach(vApproach),
26     _vTouchdown(vTouchdown),
27     _vTaxi(vTaxi)
28 {
29     _rollrate = 9.0; // degrees per second
30     _maxbank = 30.0; // passenger friendly bank angle
31 }
32
33 // read perf data from file
34 PerformanceData::PerformanceData( const std::string& filename)
35 {}
36
37 PerformanceData::~PerformanceData()
38 {}
39
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 :-)
44     
45     double speed = ac->getSpeed();
46     double speed_diff = tgt_speed - speed;
47
48     if (speed_diff > 0.0)        // need to accelerate
49     {
50         speed += _acceleration * dt;
51         if ( speed > tgt_speed )
52             speed = tgt_speed;
53
54     } else if (speed_diff < 0.0) { // decelerate
55         if (ac->onGround()) {
56             // deceleration performance is better due to wheel brakes.
57             speed -= 3 * _deceleration * dt;
58         } else {
59             speed -= _deceleration * dt;
60         }
61
62         if ( speed < tgt_speed )
63             speed = tgt_speed;
64
65     }
66
67     return speed;
68 }
69
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);
74     
75     double roll = ac->getRoll();
76     double bank_diff = tgt_roll - roll;
77     
78     if (fabs(bank_diff) > 0.2) {
79         if (bank_diff > 0.0) {
80             roll += _rollrate * dt;
81             if (roll > tgt_roll)
82                 roll = tgt_roll;
83         }
84         else if (bank_diff < 0.0) {
85             roll -= _rollrate * dt;
86
87             if (roll < tgt_roll)
88                 roll = tgt_roll;
89         }
90         //while (roll > 180) roll -= 360;
91         //while (roll < 180) roll += 360;
92     }
93
94     return roll;
95 }
96
97 double PerformanceData::actualPitch(FGAIAircraft* ac, double tgt_pitch, double dt) {
98     double pitch = ac->getPitch();
99     double pdiff = tgt_pitch - pitch;
100
101     if (pdiff > 0.0) { // nose up
102         pitch += 0.005*_climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs
103
104         if (pitch > tgt_pitch)
105             pitch = tgt_pitch;
106             
107     } else if (pdiff < 0.0) { // nose down
108         pitch -= 0.002*_descentRate * dt / 3.0;
109
110         if (pitch < tgt_pitch)
111             pitch = tgt_pitch;
112     }
113
114     return pitch;
115 }
116
117 double PerformanceData::actualAltitude(FGAIAircraft* ac, double tgt_altitude, double dt) {
118     if (ac->onGround()) {
119     } else
120         return ac->getAltitude() + ac->getVerticalSpeed()*dt/60.0;
121 }
122
123 double PerformanceData::actualVerticalSpeed(FGAIAircraft* ac, double tgt_vs, double dt) {
124     double vs = ac->getVerticalSpeed();
125     double vs_diff = tgt_vs - vs;
126     
127     if (fabs(vs_diff) > 10.0) {
128         if (vs_diff > 0.0) {
129             vs += _climbRate * dt / 3.0; //TODO avoid hardcoded 3 secs to attain climb rate from level flight
130
131             if (vs > tgt_vs)
132                 vs = tgt_vs;
133             
134         } else if (vs_diff < 0.0) {
135             vs -= _descentRate * dt / 3.0;
136
137             if (vs < tgt_vs)
138                 vs = tgt_vs;
139         }
140     }
141
142     return vs;
143 }
144
145 bool PerformanceData::gearExtensible(const FGAIAircraft* ac) {
146     return (ac->altitudeAGL() < 900.0)
147             && (ac->airspeed() < _vTouchdown * 1.25);
148 }