]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.hxx
Merge branch 'work4' into next
[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., 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 "math/FGColumnVector3.h"
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 // Adding it here will cause a namespace clash in FlightGear -EMH-
76 // using namespace JSBSim;
77
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 CLASS DOCUMENTATION
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81
82 /** FGFS / JSBSim interface (aka "The Bus").
83     This class provides for an interface between FlightGear and its data
84     structures and JSBSim and its data structures. This is the class which is
85     used to command JSBSim when integrated with FlightGear. See the
86     documentation for main for direction on running JSBSim apart from FlightGear.
87     @author Curtis L. Olson (original)
88     @author Tony Peden (Maintained and refined)
89     @version $Id: JSBSim.hxx,v 1.13 2010/07/07 20:46:36 andgi Exp $
90     @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
91 */
92
93 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 CLASS DECLARATION
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96
97 class FGJSBsim: public FGInterface {
98
99 public:
100     /// Constructor
101     FGJSBsim( double dt );
102     /// Destructor
103     ~FGJSBsim();
104
105     /// copy FDM state to LaRCsim structures
106     bool copy_to_JSBsim();
107
108     /// copy FDM state from LaRCsim structures
109     bool copy_from_JSBsim();
110
111     /// Reset flight params to a specific position
112     void init();
113
114     /// @name Position Parameter Set
115     //@{
116     /** Set geocentric latitude
117         @param lat latitude in radians measured from the 0 meridian where
118                    the westerly direction is positive and east is negative */
119     void set_Latitude(double lat);  // geocentric
120
121     /** Set longitude
122         @param lon longitude in radians measured from the equator where
123                    the northerly direction is positive and south is negative */
124     void set_Longitude(double lon);
125
126     /** Set altitude
127         Note: this triggers a recalculation of AGL altitude
128         @param alt altitude in feet */
129     void set_Altitude(double alt);        // triggers re-calc of AGL altitude
130     //@}
131
132     //void set_AltitudeAGL(double altagl); // and vice-versa
133
134     /// @name Velocity Parameter Set
135     //@{
136     /** Sets calibrated airspeed
137         Setting this will trigger a recalc of the other velocity terms.
138         @param vc Calibrated airspeed in ft/sec */
139     void set_V_calibrated_kts(double vc);
140
141     /** Sets Mach number.
142         Setting this will trigger a recalc of the other velocity terms.
143         @param mach Mach number */
144     void set_Mach_number(double mach);
145
146     /** Sets velocity in N-E-D coordinates.
147         Setting this will trigger a recalc of the other velocity terms.
148         @param north velocity northward in ft/sec
149         @param east velocity eastward in ft/sec
150         @param down velocity downward in ft/sec */
151     void set_Velocities_Local( double north, double east, double down );
152
153     /** Sets aircraft velocity in stability frame.
154         Setting this will trigger a recalc of the other velocity terms.
155         @param u X velocity in ft/sec
156         @param v Y velocity  in ft/sec
157         @param w Z velocity in ft/sec */
158     void set_Velocities_Wind_Body( double u, double v, double w);
159     //@}
160
161     /** Euler Angle Parameter Set
162         @param phi roll angle in radians
163         @param theta pitch angle in radians
164         @param psi heading angle in radians */
165     void set_Euler_Angles( double phi, double theta, double psi );
166
167     /// @name Flight Path Parameter Set
168     //@{
169     /** Sets rate of climb
170         @param roc Rate of climb in ft/sec */
171     void set_Climb_Rate( double roc);
172
173     /** Sets the flight path angle in radians
174         @param gamma flight path angle in radians. */
175     void set_Gamma_vert_rad( double gamma);
176     //@}
177
178
179     /// @name Atmospheric Parameter Set
180     //@{
181     /** Sets the atmospheric static pressure
182         @param p pressure in psf */
183 //     void set_Static_pressure(double p);
184
185     /** Sets the atmospheric temperature
186         @param T temperature in degrees rankine */
187 //     void set_Static_temperature(double T);
188
189     /** Sets the atmospheric density.
190         @param rho air density slugs/cubic foot */
191 //     void set_Density(double rho);
192
193     /** Sets the velocity of the local airmass for wind modeling.
194         @param wnorth velocity north in fps
195         @param weast velocity east in fps
196         @param wdown velocity down in fps*/
197     /// @name Position Parameter Update
198     //@{
199
200
201     /** Update the position based on inputs, positions, velocities, etc.
202         @param dt delta time in seconds. */
203     void update(double dt);
204     bool ToggleDataLogging(bool state);
205     bool ToggleDataLogging(void);
206     void do_trim(void);
207     void update_ic(void);
208
209     bool get_agl_ft(double t, const double pt[3], double alt_off,
210                     double contact[3], double normal[3], double vel[3],
211                     double *agl);
212 private:
213     JSBSim::FGFDMExec *fdmex;
214     JSBSim::FGInitialCondition *fgic;
215     bool needTrim;
216
217     JSBSim::FGState*        State;
218     JSBSim::FGAtmosphere*   Atmosphere;
219     JSBSim::FGFCS*          FCS;
220     JSBSim::FGPropulsion*   Propulsion;
221     JSBSim::FGMassBalance*  MassBalance;
222     JSBSim::FGAircraft*     Aircraft;
223     JSBSim::FGPropagate*    Propagate;
224     JSBSim::FGAuxiliary*    Auxiliary;
225     JSBSim::FGAerodynamics* Aerodynamics;
226     JSBSim::FGGroundReactions* GroundReactions;
227     JSBSim::FGInertial*     Inertial;
228
229     int runcount;
230     double trim_elev;
231     double trim_throttle;
232
233     SGPropertyNode_ptr startup_trim;
234     SGPropertyNode_ptr trimmed;
235     SGPropertyNode_ptr pitch_trim;
236     SGPropertyNode_ptr throttle_trim;
237     SGPropertyNode_ptr aileron_trim;
238     SGPropertyNode_ptr rudder_trim;
239     SGPropertyNode_ptr stall_warning;
240
241     /* SGPropertyNode_ptr elevator_pos_deg;
242     SGPropertyNode_ptr left_aileron_pos_deg;
243     SGPropertyNode_ptr right_aileron_pos_deg;
244     SGPropertyNode_ptr rudder_pos_deg;
245     SGPropertyNode_ptr flap_pos_deg; */
246
247
248     SGPropertyNode_ptr elevator_pos_pct;
249     SGPropertyNode_ptr left_aileron_pos_pct;
250     SGPropertyNode_ptr right_aileron_pos_pct;
251     SGPropertyNode_ptr rudder_pos_pct;
252     SGPropertyNode_ptr flap_pos_pct;
253     SGPropertyNode_ptr speedbrake_pos_pct;
254     SGPropertyNode_ptr spoilers_pos_pct;
255
256     SGPropertyNode_ptr ab_brake_engaged;
257     SGPropertyNode_ptr ab_brake_left_pct;
258     SGPropertyNode_ptr ab_brake_right_pct;
259     
260     SGPropertyNode_ptr gear_pos_pct;
261     SGPropertyNode_ptr wing_fold_pos_pct;
262     SGPropertyNode_ptr tailhook_pos_pct;
263
264     SGPropertyNode_ptr temperature;
265     SGPropertyNode_ptr pressure;
266     SGPropertyNode_ptr density;
267     SGPropertyNode_ptr turbulence_gain;
268     SGPropertyNode_ptr turbulence_rate;
269
270     SGPropertyNode_ptr wind_from_north;
271     SGPropertyNode_ptr wind_from_east;
272     SGPropertyNode_ptr wind_from_down;
273
274     SGPropertyNode_ptr slaved;
275
276     double last_hook_tip[3];
277     double last_hook_root[3];
278     JSBSim::FGColumnVector3 hook_root_struct;
279     double hook_length;
280     bool got_wire;
281
282     bool crashed;
283
284     void init_gear(void);
285     void update_gear(void);
286
287     void update_external_forces(double t_off);
288
289 };
290
291
292 #endif // _JSBSIM_HXX
293
294