]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAuxiliary.h
6420e3b975bce333e338e0dfe275ab371e489b79
[flightgear.git] / src / FDM / JSBSim / models / FGAuxiliary.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGAuxiliary.h
4  Author:       Jon Berndt
5  Date started: 01/26/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 11/22/98   JSB   Created
29   1/1/00   TP    Added calcs and getters for VTAS, VCAS, VEAS, Vground, in knots
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35 #ifndef FGAUXILIARY_H
36 #define FGAUXILIARY_H
37
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include "FGModel.h"
43 #include <FGFDMExec.h>
44 #include <math/FGColumnVector3.h>
45 #include <math/FGLocation.h>
46 #include "FGPropagate.h"
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #define ID_AUXILIARY "$Id$"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 namespace JSBSim {
59
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 CLASS DOCUMENTATION
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63
64 /** Encapsulates various uncategorized scheduled functions.
65     Pilot sensed accelerations are calculated here. This is used
66     for the coordinated turn ball instrument. Motion base platforms sometimes
67     use the derivative of pilot sensed accelerations as the driving parameter,
68     rather than straight accelerations.
69
70     The theory behind pilot-sensed calculations is presented:
71
72     For purposes of discussion and calculation, assume for a minute that the
73     pilot is in space and motionless in inertial space. She will feel
74     no accelerations. If the aircraft begins to accelerate along any axis or
75     axes (without rotating), the pilot will sense those accelerations. If
76     any rotational moment is applied, the pilot will sense an acceleration
77     due to that motion in the amount:
78
79     [wdot X R]  +  [w X (w X R)]
80     Term I          Term II
81
82     where:
83
84     wdot = omegadot, the rotational acceleration rate vector
85     w    = omega, the rotational rate vector
86     R    = the vector from the aircraft CG to the pilot eyepoint
87
88     The sum total of these two terms plus the acceleration of the aircraft
89     body axis gives the acceleration the pilot senses in inertial space.
90     In the presence of a large body such as a planet, a gravity field also
91     provides an accelerating attraction. This acceleration can be transformed
92     from the reference frame of the planet so as to be expressed in the frame
93     of reference of the aircraft. This gravity field accelerating attraction
94     is felt by the pilot as a force on her tushie as she sits in her aircraft
95     on the runway awaiting takeoff clearance.
96
97     In JSBSim the acceleration of the body frame in inertial space is given
98     by the F = ma relation. If the vForces vector is divided by the aircraft
99     mass, the acceleration vector is calculated. The term wdot is equivalent
100     to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
101     The radius R is calculated below in the vector vToEyePt.
102
103     @author Tony Peden, Jon Berndt
104     @version $Id$
105 */
106
107 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 CLASS DECLARATION
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
110
111 class FGAuxiliary : public FGModel {
112 public:
113   /** Constructor
114       @param Executive a pointer to the parent executive object */
115   FGAuxiliary(FGFDMExec* Executive);
116
117   /// Destructor
118   ~FGAuxiliary();
119
120   bool InitModel(void);
121
122   /** Runs the Auxiliary routines; called by the Executive
123       @return false if no error */
124   bool Run(void);
125
126 // GET functions
127
128   // Atmospheric parameters GET functions
129   /** Returns Calibrated airspeed in feet/second.*/
130   double GetVcalibratedFPS(void) const { return vcas; }
131   /** Returns Calibrated airspeed in knots.*/
132   double GetVcalibratedKTS(void) const { return vcas*fpstokts; }
133   /** Returns equivalent airspeed in feet/second. */
134   double GetVequivalentFPS(void) const { return veas; }
135   /** Returns equivalent airspeed in knots. */
136   double GetVequivalentKTS(void) const { return veas*fpstokts; }
137
138   /** Returns the total pressure.
139       Total pressure is freestream total pressure for
140       subsonic only. For supersonic it is the 1D total pressure
141       behind a normal shock. */
142   double GetTotalPressure(void) const { return pt; }
143
144   /** Returns the total temperature.
145     The total temperature ("tat", isentropic flow) is calculated:
146     @code
147     tat = sat*(1 + 0.2*Mach*Mach)
148     @endcode
149     (where "sat" is standard temperature) */
150
151   double GetTotalTemperature(void) const { return tat; }
152   double GetTAT_C(void) const { return tatc; }
153
154   double GetPilotAccel(int idx)  const { return vPilotAccel(idx);  }
155   double GetNpilot(int idx)      const { return vPilotAccelN(idx); }
156   double GetAeroPQR(int axis)    const { return vAeroPQR(axis);    }
157   double GetEulerRates(int axis) const { return vEulerRates(axis); }
158
159   const FGColumnVector3& GetPilotAccel (void) const { return vPilotAccel;  }
160   const FGColumnVector3& GetNpilot     (void) const { return vPilotAccelN; }
161   const FGColumnVector3& GetAeroPQR    (void) const { return vAeroPQR;     }
162   const FGColumnVector3& GetEulerRates (void) const { return vEulerRates;  }
163   const FGColumnVector3& GetAeroUVW    (void) const { return vAeroUVW;     }
164   const FGLocation&      GetLocationVRP(void) const { return vLocationVRP; }
165
166   double GethVRP(void) const { return vLocationVRP.GetRadius() - Propagate->GetSeaLevelRadius(); }
167   double GetAeroUVW (int idx) const { return vAeroUVW(idx); }
168   double Getalpha   (void) const { return alpha;      }
169   double Getbeta    (void) const { return beta;       }
170   double Getadot    (void) const { return adot;       }
171   double Getbdot    (void) const { return bdot;       }
172   double GetMagBeta (void) const { return fabs(beta); }
173
174   double Getalpha   (int unit) const { if (unit == inDegrees) return alpha*radtodeg;
175                                        else cerr << "Bad units" << endl; return 0.0;}
176   double Getbeta    (int unit) const { if (unit == inDegrees) return beta*radtodeg;
177                                        else cerr << "Bad units" << endl; return 0.0;}
178   double Getadot    (int unit) const { if (unit == inDegrees) return adot*radtodeg;
179                                        else cerr << "Bad units" << endl; return 0.0;}
180   double Getbdot    (int unit) const { if (unit == inDegrees) return bdot*radtodeg;
181                                        else cerr << "Bad units" << endl; return 0.0;}
182   double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg;
183                                        else cerr << "Bad units" << endl; return 0.0;}
184
185   double Getqbar          (void) const { return qbar;       }
186   double GetqbarUW        (void) const { return qbarUW;     }
187   double GetqbarUV        (void) const { return qbarUV;     }
188   double GetReynoldsNumber(void) const { return Re;         }
189
190   /** Gets the magnitude of total vehicle velocity including wind effects in feet per second. */
191   double GetVt            (void) const { return Vt;         }
192
193   /** Gets the ground speed in feet per second.
194       The magnitude is the square root of the sum of the squares (RSS) of the 
195       vehicle north and east velocity components.
196       @return The magnitude of the vehicle velocity in the horizontal plane. */
197   double GetVground       (void) const { return Vground;    }
198
199   /** Gets the Mach number. */
200   double GetMach          (void) const { return Mach;       }
201
202   /** The mach number calculated using the vehicle X axis velocity. */
203   double GetMachU         (void) const { return MachU;      }
204
205   /** The vertical acceleration in g's of the aircraft center of gravity. */
206   double GetNz            (void) const { return Nz;         }
207
208   double GetHOverBCG(void) const { return hoverbcg; }
209   double GetHOverBMAC(void) const { return hoverbmac; }
210
211   double GetGamma(void)              const { return gamma;         }
212   double GetGroundTrack(void)        const { return psigt;         }
213
214   double GetHeadWind(void) const;
215   double GetCrossWind(void) const;
216
217 // SET functions
218
219   void SetAeroUVW(FGColumnVector3 tt) { vAeroUVW = tt; }
220
221   void Setalpha  (double tt) { alpha = tt;  }
222   void Setbeta   (double tt) { beta  = tt;  }
223   void Setqbar   (double tt) { qbar = tt;   }
224   void SetqbarUW (double tt) { qbarUW = tt; }
225   void SetqbarUV (double tt) { qbarUV = tt; }
226   void SetVt     (double tt) { Vt = tt;     }
227   void SetMach   (double tt) { Mach=tt;     }
228   void Setadot   (double tt) { adot = tt;   }
229   void Setbdot   (double tt) { bdot = tt;   }
230
231   void SetAB    (double t1, double t2) { alpha=t1; beta=t2; }
232   void SetGamma (double tt)            { gamma = tt;        }
233
234 // Time routines, SET and GET functions, used by FGMSIS atmosphere
235
236   void SetDayOfYear    (int doy)    { day_of_year = doy;    }
237   void SetSecondsInDay (double sid) { seconds_in_day = sid; }
238
239   int    GetDayOfYear    (void) const { return day_of_year;    }
240   double GetSecondsInDay (void) const { return seconds_in_day; }
241
242   double GetLongitudeRelativePosition (void) const { return lon_relative_position; }
243   double GetLatitudeRelativePosition  (void) const { return lat_relative_position; }
244   double GetDistanceRelativePosition  (void) const { return relative_position; }
245
246   void SetAeroPQR(FGColumnVector3 tt) { vAeroPQR = tt; }
247
248 private:
249   double vcas, veas;
250   double rhosl, rho, p, psl, pt, tat, sat, tatc; // Don't add a getter for pt!
251
252   FGColumnVector3 vPilotAccel;
253   FGColumnVector3 vPilotAccelN;
254   FGColumnVector3 vToEyePt;
255   FGColumnVector3 vAeroPQR;
256   FGColumnVector3 vAeroUVW;
257   FGColumnVector3 vEuler;
258   FGColumnVector3 vEulerRates;
259   FGColumnVector3 vMachUVW;
260   FGColumnVector3 vAircraftAccel;
261   FGLocation vLocationVRP;
262
263   double Vt, Vground, Mach, MachU;
264   double qbar, qbarUW, qbarUV;
265   double Re; // Reynolds Number = V*c/mu
266   double alpha, beta;
267   double adot,bdot;
268   double psigt, gamma;
269   double Nz;
270   double seconds_in_day;  // seconds since current GMT day began
271   int    day_of_year;     // GMT day, 1 .. 366
272
273   double hoverbcg, hoverbmac;
274
275   // helper data, calculation of distance from initial position
276
277   double lon_relative_position;
278   double lat_relative_position;
279   double relative_position;
280
281   void CalculateRelativePosition(void);
282
283   void bind(void);
284   void Debug(int from);
285 };
286
287 } // namespace JSBSim
288
289 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 #endif