]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.hxx
considering u,v,wbody-fps are the ECEF velocity expressed in body axis, change in...
[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 Lesser 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  Lesser General Public License for more details.
19
20  You should have received a copy of the GNU Lesser General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, 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
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 DEFINITIONS
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45
46 #define ID_JSBSIMXX "$Header JSBSim.hxx,v 1.4 2000/10/22 14:02:16 jsb Exp $"
47
48 #define METERS_TO_FEET 3.2808398950
49 #define RADTODEG 57.2957795
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 #include <simgear/props/props.hxx>
56
57 #include <FDM/JSBSim/FGFDMExec.h>
58
59 namespace JSBSim {
60 class FGAtmosphere;
61 class FGWinds;
62 class FGFCS;
63 class FGPropulsion;
64 class FGMassBalance;
65 class FGAerodynamics;
66 class FGInertial;
67 class FGAircraft;
68 class FGPropagate;
69 class FGAuxiliary;
70 class FGOutput;
71 class FGInitialCondition;
72 class FGLocation;
73 class FGAccelerations;
74 class FGPropertyManager;
75 }
76
77 // Adding it here will cause a namespace clash in FlightGear -EMH-
78 // using namespace JSBSim;
79
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 CLASS DOCUMENTATION
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83
84 /** FGFS / JSBSim interface (aka "The Bus").
85     This class provides for an interface between FlightGear and its data
86     structures and JSBSim and its data structures. This is the class which is
87     used to command JSBSim when integrated with FlightGear. See the
88     documentation for main for direction on running JSBSim apart from FlightGear.
89     @author Curtis L. Olson (original)
90     @author Tony Peden (Maintained and refined)
91     @version $Id: JSBSim.hxx,v 1.15 2010/10/07 03:45:40 jberndt Exp $
92     @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
93 */
94
95 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 CLASS DECLARATION
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98
99 class FGJSBsim: public FGInterface {
100
101 public:
102     /// Constructor
103     FGJSBsim( double dt );
104     /// Destructor
105     ~FGJSBsim();
106
107     /// copy FDM state to LaRCsim structures
108     bool copy_to_JSBsim();
109
110     /// copy FDM state from LaRCsim structures
111     bool copy_from_JSBsim();
112
113     /// Reset flight params to a specific position
114     void init();
115
116     /// Unbind properties
117     void unbind();
118
119     /// Suspend integration
120     void suspend();
121
122     /// Resume integration
123     void resume();
124
125     /// @name Position Parameter Set
126     //@{
127     /** Set geocentric latitude
128         @param lat latitude in radians measured from the 0 meridian where
129                    the westerly direction is positive and east is negative */
130     void set_Latitude(double lat);  // geocentric
131
132     /** Set longitude
133         @param lon longitude in radians measured from the equator where
134                    the northerly direction is positive and south is negative */
135     void set_Longitude(double lon);
136
137     /** Set altitude
138         Note: this triggers a recalculation of AGL altitude
139         @param alt altitude in feet */
140     void set_Altitude(double alt);        // triggers re-calc of AGL altitude
141     //@}
142
143     //void set_AltitudeAGL(double altagl); // and vice-versa
144
145     /// @name Velocity Parameter Set
146     //@{
147     /** Sets calibrated airspeed
148         Setting this will trigger a recalc of the other velocity terms.
149         @param vc Calibrated airspeed in ft/sec */
150     void set_V_calibrated_kts(double vc);
151
152     /** Sets Mach number.
153         Setting this will trigger a recalc of the other velocity terms.
154         @param mach Mach number */
155     void set_Mach_number(double mach);
156
157     /** Sets velocity in N-E-D coordinates.
158         Setting this will trigger a recalc of the other velocity terms.
159         @param north velocity northward in ft/sec
160         @param east velocity eastward in ft/sec
161         @param down velocity downward in ft/sec */
162     void set_Velocities_Local( double north, double east, double down );
163
164     /** Sets aircraft velocity in stability frame.
165         Setting this will trigger a recalc of the other velocity terms.
166         @param u X velocity in ft/sec
167         @param v Y velocity  in ft/sec
168         @param w Z velocity in ft/sec */
169     void set_Velocities_Body( double u, double v, double w);
170     //@}
171
172     /** Euler Angle Parameter Set
173         @param phi roll angle in radians
174         @param theta pitch angle in radians
175         @param psi heading angle in radians */
176     void set_Euler_Angles( double phi, double theta, double psi );
177
178     /// @name Flight Path Parameter Set
179     //@{
180     /** Sets rate of climb
181         @param roc Rate of climb in ft/sec */
182     void set_Climb_Rate( double roc);
183
184     /** Sets the flight path angle in radians
185         @param gamma flight path angle in radians. */
186     void set_Gamma_vert_rad( double gamma);
187     //@}
188
189
190     /// @name Atmospheric Parameter Set
191     //@{
192     /** Sets the atmospheric static pressure
193         @param p pressure in psf */
194 //     void set_Static_pressure(double p);
195
196     /** Sets the atmospheric temperature
197         @param T temperature in degrees rankine */
198 //     void set_Static_temperature(double T);
199
200     /** Sets the atmospheric density.
201         @param rho air density slugs/cubic foot */
202 //     void set_Density(double rho);
203
204     /** Sets the velocity of the local airmass for wind modeling.
205         @param wnorth velocity north in fps
206         @param weast velocity east in fps
207         @param wdown velocity down in fps*/
208     /// @name Position Parameter Update
209     //@{
210
211
212     /** Update the position based on inputs, positions, velocities, etc.
213         @param dt delta time in seconds. */
214     void update(double dt);
215
216     bool ToggleDataLogging(bool state);
217     bool ToggleDataLogging(void);
218
219     bool get_agl_ft(double t, const double pt[3], double alt_off,
220                     double contact[3], double normal[3], double vel[3],
221                     double angularVel[3], double *agl);
222 private:
223     JSBSim::FGFDMExec *fdmex;
224     JSBSim::FGInitialCondition *fgic;
225     bool needTrim;
226
227     JSBSim::FGAtmosphere*      Atmosphere;
228     JSBSim::FGWinds*           Winds;
229     JSBSim::FGFCS*             FCS;
230     JSBSim::FGPropulsion*      Propulsion;
231     JSBSim::FGMassBalance*     MassBalance;
232     JSBSim::FGAircraft*        Aircraft;
233     JSBSim::FGPropagate*       Propagate;
234     JSBSim::FGAuxiliary*       Auxiliary;
235     JSBSim::FGAerodynamics*    Aerodynamics;
236     JSBSim::FGGroundReactions* GroundReactions;
237     JSBSim::FGInertial*        Inertial;
238     JSBSim::FGAccelerations*   Accelerations;
239     JSBSim::FGPropertyManager* PropertyManager;
240
241     int runcount;
242     double trim_elev;
243     double trim_throttle;
244
245     SGPropertyNode_ptr startup_trim;
246     SGPropertyNode_ptr trimmed;
247     SGPropertyNode_ptr pitch_trim;
248     SGPropertyNode_ptr throttle_trim;
249     SGPropertyNode_ptr aileron_trim;
250     SGPropertyNode_ptr rudder_trim;
251     SGPropertyNode_ptr stall_warning;
252
253     /* SGPropertyNode_ptr elevator_pos_deg;
254     SGPropertyNode_ptr left_aileron_pos_deg;
255     SGPropertyNode_ptr right_aileron_pos_deg;
256     SGPropertyNode_ptr rudder_pos_deg;
257     SGPropertyNode_ptr flap_pos_deg; */
258
259
260     SGPropertyNode_ptr elevator_pos_pct;
261     SGPropertyNode_ptr left_aileron_pos_pct;
262     SGPropertyNode_ptr right_aileron_pos_pct;
263     SGPropertyNode_ptr rudder_pos_pct;
264     SGPropertyNode_ptr flap_pos_pct;
265     SGPropertyNode_ptr speedbrake_pos_pct;
266     SGPropertyNode_ptr spoilers_pos_pct;
267
268     SGPropertyNode_ptr ab_brake_engaged;
269     SGPropertyNode_ptr ab_brake_left_pct;
270     SGPropertyNode_ptr ab_brake_right_pct;
271     
272     SGPropertyNode_ptr gear_pos_pct;
273     SGPropertyNode_ptr wing_fold_pos_pct;
274     SGPropertyNode_ptr tailhook_pos_pct;
275
276     SGConstPropertyNode_ptr altitude;
277     SGPropertyNode_ptr temperature;
278     SGPropertyNode_ptr pressure;
279     SGPropertyNode_ptr pressureSL;
280     SGPropertyNode_ptr ground_wind;
281     SGPropertyNode_ptr turbulence_gain;
282     SGPropertyNode_ptr turbulence_rate;
283     SGPropertyNode_ptr turbulence_model;
284
285     SGPropertyNode_ptr wind_from_north;
286     SGPropertyNode_ptr wind_from_east;
287     SGPropertyNode_ptr wind_from_down;
288
289     SGPropertyNode_ptr slaved;
290
291     static std::map<std::string,int> TURBULENCE_TYPE_NAMES;
292
293     double last_hook_tip[3];
294     double last_hook_root[3];
295     JSBSim::FGColumnVector3 hook_root_struct;
296     double hook_length;
297     bool got_wire;
298
299     bool crashed;
300
301     void do_trim(void);
302
303     bool update_ground_cache(JSBSim::FGLocation cart, double* cart_pos, double dt);
304     void init_gear(void);
305     void update_gear(void);
306
307     void update_external_forces(double t_off);
308 };
309
310
311 #endif // _JSBSIM_HXX
312
313