1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Author: Curtis L. Olson
5 Maintained by: Tony Peden, Curt Olson
6 Date started: 02/01/1999
8 ------ Copyright (C) 1999 - 2000 Curtis L. Olson (curt@flightgear.org) ------
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.
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.
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.
25 --------------------------------------------------------------------------------
26 02/01/1999 CLO Created
27 Additional log messages stored in CVS
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #define ID_JSBSIMXX "$Header JSBSim.hxx,v 1.4 2000/10/22 14:02:16 jsb Exp $"
48 #define METERS_TO_FEET 3.2808398950
49 #define RADTODEG 57.2957795
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 #include <simgear/props/props.hxx>
57 #include <FDM/JSBSim/FGFDMExec.h>
71 class FGInitialCondition;
73 class FGAccelerations;
74 class FGPropertyManager;
77 // Adding it here will cause a namespace clash in FlightGear -EMH-
78 // using namespace JSBSim;
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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)
95 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
99 class FGJSBsim: public FGInterface {
103 FGJSBsim( double dt );
107 /// copy FDM state to LaRCsim structures
108 bool copy_to_JSBsim();
110 /// copy FDM state from LaRCsim structures
111 bool copy_from_JSBsim();
113 /// Reset flight params to a specific position
116 /// Unbind properties
119 /// Suspend integration
122 /// Resume integration
125 /// @name Position Parameter Set
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
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);
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
143 //void set_AltitudeAGL(double altagl); // and vice-versa
145 /// @name Velocity Parameter Set
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);
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);
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 );
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_Wind_Body( double u, double v, double w);
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 );
178 /// @name Flight Path Parameter Set
180 /** Sets rate of climb
181 @param roc Rate of climb in ft/sec */
182 void set_Climb_Rate( double roc);
184 /** Sets the flight path angle in radians
185 @param gamma flight path angle in radians. */
186 void set_Gamma_vert_rad( double gamma);
190 /// @name Atmospheric Parameter Set
192 /** Sets the atmospheric static pressure
193 @param p pressure in psf */
194 // void set_Static_pressure(double p);
196 /** Sets the atmospheric temperature
197 @param T temperature in degrees rankine */
198 // void set_Static_temperature(double T);
200 /** Sets the atmospheric density.
201 @param rho air density slugs/cubic foot */
202 // void set_Density(double rho);
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
212 /** Update the position based on inputs, positions, velocities, etc.
213 @param dt delta time in seconds. */
214 void update(double dt);
216 bool ToggleDataLogging(bool state);
217 bool ToggleDataLogging(void);
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);
223 JSBSim::FGFDMExec *fdmex;
224 JSBSim::FGInitialCondition *fgic;
227 JSBSim::FGAtmosphere* Atmosphere;
228 JSBSim::FGWinds* Winds;
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;
243 double trim_throttle;
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;
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; */
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;
268 SGPropertyNode_ptr ab_brake_engaged;
269 SGPropertyNode_ptr ab_brake_left_pct;
270 SGPropertyNode_ptr ab_brake_right_pct;
272 SGPropertyNode_ptr gear_pos_pct;
273 SGPropertyNode_ptr wing_fold_pos_pct;
274 SGPropertyNode_ptr tailhook_pos_pct;
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;
285 SGPropertyNode_ptr wind_from_north;
286 SGPropertyNode_ptr wind_from_east;
287 SGPropertyNode_ptr wind_from_down;
289 SGPropertyNode_ptr slaved;
291 static std::map<std::string,int> TURBULENCE_TYPE_NAMES;
293 double last_hook_tip[3];
294 double last_hook_root[3];
295 JSBSim::FGColumnVector3 hook_root_struct;
303 bool update_ground_cache(JSBSim::FGLocation cart, double* cart_pos, double dt);
304 void init_gear(void);
305 void update_gear(void);
307 void update_external_forces(double t_off);
311 #endif // _JSBSIM_HXX