]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAuxiliary.h
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[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 "math/FGColumnVector3.h"
44 #include "math/FGLocation.h"
45
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 DEFINITIONS
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50 #define ID_AUXILIARY "$Id: FGAuxiliary.h,v 1.20 2011/05/20 03:18:36 jberndt Exp $"
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FORWARD DECLARATIONS
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 namespace JSBSim {
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS DOCUMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 /** Encapsulates various uncategorized scheduled functions.
63     Pilot sensed accelerations are calculated here. This is used
64     for the coordinated turn ball instrument. Motion base platforms sometimes
65     use the derivative of pilot sensed accelerations as the driving parameter,
66     rather than straight accelerations.
67
68     The theory behind pilot-sensed calculations is presented:
69
70     For purposes of discussion and calculation, assume for a minute that the
71     pilot is in space and motionless in inertial space. She will feel
72     no accelerations. If the aircraft begins to accelerate along any axis or
73     axes (without rotating), the pilot will sense those accelerations. If
74     any rotational moment is applied, the pilot will sense an acceleration
75     due to that motion in the amount:
76
77     [wdot X R]  +  [w X (w X R)]
78     Term I          Term II
79
80     where:
81
82     wdot = omegadot, the rotational acceleration rate vector
83     w    = omega, the rotational rate vector
84     R    = the vector from the aircraft CG to the pilot eyepoint
85
86     The sum total of these two terms plus the acceleration of the aircraft
87     body axis gives the acceleration the pilot senses in inertial space.
88     In the presence of a large body such as a planet, a gravity field also
89     provides an accelerating attraction. This acceleration can be transformed
90     from the reference frame of the planet so as to be expressed in the frame
91     of reference of the aircraft. This gravity field accelerating attraction
92     is felt by the pilot as a force on her tushie as she sits in her aircraft
93     on the runway awaiting takeoff clearance.
94
95     In JSBSim the acceleration of the body frame in inertial space is given
96     by the F = ma relation. If the vForces vector is divided by the aircraft
97     mass, the acceleration vector is calculated. The term wdot is equivalent
98     to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
99     The radius R is calculated below in the vector vToEyePt.
100
101     @author Tony Peden, Jon Berndt
102     @version $Id: FGAuxiliary.h,v 1.20 2011/05/20 03:18:36 jberndt Exp $
103 */
104
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 CLASS DECLARATION
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108
109 class FGAuxiliary : public FGModel {
110 public:
111   /** Constructor
112       @param Executive a pointer to the parent executive object */
113   FGAuxiliary(FGFDMExec* Executive);
114
115   /// Destructor
116   ~FGAuxiliary();
117
118   bool InitModel(void);
119
120   /** Runs the Auxiliary routines; called by the Executive
121       Can pass in a value indicating if the executive is directing the simulation to Hold.
122       @param Holding if true, the executive has been directed to hold the sim from 
123                      advancing time. Some models may ignore this flag, such as the Input
124                      model, which may need to be active to listen on a socket for the
125                      "Resume" command to be given.
126       @return false if no error */
127   bool Run(bool Holding);
128
129 // GET functions
130
131   // Atmospheric parameters GET functions
132   /** Returns Calibrated airspeed in feet/second.*/
133   double GetVcalibratedFPS(void) const { return vcas; }
134   /** Returns Calibrated airspeed in knots.*/
135   double GetVcalibratedKTS(void) const { return vcas*fpstokts; }
136   /** Returns equivalent airspeed in feet/second. */
137   double GetVequivalentFPS(void) const { return veas; }
138   /** Returns equivalent airspeed in knots. */
139   double GetVequivalentKTS(void) const { return veas*fpstokts; }
140
141   /** Returns the total pressure.
142       Total pressure is freestream total pressure for
143       subsonic only. For supersonic it is the 1D total pressure
144       behind a normal shock. */
145   double GetTotalPressure(void) const { return pt; }
146
147   /** Returns the total temperature.
148     The total temperature ("tat", isentropic flow) is calculated:
149     @code
150     tat = sat*(1 + 0.2*Mach*Mach)
151     @endcode
152     (where "sat" is standard temperature) */
153
154   double GetTotalTemperature(void) const { return tat; }
155   double GetTAT_C(void) const { return tatc; }
156
157   double GetPilotAccel(int idx)  const { return vPilotAccel(idx);  }
158   double GetNpilot(int idx)      const { return vPilotAccelN(idx); }
159   double GetAeroPQR(int axis)    const { return vAeroPQR(axis);    }
160   double GetEulerRates(int axis) const { return vEulerRates(axis); }
161
162   const FGColumnVector3& GetPilotAccel (void) const { return vPilotAccel;  }
163   const FGColumnVector3& GetNpilot     (void) const { return vPilotAccelN; }
164   const FGColumnVector3& GetAeroPQR    (void) const { return vAeroPQR;     }
165   const FGColumnVector3& GetEulerRates (void) const { return vEulerRates;  }
166   const FGColumnVector3& GetAeroUVW    (void) const { return vAeroUVW;     }
167   const FGLocation&      GetLocationVRP(void) const { return vLocationVRP; }
168
169   double GethVRP(void) const;
170   double GetAeroUVW (int idx) const { return vAeroUVW(idx); }
171   double Getalpha   (void) const { return alpha;      }
172   double Getbeta    (void) const { return beta;       }
173   double Getadot    (void) const { return adot;       }
174   double Getbdot    (void) const { return bdot;       }
175   double GetMagBeta (void) const { return fabs(beta); }
176
177   double Getalpha   (int unit) const { if (unit == inDegrees) return alpha*radtodeg;
178                                        else return BadUnits(); }
179   double Getbeta    (int unit) const { if (unit == inDegrees) return beta*radtodeg;
180                                        else return BadUnits(); }
181   double Getadot    (int unit) const { if (unit == inDegrees) return adot*radtodeg;
182                                        else return BadUnits(); }
183   double Getbdot    (int unit) const { if (unit == inDegrees) return bdot*radtodeg;
184                                        else return BadUnits(); }
185   double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg;
186                                        else return BadUnits(); }
187
188   double Getqbar          (void) const { return qbar;       }
189   double GetqbarUW        (void) const { return qbarUW;     }
190   double GetqbarUV        (void) const { return qbarUV;     }
191   double GetReynoldsNumber(void) const { return Re;         }
192
193   /** Gets the magnitude of total vehicle velocity including wind effects in feet per second. */
194   double GetVt            (void) const { return Vt;         }
195
196   /** Gets the ground speed in feet per second.
197       The magnitude is the square root of the sum of the squares (RSS) of the 
198       vehicle north and east velocity components.
199       @return The magnitude of the vehicle velocity in the horizontal plane. */
200   double GetVground       (void) const { return Vground;    }
201
202   /** Gets the Mach number. */
203   double GetMach          (void) const { return Mach;       }
204
205   /** The mach number calculated using the vehicle X axis velocity. */
206   double GetMachU         (void) const { return MachU;      }
207
208   /** The vertical acceleration in g's of the aircraft center of gravity. */
209   double GetNz            (void) const { return Nz;         }
210
211   double GetHOverBCG(void) const { return hoverbcg; }
212   double GetHOverBMAC(void) const { return hoverbmac; }
213
214   double GetGamma(void)              const { return gamma;         }
215   double GetGroundTrack(void)        const { return psigt;         }
216
217   double GetHeadWind(void) const;
218   double GetCrossWind(void) const;
219
220 // SET functions
221
222   void SetAeroUVW(FGColumnVector3 tt) { vAeroUVW = tt; }
223
224   void Setalpha  (double tt) { alpha = tt;  }
225   void Setbeta   (double tt) { beta  = tt;  }
226   void Setqbar   (double tt) { qbar = tt;   }
227   void SetqbarUW (double tt) { qbarUW = tt; }
228   void SetqbarUV (double tt) { qbarUV = tt; }
229   void SetVt     (double tt) { Vt = tt;     }
230   void SetMach   (double tt) { Mach=tt;     }
231   void Setadot   (double tt) { adot = tt;   }
232   void Setbdot   (double tt) { bdot = tt;   }
233
234   void SetAB    (double t1, double t2) { alpha=t1; beta=t2; }
235   void SetGamma (double tt)            { gamma = tt;        }
236
237 // Time routines, SET and GET functions, used by FGMSIS atmosphere
238
239   void SetDayOfYear    (int doy)    { day_of_year = doy;    }
240   void SetSecondsInDay (double sid) { seconds_in_day = sid; }
241
242   int    GetDayOfYear    (void) const { return day_of_year;    }
243   double GetSecondsInDay (void) const { return seconds_in_day; }
244
245   double GetLongitudeRelativePosition (void) const { return lon_relative_position; }
246   double GetLatitudeRelativePosition  (void) const { return lat_relative_position; }
247   double GetDistanceRelativePosition  (void) const { return relative_position; }
248
249   void SetAeroPQR(FGColumnVector3 tt) { vAeroPQR = tt; }
250
251 private:
252   double vcas, veas;
253   double rhosl, rho, p, psl, pt, tat, sat, tatc; // Don't add a getter for pt!
254
255   FGColumnVector3 vPilotAccel;
256   FGColumnVector3 vPilotAccelN;
257   FGColumnVector3 vToEyePt;
258   FGColumnVector3 vAeroPQR;
259   FGColumnVector3 vAeroUVW;
260   FGColumnVector3 vEuler;
261   FGColumnVector3 vEulerRates;
262   FGColumnVector3 vMachUVW;
263   FGColumnVector3 vAircraftAccel;
264   FGLocation vLocationVRP;
265
266   double Vt, Vground, Mach, MachU;
267   double qbar, qbarUW, qbarUV;
268   double Re; // Reynolds Number = V*c/mu
269   double alpha, beta;
270   double adot,bdot;
271   double psigt, gamma;
272   double Nz;
273   double seconds_in_day;  // seconds since current GMT day began
274   int    day_of_year;     // GMT day, 1 .. 366
275
276   double hoverbcg, hoverbmac;
277
278   // helper data, calculation of distance from initial position
279
280   double lon_relative_position;
281   double lat_relative_position;
282   double relative_position;
283
284   void CalculateRelativePosition(void);
285
286   void bind(void);
287   double BadUnits(void) const;
288   void Debug(int from);
289 };
290
291 } // namespace JSBSim
292
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 #endif