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 #include "FDM/AIWake/AircraftMesh.hxx"
59 
60 namespace JSBSim {
61 class FGAtmosphere;
62 class FGWinds;
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 class FGLocation;
74 class FGAccelerations;
75 class FGPropertyManager;
76 class FGColumnVector3;
77 }
78 
79 // Adding it here will cause a namespace clash in FlightGear -EMH-
80 // using namespace JSBSim;
81 
82 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 CLASS DOCUMENTATION
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
85 
86 /** FGFS / JSBSim interface (aka "The Bus").
87     This class provides for an interface between FlightGear and its data
88     structures and JSBSim and its data structures. This is the class which is
89     used to command JSBSim when integrated with FlightGear. See the
90     documentation for main for direction on running JSBSim apart from FlightGear.
91     @author Curtis L. Olson (original)
92     @author Tony Peden (Maintained and refined)
93     @version $Id: FlightGear.hxx,v 1.16 2014/01/28 09:42:21 ehofman Exp $
94     @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
95 */
96 
97 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 CLASS DECLARATION
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
100 
101 class FGJSBsim : public FGInterface
102 {
103 public:
104     /// Constructor
105     FGJSBsim( double dt );
106 
107     /// Destructor
108     ~FGJSBsim();
109 
110     // Subsystem API.
111     void init() override;
112     void resume() override;
113     void suspend() override;
114     void unbind() override;
115     void update(double dt) override;
116 
117     // Subsystem identification.
staticSubsystemClassId()118     static const char* staticSubsystemClassId() { return "jsb"; }
119 
120     /// copy FDM state to LaRCsim structures
121     bool copy_to_JSBsim();
122 
123     /// copy FDM state from LaRCsim structures
124     bool copy_from_JSBsim();
125 
126     /// @name Position Parameter Set
127     //@{
128     /** Set geocentric latitude
129         @param lat latitude in radians measured from the 0 meridian where
130                    the westerly direction is positive and east is negative */
131     void set_Latitude(double lat);  // geocentric
132 
133     /** Set longitude
134         @param lon longitude in radians measured from the equator where
135                    the northerly direction is positive and south is negative */
136     void set_Longitude(double lon);
137 
138     /** Set altitude
139         Note: this triggers a recalculation of AGL altitude
140         @param alt altitude in feet */
141     void set_Altitude(double alt);        // triggers re-calc of AGL altitude
142     //@}
143 
144     //void set_AltitudeAGL(double altagl); // and vice-versa
145 
146     /// @name Velocity Parameter Set
147     //@{
148     /** Sets calibrated airspeed
149         Setting this will trigger a recalc of the other velocity terms.
150         @param vc Calibrated airspeed in ft/sec */
151     void set_V_calibrated_kts(double vc);
152 
153     /** Sets Mach number.
154         Setting this will trigger a recalc of the other velocity terms.
155         @param mach Mach number */
156     void set_Mach_number(double mach);
157 
158     /** Sets velocity in N-E-D coordinates.
159         Setting this will trigger a recalc of the other velocity terms.
160         @param north velocity northward in ft/sec
161         @param east velocity eastward in ft/sec
162         @param down velocity downward in ft/sec */
163     void set_Velocities_Local( double north, double east, double down );
164 
165     /** Sets aircraft velocity in stability frame.
166         Setting this will trigger a recalc of the other velocity terms.
167         @param u X velocity in ft/sec
168         @param v Y velocity  in ft/sec
169         @param w Z velocity in ft/sec */
170     void set_Velocities_Body( double u, double v, double w);
171     //@}
172 
173     /** Euler Angle Parameter Set
174         @param phi roll angle in radians
175         @param theta pitch angle in radians
176         @param psi heading angle in radians */
177     void set_Euler_Angles( double phi, double theta, double psi );
178 
179     /// @name Flight Path Parameter Set
180     //@{
181     /** Sets rate of climb
182         @param roc Rate of climb in ft/sec */
183     void set_Climb_Rate( double roc);
184 
185     /** Sets the flight path angle in radians
186         @param gamma flight path angle in radians. */
187     void set_Gamma_vert_rad( double gamma);
188     //@}
189 
190 
191     /// @name Atmospheric Parameter Set
192     //@{
193     /** Sets the atmospheric static pressure
194         @param p pressure in psf */
195 //     void set_Static_pressure(double p);
196 
197     /** Sets the atmospheric temperature
198         @param T temperature in degrees rankine */
199 //     void set_Static_temperature(double T);
200 
201     /** Sets the atmospheric density.
202         @param rho air density slugs/cubic foot */
203 //     void set_Density(double rho);
204 
205     /** Sets the velocity of the local airmass for wind modeling.
206         @param wnorth velocity north in fps
207         @param weast velocity east in fps
208         @param wdown velocity down in fps*/
209     /// @name Position Parameter Update
210     //@{
211 
212     bool ToggleDataLogging(bool state);
213     bool ToggleDataLogging(void);
214 
215     double get_agl_ft(double t, const JSBSim::FGColumnVector3& loc,
216                       double alt_off, double contact[3], double normal[3],
217                       double vel[3], double angularVel[3]);
218 
219 private:
220     JSBSim::FGFDMExec *fdmex;
221     JSBSim::FGInitialCondition *fgic;
222     bool needTrim;
223 
224     JSBSim::FGAtmosphere*      Atmosphere;
225     JSBSim::FGWinds*           Winds;
226     JSBSim::FGFCS*             FCS;
227     JSBSim::FGPropulsion*      Propulsion;
228     JSBSim::FGMassBalance*     MassBalance;
229     JSBSim::FGAircraft*        Aircraft;
230     JSBSim::FGPropagate*       Propagate;
231     JSBSim::FGAuxiliary*       Auxiliary;
232     JSBSim::FGAerodynamics*    Aerodynamics;
233     JSBSim::FGGroundReactions* GroundReactions;
234     JSBSim::FGInertial*        Inertial;
235     JSBSim::FGAccelerations*   Accelerations;
236     JSBSim::FGPropertyManager* PropertyManager;
237 
238     // disabling unused members
239     /*
240     int runcount;
241     double trim_elev;
242     double trim_throttle;
243      */
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 override_fg_brake_prop;
269     SGPropertyNode_ptr ab_brake_engaged;
270     SGPropertyNode_ptr ab_brake_left_pct;
271     SGPropertyNode_ptr ab_brake_right_pct;
272 
273     SGPropertyNode_ptr gear_pos_pct;
274     SGPropertyNode_ptr wing_fold_pos_pct;
275     SGPropertyNode_ptr tailhook_pos_pct;
276 
277     SGConstPropertyNode_ptr altitude;
278     SGPropertyNode_ptr temperature;
279     SGPropertyNode_ptr pressure;
280     SGPropertyNode_ptr pressureSL;
281     SGPropertyNode_ptr dew_point;
282     SGPropertyNode_ptr ground_wind;
283     SGPropertyNode_ptr turbulence_gain;
284     SGPropertyNode_ptr turbulence_rate;
285     SGPropertyNode_ptr turbulence_model;
286 
287     SGPropertyNode_ptr wind_from_north;
288     SGPropertyNode_ptr wind_from_east;
289     SGPropertyNode_ptr wind_from_down;
290 
291     SGPropertyNode_ptr arrestor_wire_engaged_hook;
292     SGPropertyNode_ptr release_hook;
293 
294     SGPropertyNode_ptr slaved;
295 
296     SGPropertyNode_ptr terrain;
297 
298     static std::map<std::string,int> TURBULENCE_TYPE_NAMES;
299 
300     double last_hook_tip[3];
301     double last_hook_root[3];
302     JSBSim::FGColumnVector3 hook_root_struct;
303     double hook_length;
304 
305     bool crashed;
306 
307     AircraftMesh_ptr mesh;
308     SGPropertyNode_ptr _ai_wake_enabled;
309     SGPropertyNode_ptr _fmag{nullptr}, _mmag{nullptr};
310     SGPropertyNode_ptr _fbx{nullptr}, _fby{nullptr}, _fbz{nullptr};
311     SGPropertyNode_ptr _mbx{nullptr}, _mby{nullptr}, _mbz{nullptr};
312 
313     void do_trim(void);
314 
315     bool update_ground_cache(const JSBSim::FGLocation& cart, double dt);
316     void init_gear(void);
317     void update_gear(void);
318 
319     void update_external_forces(double t_off);
320 };
321 
322 #endif // _JSBSIM_HXX
323