JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGJSBBase Class Reference

Detailed Description

JSBSim Base class.

This class provides universal constants, utility functions, messaging functions, and enumerated constants to JSBSim.

Author
Jon S. Berndt

Definition at line 78 of file FGJSBBase.h.

#include <FGJSBBase.h>

+ Inheritance diagram for FGJSBBase:
+ Collaboration diagram for FGJSBBase:

Classes

class  Filter
 First order, (low pass / lag) filter. More...
 
struct  Message
 JSBSim Message structure. More...
 

Public Member Functions

 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 

Static Public Attributes

JSBSim console output highlighting terms.
static char highint [5] = {27, '[', '1', 'm', '\0' }
 highlights text
 
static char halfint [5] = {27, '[', '2', 'm', '\0' }
 low intensity text
 
static char normint [6] = {27, '[', '2', '2', 'm', '\0' }
 normal intensity text
 
static char reset [5] = {27, '[', '0', 'm', '\0' }
 resets text properties
 
static char underon [5] = {27, '[', '4', 'm', '\0' }
 underlines text
 
static char underoff [6] = {27, '[', '2', '4', 'm', '\0' }
 underline off
 
static char fgblue [6] = {27, '[', '3', '4', 'm', '\0' }
 blue text
 
static char fgcyan [6] = {27, '[', '3', '6', 'm', '\0' }
 cyan text
 
static char fgred [6] = {27, '[', '3', '1', 'm', '\0' }
 red text
 
static char fggreen [6] = {27, '[', '3', '2', 'm', '\0' }
 green text
 
static char fgdef [6] = {27, '[', '3', '9', 'm', '\0' }
 default text
 

JSBSim Messaging functions

enum  { eL = 1, eM, eN }
 Moments L, M, N.
 
enum  { eP = 1, eQ, eR }
 Rates P, Q, R.
 
enum  { eU = 1, eV, eW }
 Velocities U, V, W.
 
enum  { eX = 1, eY, eZ }
 Positions X, Y, Z.
 
enum  { ePhi = 1, eTht, ePsi }
 Euler angles Phi, Theta, Psi.
 
enum  { eDrag = 1, eSide, eLift }
 Stability axis forces, Drag, Side force, Lift.
 
enum  { eRoll = 1, ePitch, eYaw }
 Local frame orientation Roll, Pitch, Yaw.
 
enum  { eNorth = 1, eEast, eDown }
 Local frame position North, East, Down.
 
enum  { eLat = 1, eLong, eRad }
 Locations Radius, Latitude, Longitude.
 
enum  {
  inNone = 0, inDegrees, inRadians, inMeters,
  inFeet
}
 Conversion specifiers.
 
static short debug_lvl = 1
 
static Message localMsg
 
static std::queue< MessageMessages
 
static unsigned int messageId = 0
 
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double degtorad = M_PI / 180.
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double ktstofps = 1.68781
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double fttom = 0.3048
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inhgtopa = 3386.38
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff. More...
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static const std::string needed_cfg_version = "2.0"
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 
static int gaussian_random_number_phase = 0
 
void PutMessage (const Message &msg)
 Places a Message structure on the Message queue. More...
 
void PutMessage (const std::string &text)
 Creates a message with the given text and places it on the queue. More...
 
void PutMessage (const std::string &text, bool bVal)
 Creates a message with the given text and boolean value and places it on the queue. More...
 
void PutMessage (const std::string &text, int iVal)
 Creates a message with the given text and integer value and places it on the queue. More...
 
void PutMessage (const std::string &text, double dVal)
 Creates a message with the given text and double value and places it on the queue. More...
 
int SomeMessages (void) const
 Reads the message on the queue (but does not delete it). More...
 
void ProcessMessage (void)
 Reads the message on the queue and removes it from the queue. More...
 
MessageProcessNextMessage (void)
 Reads the next message on the queue and removes it from the queue. More...
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 
static const std::string & GetVersion (void)
 Returns the version number of JSBSim. More...
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double MachFromImpactPressure (double qc, double p)
 Compute the Mach number from the differential pressure (qc) and the static pressure. More...
 
