1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
29 1/1/00 TP Added calcs and getters for VTAS, VCAS, VEAS, Vground, in knots
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "math/FGColumnVector3.h"
44 #include "math/FGMatrix33.h"
45 #include "math/FGLocation.h"
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_AUXILIARY "$Id: FGAuxiliary.h,v 1.25 2011/11/12 18:59:11 bcoconni Exp $"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /** Encapsulates various uncategorized scheduled functions.
64 Pilot sensed accelerations are calculated here. This is used
65 for the coordinated turn ball instrument. Motion base platforms sometimes
66 use the derivative of pilot sensed accelerations as the driving parameter,
67 rather than straight accelerations.
69 The theory behind pilot-sensed calculations is presented:
71 For purposes of discussion and calculation, assume for a minute that the
72 pilot is in space and motionless in inertial space. She will feel
73 no accelerations. If the aircraft begins to accelerate along any axis or
74 axes (without rotating), the pilot will sense those accelerations. If
75 any rotational moment is applied, the pilot will sense an acceleration
76 due to that motion in the amount:
78 [wdot X R] + [w X (w X R)]
83 wdot = omegadot, the rotational acceleration rate vector
84 w = omega, the rotational rate vector
85 R = the vector from the aircraft CG to the pilot eyepoint
87 The sum total of these two terms plus the acceleration of the aircraft
88 body axis gives the acceleration the pilot senses in inertial space.
89 In the presence of a large body such as a planet, a gravity field also
90 provides an accelerating attraction. This acceleration can be transformed
91 from the reference frame of the planet so as to be expressed in the frame
92 of reference of the aircraft. This gravity field accelerating attraction
93 is felt by the pilot as a force on her tushie as she sits in her aircraft
94 on the runway awaiting takeoff clearance.
96 In JSBSim the acceleration of the body frame in inertial space is given
97 by the F = ma relation. If the vForces vector is divided by the aircraft
98 mass, the acceleration vector is calculated. The term wdot is equivalent
99 to the JSBSim vPQRdot vector, and the w parameter is equivalent to vPQR.
101 @author Tony Peden, Jon Berndt
102 @version $Id: FGAuxiliary.h,v 1.25 2011/11/12 18:59:11 bcoconni Exp $
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109 class FGAuxiliary : public FGModel {
112 @param Executive a pointer to the parent executive object */
113 FGAuxiliary(FGFDMExec* Executive);
118 bool InitModel(void);
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);
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 /** Returns the true airspeed in feet per second. */
141 double GetVtrueFPS() const { return vtrue; }
142 /** Returns the true airspeed in knots. */
143 double GetVtrueKTS() const { return vtrue * fpstokts; }
145 /** Returns the total pressure.
146 Total pressure is freestream total pressure for
147 subsonic only. For supersonic it is the 1D total pressure
148 behind a normal shock. */
149 double GetTotalPressure(void) const { return pt; }
151 /** Returns the total temperature.
152 The total temperature ("tat", isentropic flow) is calculated:
154 tat = in.Temperature*(1 + 0.2*Mach*Mach)
156 (where "in.Temperature" is standard temperature calculated by the atmosphere model) */
158 double GetTotalTemperature(void) const { return tat; }
159 double GetTAT_C(void) const { return tatc; }
161 double GetPilotAccel(int idx) const { return vPilotAccel(idx); }
162 double GetNpilot(int idx) const { return vPilotAccelN(idx); }
163 double GetAeroPQR(int axis) const { return vAeroPQR(axis); }
164 double GetEulerRates(int axis) const { return vEulerRates(axis); }
166 const FGColumnVector3& GetPilotAccel (void) const { return vPilotAccel; }
167 const FGColumnVector3& GetNpilot (void) const { return vPilotAccelN; }
168 const FGColumnVector3& GetNcg (void) const { return vNcg; }
169 double GetNcg (int idx) const { return vNcg(idx); }
170 double GetNlf (void) const;
171 const FGColumnVector3& GetAeroPQR (void) const { return vAeroPQR; }
172 const FGColumnVector3& GetEulerRates (void) const { return vEulerRates; }
173 const FGColumnVector3& GetAeroUVW (void) const { return vAeroUVW; }
174 const FGLocation& GetLocationVRP(void) const { return vLocationVRP; }
176 double GethVRP(void) const;
177 double GetAeroUVW (int idx) const { return vAeroUVW(idx); }
178 double Getalpha (void) const { return alpha; }
179 double Getbeta (void) const { return beta; }
180 double Getadot (void) const { return adot; }
181 double Getbdot (void) const { return bdot; }
182 double GetMagBeta (void) const { return fabs(beta); }
184 double Getalpha (int unit) const { if (unit == inDegrees) return alpha*radtodeg;
185 else return BadUnits(); }
186 double Getbeta (int unit) const { if (unit == inDegrees) return beta*radtodeg;
187 else return BadUnits(); }
188 double Getadot (int unit) const { if (unit == inDegrees) return adot*radtodeg;
189 else return BadUnits(); }
190 double Getbdot (int unit) const { if (unit == inDegrees) return bdot*radtodeg;
191 else return BadUnits(); }
192 double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg;
193 else return BadUnits(); }
195 /** Calculates and returns the wind-to-body axis transformation matrix.
196 @return a reference to the wind-to-body transformation matrix.
198 const FGMatrix33& GetTw2b(void) { return mTw2b; }
200 /** Calculates and returns the body-to-wind axis transformation matrix.
201 @return a reference to the wind-to-body transformation matrix.
203 const FGMatrix33& GetTb2w(void) { return mTb2w; }
205 double Getqbar (void) const { return qbar; }
206 double GetqbarUW (void) const { return qbarUW; }
207 double GetqbarUV (void) const { return qbarUV; }
208 double GetReynoldsNumber(void) const { return Re; }
210 /** Gets the magnitude of total vehicle velocity including wind effects in feet per second. */
211 double GetVt (void) const { return Vt; }
213 /** Gets the ground speed in feet per second.
214 The magnitude is the square root of the sum of the squares (RSS) of the
215 vehicle north and east velocity components.
216 @return The magnitude of the vehicle velocity in the horizontal plane. */
217 double GetVground (void) const { return Vground; }
219 /** Gets the Mach number. */
220 double GetMach (void) const { return Mach; }
222 /** The mach number calculated using the vehicle X axis velocity. */
223 double GetMachU (void) const { return MachU; }
225 /** The vertical acceleration in g's of the aircraft center of gravity. */
226 double GetNz (void) const { return Nz; }
228 const FGColumnVector3& GetNwcg(void) const { return vNwcg; }
230 double GetHOverBCG(void) const { return hoverbcg; }
231 double GetHOverBMAC(void) const { return hoverbmac; }
233 double GetGamma(void) const { return gamma; }
234 double GetGroundTrack(void) const { return psigt; }
236 double GetHeadWind(void) const;
237 double GetCrossWind(void) const;
239 // Time routines, SET and GET functions, used by FGMSIS atmosphere
241 void SetDayOfYear (int doy) { day_of_year = doy; }
242 void SetSecondsInDay (double sid) { seconds_in_day = sid; }
244 int GetDayOfYear (void) const { return day_of_year; }
245 double GetSecondsInDay (void) const { return seconds_in_day; }
247 double GetLongitudeRelativePosition (void) const { return lon_relative_position; }
248 double GetLatitudeRelativePosition (void) const { return lat_relative_position; }
249 double GetDistanceRelativePosition (void) const { return relative_position; }
251 void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; }
260 double KinematicViscosity;
269 FGColumnVector3 vPQR;
270 FGColumnVector3 vPQRdot;
271 FGColumnVector3 vUVW;
272 FGColumnVector3 vUVWdot;
273 FGColumnVector3 vVel;
274 FGColumnVector3 vBodyAccel;
275 FGColumnVector3 ToEyePt;
276 FGColumnVector3 RPBody;
277 FGColumnVector3 VRPBody;
279 FGLocation vLocation;
282 double InitialLatitude;
283 double InitialLongitude;
284 double ReferenceRadius;
290 FGColumnVector3 TotalWindNED;
291 FGColumnVector3 TurbPQR;
297 double vcas, veas, vtrue;
298 double pt, tat, tatc; // Don't add a getter for pt!
303 FGColumnVector3 vPilotAccel;
304 FGColumnVector3 vPilotAccelN;
305 FGColumnVector3 vNcg;
306 FGColumnVector3 vNwcg;
307 FGColumnVector3 vAeroPQR;
308 FGColumnVector3 vAeroUVW;
309 FGColumnVector3 vEuler;
310 FGColumnVector3 vEulerRates;
311 FGColumnVector3 vMachUVW;
312 FGLocation vLocationVRP;
314 double Vt, Vground, Mach, MachU;
315 double qbar, qbarUW, qbarUV;
316 double Re; // Reynolds Number = V*c/mu
321 double seconds_in_day; // seconds since current GMT day began
322 int day_of_year; // GMT day, 1 .. 366
324 double hoverbcg, hoverbmac;
326 // helper data, calculation of distance from initial position
328 double lon_relative_position;
329 double lat_relative_position;
330 double relative_position;
332 void UpdateWindMatrices(void);
334 void CalculateRelativePosition(void);
337 double BadUnits(void) const;
338 void Debug(int from);
341 } // namespace JSBSim
343 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%