]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.h
First steps in a weather reorganization. Note especially that
[flightgear.git] / src / FDM / JSBSim / FGJSBBase.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGJSBBase.h
4  Author:       Jon S. Berndt
5  Date started: 07/01/01
6
7  ------------- Copyright (C) 2001  Jon S. Berndt (jsb@hal-pc.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 07/01/01  JSB  Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGJSBBASE_H
35 #define FGJSBBASE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  include <math.h>
44 #  include <queue>
45 #  include STL_STRING
46
47 SG_USING_STD(string);
48 SG_USING_STD(queue);
49
50 #else
51
52 #  include <queue>
53 #  include <string>
54 #  if defined(sgi) && !defined(__GNUC__)
55 #    include <math.h>
56 #  else
57 #    include <cmath>
58 #  endif
59
60 using std::string;
61 using std::queue;
62 #endif
63
64 #ifndef M_PI 
65 #  include <simgear/constants.h>
66 #  define M_PI SG_PI
67 #endif
68
69 #ifdef __FreeBSD__ // define gcvt on FreeBSD
70
71 #include <stdio.h>
72
73 static char *gcvt(double number, size_t ndigit, char *buf)
74 {
75      sprintf(buf, "%f", number);
76      return buf;
77 }
78 #endif
79
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 DEFINITIONS
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83
84 #define ID_JSBBASE "$Id$"
85
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 FORWARD DECLARATIONS
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89
90 enum eParam {
91   FG_UNDEF = 0,
92   FG_TIME,
93   FG_QBAR,
94   FG_WINGAREA,
95   FG_WINGSPAN,
96   FG_CBAR,
97   FG_ALPHA,
98   FG_ALPHADOT,
99   FG_BETA,
100   FG_ABETA,
101   FG_BETADOT,
102   FG_PHI,
103   FG_THT,
104   FG_PSI,
105   FG_PITCHRATE,
106   FG_ROLLRATE,
107   FG_YAWRATE,
108   FG_AEROP,
109   FG_AEROQ,
110   FG_AEROR,
111   FG_CL_SQRD,
112   FG_MACH,
113   FG_ALTITUDE,
114   FG_BI2VEL,
115   FG_CI2VEL,
116   FG_ELEVATOR_POS,
117   FG_AILERON_POS,
118   FG_RUDDER_POS,
119   FG_SPDBRAKE_POS,
120   FG_SPOILERS_POS,
121   FG_FLAPS_POS,
122   FG_ELEVATOR_CMD,
123   FG_AILERON_CMD,
124   FG_RUDDER_CMD,
125   FG_SPDBRAKE_CMD,
126   FG_SPOILERS_CMD,
127   FG_FLAPS_CMD,
128   FG_THROTTLE_CMD,
129   FG_THROTTLE_POS,
130   FG_MIXTURE_CMD,
131   FG_MIXTURE_POS,
132   FG_MAGNETO_CMD,
133   FG_STARTER_CMD,
134   FG_ACTIVE_ENGINE,
135   FG_HOVERB,
136   FG_PITCH_TRIM_CMD,
137   FG_YAW_TRIM_CMD,
138   FG_ROLL_TRIM_CMD,
139   FG_LEFT_BRAKE_CMD,
140   FG_CENTER_BRAKE_CMD,
141   FG_RIGHT_BRAKE_CMD,
142   FG_SET_LOGGING,
143   FG_ALPHAH,
144   FG_ALPHAW,
145   FG_LBARH,     //normalized horizontal tail arm
146   FG_LBARV,     //normalized vertical tail arm
147   FG_HTAILAREA,
148   FG_VTAILAREA,
149   FG_VBARH,    //horizontal tail volume 
150   FG_VBARV,     //vertical tail volume 
151   FG_GEAR_CMD,
152   FG_GEAR_POS
153 };
154
155 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
158
159 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 CLASS DOCUMENTATION
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
162
163 /** JSBSim Base class.
164     @author Jon S. Berndt
165     @version $Id$
166 */
167
168 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 CLASS DECLARATION
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
171
172 class FGJSBBase {
173 public:
174   /// Constructor for FGJSBBase.
175   FGJSBBase();
176
177   /// Destructor for FGJSBBase.
178   virtual ~FGJSBBase() {};
179
180   /// JSBSim Message structure
181   typedef struct Msg {
182     unsigned int fdmId;
183     unsigned int messageId;
184     string text;
185     string subsystem;
186     enum mType {eText, eInteger, eDouble, eBool} type;
187     bool bVal;
188     int  iVal;
189     double dVal;
190   } Message;
191
192   ///@name JSBSim Enums.
193   //@{
194   /// Moments L, M, N
195   enum {eL     = 1, eM,     eN    };
196   /// Rates P, Q, R
197   enum {eP     = 1, eQ,     eR    };
198   /// Velocities U, V, W
199   enum {eU     = 1, eV,     eW    };
200   /// Positions X, Y, Z
201   enum {eX     = 1, eY,     eZ    };
202   /// Euler angles Phi, Theta, Psi
203   enum {ePhi   = 1, eTht,   ePsi  };
204   /// Stability axis forces, Drag, Side force, Lift
205   enum {eDrag  = 1, eSide,  eLift };
206   /// Local frame orientation Roll, Pitch, Yaw
207   enum {eRoll  = 1, ePitch, eYaw  };
208   /// Local frame position North, East, Down
209   enum {eNorth = 1, eEast,  eDown };
210   //@}
211   
212   ///@name JSBSim console output highlighting terms.
213   //@{
214   /// highlights text
215   static char highint[5];
216   /// low intensity text
217   static char halfint[5];
218   /// normal intensity text
219   static char normint[6];
220   /// resets text properties
221   static char reset[5];
222   /// underlines text
223   static char underon[5];
224   /// underline off
225   static char underoff[6];
226   /// blue text
227   static char fgblue[6];
228   /// cyan text
229   static char fgcyan[6];
230   /// red text
231   static char fgred[6];
232   /// green text
233   static char fggreen[6];
234   /// default text
235   static char fgdef[6];
236   //@}
237
238   ///@name JSBSim Messaging functions
239   //@{
240   /** Places a Message structure on the Message queue.
241       @param msg pointer to a Message structure
242       @return pointer to a Message structure */
243   Message* PutMessage(Message* msg);
244   /** Creates a message with the given text and places it on the queue.
245       @param text message text
246       @return pointer to a Message structure */
247   Message* PutMessage(string text);
248   /** Creates a message with the given text and boolean value and places it on the queue.
249       @param text message text
250       @param bVal boolean value associated with the message
251       @return pointer to a Message structure */
252   Message* PutMessage(string text, bool bVal);
253   /** Creates a message with the given text and integer value and places it on the queue.
254       @param text message text
255       @param iVal integer value associated with the message
256       @return pointer to a Message structure */
257   Message* PutMessage(string text, int iVal);
258   /** Creates a message with the given text and double value and places it on the queue.
259       @param text message text
260       @param dVal double value associated with the message
261       @return pointer to a Message structure */
262   Message* PutMessage(string text, double dVal);
263   /** Reads the message on the queue (but does not delete it).
264       @return pointer to a Message structure (or NULL if no mesage) */
265   Message* ReadMessage(void);
266   /** Reads the message on the queue and removes it from the queue.
267       @return pointer to a Message structure (or NULL if no mesage) */
268   Message* ProcessMessage(void);
269   //@}
270   string GetVersion(void) {return JSBSim_version;}
271
272 protected:
273   static Message localMsg;
274   
275   static queue <Message*> Messages;
276
277   virtual void Debug(int from) {};
278
279   static short debug_lvl;
280   static unsigned int frame;
281   static unsigned int messageId;
282   
283   static const double radtodeg;
284   static const double degtorad;
285   static const double hptoftlbssec;
286   static const double fpstokts;
287   static const double ktstofps;
288   static const double inchtoft;
289   static const double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
290   static const double SHRatio;
291   static const string needed_cfg_version;
292   static const string JSBSim_version;
293 };
294
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 #endif
297