JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGJSBBase Class Reference

JSBSim Base class. More...

#include <FGJSBBase.h>

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

Classes

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

Public Types

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.
 

Public Member Functions

 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 
void disableHighLighting (void)
 Disables highlighting in the console output.
 
std::string GetVersion (void)
 Returns the version number of JSBSim. More...
 
JSBSim Messaging functions
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)
 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...
 

Static Public Member Functions

static double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit. More...
 
static double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin. More...
 
static double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine. More...
 
static double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
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 double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius. More...
 
static double FeetToMeters (double measure)
 Converts from feet to meters. More...
 
static double GaussianRandomNumber (void)
 
static double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius. More...
 
static double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit. More...
 
static double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine. More...
 
static double MachFromVcalibrated (double vcas, double p, double psl, double rhosl)
 Calculate the Mach number from the calibrated airspeed. More...
 
static double PitotTotalPressure (double mach, double p)
 Compute the total pressure in front of the Pitot tube. More...
 
static double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius. More...
 
static double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin. More...
 
static double sign (double num)
 
static double VcalibratedFromMach (double mach, double p, double psl, double rhosl)
 Calculate the calibrated airspeed from the Mach number. More...
 

Static Public Attributes

static short debug_lvl = 1
 
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
 

Protected Member Functions

void Debug (int)
 

Static Protected Member Functions

static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 

Static Protected Attributes

static const double degtorad = 0.017453292519943295769236907684886
 
static const double fpstokts = 1.0/ktstofps
 
static const double fttom = 0.3048
 
static int gaussian_random_number_phase = 0
 
static const double hptoftlbssec = 550.0
 
static const double in3tom3 = 1.638706E-5
 
static const double inchtoft = 0.08333333
 
static const double inhgtopa = 3386.38
 
static const std::string JSBSim_version = "1.0 " __DATE__ " " __TIME__
 
static const double kgtolb = 2.20462
 
static const double kgtoslug = 0.06852168
 
static const double ktstofps = 1.68781
 
static const double lbtoslug = 1.0/slugtolb
 
static Message localMsg
 
static const double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static double Mair = 28.9645
 
static unsigned int messageId = 0
 
static std::queue< MessageMessages
 
static const std::string needed_cfg_version = "2.0"
 
static const double psftoinhg = 0.014138
 
static const double psftopa = 47.88
 
static const double radtodeg = 57.295779513082320876798154814105
 
static double Reng = 1716.56
 
static double Rstar = 1545.348
 
static const double SHRatio = 1.40
 
static const double slugtolb = 32.174049
 

Detailed Description

JSBSim Base class.

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

Author
Jon S. Berndt
Version
Id
FGJSBBase.h,v 1.45 2016/01/10 12:07:49 bcoconni Exp

Definition at line 80 of file FGJSBBase.h.

Member Function Documentation

◆ CelsiusToFahrenheit()

static double CelsiusToFahrenheit ( double  celsius)
inlinestatic

Converts from degrees Celsius to degrees Fahrenheit.

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

Definition at line 239 of file FGJSBBase.h.

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

◆ CelsiusToKelvin()

static double CelsiusToKelvin ( double  celsius)
inlinestatic

Converts from degrees Celsius to degrees Kelvin.

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

Definition at line 246 of file FGJSBBase.h.

246  {
247  return celsius + 273.15;
248  }

◆ CelsiusToRankine()

static double CelsiusToRankine ( double  celsius)
inlinestatic

Converts from degrees Celsius to degrees Rankine.

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

Definition at line 204 of file FGJSBBase.h.

204  {
205  return celsius * 1.8 + 491.67;
206  }

◆ 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 300 of file FGJSBBase.h.

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