static double VcalibratedFromMach (double mach, double p)
 Calculate the calibrated airspeed from the Mach number. More...
 
static double MachFromVcalibrated (double vcas, double p)
 Calculate the Mach number from the calibrated airspeed.Based on the formulas in the US Air Force Aircraft Performance Flight Testing Manual (AFFTC-TIH-99-01). More...
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison. More...
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison. More...
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static constexpr double sign (double num)
 
static double GaussianRandomNumber (void)
 
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 

Member Function Documentation

◆ CelsiusToFahrenheit()

static constexpr double CelsiusToFahrenheit ( double  celsius)
inlinestaticconstexpr

Converts from degrees Celsius to degrees Fahrenheit.

Parameters
celsiusThe temperature in degrees Celsius.
Returns
The temperature in Fahrenheit.

Definition at line 237 of file FGJSBBase.h.

237  {
238  return celsius * 1.8 + 32.0;
239  }
+ Here is the caller graph for this function:

◆ CelsiusToKelvin()

static constexpr double CelsiusToKelvin ( double  celsius)
inlinestaticconstexpr

Converts from degrees Celsius to degrees Kelvin.

Parameters
celsiusThe temperature in degrees Celsius.
Returns
The temperature in Kelvin.

Definition at line 244 of file FGJSBBase.h.

244  {
245  return celsius + 273.15;
246  }

◆ CelsiusToRankine()

static constexpr double CelsiusToRankine ( double  celsius)
inlinestaticconstexpr

Converts from degrees Celsius to degrees Rankine.

Parameters
celsiusThe temperature in degrees Celsius.
Returns
The temperature in Rankine.

Definition at line 202 of file FGJSBBase.h.

202  {
203  return celsius * 1.8 + 491.67;
204  }

◆ EqualToRoundoff() [1/4]

static bool EqualToRoundoff ( double  a,
double  b 
)
inlinestatic

Finite precision comparison.

Parameters
afirst value to compare
bsecond value to compare
Returns
if the two values can be considered equal up to roundoff

Definition at line 301 of file FGJSBBase.h.

301  {
302  double eps = 2.0*DBL_EPSILON;
303  return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
304  }
+ Here is the caller graph for this function:

◆ EqualToRoundoff() [2/4]

static bool EqualToRoundoff ( double  a,
float  b 
)
inlinestatic

Finite precision comparison.

Parameters
afirst value to compare
bsecond value to compare
Returns
if the two values can be considered equal up to roundoff

Definition at line 327 of file FGJSBBase.h.

327  {
328  return EqualToRoundoff((float)a, b);
329  }
+ Here is the call graph for this function:

◆ EqualToRoundoff() [3/4]

static bool EqualToRoundoff ( float  a,
double  b 
)
inlinestatic

Finite precision comparison.

Parameters
afirst value to compare
bsecond value to compare
Returns
if the two values can be considered equal up to roundoff

Definition at line 319 of file FGJSBBase.h.

319  {
320  return EqualToRoundoff(a, (float)b);
321  }
+ Here is the call graph for this function:

◆ EqualToRoundoff() [4/4]

static bool EqualToRoundoff ( float  a,
float  b 
)
inlinestatic

Finite precision comparison.

Parameters
afirst value to compare
bsecond value to compare
Returns
if the two values can be considered equal up to roundoff

Definition at line 310 of file FGJSBBase.h.

310  {
311  float eps = 2.0*FLT_EPSILON;
312  return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
313  }

◆ FahrenheitToCelsius()

static constexpr double FahrenheitToCelsius ( double  fahrenheit)
inlinestaticconstexpr

Converts from degrees Fahrenheit to degrees Celsius.

Parameters
fahrenheitThe temperature in degrees Fahrenheit.
Returns
The temperature in Celsius.

Definition at line 230 of file FGJSBBase.h.

