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
11  Software Foundation; either version 2 of the License, or (at your option) any
12  later 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
20  with this program; if not, write to the Free Software Foundation, Inc., 59
21  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be
24  found on 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/FGLocation.h"
44 
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 FORWARD DECLARATIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 
49 namespace JSBSim {
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 CLASS DOCUMENTATION
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
55 /** Encapsulates various uncategorized scheduled functions.
56     Pilot sensed accelerations are calculated here. This is used
57     for the coordinated turn ball instrument. Motion base platforms sometimes
58     use the derivative of pilot sensed accelerations as the driving parameter,
59     rather than straight accelerations.
60 
61     The theory behind pilot-sensed calculations is presented:
62 
63     For purposes of discussion and calculation, assume for a minute that the
64     pilot is in space and motionless in inertial space. She will feel
65     no accelerations. If the aircraft begins to accelerate along any axis or
66     axes (without rotating), the pilot will sense those accelerations. If
67     any rotational moment is applied, the pilot will sense an acceleration
68     due to that motion in the amount:
69 
70     [wdot X R]  +  [w X (w X R)]
71     Term I          Term II
72 
73     where:
74 
75     wdot = omegadot, the rotational acceleration rate vector
76     w    = omega, the rotational rate vector
77     R    = the vector from the aircraft CG to the pilot eyepoint
78 
79     The sum total of these two terms plus the acceleration of the aircraft
80     body axis gives the acceleration the pilot senses in inertial space.
81     In the presence of a large body such as a planet, a gravity field also
82     provides an accelerating attraction. This acceleration can be transformed
83     from the reference frame of the planet so as to be expressed in the frame
84     of reference of the aircraft. This gravity field accelerating attraction
85     is felt by the pilot as a force on her tushie as she sits in her aircraft
86     on the runway awaiting takeoff clearance.
87 
88     In JSBSim the acceleration of the body frame in inertial space is given
89     by the F = ma relation. If the vForces vector is divided by the aircraft
90     mass, the acceleration vector is calculated. The term wdot is equivalent
91     to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
92 
93     @author Tony Peden, Jon Berndt
94 */
95 
96 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 CLASS DECLARATION
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
99 
100 class FGAuxiliary : public FGModel {
101 public:
102   /** Constructor
103       @param Executive a pointer to the parent executive object */
104   explicit FGAuxiliary(FGFDMExec* Executive);
105 
106   /// Destructor
107   ~FGAuxiliary();
108 
109   bool InitModel(void) override;
110 
111   /** Runs the Auxiliary routines; called by the Executive
112       Can pass in a value indicating if the executive is directing the
113       simulation to Hold.
114       @param Holding if true, the executive has been directed to hold the sim
115                      from advancing time. Some models may ignore this flag, such
116                      as the Input model, which may need to be active to listen
117                      on a socket for the "Resume" command to be given.  @return
118                      false if no error */
119   bool Run(bool Holding) override;
120 
121 // GET functions
122 
123   // Atmospheric parameters GET functions
124   /** Returns Calibrated airspeed in feet/second.*/
GetVcalibratedFPS(void)125   double GetVcalibratedFPS(void) const { return vcas; }
126   /** Returns Calibrated airspeed in knots.*/
GetVcalibratedKTS(void)127   double GetVcalibratedKTS(void) const { return vcas*fpstokts; }
128   /** Returns equivalent airspeed in feet/second. */
GetVequivalentFPS(void)129   double GetVequivalentFPS(void) const { return veas; }
130   /** Returns equivalent airspeed in knots. */
GetVequivalentKTS(void)131   double GetVequivalentKTS(void) const { return veas*fpstokts; }
132   /** Returns the true airspeed in feet per second. */
GetVtrueFPS()133   double GetVtrueFPS() const { return Vt; }
134   /** Returns the true airspeed in knots. */
GetVtrueKTS()135   double GetVtrueKTS() const { return Vt * fpstokts; }
136 
137   /** Returns the total pressure.
138       Total pressure is freestream total pressure for
139       subsonic only. For supersonic it is the 1D total pressure
140       behind a normal shock. */
GetTotalPressure(void)141   double GetTotalPressure(void) const { return pt; }
142 
143   /** Returns the total temperature.
144     The total temperature ("tat", isentropic flow) is calculated:
145     @code
146     tat = in.Temperature*(1 + 0.2*Mach*Mach)
147     @endcode
148     (where "in.Temperature" is standard temperature calculated by the atmosphere
149     model) */
150 
GetTotalTemperature(void)151   double GetTotalTemperature(void) const { return tat; }
GetTAT_C(void)152   double GetTAT_C(void) const { return tatc; }
153 
GetPilotAccel(int idx)154   double GetPilotAccel(int idx)  const { return vPilotAccel(idx);  }
GetNpilot(int idx)155   double GetNpilot(int idx)      const { return vPilotAccelN(idx); }
GetAeroPQR(int axis)156   double GetAeroPQR(int axis)    const { return vAeroPQR(axis);    }
GetEulerRates(int axis)157   double GetEulerRates(int axis) const { return vEulerRates(axis); }
158 
GetPilotAccel(void)159   const FGColumnVector3& GetPilotAccel (void) const { return vPilotAccel;  }
GetNpilot(void)160   const FGColumnVector3& GetNpilot     (void) const { return vPilotAccelN; }
GetNcg(void)161   const FGColumnVector3& GetNcg        (void) const { return vNcg;         }
GetNcg(int idx)162   double GetNcg                     (int idx) const { return vNcg(idx);    }
163   double GetNlf                        (void) const;
GetAeroPQR(void)164   const FGColumnVector3& GetAeroPQR    (void) const { return vAeroPQR;     }
GetEulerRates(void)165   const FGColumnVector3& GetEulerRates (void) const { return vEulerRates;  }
GetAeroUVW(void)166   const FGColumnVector3& GetAeroUVW    (void) const { return vAeroUVW;     }
GetLocationVRP(void)167   const FGLocation&      GetLocationVRP(void) const { return vLocationVRP; }
168 
GetAeroUVW(int idx)169   double GetAeroUVW (int idx) const { return vAeroUVW(idx); }
Getalpha(void)170   double Getalpha   (void) const { return alpha;      }
Getbeta(void)171   double Getbeta    (void) const { return beta;       }
Getadot(void)172   double Getadot    (void) const { return adot;       }
Getbdot(void)173   double Getbdot    (void) const { return bdot;       }
GetMagBeta(void)174   double GetMagBeta (void) const { return fabs(beta); }
175 
Getalpha(int unit)176   double Getalpha   (int unit) const { if (unit == inDegrees) return alpha*radtodeg;
177                                        else return BadUnits(); }
Getbeta(int unit)178   double Getbeta    (int unit) const { if (unit == inDegrees) return beta*radtodeg;
179                                        else return BadUnits(); }
Getadot(int unit)180   double Getadot    (int unit) const { if (unit == inDegrees) return adot*radtodeg;
181                                        else return BadUnits(); }
Getbdot(int unit)182   double Getbdot    (int unit) const { if (unit == inDegrees) return bdot*radtodeg;
183                                        else return BadUnits(); }
GetMagBeta(int unit)184   double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg;
185                                        else return BadUnits(); }
186 
187   /** Calculates and returns the wind-to-body axis transformation matrix.
188       @return a reference to the wind-to-body transformation matrix.
189       */
GetTw2b(void)190   const FGMatrix33& GetTw2b(void) const { return mTw2b; }
191 
192   /** Calculates and returns the body-to-wind axis transformation matrix.
193       @return a reference to the wind-to-body transformation matrix.
194       */
GetTb2w(void)195   const FGMatrix33& GetTb2w(void) const { return mTb2w; }
196 
Getqbar(void)197   double Getqbar          (void) const { return qbar;       }
GetqbarUW(void)198   double GetqbarUW        (void) const { return qbarUW;     }
GetqbarUV(void)199   double GetqbarUV        (void) const { return qbarUV;     }
GetReynoldsNumber(void)200   double GetReynoldsNumber(void) const { return Re;         }
201 
202   /** Gets the magnitude of total vehicle velocity including wind effects in
203       feet per second. */
GetVt(void)204   double GetVt            (void) const { return Vt;         }
205 
206   /** Gets the ground speed in feet per second.
207       The magnitude is the square root of the sum of the squares (RSS) of the
208       vehicle north and east velocity components.
209       @return The magnitude of the vehicle velocity in the horizontal plane. */
GetVground(void)210   double GetVground       (void) const { return Vground;    }
211 
212   /** Gets the Mach number. */
GetMach(void)213   double GetMach          (void) const { return Mach;       }
214 
215   /** The mach number calculated using the vehicle X axis velocity. */
GetMachU(void)216   double GetMachU         (void) const { return MachU;      }
217 
218   /** The longitudinal acceleration in g's of the aircraft center of gravity. */
GetNx(void)219   double GetNx            (void) const { return Nx;         }
220 
221   /** The lateral acceleration in g's of the aircraft center of gravity. */
GetNy(void)222   double GetNy            (void) const { return Ny;         }
223 
224   /** The vertical acceleration in g's of the aircraft center of gravity. */
GetNz(void)225   double GetNz            (void) const { return Nz;         }
226 
GetNwcg(void)227   const FGColumnVector3& GetNwcg(void) const { return vNwcg; }
228 
GetHOverBCG(void)229   double GetHOverBCG(void) const { return hoverbcg; }
GetHOverBMAC(void)230   double GetHOverBMAC(void) const { return hoverbmac; }
231 
GetGamma(void)232   double GetGamma(void)              const { return gamma;         }
GetGroundTrack(void)233   double GetGroundTrack(void)        const { return psigt;         }
234 
GetGamma(int unit)235   double GetGamma(int unit) const {
236     if (unit == inDegrees) return gamma*radtodeg;
237     else return BadUnits();
238   }
239 
240 // Time routines, SET and GET functions, used by FGMSIS atmosphere
241 
SetDayOfYear(int doy)242   void SetDayOfYear    (int doy)    { day_of_year = doy;    }
SetSecondsInDay(double sid)243   void SetSecondsInDay (double sid) { seconds_in_day = sid; }
244 
GetDayOfYear(void)245   int    GetDayOfYear    (void) const { return day_of_year;    }
GetSecondsInDay(void)246   double GetSecondsInDay (void) const { return seconds_in_day; }
247 
248   double GetLongitudeRelativePosition (void) const;
249   double GetLatitudeRelativePosition  (void) const;
250   double GetDistanceRelativePosition  (void) const;
251 
SetAeroPQR(const FGColumnVector3 & tt)252   void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; }
253 
254   struct Inputs {
255     double Pressure;
256     double Density;
257     double DensitySL;
258     double PressureSL;
259     double Temperature;
260     double SoundSpeed;
261     double KinematicViscosity;
262     double DistanceAGL;
263     double Wingspan;
264     double Wingchord;
265     double SLGravity;
266     double Mass;
267     FGMatrix33 Tl2b;
268     FGMatrix33 Tb2l;
269     FGColumnVector3 vPQR;
270     FGColumnVector3 vPQRi;
271     FGColumnVector3 vPQRidot;
272     FGColumnVector3 vUVW;
273     FGColumnVector3 vUVWdot;
274     FGColumnVector3 vVel;
275     FGColumnVector3 vBodyAccel;
276     FGColumnVector3 ToEyePt;
277     FGColumnVector3 RPBody;
278     FGColumnVector3 VRPBody;
279     FGColumnVector3 vFw;
280     FGLocation vLocation;
281     double CosTht;
282     double SinTht;
283     double CosPhi;
284     double SinPhi;
285     FGColumnVector3 TotalWindNED;
286     FGColumnVector3 TurbPQR;
287   } in;
288 
289 private:
290   double vcas, veas;
291   double pt, tat, tatc; // Don't add a getter for pt!
292 
293   FGMatrix33 mTw2b;
294   FGMatrix33 mTb2w;
295 
296   FGColumnVector3 vPilotAccel;
297   FGColumnVector3 vPilotAccelN;
298   FGColumnVector3 vNcg;
299   FGColumnVector3 vNwcg;
300   FGColumnVector3 vAeroPQR;
301   FGColumnVector3 vAeroUVW;
302   FGColumnVector3 vEulerRates;
303   FGColumnVector3 vMachUVW;
304   FGLocation vLocationVRP;
305 
306   double Vt, Vground;
307   double Mach, MachU;
308   double qbar, qbarUW, qbarUV;
309   double Re; // Reynolds Number = V*c/mu
310   double alpha, beta;
311   double adot,bdot;
312   double psigt, gamma;
313   double Nx, Ny, Nz;
314   double seconds_in_day;  // seconds since current GMT day began
315   int    day_of_year;     // GMT day, 1 .. 366
316 
317   double hoverbcg, hoverbmac;
318 
319   void UpdateWindMatrices(void);
320 
321   void CalculateRelativePosition(void);
322 
323   void bind(void);
324   double BadUnits(void) const;
325   void Debug(int from) override;
326 };
327 
328 } // namespace JSBSim
329 
330 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331 #endif
332