1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.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 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 # define M_PI 3.14159265358979323846
53 #if !defined(WIN32) || defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300))
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 #define ID_JSBBASE "$Id$"
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 /** JSBSim Base class.
74 * This class provides universal constants, utility functions, messaging
75 * functions, and enumerated constants to JSBSim.
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86 /// Constructor for FGJSBBase.
89 /// Destructor for FGJSBBase.
92 /// JSBSim Message structure
96 unsigned int messageId;
99 enum mType {eText, eInteger, eDouble, eBool} type;
105 ///@name JSBSim console output highlighting terms.
108 static char highint[5];
109 /// low intensity text
110 static char halfint[5];
111 /// normal intensity text
112 static char normint[6];
113 /// resets text properties
114 static char reset[5];
116 static char underon[5];
118 static char underoff[6];
120 static char fgblue[6];
122 static char fgcyan[6];
124 static char fgred[6];
126 static char fggreen[6];
128 static char fgdef[6];
131 ///@name JSBSim Messaging functions
133 /** Places a Message structure on the Message queue.
134 @param msg pointer to a Message structure
135 @return pointer to a Message structure */
136 void PutMessage(const Message& msg);
137 /** Creates a message with the given text and places it on the queue.
138 @param text message text
139 @return pointer to a Message structure */
140 void PutMessage(const string& text);
141 /** Creates a message with the given text and boolean value and places it on the queue.
142 @param text message text
143 @param bVal boolean value associated with the message
144 @return pointer to a Message structure */
145 void PutMessage(const string& text, bool bVal);
146 /** Creates a message with the given text and integer value and places it on the queue.
147 @param text message text
148 @param iVal integer value associated with the message
149 @return pointer to a Message structure */
150 void PutMessage(const string& text, int iVal);
151 /** Creates a message with the given text and double value and places it on the queue.
152 @param text message text
153 @param dVal double value associated with the message
154 @return pointer to a Message structure */
155 void PutMessage(const string& text, double dVal);
156 /** Reads the message on the queue (but does not delete it).
157 @return 1 if some messages */
158 int SomeMessages(void);
159 /** Reads the message on the queue and removes it from the queue.
160 @return pointer to a Message structure (or NULL if no mesage) */
161 Message* ProcessMessage(void);
164 /** Returns the version number of JSBSim.
165 * @return The version number of JSBSim. */
166 string GetVersion(void) {return JSBSim_version;}
168 /// Disables highlighting in the console output.
169 void disableHighLighting(void);
171 static short debug_lvl;
173 /** Converts from degrees Kelvin to degrees Fahrenheit.
174 * @param kelvin The temperature in degrees Kelvin.
175 * @return The temperature in Fahrenheit. */
176 static double KelvinToFahrenheit (double kelvin) {
177 return 1.8*kelvin - 459.4;
180 /** Converts from degrees Celsius to degrees Rankine.
181 * @param celsius The temperature in degrees Celsius.
182 * @return The temperature in Rankine. */
183 static double CelsiusToRankine (double celsius) {
184 return celsius * 1.8 + 491.67;
187 /** Converts from degrees Rankine to degrees Celsius.
188 * @param rankine The temperature in degrees Rankine.
189 * @return The temperature in Celsius. */
190 static double RankineToCelsius (double rankine) {
191 return (rankine - 491.67)/1.8;
194 /** Converts from degrees Kelvin to degrees Rankine.
195 * @param kelvin The temperature in degrees Kelvin.
196 * @return The temperature in Rankine. */
197 static double KelvinToRankine (double kelvin) {
201 /** Converts from degrees Rankine to degrees Kelvin.
202 * @param rankine The temperature in degrees Rankine.
203 * @return The temperature in Kelvin. */
204 static double RankineToKelvin (double rankine) {
208 /** Converts from degrees Fahrenheit to degrees Celsius.
209 * @param fahrenheit The temperature in degrees Fahrenheit.
210 * @return The temperature in Celsius. */
211 static double FahrenheitToCelsius (double fahrenheit) {
212 return (fahrenheit - 32.0)/1.8;
215 /** Converts from degrees Celsius to degrees Fahrenheit.
216 * @param celsius The temperature in degrees Celsius.
217 * @return The temperature in Fahrenheit. */
218 static double CelsiusToFahrenheit (double celsius) {
219 return celsius * 1.8 + 32.0;
222 /** Converts from degrees Celsius to degrees Kelvin
223 * @param celsius The temperature in degrees Celsius.
224 * @return The temperature in Kelvin. */
225 static double CelsiusToKelvin (double celsius) {
226 return celsius + 273.15;
229 /** Converts from degrees Kelvin to degrees Celsius
230 * @param celsius The temperature in degrees Kelvin.
231 * @return The temperature in Celsius. */
232 static double KelvinToCelsius (double kelvin) {
233 return kelvin - 273.15;
236 /** Finite precision comparison.
237 @param a first value to compare
238 @param b second value to compare
239 @return if the two values can be considered equal up to roundoff */
240 static bool EqualToRoundoff(double a, double b) {
241 double eps = 2.0*DBL_EPSILON;
242 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
245 /** Finite precision comparison.
246 @param a first value to compare
247 @param b second value to compare
248 @return if the two values can be considered equal up to roundoff */
249 static bool EqualToRoundoff(float a, float b) {
250 float eps = 2.0*FLT_EPSILON;
251 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
254 /** Finite precision comparison.
255 @param a first value to compare
256 @param b second value to compare
257 @return if the two values can be considered equal up to roundoff */
258 static bool EqualToRoundoff(float a, double b) {
259 return EqualToRoundoff(a, (float)b);
262 /** Finite precision comparison.
263 @param a first value to compare
264 @param b second value to compare
265 @return if the two values can be considered equal up to roundoff */
266 static bool EqualToRoundoff(double a, float b) {
267 return EqualToRoundoff((float)a, b);
270 /** Constrain a value between a minimum and a maximum value.
272 static double Constrain(double min, double value, double max) {
273 return value<min?(min):(value>max?(max):(value));
277 static Message localMsg;
279 static std::queue <Message> Messages;
281 void Debug(int from) {};
283 static unsigned int messageId;
285 static const double radtodeg;
286 static const double degtorad;
287 static const double hptoftlbssec;
288 static const double psftoinhg;
289 static const double psftopa;
290 static const double fpstokts;
291 static const double ktstofps;
292 static const double inchtoft;
293 static const double in3tom3;
294 static const double m3toft3;
295 static const double inhgtopa;
296 static const double fttom;
297 static double Reng; // Specific Gas Constant,ft^2/(sec^2*R)
298 static const double SHRatio;
299 static const double lbtoslug;
300 static const double slugtolb;
301 static const double kgtolb;
302 static const double kgtoslug;
303 static const string needed_cfg_version;
304 static const string JSBSim_version;
308 enum {eL = 1, eM, eN };
310 enum {eP = 1, eQ, eR };
311 /// Velocities U, V, W
312 enum {eU = 1, eV, eW };
313 /// Positions X, Y, Z
314 enum {eX = 1, eY, eZ };
315 /// Euler angles Phi, Theta, Psi
316 enum {ePhi = 1, eTht, ePsi };
317 /// Stability axis forces, Drag, Side force, Lift
318 enum {eDrag = 1, eSide, eLift };
319 /// Local frame orientation Roll, Pitch, Yaw
320 enum {eRoll = 1, ePitch, eYaw };
321 /// Local frame position North, East, Down
322 enum {eNorth = 1, eEast, eDown };
323 /// Locations Radius, Latitude, Longitude
324 enum {eLat = 1, eLong, eRad };
325 /// Conversion specifiers
326 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
331 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%