230  {
231  return (fahrenheit - 32.0)/1.8;
232  }
+ Here is the caller graph for this function:

◆ FeetToMeters()

static constexpr double FeetToMeters ( double  measure)
inlinestaticconstexpr

Converts from feet to meters.

Parameters
measureThe length in feet.
Returns
The length in meters.

Definition at line 258 of file FGJSBBase.h.

258  {
259  return measure*0.3048;
260  }

◆ GetVersion()

static const std::string& GetVersion ( void  )
inlinestatic

Returns the version number of JSBSim.

Returns
The version number of JSBSim.

Definition at line 185 of file FGJSBBase.h.

185 {return JSBSim_version;}

◆ KelvinToCelsius()

static constexpr double KelvinToCelsius ( double  kelvin)
inlinestaticconstexpr

Converts from degrees Kelvin to degrees Celsius.

Parameters
celsiusThe temperature in degrees Kelvin.
Returns
The temperature in Celsius.

Definition at line 251 of file FGJSBBase.h.

251  {
252  return kelvin - 273.15;
253  }

◆ KelvinToFahrenheit()

static constexpr double KelvinToFahrenheit ( double  kelvin)
inlinestaticconstexpr

Converts from degrees Kelvin to degrees Fahrenheit.

Parameters
kelvinThe temperature in degrees Kelvin.
Returns
The temperature in Fahrenheit.

Definition at line 195 of file FGJSBBase.h.

195  {
196  return 1.8*kelvin - 459.4;
197  }

◆ KelvinToRankine()

static constexpr double KelvinToRankine ( double  kelvin)
inlinestaticconstexpr

Converts from degrees Kelvin to degrees Rankine.

Parameters
kelvinThe temperature in degrees Kelvin.
Returns
The temperature in Rankine.

Definition at line 216 of file FGJSBBase.h.

216  {
217  return kelvin * 1.8;
218  }

◆ MachFromImpactPressure()

double MachFromImpactPressure ( double  qc,
double  p 
)
static

Compute the Mach number from the differential pressure (qc) and the static pressure.

Based on the formulas in the US Air Force Aircraft Performance Flight Testing Manual (AFFTC-TIH-99-01).

Parameters
qcThe differential/impact pressure
pPressure in psf
Returns
The Mach number

Definition at line 275 of file FGJSBBase.cpp.

276 {
277  double A = qc / p + 1;
278  double M = sqrt(5.0*(pow(A, 1. / 3.5) - 1)); // Equation (4.12)
279 
280  if (M > 1.0)
281  for (unsigned int i = 0; i<10; i++)
282  M = 0.8812848543473311*sqrt(A*pow(1 - 1.0 / (7.0*M*M), 2.5)); // Equation (4.17)
283 
284  return M;
285 }

◆ MachFromVcalibrated()

double MachFromVcalibrated ( double  vcas,
double  p 
)
static

Calculate the Mach number from the calibrated airspeed.Based on the formulas in the US Air Force Aircraft Performance Flight Testing Manual (AFFTC-TIH-99-01).

Parameters
vcasThe calibrated airspeed (CAS) in ft/s
pPressure in psf
Returns
The Mach number

Definition at line 300 of file FGJSBBase.cpp.

301 {
302  double asl = FGAtmosphere::StdDaySLsoundspeed;
303  double psl = FGAtmosphere::StdDaySLpressure;
304  double qc = PitotTotalPressure(vcas / asl, psl) - psl;
305 
306  return MachFromImpactPressure(qc, p);
307 }
+ Here is the caller graph for this function:

◆ PitotTotalPressure()

double PitotTotalPressure ( double  mach,
double  p 
)
static

Compute the total pressure in front of the Pitot tube.

It uses the Rayleigh formula for supersonic speeds (See "Introduction to Aerodynamics of a Compressible Fluid - H.W. Liepmann, A.E. Puckett - Wiley & sons (1947)" ยง5.4 pp 75-80)

Parameters
machThe Mach number
pPressure in psf
Returns
The total pressure in front of the Pitot tube in psf

