]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.hxx
Mathias Fröhlich:
[flightgear.git] / src / FDM / JSBSim / JSBSim.hxx
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:        JSBSim.hxx
4  Author:        Curtis L. Olson
5  Maintained by: Tony Peden, Curt Olson
6  Date started:  02/01/1999
7
8 ------ Copyright (C) 1999 - 2000  Curtis L. Olson (curt@flightgear.org) ------
9
10  This program is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 HISTORY
25 --------------------------------------------------------------------------------
26 02/01/1999   CLO   Created
27 Additional log messages stored in CVS
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33 #ifndef _JSBSIM_HXX
34 #define _JSBSIM_HXX
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #undef MAX_ENGINES
41 #include <Aircraft/aircraft.hxx>
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_JSBSIMXX "$Header JSBSim.hxx,v 1.4 2000/10/22 14:02:16 jsb Exp $"
48
49 #define METERS_TO_FEET 3.2808398950
50 #define RADTODEG 57.2957795
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FORWARD DECLARATIONS
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 #include <simgear/props/props.hxx>
57
58 #include <FDM/JSBSim/FGFDMExec.h>
59
60 namespace JSBSim {
61 class FGState;
62 class FGAtmosphere;
63 class FGFCS;
64 class FGPropulsion;
65 class FGMassBalance;
66 class FGAerodynamics;
67 class FGInertial;
68 class FGAircraft;
69 class FGPropagate;
70 class FGAuxiliary;
71 class FGOutput;
72 class FGInitialCondition;
73 }
74
75 using namespace JSBSim;
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 CLASS DOCUMENTATION
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80
81 /** FGFS / JSBSim interface (aka "The Bus").
82     This class provides for an interface between FlightGear and its data
83     structures and JSBSim and its data structures. This is the class which is
84     used to command JSBSim when integrated with FlightGear. See the
85     documentation for main for direction on running JSBSim apart from FlightGear.
86     @author Curtis L. Olson (original)
87     @author Tony Peden (Maintained and refined)
88     @version $Id$
89     @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
90 */
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 CLASS DECLARATION
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 class FGJSBsim: public FGInterface {
97
98 public:
99     /// Constructor
100     FGJSBsim( double dt );
101     /// Destructor
102     ~FGJSBsim();
103
104     /// copy FDM state to LaRCsim structures
105     bool copy_to_JSBsim();
106
107     /// copy FDM state from LaRCsim structures
108     bool copy_from_JSBsim();
109
110     /// Reset flight params to a specific position
111     void init();
112
113     /// @name Position Parameter Set
114     //@{
115     /** Set geocentric latitude
116         @param lat latitude in radians measured from the 0 meridian where
117                    the westerly direction is positive and east is negative */
118     void set_Latitude(double lat);  // geocentric
119
120     /** Set longitude
121         @param lon longitude in radians measured from the equator where
122                    the northerly direction is positive and south is negative */
123     void set_Longitude(double lon);
124
125     /** Set altitude
126         Note: this triggers a recalculation of AGL altitude
127         @param alt altitude in feet */
128     void set_Altitude(double alt);        // triggers re-calc of AGL altitude
129     //@}
130
131     //void set_AltitudeAGL(double altagl); // and vice-versa
132
133     /// @name Velocity Parameter Set
134     //@{
135     /** Sets calibrated airspeed
136         Setting this will trigger a recalc of the other velocity terms.
137         @param vc Calibrated airspeed in ft/sec */
138     void set_V_calibrated_kts(double vc);
139
140     /** Sets Mach number.
141         Setting this will trigger a recalc of the other velocity terms.
142         @param mach Mach number */
143     void set_Mach_number(double mach);
144
145     /** Sets velocity in N-E-D coordinates.
146         Setting this will trigger a recalc of the other velocity terms.
147         @param north velocity northward in ft/sec
148         @param east velocity eastward in ft/sec
149         @param down velocity downward in ft/sec */
150     void set_Velocities_Local( double north, double east, double down );
151
152     /** Sets aircraft velocity in stability frame.
153         Setting this will trigger a recalc of the other velocity terms.
154         @param u X velocity in ft/sec
155         @param v Y velocity  in ft/sec
156         @param w Z velocity in ft/sec */
157     void set_Velocities_Wind_Body( double u, double v, double w);
158     //@}
159
160     /** Euler Angle Parameter Set
161         @param phi roll angle in radians
162         @param theta pitch angle in radians
163         @param psi heading angle in radians */
164     void set_Euler_Angles( double phi, double theta, double psi );
165
166     /// @name Flight Path Parameter Set
167     //@{
168     /** Sets rate of climb
169         @param roc Rate of climb in ft/sec */
170     void set_Climb_Rate( double roc);
171
172     /** Sets the flight path angle in radians
173         @param gamma flight path angle in radians. */
174     void set_Gamma_vert_rad( double gamma);
175     //@}
176
177
178     /// @name Atmospheric Parameter Set
179     //@{
180     /** Sets the atmospheric static pressure
181         @param p pressure in psf */
182 //     void set_Static_pressure(double p);
183
184     /** Sets the atmospheric temperature
185         @param T temperature in degrees rankine */
186 //     void set_Static_temperature(double T);
187
188     /** Sets the atmospheric density.
189         @param rho air density slugs/cubic foot */
190 //     void set_Density(double rho);
191
192     /** Sets the velocity of the local airmass for wind modeling.
193         @param wnorth velocity north in fps
194         @param weast velocity east in fps
195         @param wdown velocity down in fps*/
196     /// @name Position Parameter Update
197     //@{
198
199
200     /** Update the position based on inputs, positions, velocities, etc.
201         @param dt delta time in seconds. */
202     void update(double dt);
203     bool ToggleDataLogging(bool state);
204     bool ToggleDataLogging(void);
205     void do_trim(void);
206     void update_ic(void);
207
208 private:
209     FGFDMExec *fdmex;
210     FGInitialCondition *fgic;
211     bool needTrim;
212
213     FGState*        State;
214     FGAtmosphere*   Atmosphere;
215     FGFCS*          FCS;
216     FGPropulsion*   Propulsion;
217     FGMassBalance*  MassBalance;
218     FGAircraft*     Aircraft;
219     FGPropagate*    Propagate;
220     FGAuxiliary*    Auxiliary;
221     FGAerodynamics* Aerodynamics;
222     FGGroundReactions *GroundReactions;
223
224     int runcount;
225     double trim_elev;
226     double trim_throttle;
227
228     SGPropertyNode *startup_trim;
229     SGPropertyNode *trimmed;
230     SGPropertyNode *pitch_trim;
231     SGPropertyNode *throttle_trim;
232     SGPropertyNode *aileron_trim;
233     SGPropertyNode *rudder_trim;
234     SGPropertyNode *stall_warning;
235
236     /* SGPropertyNode *elevator_pos_deg;
237     SGPropertyNode *left_aileron_pos_deg;
238     SGPropertyNode *right_aileron_pos_deg;
239     SGPropertyNode *rudder_pos_deg;
240     SGPropertyNode *flap_pos_deg; */
241
242
243     SGPropertyNode *elevator_pos_pct;
244     SGPropertyNode *left_aileron_pos_pct;
245     SGPropertyNode *right_aileron_pos_pct;
246     SGPropertyNode *rudder_pos_pct;
247     SGPropertyNode *flap_pos_pct;
248     SGPropertyNode *speedbrake_pos_pct;
249     SGPropertyNode *spoilers_pos_pct;
250
251     SGPropertyNode *gear_pos_pct;
252
253     SGPropertyNode *temperature;
254     SGPropertyNode *pressure;
255     SGPropertyNode *density;
256     SGPropertyNode *turbulence_gain;
257     SGPropertyNode *turbulence_rate;
258
259     SGPropertyNode *wind_from_north;
260     SGPropertyNode *wind_from_east;
261     SGPropertyNode *wind_from_down;
262
263     void init_gear(void);
264     void update_gear(void);
265
266 };
267
268
269 #endif // _JSBSIM_HXX
270
271