| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGAuxiliary.h |
| 4 | Author: Jon Berndt |
| 5 | Date started: 01/26/99 |
| 6 | |
| 7 | ------------- Copyright (C) 1999 Jon S. Berndt ([email protected]) ------------- |
| 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 JSBSIM_API 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 | /** Compute the total pressure in front of the Pitot tube. It uses the |
| 124 | * Rayleigh formula for supersonic speeds (See "Introduction to Aerodynamics |
| 125 | * of a Compressible Fluid - H.W. Liepmann, A.E. Puckett - Wiley & sons |
| 126 | * (1947)" §5.4 pp 75-80) |
| 127 | * @param mach The Mach number |
| 128 | * @param pressure Pressure in psf |
| 129 | * @return The total pressure in front of the Pitot tube in psf */ |
| 130 | double PitotTotalPressure(double mach, double pressure) const; |
| 131 | |
| 132 | /** Compute the Mach number from the differential pressure (qc) and the |
| 133 | * static pressure. Based on the formulas in the US Air Force Aircraft |
| 134 | * Performance Flight Testing Manual (AFFTC-TIH-99-01). |
| 135 | * @param qc The differential/impact pressure |
| 136 | * @param pressure Pressure in psf |
| 137 | * @return The Mach number */ |
| 138 | double MachFromImpactPressure(double qc, double p) const; |
| 139 | |
| 140 | /** Calculate the calibrated airspeed from the Mach number. Based on the |
| 141 | * formulas in the US Air Force Aircraft Performance Flight Testing |
| 142 | * Manual (AFFTC-TIH-99-01). |
| 143 | * @param mach The Mach number |
| 144 | * @param pressure Pressure in psf |
| 145 | * @return The calibrated airspeed (CAS) in ft/s |
| 146 | * */ |
| 147 | double VcalibratedFromMach(double mach, double pressure) const; |
| 148 | |
| 149 | /** Calculate the Mach number from the calibrated airspeed.Based on the |
| 150 | * formulas in the US Air Force Aircraft Performance Flight Testing |
| 151 | * Manual (AFFTC-TIH-99-01). |
| 152 | * @param vcas The calibrated airspeed (CAS) in ft/s |
| 153 | * @param pressure Pressure in psf |
| 154 | * @return The Mach number |
| 155 | * */ |
| 156 | double MachFromVcalibrated(double vcas, double pressure) const; |
| 157 | |
| 158 | // Atmospheric parameters GET functions |
| 159 | /** Returns Calibrated airspeed in feet/second.*/ |
| 160 | double GetVcalibratedFPS(void) const { return vcas; } |
| 161 | /** Returns Calibrated airspeed in knots.*/ |
| 162 | double GetVcalibratedKTS(void) const { return vcas*fpstokts; } |
| 163 | /** Returns equivalent airspeed in feet/second. */ |
| 164 | double GetVequivalentFPS(void) const { return veas; } |
| 165 | /** Returns equivalent airspeed in knots. */ |
| 166 | double GetVequivalentKTS(void) const { return veas*fpstokts; } |
| 167 | /** Returns the true airspeed in feet per second. */ |
| 168 | double GetVtrueFPS() const { return Vt; } |
| 169 | /** Returns the true airspeed in knots. */ |
| 170 | double GetVtrueKTS() const { return Vt * fpstokts; } |
| 171 | |
| 172 | /** Returns the total pressure. |
| 173 | Total pressure is freestream total pressure for |
| 174 | subsonic only. For supersonic it is the 1D total pressure |
| 175 | behind a normal shock. */ |
| 176 | double GetTotalPressure(void) const { return pt; } |
| 177 | |
| 178 | /** Returns the total temperature. |
| 179 | The total temperature ("tat", isentropic flow) is calculated: |
| 180 | @code |
| 181 | tat = in.Temperature*(1 + 0.2*Mach*Mach) |
| 182 | @endcode |
| 183 | (where "in.Temperature" is standard temperature calculated by the atmosphere |
| 184 | model) */ |
| 185 | |
| 186 | double GetTotalTemperature(void) const { return tat; } |
| 187 | double GetTAT_C(void) const { return tatc; } |
| 188 | |
| 189 | double GetPilotAccel(int idx) const { return vPilotAccel(idx); } |
| 190 | double GetNpilot(int idx) const { return vPilotAccelN(idx); } |
| 191 | double GetAeroPQR(int axis) const { return vAeroPQR(axis); } |
| 192 | double GetEulerRates(int axis) const { return vEulerRates(axis); } |
| 193 | |
| 194 | const FGColumnVector3& GetPilotAccel (void) const { return vPilotAccel; } |
| 195 | const FGColumnVector3& GetNpilot (void) const { return vPilotAccelN; } |
| 196 | const FGColumnVector3& GetNcg (void) const { return vNcg; } |
| 197 | double GetNcg (int idx) const { return vNcg(idx); } |
| 198 | double GetNlf (void) const; |
| 199 | const FGColumnVector3& GetAeroPQR (void) const { return vAeroPQR; } |
| 200 | const FGColumnVector3& GetEulerRates (void) const { return vEulerRates; } |
| 201 | const FGColumnVector3& GetAeroUVW (void) const { return vAeroUVW; } |
| 202 | const FGLocation& GetLocationVRP(void) const { return vLocationVRP; } |
| 203 | |
| 204 | double GetAeroUVW (int idx) const { return vAeroUVW(idx); } |
| 205 | double Getalpha (void) const { return alpha; } |
| 206 | double Getbeta (void) const { return beta; } |
| 207 | double Getadot (void) const { return adot; } |
| 208 | double Getbdot (void) const { return bdot; } |
| 209 | double GetMagBeta (void) const { return fabs(beta); } |
| 210 | |
| 211 | double Getalpha (int unit) const { if (unit == inDegrees) return alpha*radtodeg; |
| 212 | else return BadUnits(); } |
| 213 | double Getbeta (int unit) const { if (unit == inDegrees) return beta*radtodeg; |
| 214 | else return BadUnits(); } |
| 215 | double Getadot (int unit) const { if (unit == inDegrees) return adot*radtodeg; |
| 216 | else return BadUnits(); } |
| 217 | double Getbdot (int unit) const { if (unit == inDegrees) return bdot*radtodeg; |
| 218 | else return BadUnits(); } |
| 219 | double GetMagBeta (int unit) const { if (unit == inDegrees) return fabs(beta)*radtodeg; |
| 220 | else return BadUnits(); } |
| 221 | |
| 222 | /** Calculates and returns the wind-to-body axis transformation matrix. |
| 223 | @return a reference to the wind-to-body transformation matrix. |
| 224 | */ |
| 225 | const FGMatrix33& GetTw2b(void) const { return mTw2b; } |
| 226 | |
| 227 | /** Calculates and returns the body-to-wind axis transformation matrix. |
| 228 | @return a reference to the wind-to-body transformation matrix. |
| 229 | */ |
| 230 | const FGMatrix33& GetTb2w(void) const { return mTb2w; } |
| 231 | |
| 232 | double Getqbar (void) const { return qbar; } |
| 233 | double GetqbarUW (void) const { return qbarUW; } |
| 234 | double GetqbarUV (void) const { return qbarUV; } |
| 235 | double GetReynoldsNumber(void) const { return Re; } |
| 236 | |
| 237 | /** Gets the magnitude of total vehicle velocity including wind effects in |
| 238 | feet per second. */ |
| 239 | double GetVt (void) const { return Vt; } |
| 240 | |
| 241 | /** Gets the ground speed in feet per second. |
| 242 | The magnitude is the square root of the sum of the squares (RSS) of the |
| 243 | vehicle north and east velocity components. |
| 244 | @return The magnitude of the vehicle velocity in the horizontal plane. */ |
| 245 | double GetVground (void) const { return Vground; } |
| 246 | |
| 247 | /** Gets the Mach number. */ |
| 248 | double GetMach (void) const { return Mach; } |
| 249 | |
| 250 | /** The mach number calculated using the vehicle X axis velocity. */ |
| 251 | double GetMachU (void) const { return MachU; } |
| 252 | |
| 253 | /** The longitudinal acceleration in g's of the aircraft center of gravity. */ |
| 254 | double GetNx (void) const { return Nx; } |
| 255 | |
| 256 | /** The lateral acceleration in g's of the aircraft center of gravity. */ |
| 257 | double GetNy (void) const { return Ny; } |
| 258 | |
| 259 | /** The vertical acceleration in g's of the aircraft center of gravity. */ |
| 260 | double GetNz (void) const { return Nz; } |
| 261 | |
| 262 | const FGColumnVector3& GetNwcg(void) const { return vNwcg; } |
| 263 | |
| 264 | double GetHOverBCG(void) const { return hoverbcg; } |
| 265 | double GetHOverBMAC(void) const { return hoverbmac; } |
| 266 | |
| 267 | double GetGamma(void) const { return gamma; } |
| 268 | double GetGroundTrack(void) const { return psigt; } |
| 269 | |
| 270 | double GetGamma(int unit) const { |
| 271 | if (unit == inDegrees) return gamma*radtodeg; |
| 272 | else return BadUnits(); |
| 273 | } |
| 274 | |
| 275 | double GetLongitudeRelativePosition (void) const; |
| 276 | double GetLatitudeRelativePosition (void) const; |
| 277 | double GetDistanceRelativePosition (void) const; |
| 278 | |
| 279 | void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; } |
| 280 | |
| 281 | struct Inputs { |
| 282 | double Pressure; |
| 283 | double Density; |
| 284 | double Temperature; |
| 285 | double StdDaySLsoundspeed; |
| 286 | double SoundSpeed; |
| 287 | double KinematicViscosity; |
| 288 | double DistanceAGL; |
| 289 | double Wingspan; |
| 290 | double Wingchord; |
| 291 | double StandardGravity; |
| 292 | double Mass; |
| 293 | FGMatrix33 Tl2b; |
| 294 | FGMatrix33 Tb2l; |
| 295 | FGColumnVector3 vPQR; |
| 296 | FGColumnVector3 vPQRi; |
| 297 | FGColumnVector3 vPQRidot; |
| 298 | FGColumnVector3 vUVW; |
| 299 | FGColumnVector3 vUVWdot; |
| 300 | FGColumnVector3 vVel; |
| 301 | FGColumnVector3 vBodyAccel; |
| 302 | FGColumnVector3 ToEyePt; |
| 303 | FGColumnVector3 RPBody; |
| 304 | FGColumnVector3 VRPBody; |
| 305 | FGColumnVector3 vFw; |
| 306 | FGLocation vLocation; |
| 307 | double CosTht; |
| 308 | double SinTht; |
| 309 | double CosPhi; |
| 310 | double SinPhi; |
| 311 | FGColumnVector3 TotalWindNED; |
| 312 | FGColumnVector3 TurbPQR; |
| 313 | } in; |
| 314 | |
| 315 | private: |
| 316 | double vcas, veas; |
| 317 | double pt, tat, tatc; // Don't add a getter for pt! |
| 318 | |
| 319 | FGMatrix33 mTw2b; |
| 320 | FGMatrix33 mTb2w; |
| 321 | |
| 322 | FGColumnVector3 vPilotAccel; |
| 323 | FGColumnVector3 vPilotAccelN; |
| 324 | FGColumnVector3 vNcg; |
| 325 | FGColumnVector3 vNwcg; |
| 326 | FGColumnVector3 vAeroPQR; |
| 327 | FGColumnVector3 vAeroUVW; |
| 328 | FGColumnVector3 vEulerRates; |
| 329 | FGColumnVector3 vMachUVW; |
| 330 | FGLocation vLocationVRP; |
| 331 | |
| 332 | double Vt, Vground; |
| 333 | double Mach, MachU; |
| 334 | double qbar, qbarUW, qbarUV; |
| 335 | double Re; // Reynolds Number = V*c/mu |
| 336 | double alpha, beta; |
| 337 | double adot,bdot; |
| 338 | double psigt, gamma; |
| 339 | double Nx, Ny, Nz; |
| 340 | |
| 341 | double hoverbcg, hoverbmac; |
| 342 | |
| 343 | void UpdateWindMatrices(void); |
| 344 | |
| 345 | void CalculateRelativePosition(void); |
| 346 | |
| 347 | void bind(void); |
| 348 | double BadUnits(void) const; |
| 349 | void Debug(int from) override; |
| 350 | }; |
| 351 | |
| 352 | } // namespace JSBSim |
| 353 | |
| 354 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 355 | #endif |