Definition at line 245 of file FGJSBBase.cpp.

246 {
247  if (mach < 0) return p;
248  if (mach < 1) //calculate total pressure assuming isentropic flow
249  return p*pow((1 + 0.2*mach*mach),3.5);
250  else {
251  // shock in front of pitot tube, we'll assume its normal and use
252  // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
253  // pressure behind the shock to the static pressure in front of
254  // the normal shock assumption should not be a bad one -- most supersonic
255  // aircraft place the pitot probe out front so that it is the forward
256  // most point on the aircraft. The real shock would, of course, take
257  // on something like the shape of a rounded-off cone but, here again,
258  // the assumption should be good since the opening of the pitot probe
259  // is very small and, therefore, the effects of the shock curvature
260  // should be small as well. AFAIK, this approach is fairly well accepted
261  // within the aerospace community
262 
263  // The denominator below is zero for Mach ~ 0.38, for which
264  // we'll never be here, so we're safe
265 
266  return p*166.92158009316827*pow(mach,7.0)/pow(7*mach*mach-1,2.5);
267  }
268 }
+ Here is the caller graph for this function:

◆ ProcessMessage()

void ProcessMessage ( void  )

Reads the message on the queue and removes it from the queue.

This function also prints out the message.

Definition at line 148 of file FGJSBBase.cpp.

149 {
150  if (Messages.empty()) return;
151  localMsg = Messages.front();
152 
153  while (SomeMessages()) {
154  switch (localMsg.type) {
155  case JSBSim::FGJSBBase::Message::eText:
156  cout << localMsg.messageId << ": " << localMsg.text << endl;
157  break;
158  case JSBSim::FGJSBBase::Message::eBool:
159  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl;
160  break;
161  case JSBSim::FGJSBBase::Message::eInteger:
162  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl;
163  break;
164  case JSBSim::FGJSBBase::Message::eDouble:
165  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl;
166  break;
167  default:
168  cerr << "Unrecognized message type." << endl;
169  break;
170  }
171  Messages.pop();
172  if (SomeMessages()) localMsg = Messages.front();
173  else break;
174  }
175 
176 }

◆ ProcessNextMessage()

FGJSBBase::Message * ProcessNextMessage ( void  )

Reads the next message on the queue and removes it from the queue.

This function also prints out the message.

Returns
a pointer to the message, or NULL if there are no messages.

Definition at line 180 of file FGJSBBase.cpp.

181 {
182  if (Messages.empty()) return NULL;
183  localMsg = Messages.front();
184 
185  Messages.pop();
186  return &localMsg;
187 }

◆ PutMessage() [1/5]

void PutMessage ( const Message msg)

Places a Message structure on the Message queue.

Parameters
msgpointer to a Message structure
Returns
pointer to a Message structure

Definition at line 90 of file FGJSBBase.cpp.

91 {
92  Messages.push(msg);
93 }

◆ PutMessage() [2/5]

void PutMessage ( const std::string &  text)

Creates a message with the given text and places it on the queue.

Parameters
textmessage text
Returns
pointer to a Message structure

Definition at line 97 of file FGJSBBase.cpp.

98 {
99  Message msg;
100  msg.text = text;
101  msg.messageId = messageId++;
102  msg.subsystem = "FDM";
103  msg.type = Message::eText;
104  Messages.push(msg);
105 }

◆ PutMessage() [3/5]

void PutMessage ( const std::string &  text,
bool  bVal 
)

Creates a message with the given text and boolean value and places it on the queue.

Parameters
textmessage text
bValboolean value associated with the message
Returns
pointer to a Message structure

Definition at line 109 of file FGJSBBase.cpp.

110 {
111  Message msg;
112  msg.text = text;
113  msg.messageId = messageId++;
114  msg.subsystem = "FDM";
115  msg.type = Message::eBool;
116  msg.bVal = bVal;
117  Messages.push(msg);
118 }

◆ PutMessage() [4/5]

