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., 675 Mass Ave, Cambridge, MA 02139, USA.
25 --------------------------------------------------------------------------------
26 02/01/1999 CLO Created
27 Additional log messages stored in CVS
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "math/FGColumnVector3.h"
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_JSBSIMXX "$Header JSBSim.hxx,v 1.4 2000/10/22 14:02:16 jsb Exp $"
49 #define METERS_TO_FEET 3.2808398950
50 #define RADTODEG 57.2957795
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 #include <simgear/props/props.hxx>
58 #include <FDM/JSBSim/FGFDMExec.h>
71 class FGInitialCondition;
74 // Adding it here will cause a namespace clash in FlightGear -EMH-
75 // using namespace JSBSim;
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81 /** FGFS / JSBSim interface (aka "The Bus").
82 This class provides for an interface between FlightGear and its data
83 structures and JSBSim and its data structures. This is the class which is
84 used to command JSBSim when integrated with FlightGear. See the
85 documentation for main for direction on running JSBSim apart from FlightGear.
86 @author Curtis L. Olson (original)
87 @author Tony Peden (Maintained and refined)
88 @version $Id: JSBSim.hxx,v 1.15 2010/10/07 03:45:40 jberndt Exp $
89 @see main in file JSBSim.cpp (use main() wrapper for standalone usage)
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 class FGJSBsim: public FGInterface {
100 FGJSBsim( double dt );
104 /// copy FDM state to LaRCsim structures
105 bool copy_to_JSBsim();
107 /// copy FDM state from LaRCsim structures
108 bool copy_from_JSBsim();
110 /// Reset flight params to a specific position
113 /// Unbind properties
116 /// @name Position Parameter Set
118 /** Set geocentric latitude
119 @param lat latitude in radians measured from the 0 meridian where
120 the westerly direction is positive and east is negative */
121 void set_Latitude(double lat); // geocentric
124 @param lon longitude in radians measured from the equator where
125 the northerly direction is positive and south is negative */
126 void set_Longitude(double lon);
129 Note: this triggers a recalculation of AGL altitude
130 @param alt altitude in feet */
131 void set_Altitude(double alt); // triggers re-calc of AGL altitude
134 //void set_AltitudeAGL(double altagl); // and vice-versa
136 /// @name Velocity Parameter Set
138 /** Sets calibrated airspeed
139 Setting this will trigger a recalc of the other velocity terms.
140 @param vc Calibrated airspeed in ft/sec */
141 void set_V_calibrated_kts(double vc);
143 /** Sets Mach number.
144 Setting this will trigger a recalc of the other velocity terms.
145 @param mach Mach number */
146 void set_Mach_number(double mach);
148 /** Sets velocity in N-E-D coordinates.
149 Setting this will trigger a recalc of the other velocity terms.
150 @param north velocity northward in ft/sec
151 @param east velocity eastward in ft/sec
152 @param down velocity downward in ft/sec */
153 void set_Velocities_Local( double north, double east, double down );
155 /** Sets aircraft velocity in stability frame.
156 Setting this will trigger a recalc of the other velocity terms.
157 @param u X velocity in ft/sec
158 @param v Y velocity in ft/sec
159 @param w Z velocity in ft/sec */
160 void set_Velocities_Wind_Body( double u, double v, double w);
163 /** Euler Angle Parameter Set
164 @param phi roll angle in radians
165 @param theta pitch angle in radians
166 @param psi heading angle in radians */
167 void set_Euler_Angles( double phi, double theta, double psi );
169 /// @name Flight Path Parameter Set
171 /** Sets rate of climb
172 @param roc Rate of climb in ft/sec */
173 void set_Climb_Rate( double roc);
175 /** Sets the flight path angle in radians
176 @param gamma flight path angle in radians. */
177 void set_Gamma_vert_rad( double gamma);
181 /// @name Atmospheric Parameter Set
183 /** Sets the atmospheric static pressure
184 @param p pressure in psf */
185 // void set_Static_pressure(double p);
187 /** Sets the atmospheric temperature
188 @param T temperature in degrees rankine */
189 // void set_Static_temperature(double T);
191 /** Sets the atmospheric density.
192 @param rho air density slugs/cubic foot */
193 // void set_Density(double rho);
195 /** Sets the velocity of the local airmass for wind modeling.
196 @param wnorth velocity north in fps
197 @param weast velocity east in fps
198 @param wdown velocity down in fps*/
199 /// @name Position Parameter Update
203 /** Update the position based on inputs, positions, velocities, etc.
204 @param dt delta time in seconds. */
205 void update(double dt);
206 bool ToggleDataLogging(bool state);
207 bool ToggleDataLogging(void);
209 void update_ic(void);
211 bool get_agl_ft(double t, const double pt[3], double alt_off,
212 double contact[3], double normal[3], double vel[3],
213 double angularVel[3], double *agl);
215 JSBSim::FGFDMExec *fdmex;
216 JSBSim::FGInitialCondition *fgic;
219 JSBSim::FGAtmosphere* Atmosphere;
221 JSBSim::FGPropulsion* Propulsion;
222 JSBSim::FGMassBalance* MassBalance;
223 JSBSim::FGAircraft* Aircraft;
224 JSBSim::FGPropagate* Propagate;
225 JSBSim::FGAuxiliary* Auxiliary;
226 JSBSim::FGAerodynamics* Aerodynamics;
227 JSBSim::FGGroundReactions* GroundReactions;
228 JSBSim::FGInertial* Inertial;
232 double trim_throttle;
234 SGPropertyNode_ptr startup_trim;
235 SGPropertyNode_ptr trimmed;
236 SGPropertyNode_ptr pitch_trim;
237 SGPropertyNode_ptr throttle_trim;
238 SGPropertyNode_ptr aileron_trim;
239 SGPropertyNode_ptr rudder_trim;
240 SGPropertyNode_ptr stall_warning;
242 /* SGPropertyNode_ptr elevator_pos_deg;
243 SGPropertyNode_ptr left_aileron_pos_deg;
244 SGPropertyNode_ptr right_aileron_pos_deg;
245 SGPropertyNode_ptr rudder_pos_deg;
246 SGPropertyNode_ptr flap_pos_deg; */
249 SGPropertyNode_ptr elevator_pos_pct;
250 SGPropertyNode_ptr left_aileron_pos_pct;
251 SGPropertyNode_ptr right_aileron_pos_pct;
252 SGPropertyNode_ptr rudder_pos_pct;
253 SGPropertyNode_ptr flap_pos_pct;
254 SGPropertyNode_ptr speedbrake_pos_pct;
255 SGPropertyNode_ptr spoilers_pos_pct;
257 SGPropertyNode_ptr ab_brake_engaged;
258 SGPropertyNode_ptr ab_brake_left_pct;
259 SGPropertyNode_ptr ab_brake_right_pct;
261 SGPropertyNode_ptr gear_pos_pct;
262 SGPropertyNode_ptr wing_fold_pos_pct;
263 SGPropertyNode_ptr tailhook_pos_pct;
265 SGPropertyNode_ptr temperature;
266 SGPropertyNode_ptr pressure;
267 SGPropertyNode_ptr density;
268 SGPropertyNode_ptr turbulence_gain;
269 SGPropertyNode_ptr turbulence_rate;
271 SGPropertyNode_ptr wind_from_north;
272 SGPropertyNode_ptr wind_from_east;
273 SGPropertyNode_ptr wind_from_down;
275 SGPropertyNode_ptr slaved;
277 double last_hook_tip[3];
278 double last_hook_root[3];
279 JSBSim::FGColumnVector3 hook_root_struct;
285 void init_gear(void);
286 void update_gear(void);
288 void update_external_forces(double t_off);
292 #endif // _JSBSIM_HXX