]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGPropagate.h
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGPropagate.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGPropagate.h
4  Author:       Jon S. Berndt
5  Date started: 1/5/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 01/05/99   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGPROPAGATE_H
35 #define FGPROPAGATE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "models/FGModel.h"
42 #include "math/FGColumnVector3.h"
43 #include "math/FGLocation.h"
44 #include "math/FGQuaternion.h"
45 #include "math/FGMatrix33.h"
46 #include <deque>
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #define ID_PROPAGATE "$Id: FGPropagate.h,v 1.59 2011/05/20 03:18:36 jberndt Exp $"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 namespace JSBSim {
59
60 using std::deque;
61 class FGInitialCondition;
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /** Models the EOM and integration/propagation of state.
68     The Equations of Motion (EOM) for JSBSim are integrated to propagate the
69     state of the vehicle given the forces and moments that act on it. The
70     integration accounts for a rotating Earth.
71
72     The general execution of this model follows this process:
73
74     -Calculate the angular accelerations
75     -Calculate the translational accelerations
76     -Calculate the angular rate
77     -Calculate the translational velocity
78
79     -Integrate accelerations and rates
80
81     Integration of rotational and translation position and rate can be 
82     customized as needed or frozen by the selection of no integrator. The
83     selection of which integrator to use is done through the setting of 
84     the associated property. There are four properties which can be set:
85     
86     @code
87     simulation/integrator/rate/rotational
88     simulation/integrator/rate/translational
89     simulation/integrator/position/rotational
90     simulation/integrator/position/translational
91     @endcode
92     
93     Each of the integrators listed above can be set to one of the following values:
94
95     @code
96     0: No integrator (Freeze)
97     1: Rectangular Euler
98     2: Trapezoidal
99     3: Adams Bashforth 2
100     4: Adams Bashforth 3
101     5: Adams Bashforth 4
102     @endcode
103
104     @author Jon S. Berndt, Mathias Froehlich
105     @version $Id: FGPropagate.h,v 1.59 2011/05/20 03:18:36 jberndt Exp $
106   */
107
108 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 CLASS DECLARATION
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
111
112 class FGPropagate : public FGModel {
113 public:
114
115   /** The current vehicle state vector structure contains the translational and
116     angular position, and the translational and angular velocity. */
117   struct VehicleState {
118     /** Represents the current location of the vehicle in Earth centered Earth
119         fixed (ECEF) frame.
120         units ft */
121     FGLocation vLocation;
122
123     /** The velocity vector of the vehicle with respect to the ECEF frame,
124         expressed in the body system.
125         units ft/sec */
126     FGColumnVector3 vUVW;
127
128     /** The angular velocity vector for the vehicle relative to the ECEF frame,
129         expressed in the body frame.
130         units rad/sec */
131     FGColumnVector3 vPQR;
132
133     /** The angular velocity vector for the vehicle body frame relative to the
134         ECI frame, expressed in the body frame.
135         units rad/sec */
136     FGColumnVector3 vPQRi;
137
138     /** The current orientation of the vehicle, that is, the orientation of the
139         body frame relative to the local, NED frame. */
140     FGQuaternion qAttitudeLocal;
141
142     /** The current orientation of the vehicle, that is, the orientation of the
143         body frame relative to the inertial (ECI) frame. */
144     FGQuaternion qAttitudeECI;
145
146     FGColumnVector3 vInertialVelocity;
147
148     FGColumnVector3 vInertialPosition;
149
150     deque <FGColumnVector3> dqPQRidot;
151     deque <FGColumnVector3> dqUVWidot;
152     deque <FGColumnVector3> dqInertialVelocity;
153     deque <FGQuaternion>    dqQtrndot;
154   };
155
156   /** Constructor.
157       The constructor initializes several variables, and sets the initial set
158       of integrators to use as follows:
159       - integrator, rotational rate = Adams Bashforth 2
160       - integrator, translational rate = Adams Bashforth 2
161       - integrator, rotational position = Trapezoidal
162       - integrator, translational position = Trapezoidal
163       @param Executive a pointer to the parent executive object */
164   FGPropagate(FGFDMExec* Executive);
165
166   /// Destructor
167   ~FGPropagate();
168   
169   /// These define the indices use to select the various integrators.
170   enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2, eAdamsBashforth3, eAdamsBashforth4};
171
172   /// These define the indices use to select the gravitation models.
173   enum eGravType {gtStandard, gtWGS84}; 
174
175   /** Initializes the FGPropagate class after instantiation and prior to first execution.
176       The base class FGModel::InitModel is called first, initializing pointers to the 
177       other FGModel objects (and others).  */
178   bool InitModel(void);
179
180   /** Runs the state propagation model; called by the Executive
181       Can pass in a value indicating if the executive is directing the simulation to Hold.
182       @param Holding if true, the executive has been directed to hold the sim from 
183                      advancing time. Some models may ignore this flag, such as the Input
184                      model, which may need to be active to listen on a socket for the
185                      "Resume" command to be given.
186       @return false if no error */
187   bool Run(bool Holding);
188
189   const FGQuaternion& GetQuaterniondot(void) const {return vQtrndot;}
190
191   /** Retrieves the velocity vector.
192       The vector returned is represented by an FGColumnVector reference. The vector
193       for the velocity in Local frame is organized (Vnorth, Veast, Vdown). The vector
194       is 1-based, so that the first element can be retrieved using the "()" operator.
195       In other words, vVel(1) is Vnorth. Various convenience enumerators are defined
196       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
197       eNorth=1, eEast=2, eDown=3.
198       units ft/sec
199       @return The vehicle velocity vector with respect to the Earth centered frame,
200               expressed in Local horizontal frame.
201   */
202   const FGColumnVector3& GetVel(void) const { return vVel; }
203   
204   /** Retrieves the body frame vehicle velocity vector.
205       The vector returned is represented by an FGColumnVector reference. The vector
206       for the velocity in Body frame is organized (Vx, Vy, Vz). The vector
207       is 1-based, so that the first element can be retrieved using the "()" operator.
208       In other words, vUVW(1) is Vx. Various convenience enumerators are defined
209       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
210       eX=1, eY=2, eZ=3.
211       units ft/sec
212       @return The body frame vehicle velocity vector in ft/sec.
213   */
214   const FGColumnVector3& GetUVW(void) const { return VState.vUVW; }
215   
216   /** Retrieves the body axis acceleration.
217       Retrieves the computed body axis accelerations based on the
218       applied forces and accounting for a rotating body frame.
219       The vector returned is represented by an FGColumnVector reference. The vector
220       for the acceleration in Body frame is organized (Ax, Ay, Az). The vector
221       is 1-based, so that the first element can be retrieved using the "()" operator.
222       In other words, vUVWdot(1) is Ax. Various convenience enumerators are defined
223       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
224       eX=1, eY=2, eZ=3.
225       units ft/sec^2
226       @return Body axis translational acceleration in ft/sec^2.
227   */
228   const FGColumnVector3& GetUVWdot(void) const { return vUVWdot; }
229   
230   /** Retrieves the body angular rates vector, relative to the ECEF frame.
231       Retrieves the body angular rates (p, q, r), which are calculated by integration
232       of the angular acceleration.
233       The vector returned is represented by an FGColumnVector reference. The vector
234       for the angular velocity in Body frame is organized (P, Q, R). The vector
235       is 1-based, so that the first element can be retrieved using the "()" operator.
236       In other words, vPQR(1) is P. Various convenience enumerators are defined
237       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
238       eP=1, eQ=2, eR=3.
239       units rad/sec
240       @return The body frame angular rates in rad/sec.
241   */
242   const FGColumnVector3& GetPQR(void) const {return VState.vPQR;}
243   
244   /** Retrieves the body angular rates vector, relative to the ECI (inertial) frame.
245       Retrieves the body angular rates (p, q, r), which are calculated by integration
246       of the angular acceleration.
247       The vector returned is represented by an FGColumnVector reference. The vector
248       for the angular velocity in Body frame is organized (P, Q, R). The vector
249       is 1-based, so that the first element can be retrieved using the "()" operator.
250       In other words, vPQR(1) is P. Various convenience enumerators are defined
251       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
252       eP=1, eQ=2, eR=3.
253       units rad/sec
254       @return The body frame inertial angular rates in rad/sec.
255   */
256   const FGColumnVector3& GetPQRi(void) const {return VState.vPQRi;}
257
258   /** Retrieves the body axis angular acceleration vector.
259       Retrieves the body axis angular acceleration vector in rad/sec^2. The
260       angular acceleration vector is determined from the applied forces and
261       accounts for a rotating frame.
262       The vector returned is represented by an FGColumnVector reference. The vector
263       for the angular acceleration in Body frame is organized (Pdot, Qdot, Rdot). The vector
264       is 1-based, so that the first element can be retrieved using the "()" operator.
265       In other words, vPQRdot(1) is Pdot. Various convenience enumerators are defined
266       in FGJSBBase. The relevant enumerators for the vector returned by this call are,
267       eP=1, eQ=2, eR=3.
268       units rad/sec^2
269       @return The angular acceleration vector.
270   */
271   const FGColumnVector3& GetPQRdot(void) const {return vPQRdot;}
272   
273   /** Retrieves the Euler angles that define the vehicle orientation.
274       Extracts the Euler angles from the quaternion that stores the orientation
275       in the Local frame. The order of rotation used is Yaw-Pitch-Roll. The
276       vector returned is represented by an FGColumnVector reference. The vector
277       for the Euler angles is organized (Phi, Theta, Psi). The vector
278       is 1-based, so that the first element can be retrieved using the "()" operator.
279       In other words, the returned vector item with subscript (1) is Phi.
280       Various convenience enumerators are defined in FGJSBBase. The relevant
281       enumerators for the vector returned by this call are, ePhi=1, eTht=2, ePsi=3.
282       units radians
283       @return The Euler angle vector, where the first item in the
284               vector is the angle about the X axis, the second is the
285               angle about the Y axis, and the third item is the angle
286               about the Z axis (Phi, Theta, Psi).
287   */
288   const FGColumnVector3& GetEuler(void) const { return VState.qAttitudeLocal.GetEuler(); }
289
290   /** Retrieves a body frame velocity component.
291       Retrieves a body frame velocity component. The velocity returned is
292       extracted from the vUVW vector (an FGColumnVector). The vector for the
293       velocity in Body frame is organized (Vx, Vy, Vz). The vector is 1-based.
294       In other words, GetUVW(1) returns Vx. Various convenience enumerators
295       are defined in FGJSBBase. The relevant enumerators for the velocity
296       returned by this call are, eX=1, eY=2, eZ=3.
297       units ft/sec
298       @param idx the index of the velocity component desired (1-based).
299       @return The body frame velocity component.
300   */
301   double GetUVW   (int idx) const { return VState.vUVW(idx); }
302
303   /** Retrieves a body frame acceleration component.
304       Retrieves a body frame acceleration component. The acceleration returned
305       is extracted from the vUVWdot vector (an FGColumnVector). The vector for
306       the acceleration in Body frame is organized (Ax, Ay, Az). The vector is
307       1-based. In other words, GetUVWdot(1) returns Ax. Various convenience
308       enumerators are defined in FGJSBBase. The relevant enumerators for the
309       acceleration returned by this call are, eX=1, eY=2, eZ=3.
310       units ft/sec^2
311       @param idx the index of the acceleration component desired (1-based).
312       @return The body frame acceleration component.
313   */
314   double GetUVWdot(int idx) const { return vUVWdot(idx); }
315
316   /** Retrieves a Local frame velocity component.
317       Retrieves a Local frame velocity component. The velocity returned is
318       extracted from the vVel vector (an FGColumnVector). The vector for the
319       velocity in Local frame is organized (Vnorth, Veast, Vdown). The vector
320       is 1-based. In other words, GetVel(1) returns Vnorth. Various convenience
321       enumerators are defined in FGJSBBase. The relevant enumerators for the
322       velocity returned by this call are, eNorth=1, eEast=2, eDown=3.
323       units ft/sec
324       @param idx the index of the velocity component desired (1-based).
325       @return The body frame velocity component.
326   */
327   double GetVel(int idx) const { return vVel(idx); }
328
329   /** Retrieves the total inertial velocity in ft/sec.
330   */
331   double GetInertialVelocityMagnitude(void) const { return VState.vInertialVelocity.Magnitude(); }
332
333   /** Retrieves the inertial velocity vector in ft/sec.
334   */
335   const FGColumnVector3& GetInertialVelocity(void) const { return VState.vInertialVelocity; }
336
337   /** Retrieves the inertial position vector.
338   */
339   const FGColumnVector3& GetInertialPosition(void) const { return VState.vInertialPosition; }
340
341   /** Calculates and retrieves the velocity vector relative to the earth centered earth fixed (ECEF) frame.
342   */
343   const FGColumnVector3 GetECEFVelocity(void) const {return Tb2ec * VState.vUVW; }
344
345   /** Returns the current altitude above sea level.
346       This function returns the altitude above sea level.
347       units ft
348       @return The current altitude above sea level in feet.
349   */
350   double GetAltitudeASL(void)   const { return VState.vLocation.GetRadius() - SeaLevelRadius; }
351
352   /** Returns the current altitude above sea level.
353       This function returns the altitude above sea level.
354       units meters
355       @return The current altitude above sea level in meters.
356   */
357   double GetAltitudeASLmeters(void) const { return GetAltitudeASL()*fttom;}
358
359   /** Retrieves a body frame angular velocity component relative to the ECEF frame.
360       Retrieves a body frame angular velocity component. The angular velocity
361       returned is extracted from the vPQR vector (an FGColumnVector). The vector
362       for the angular velocity in Body frame is organized (P, Q, R). The vector
363       is 1-based. In other words, GetPQR(1) returns P (roll rate). Various
364       convenience enumerators are defined in FGJSBBase. The relevant enumerators
365       for the angular velocity returned by this call are, eP=1, eQ=2, eR=3.
366       units rad/sec
367       @param axis the index of the angular velocity component desired (1-based).
368       @return The body frame angular velocity component.
369   */
370   double GetPQR(int axis) const {return VState.vPQR(axis);}
371
372   /** Retrieves a body frame angular velocity component relative to the ECI (inertial) frame.
373       Retrieves a body frame angular velocity component. The angular velocity
374       returned is extracted from the vPQR vector (an FGColumnVector). The vector
375       for the angular velocity in Body frame is organized (P, Q, R). The vector
376       is 1-based. In other words, GetPQR(1) returns P (roll rate). Various
377       convenience enumerators are defined in FGJSBBase. The relevant enumerators
378       for the angular velocity returned by this call are, eP=1, eQ=2, eR=3.
379       units rad/sec
380       @param axis the index of the angular velocity component desired (1-based).
381       @return The body frame angular velocity component.
382   */
383   double GetPQRi(int axis) const {return VState.vPQRi(axis);}
384
385   /** Retrieves a body frame angular acceleration component.
386       Retrieves a body frame angular acceleration component. The angular
387       acceleration returned is extracted from the vPQRdot vector (an
388       FGColumnVector). The vector for the angular acceleration in Body frame
389       is organized (Pdot, Qdot, Rdot). The vector is 1-based. In other words,
390       GetPQRdot(1) returns Pdot (roll acceleration). Various convenience
391       enumerators are defined in FGJSBBase. The relevant enumerators for the
392       angular acceleration returned by this call are, eP=1, eQ=2, eR=3.
393       units rad/sec^2
394       @param axis the index of the angular acceleration component desired (1-based).
395       @return The body frame angular acceleration component.
396   */
397   double GetPQRdot(int axis) const {return vPQRdot(axis);}
398
399   /** Retrieves a vehicle Euler angle component.
400       Retrieves an Euler angle (Phi, Theta, or Psi) from the quaternion that
401       stores the vehicle orientation relative to the Local frame. The order of
402       rotations used is Yaw-Pitch-Roll. The Euler angle with subscript (1) is
403       Phi. Various convenience enumerators are defined in FGJSBBase. The
404       relevant enumerators for the Euler angle returned by this call are,
405       ePhi=1, eTht=2, ePsi=3 (e.g. GetEuler(eTht) returns Theta).
406       units radians
407       @return An Euler angle.
408   */
409   double GetEuler(int axis) const { return VState.qAttitudeLocal.GetEuler(axis); }
410
411   /** Retrieves the cosine of a vehicle Euler angle component.
412       Retrieves the cosine of an Euler angle (Phi, Theta, or Psi) from the
413       quaternion that stores the vehicle orientation relative to the Local frame.
414       The order of rotations used is Yaw-Pitch-Roll. The Euler angle
415       with subscript (1) is Phi. Various convenience enumerators are defined in
416       FGJSBBase. The relevant enumerators for the Euler angle referred to in this
417       call are, ePhi=1, eTht=2, ePsi=3 (e.g. GetCosEuler(eTht) returns cos(theta)).
418       units none
419       @return The cosine of an Euler angle.
420   */
421   double GetCosEuler(int idx) const { return VState.qAttitudeLocal.GetCosEuler(idx); }
422
423   /** Retrieves the sine of a vehicle Euler angle component.
424       Retrieves the sine of an Euler angle (Phi, Theta, or Psi) from the
425       quaternion that stores the vehicle orientation relative to the Local frame.
426       The order of rotations used is Yaw-Pitch-Roll. The Euler angle
427       with subscript (1) is Phi. Various convenience enumerators are defined in
428       FGJSBBase. The relevant enumerators for the Euler angle referred to in this
429       call are, ePhi=1, eTht=2, ePsi=3 (e.g. GetSinEuler(eTht) returns sin(theta)).
430       units none
431       @return The sine of an Euler angle.
432   */
433   double GetSinEuler(int idx) const { return VState.qAttitudeLocal.GetSinEuler(idx); }
434
435   /** Returns the current altitude rate.
436       Returns the current altitude rate (rate of climb).
437       units ft/sec
438       @return The current rate of change in altitude.
439   */
440   double Gethdot(void) const { return -vVel(eDown); }
441
442   /** Returns the "constant" LocalTerrainRadius.
443       The LocalTerrainRadius parameter is set by the calling application or set to
444       sea level + terrain elevation if JSBSim is running in standalone mode.
445       units feet
446       @return distance of the local terrain from the center of the earth.
447       */
448   double GetLocalTerrainRadius(void) const { return LocalTerrainRadius; }
449
450   double GetSeaLevelRadius(void) const { return SeaLevelRadius; }
451   double GetTerrainElevation(void) const;
452   double GetDistanceAGL(void)  const;
453   double GetRadius(void) const {
454       if (VState.vLocation.GetRadius() == 0) return 1.0;
455       else return VState.vLocation.GetRadius();
456   }
457   double GetLongitude(void) const { return VState.vLocation.GetLongitude(); }
458   double GetLatitude(void) const { return VState.vLocation.GetLatitude(); }
459
460   double GetGeodLatitudeRad(void) const { return VState.vLocation.GetGeodLatitudeRad(); }
461   double GetGeodLatitudeDeg(void) const { return VState.vLocation.GetGeodLatitudeDeg(); }
462
463   double GetGeodeticAltitude(void) const { return VState.vLocation.GetGeodAltitude(); }
464
465   double GetLongitudeDeg(void) const { return VState.vLocation.GetLongitudeDeg(); }
466   double GetLatitudeDeg(void) const { return VState.vLocation.GetLatitudeDeg(); }
467   const FGLocation& GetLocation(void) const { return VState.vLocation; }
468
469   /** Retrieves the local-to-body transformation matrix.
470       The quaternion class, being the means by which the orientation of the
471       vehicle is stored, manages the local-to-body transformation matrix.
472       @return a reference to the local-to-body transformation matrix.  */
473   const FGMatrix33& GetTl2b(void) const { return Tl2b; }
474
475   /** Retrieves the body-to-local transformation matrix.
476       The quaternion class, being the means by which the orientation of the
477       vehicle is stored, manages the body-to-local transformation matrix.
478       @return a reference to the body-to-local matrix.  */
479   const FGMatrix33& GetTb2l(void) const { return Tb2l; }
480
481   /** Retrieves the ECEF-to-body transformation matrix.
482       @return a reference to the ECEF-to-body transformation matrix.  */
483   const FGMatrix33& GetTec2b(void) const { return Tec2b; }
484
485   /** Retrieves the body-to-ECEF transformation matrix.
486       @return a reference to the body-to-ECEF matrix.  */
487   const FGMatrix33& GetTb2ec(void) const { return Tb2ec; }
488
489   /** Retrieves the ECI-to-body transformation matrix.
490       @return a reference to the ECI-to-body transformation matrix.  */
491   const FGMatrix33& GetTi2b(void) const { return Ti2b; }
492
493   /** Retrieves the body-to-ECI transformation matrix.
494       @return a reference to the body-to-ECI matrix.  */
495   const FGMatrix33& GetTb2i(void) const { return Tb2i; }
496
497   /** Retrieves the ECEF-to-ECI transformation matrix.
498       @return a reference to the ECEF-to-ECI transformation matrix.  */
499   const FGMatrix33& GetTec2i(void) const { return Tec2i; }
500
501   /** Retrieves the ECI-to-ECEF transformation matrix.
502       @return a reference to the ECI-to-ECEF matrix.  */
503   const FGMatrix33& GetTi2ec(void) const { return Ti2ec; }
504
505   /** Retrieves the ECEF-to-local transformation matrix.
506       Retrieves the ECEF-to-local transformation matrix. Note that the so-called
507       local from is also know as the NED frame (for North, East, Down).
508       @return a reference to the ECEF-to-local matrix.  */
509   const FGMatrix33& GetTec2l(void) const { return Tec2l; }
510
511   /** Retrieves the local-to-ECEF transformation matrix.
512       Retrieves the local-to-ECEF transformation matrix. Note that the so-called
513       local from is also know as the NED frame (for North, East, Down).
514       @return a reference to the local-to-ECEF matrix.  */
515   const FGMatrix33& GetTl2ec(void) const { return Tl2ec; }
516
517   /** Retrieves the local-to-inertial transformation matrix.
518       @return a reference to the local-to-inertial transformation matrix.  */
519   const FGMatrix33& GetTl2i(void) const { return Tl2i; }
520
521   /** Retrieves the inertial-to-local transformation matrix.
522       @return a reference to the inertial-to-local matrix.  */
523   const FGMatrix33& GetTi2l(void) const { return Ti2l; }
524
525   const VehicleState& GetVState(void) const { return VState; }
526
527   void SetVState(const VehicleState& vstate);
528
529   void InitializeDerivatives(void);
530
531   void SetInertialOrientation(FGQuaternion Qi);
532   void SetInertialVelocity(FGColumnVector3 Vi);
533   void SetInertialRates(FGColumnVector3 vRates);
534
535   const FGQuaternion GetQuaternion(void) const { return VState.qAttitudeLocal; }
536
537   void SetPQR(unsigned int i, double val) {
538       if ((i>=1) && (i<=3) )
539           VState.vPQR(i) = val;
540   }
541
542   void SetUVW(unsigned int i, double val) {
543       if ((i>=1) && (i<=3) )
544           VState.vUVW(i) = val;
545   }
546
547 // SET functions
548
549   void SetLongitude(double lon)
550   {
551     VState.vLocation.SetLongitude(lon);
552     UpdateVehicleState();
553   }
554   void SetLongitudeDeg(double lon) { SetLongitude(lon*degtorad); }
555   void SetLatitude(double lat)
556   {
557     VState.vLocation.SetLatitude(lat);
558     UpdateVehicleState();
559   }
560   void SetLatitudeDeg(double lat) { SetLatitude(lat*degtorad); }
561   void SetRadius(double r)
562   {
563     VState.vLocation.SetRadius(r);
564     VehicleRadius = r;
565     VState.vInertialPosition = Tec2i * VState.vLocation;
566   }
567   void SetAltitudeASL(double altASL) { SetRadius(altASL + SeaLevelRadius); }
568   void SetAltitudeASLmeters(double altASL) { SetRadius(altASL/fttom + SeaLevelRadius); }
569   void SetSeaLevelRadius(double tt) { SeaLevelRadius = tt; }
570   void SetTerrainElevation(double tt);
571   void SetDistanceAGL(double tt) { SetRadius(tt + LocalTerrainRadius); }
572   void SetInitialState(const FGInitialCondition *);
573   void SetLocation(const FGLocation& l);
574   void SetLocation(const FGColumnVector3& lv)
575   {
576       FGLocation l = FGLocation(lv);
577       SetLocation(l);
578   }
579   void SetPosition(const double Lon, const double Lat, const double Radius)
580   {
581       FGLocation l = FGLocation(Lon, Lat, Radius);
582       SetLocation(l);
583   }
584
585   void RecomputeLocalTerrainRadius(void);
586
587   void NudgeBodyLocation(FGColumnVector3 deltaLoc) {
588     VState.vInertialPosition -= Tb2i*deltaLoc;
589     VState.vLocation -= Tb2ec*deltaLoc;
590   }
591
592   struct LagrangeMultiplier {
593     FGColumnVector3 ForceJacobian;
594     FGColumnVector3 MomentJacobian;
595     double Min;
596     double Max;
597     double value;
598   };
599
600   void DumpState(void);
601
602 private:
603
604 // state vector
605
606   struct VehicleState VState;
607
608   FGColumnVector3 vVel;
609   FGColumnVector3 vPQRdot, vPQRidot;
610   FGColumnVector3 vUVWdot, vUVWidot;
611   FGColumnVector3 vInertialVelocity;
612   FGColumnVector3 vLocation;
613   FGColumnVector3 vDeltaXYZEC;
614   FGColumnVector3 vGravAccel;
615   FGColumnVector3 vOmegaEarth;  // The Earth angular velocity vector
616   FGQuaternion vQtrndot;
617   FGMatrix33 Tec2b;
618   FGMatrix33 Tb2ec;
619   FGMatrix33 Tl2b;   // local to body frame matrix copy for immediate local use
620   FGMatrix33 Tb2l;   // body to local frame matrix copy for immediate local use
621   FGMatrix33 Tl2ec;  // local to ECEF matrix copy for immediate local use
622   FGMatrix33 Tec2l;  // ECEF to local frame matrix copy for immediate local use
623   FGMatrix33 Tec2i;  // ECEF to ECI frame matrix copy for immediate local use
624   FGMatrix33 Ti2ec;  // ECI to ECEF frame matrix copy for immediate local use
625   FGMatrix33 Ti2b;   // ECI to body frame rotation matrix
626   FGMatrix33 Tb2i;   // body to ECI frame rotation matrix
627   FGMatrix33 Ti2l;
628   FGMatrix33 Tl2i;
629   
630   double LocalTerrainRadius, SeaLevelRadius, VehicleRadius;
631   FGColumnVector3 LocalTerrainVelocity, LocalTerrainAngularVelocity;
632   eIntegrateType integrator_rotational_rate;
633   eIntegrateType integrator_translational_rate;
634   eIntegrateType integrator_rotational_position;
635   eIntegrateType integrator_translational_position;
636   int gravType;
637
638   void CalculatePQRdot(void);
639   void CalculateQuatdot(void);
640   void CalculateInertialVelocity(void);
641   void CalculateUVW(void);
642   void CalculateUVWdot(void);
643
644   void Integrate( FGColumnVector3& Integrand,
645                   FGColumnVector3& Val,
646                   deque <FGColumnVector3>& ValDot,
647                   double dt,
648                   eIntegrateType integration_type);
649
650   void Integrate( FGQuaternion& Integrand,
651                   FGQuaternion& Val,
652                   deque <FGQuaternion>& ValDot,
653                   double dt,
654                   eIntegrateType integration_type);
655
656   void EvaluateRateToResistTo(FGColumnVector3& vdot,
657                               const FGColumnVector3& Val,
658                               const FGColumnVector3& ValDot,
659                               const FGColumnVector3& LocalTerrainVal,
660                               deque <FGColumnVector3>& dqValDot,
661                               const double dt,
662                               const eIntegrateType integration_type);
663
664   void ResolveFrictionForces(double dt);
665
666   void UpdateLocationMatrices(void);
667   void UpdateBodyMatrices(void);
668   void UpdateVehicleState(void);
669
670   void bind(void);
671   void Debug(int from);
672 };
673 }
674 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 #endif