◆ EqualToRoundoff() [2/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 309 of file FGJSBBase.h.

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

◆ 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 318 of file FGJSBBase.h.

318  {
319  return EqualToRoundoff(a, (float)b);
320  }
static bool EqualToRoundoff(double a, double b)
Finite precision comparison.
Definition: FGJSBBase.h:300
+ Here is the call graph for this function:

◆ EqualToRoundoff() [4/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 326 of file FGJSBBase.h.

326  {
327  return EqualToRoundoff((float)a, b);
328  }
static bool EqualToRoundoff(double a, double b)
Finite precision comparison.
Definition: FGJSBBase.h:300
+ Here is the call graph for this function:

◆ FahrenheitToCelsius()

static double FahrenheitToCelsius ( double  fahrenheit)
inlinestatic

Converts from degrees Fahrenheit to degrees Celsius.

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

Definition at line 232 of file FGJSBBase.h.

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

◆ FeetToMeters()

static double FeetToMeters ( double  measure)
inlinestatic

Converts from feet to meters.

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

Definition at line 260 of file FGJSBBase.h.

260  {
261  return measure*0.3048;
262  }
+ Here is the call graph for this function:

◆ GetVersion()

std::string GetVersion ( void  )
inline

Returns the version number of JSBSim.

Returns
The version number of JSBSim.

Definition at line 187 of file FGJSBBase.h.

187 {return JSBSim_version;}
+ Here is the call graph for this function:

◆ KelvinToCelsius()

static double KelvinToCelsius ( double  kelvin)
inlinestatic

Converts from degrees Kelvin to degrees Celsius.

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

Definition at line 253 of file FGJSBBase.h.

253  {
254  return kelvin - 273.15;
255  }

◆ KelvinToFahrenheit()

static double KelvinToFahrenheit ( double  kelvin)
inlinestatic

Converts from degrees Kelvin to degrees Fahrenheit.

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

Definition at line 197 of file FGJSBBase.h.

197  {
198  return 1.8*kelvin - 459.4;
199  }

◆ KelvinToRankine()

static double KelvinToRankine ( double  kelvin)
inlinestatic

Converts from degrees Kelvin to degrees Rankine.

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

Definition at line 218 of file FGJSBBase.h.

218  {
219  return kelvin * 1.8;
220  }

◆ MachFromVcalibrated()

double MachFromVcalibrated ( double  vcas,
double  p,
double  psl,
double  rhosl 
)
static

Calculate the Mach number from the calibrated airspeed.

For subsonic speeds, the reversed formula has a closed form. For supersonic speeds, the Rayleigh formula is reversed by the Newton-Raphson algorithm.

Parameters
vcasThe calibrated airspeed (CAS) in ft/s
pPressure in psf
pslPressure at sea level in psf
rhoslDensity at sea level in slugs/ft^3
Returns
The Mach number

Definition at line 315 of file FGJSBBase.cpp.

316 {
317  double pt = p + psl*(pow(1+vcas*vcas*rhosl/(7.0*psl),3.5)-1);
318 
319  if (pt/p < 1.89293)
320  return sqrt(5.0*(pow(pt/p, 1./3.5) -1)); // Mach < 1
321  else {
322  // Mach >= 1
323  double mach = sqrt(0.77666*pt/p); // Initial guess is based on a quadratic approximation of the Rayleigh formula
324  double delta = 1.;
325  double target = pt/(166.92158*p);
326  int iter = 0;
327 
328  // Find the root with Newton-Raphson. Since the differential is never zero,
329  // the function is monotonic and has only one root with a multiplicity of one.
330  // Convergence is certain.
331  while (delta > 1E-5 && iter < 10) {
332  double m2 = mach*mach; // Mach^2
333  double m6 = m2*m2*m2; // Mach^6
334  delta = mach*m6/pow(7.0*m2-1.0,2.5) - target;
335  double diff = 7.0*m6*(2.0*m2-1)/pow(7.0*m2-1.0,3.5); // Never zero when Mach >= 1
336  mach -= delta/diff;
337  iter++;
338  }
339 
340  return mach;
341  }
342 }
+ 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 278 of file FGJSBBase.cpp.

279 {
280  if (mach < 0) return p;
281  if (mach < 1) //calculate total pressure assuming isentropic flow
282  return p*pow((1 + 0.2*mach*mach),3.5);
283  else {
284  // shock in front of pitot tube, we'll assume its normal and use
285  // the Rayleigh Pitot Tube Formula, i.e. the ratio of total
286  // pressure behind the shock to the static pressure in front of
287  // the normal shock assumption should not be a bad one -- most supersonic
288  // aircraft place the pitot probe out front so that it is the forward
289  // most point on the aircraft. The real shock would, of course, take
290  // on something like the shape of a rounded-off cone but, here again,
291  // the assumption should be good since the opening of the pitot probe
292  // is very small and, therefore, the effects of the shock curvature
293  // should be small as well. AFAIK, this approach is fairly well accepted
294  // within the aerospace community
295 
296  // The denominator below is zero for Mach ~ 0.38, for which
297  // we'll never be here, so we're safe
298 
299  return p*166.92158*pow(mach,7.0)/pow(7*mach*mach-1,2.5);
300  }
301 }
+ 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 181 of file FGJSBBase.cpp.

182 {
183  if (Messages.empty()) return;
184  localMsg = Messages.front();
185 
186  while (SomeMessages()) {
187  switch (localMsg.type) {
188  case JSBSim::FGJSBBase::Message::eText:
189  cout << localMsg.messageId << ": " << localMsg.text << endl;
190  break;
191  case JSBSim::FGJSBBase::Message::eBool:
192  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl;
193  break;
194  case JSBSim::FGJSBBase::Message::eInteger:
195  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl;
196  break;
197  case JSBSim::FGJSBBase::Message::eDouble:
198  cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl;
199  break;
200  default:
201  cerr << "Unrecognized message type." << endl;
202  break;
203  }
204  Messages.pop();
205  if (SomeMessages()) localMsg = Messages.front();
206  else break;
207  }
208 
209 }
int SomeMessages(void)
Reads the message on the queue (but does not delete it).
Definition: FGJSBBase.h:175
+ Here is the caller graph for this function:

◆ 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 213 of file FGJSBBase.cpp.

214 {
215  if (Messages.empty()) return NULL;
216  localMsg = Messages.front();
217 
218  Messages.pop();
219  return &localMsg;
220 }
+ Here is the caller graph for this function:

◆ 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 123 of file FGJSBBase.cpp.

124 {
125  Messages.push(msg);
126 }
+ Here is the caller graph for this function:

◆ 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 130 of file FGJSBBase.cpp.

131 {
132  Message msg;
133  msg.text = text;
134  msg.messageId = messageId++;
135  msg.subsystem = "FDM";
136  msg.type = Message::eText;
137  Messages.push(msg);
138 }

◆ 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 142 of file FGJSBBase.cpp.

143 {
144  Message msg;
145  msg.text = text;
146  msg.messageId = messageId++;
147  msg.subsystem = "FDM";
148  msg.type = Message::eBool;
149  msg.bVal = bVal;
150  Messages.push(msg);
151 }

◆ PutMessage() [4/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 155 of file FGJSBBase.cpp.

156 {
157  Message msg;
158  msg.text = text;
159  msg.messageId = messageId++;
160  msg.subsystem = "FDM";
161  msg.type = Message::eInteger;
162  msg.iVal = iVal;
163  Messages.push(msg);
164 }

◆ PutMessage() [5/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 168 of file FGJSBBase.cpp.

169 {
170  Message msg;
171  msg.text = text;
172  msg.messageId = messageId++;
173  msg.subsystem = "FDM";
174  msg.type = Message::eDouble;
175  msg.dVal = dVal;
176  Messages.push(msg);
177 }

◆ RankineToCelsius()

static double RankineToCelsius ( double  rankine)
inlinestatic

Converts from degrees Rankine to degrees Celsius.

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

Definition at line 211 of file FGJSBBase.h.

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

◆ RankineToKelvin()

static double RankineToKelvin ( double  rankine)
inlinestatic

Converts from degrees Rankine to degrees Kelvin.

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

Definition at line 225 of file FGJSBBase.h.

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

◆ SomeMessages()

int SomeMessages ( void  )
inline

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

Returns
1 if some messages

Definition at line 175 of file FGJSBBase.h.

175 { return !Messages.empty(); }
+ Here is the call graph for this function:

◆ VcalibratedFromMach()

double VcalibratedFromMach ( double  mach,
double  p,
double  psl,
double  rhosl 
)
static

Calculate the calibrated airspeed from the Mach number.

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
pslPressure at sea level in psf
rhoslDensity at sea level in slugs/ft^3
Returns
The calibrated airspeed (CAS) in ft/s

Definition at line 305 of file FGJSBBase.cpp.

306 {
307  double pt = PitotTotalPressure(mach, p);
308  double A = pow(((pt-p)/psl+1), 1./3.5);
309 
310  return sqrt(7*psl/rhosl*(A-1));
311 }
static double PitotTotalPressure(double mach, double p)
Compute the total pressure in front of the Pitot tube.
Definition: FGJSBBase.cpp:278
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: