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;
76 // Adding it here will cause a namespace clash in FlightGear -EMH-
77 // using namespace JSBSim;
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83 /** FGFS / JSBSim interface (aka "The Bus").
84 This class provides for an interface between FlightGear and its data
85 structures and JSBSim and its data structures. This is the class which is
86 used to command JSBSim when integrated with FlightGear. See the
87 documentation for main for direction on running JSBSim apart from FlightGear.
88 @author Curtis L. Olson (original)
89 @author Tony Peden (Maintained and refined)
90 @version $Id: JSBSim.hxx,v 1.15 2010/10/07 03:45:40 jberndt Exp $
91 @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98 class FGJSBsim: public FGInterface {
102 FGJSBsim( double dt );
106 /// copy FDM state to LaRCsim structures
107 bool copy_to_JSBsim();
109 /// copy FDM state from LaRCsim structures
110 bool copy_from_JSBsim();
112 /// Reset flight params to a specific position
115 /// Unbind properties
118 /// Suspend integration
121 /// Resume integration
124 /// @name Position Parameter Set
126 /** Set geocentric latitude
127 @param lat latitude in radians measured from the 0 meridian where
128 the westerly direction is positive and east is negative */
129 void set_Latitude(double lat); // geocentric
132 @param lon longitude in radians measured from the equator where
133 the northerly direction is positive and south is negative */
134 void set_Longitude(double lon);
137 Note: this triggers a recalculation of AGL altitude
138 @param alt altitude in feet */
139 void set_Altitude(double alt); // triggers re-calc of AGL altitude
142 //void set_AltitudeAGL(double altagl); // and vice-versa
144 /// @name Velocity Parameter Set
146 /** Sets calibrated airspeed
147 Setting this will trigger a recalc of the other velocity terms.
148 @param vc Calibrated airspeed in ft/sec */
149 void set_V_calibrated_kts(double vc);
151 /** Sets Mach number.
152 Setting this will trigger a recalc of the other velocity terms.
153 @param mach Mach number */
154 void set_Mach_number(double mach);
156 /** Sets velocity in N-E-D coordinates.
157 Setting this will trigger a recalc of the other velocity terms.
158 @param north velocity northward in ft/sec
159 @param east velocity eastward in ft/sec
160 @param down velocity downward in ft/sec */
161 void set_Velocities_Local( double north, double east, double down );
163 /** Sets aircraft velocity in stability frame.
164 Setting this will trigger a recalc of the other velocity terms.
165 @param u X velocity in ft/sec
166 @param v Y velocity in ft/sec
167 @param w Z velocity in ft/sec */
168 void set_Velocities_Wind_Body( double u, double v, double w);
171 /** Euler Angle Parameter Set
172 @param phi roll angle in radians
173 @param theta pitch angle in radians
174 @param psi heading angle in radians */
175 void set_Euler_Angles( double phi, double theta, double psi );
177 /// @name Flight Path Parameter Set
179 /** Sets rate of climb
180 @param roc Rate of climb in ft/sec */
181 void set_Climb_Rate( double roc);
183 /** Sets the flight path angle in radians
184 @param gamma flight path angle in radians. */
185 void set_Gamma_vert_rad( double gamma);
189 /// @name Atmospheric Parameter Set
191 /** Sets the atmospheric static pressure
192 @param p pressure in psf */
193 // void set_Static_pressure(double p);
195 /** Sets the atmospheric temperature
196 @param T temperature in degrees rankine */
197 // void set_Static_temperature(double T);
199 /** Sets the atmospheric density.
200 @param rho air density slugs/cubic foot */
201 // void set_Density(double rho);
203 /** Sets the velocity of the local airmass for wind modeling.
204 @param wnorth velocity north in fps
205 @param weast velocity east in fps
206 @param wdown velocity down in fps*/
207 /// @name Position Parameter Update
211 /** Update the position based on inputs, positions, velocities, etc.
212 @param dt delta time in seconds. */
213 void update(double dt);
215 bool ToggleDataLogging(bool state);
216 bool ToggleDataLogging(void);
218 bool get_agl_ft(double t, const double pt[3], double alt_off,
219 double contact[3], double normal[3], double vel[3],
220 double angularVel[3], double *agl);
222 JSBSim::FGFDMExec *fdmex;
223 JSBSim::FGInitialCondition *fgic;
226 JSBSim::FGAtmosphere* Atmosphere;
227 JSBSim::FGWinds* Winds;
229 JSBSim::FGPropulsion* Propulsion;
230 JSBSim::FGMassBalance* MassBalance;
231 JSBSim::FGAircraft* Aircraft;
232 JSBSim::FGPropagate* Propagate;
233 JSBSim::FGAuxiliary* Auxiliary;
234 JSBSim::FGAerodynamics* Aerodynamics;
235 JSBSim::FGGroundReactions* GroundReactions;
236 JSBSim::FGInertial* Inertial;
237 JSBSim::FGAccelerations* Accelerations;
241 double trim_throttle;
243 SGPropertyNode_ptr startup_trim;
244 SGPropertyNode_ptr trimmed;
245 SGPropertyNode_ptr pitch_trim;
246 SGPropertyNode_ptr throttle_trim;
247 SGPropertyNode_ptr aileron_trim;
248 SGPropertyNode_ptr rudder_trim;
249 SGPropertyNode_ptr stall_warning;
251 /* SGPropertyNode_ptr elevator_pos_deg;
252 SGPropertyNode_ptr left_aileron_pos_deg;
253 SGPropertyNode_ptr right_aileron_pos_deg;
254 SGPropertyNode_ptr rudder_pos_deg;
255 SGPropertyNode_ptr flap_pos_deg; */
258 SGPropertyNode_ptr elevator_pos_pct;
259 SGPropertyNode_ptr left_aileron_pos_pct;
260 SGPropertyNode_ptr right_aileron_pos_pct;
261 SGPropertyNode_ptr rudder_pos_pct;
262 SGPropertyNode_ptr flap_pos_pct;
263 SGPropertyNode_ptr speedbrake_pos_pct;
264 SGPropertyNode_ptr spoilers_pos_pct;
266 SGPropertyNode_ptr ab_brake_engaged;
267 SGPropertyNode_ptr ab_brake_left_pct;
268 SGPropertyNode_ptr ab_brake_right_pct;
270 SGPropertyNode_ptr gear_pos_pct;
271 SGPropertyNode_ptr wing_fold_pos_pct;
272 SGPropertyNode_ptr tailhook_pos_pct;
274 SGConstPropertyNode_ptr altitude;
275 SGPropertyNode_ptr temperature;
276 SGPropertyNode_ptr pressure;
277 SGPropertyNode_ptr pressureSL;
278 SGPropertyNode_ptr ground_wind;
279 SGPropertyNode_ptr turbulence_gain;
280 SGPropertyNode_ptr turbulence_rate;
281 SGPropertyNode_ptr turbulence_model;
283 SGPropertyNode_ptr wind_from_north;
284 SGPropertyNode_ptr wind_from_east;
285 SGPropertyNode_ptr wind_from_down;
287 SGPropertyNode_ptr slaved;
289 static std::map<std::string,int> TURBULENCE_TYPE_NAMES;
291 double last_hook_tip[3];
292 double last_hook_root[3];
293 JSBSim::FGColumnVector3 hook_root_struct;
301 bool update_ground_cache(JSBSim::FGLocation cart, double* cart_pos, double dt);
302 void init_gear(void);
303 void update_gear(void);
305 void update_external_forces(double t_off);
309 #endif // _JSBSIM_HXX