void PutMessage ( const std::string &  text,
double  dVal 
)

Creates a message with the given text and double value and places it on the queue.

Parameters
textmessage text
dValdouble value associated with the message
Returns
pointer to a Message structure

Definition at line 135 of file FGJSBBase.cpp.

136 {
137  Message msg;
138  msg.text = text;
139  msg.messageId = messageId++;
140  msg.subsystem = "FDM";
141  msg.type = Message::eDouble;
142  msg.dVal = dVal;
143  Messages.push(msg);
144 }

◆ PutMessage() [5/5]

void PutMessage ( const std::string &  text,
int  iVal 
)

Creates a message with the given text and integer value and places it on the queue.

Parameters
textmessage text
iValinteger value associated with the message
Returns
pointer to a Message structure

Definition at line 122 of file FGJSBBase.cpp.

123 {
124  Message msg;
125  msg.text = text;
126  msg.messageId = messageId++;
127  msg.subsystem = "FDM";
128  msg.type = Message::eInteger;
129  msg.iVal = iVal;
130  Messages.push(msg);
131 }

◆ RankineToCelsius()

static constexpr double RankineToCelsius ( double  rankine)
inlinestaticconstexpr

Converts from degrees Rankine to degrees Celsius.

Parameters
rankineThe temperature in degrees Rankine.
Returns
The temperature in Celsius.

Definition at line 209 of file FGJSBBase.h.

209  {
210  return (rankine - 491.67)/1.8;
211  }
+ Here is the caller graph for this function:

◆ RankineToKelvin()

static constexpr double RankineToKelvin ( double  rankine)
inlinestaticconstexpr

Converts from degrees Rankine to degrees Kelvin.

Parameters
rankineThe temperature in degrees Rankine.
Returns
The temperature in Kelvin.

Definition at line 223 of file FGJSBBase.h.

223  {
224  return rankine/1.8;
225  }
+ Here is the caller graph for this function:

◆ SomeMessages()

int SomeMessages ( void  ) const
inline

Reads the message on the queue (but does not delete it).

Returns
1 if some messages

Definition at line 173 of file FGJSBBase.h.

173 { return !Messages.empty(); }

◆ VcalibratedFromMach()

double VcalibratedFromMach ( double  mach,
double  p 
)
static

Calculate the calibrated airspeed from the Mach number.

Based on the formulas in the US Air Force Aircraft Performance Flight Testing Manual (AFFTC-TIH-99-01).

Parameters
machThe Mach number
pPressure in psf
Returns
The calibrated airspeed (CAS) in ft/s

Definition at line 289 of file FGJSBBase.cpp.

290 {
291  double asl = FGAtmosphere::StdDaySLsoundspeed;
292  double psl = FGAtmosphere::StdDaySLpressure;
293  double qc = PitotTotalPressure(mach, p) - p;
294 
295  return asl * MachFromImpactPressure(qc, psl);
296 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ slugtolb

constexpr double slugtolb = 32.174049
staticconstexprprotected

Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.

So converting from slug to lb and back will yield to the original value you started with up to the magnitude of roundoff. Taken from units gnu commandline tool

Definition at line 366 of file FGJSBBase.h.


The documentation for this class was generated from the following files:
JSBSim::FGJSBBase::EqualToRoundoff
static bool EqualToRoundoff(double a, double b)
Finite precision comparison.
Definition: FGJSBBase.h:301
JSBSim::FGJSBBase::PitotTotalPressure
static double PitotTotalPressure(double mach, double p)
Compute the total pressure in front of the Pitot tube.
Definition: FGJSBBase.cpp:245
JSBSim::FGJSBBase::SomeMessages
int SomeMessages(void) const
Reads the message on the queue (but does not delete it).
Definition: FGJSBBase.h:173
JSBSim::FGJSBBase::MachFromImpactPressure
static double MachFromImpactPressure(double qc, double p)
Compute the Mach number from the differential pressure (qc) and the static pressure.
Definition: FGJSBBase.cpp:275