JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
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.85 2016/04/16 12:24:39 bcoconni Exp $"
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
58 namespace JSBSim {
59 
60 class FGInitialCondition;
61 
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS DOCUMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 CLASS DECLARATION
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101 
102 class FGPropagate : public FGModel {
103 public:
104 
107  struct VehicleState {
112 
117 
122 
127 
131 
135 
136  FGQuaternion vQtrndot;
137 
138  FGColumnVector3 vInertialVelocity;
139 
140  FGColumnVector3 vInertialPosition;
141 
142  std::deque <FGColumnVector3> dqPQRidot;
143  std::deque <FGColumnVector3> dqUVWidot;
144  std::deque <FGColumnVector3> dqInertialVelocity;
145  std::deque <FGQuaternion> dqQtrndot;
146  };
147 
156  FGPropagate(FGFDMExec* Executive);
157 
159  ~FGPropagate();
160 
162  enum eIntegrateType {eNone = 0, eRectEuler, eTrapezoidal, eAdamsBashforth2,
163  eAdamsBashforth3, eAdamsBashforth4, eBuss1, eBuss2, eLocalLinearization, eAdamsBashforth5};
164 
168  bool InitModel(void);
169 
170  void InitializeDerivatives();
171 
179  bool Run(bool Holding);
180 
192  const FGColumnVector3& GetVel(void) const { return vVel; }
193 
204  const FGColumnVector3& GetUVW(void) const { return VState.vUVW; }
205 
218  const FGColumnVector3& GetPQR(void) const {return VState.vPQR;}
219 
232  const FGColumnVector3& GetPQRi(void) const {return VState.vPQRi;}
233 
243  const FGQuaternion& GetQuaterniondot(void) const {return VState.vQtrndot;}
244 
260  const FGColumnVector3& GetEuler(void) const { return VState.qAttitudeLocal.GetEuler(); }
261 
277  FGColumnVector3 GetEulerDeg(void) const;
278 
290  double GetUVW(int idx) const { return VState.vUVW(idx); }
291 
303  double GetVel(int idx) const { return vVel(idx); }
304 
307  double GetInertialVelocityMagnitude(void) const { return VState.vInertialVelocity.Magnitude(); }
308 
311  double GetNEDVelocityMagnitude(void) const { return VState.vUVW.Magnitude(); }
312 
315  const FGColumnVector3& GetInertialVelocity(void) const { return VState.vInertialVelocity; }
316  double GetInertialVelocity(int i) const { return VState.vInertialVelocity(i); }
317 
320  const FGColumnVector3& GetInertialPosition(void) const { return VState.vInertialPosition; }
321  double GetInertialPosition(int i) const { return VState.vInertialPosition(i); }
322 
325  FGColumnVector3 GetECEFVelocity(void) const {return Tb2ec * VState.vUVW; }
326 
330  double GetECEFVelocity(int idx) const {return (Tb2ec * VState.vUVW)(idx); }
331 
337  double GetAltitudeASL(void) const { return VState.vLocation.GetAltitudeASL(); }
338 
344  double GetAltitudeASLmeters(void) const { return GetAltitudeASL()*fttom;}
345 
357  double GetPQR(int axis) const {return VState.vPQR(axis);}
358 
370  double GetPQRi(int axis) const {return VState.vPQRi(axis);}
371 
382  double GetEuler(int axis) const { return VState.qAttitudeLocal.GetEuler(axis); }
383 
394  double GetEulerDeg(int axis) const { return VState.qAttitudeLocal.GetEuler(axis) * radtodeg; }
395 
406  double GetCosEuler(int idx) const { return VState.qAttitudeLocal.GetCosEuler(idx); }
407 
418  double GetSinEuler(int idx) const { return VState.qAttitudeLocal.GetSinEuler(idx); }
419 
425  double Gethdot(void) const { return -vVel(eDown); }
426 
433  double GetLocalTerrainRadius(void) const;
434 
435  double GetEarthPositionAngle(void) const { return VState.vLocation.GetEPA(); }
436 
437  double GetEarthPositionAngleDeg(void) const { return GetEarthPositionAngle()*radtodeg;}
438 
439  const FGColumnVector3& GetTerrainVelocity(void) const { return LocalTerrainVelocity; }
440  const FGColumnVector3& GetTerrainAngularVelocity(void) const { return LocalTerrainAngularVelocity; }
441  void RecomputeLocalTerrainVelocity();
442 
443  double GetTerrainElevation(void) const { return GetLocalTerrainRadius() - VState.vLocation.GetSeaLevelRadius(); }
444  double GetDistanceAGL(void) const;
445  double GetDistanceAGLKm(void) const;
446  double GetRadius(void) const {
447  if (VState.vLocation.GetRadius() == 0) return 1.0;
448  else return VState.vLocation.GetRadius();
449  }
450  double GetLongitude(void) const { return VState.vLocation.GetLongitude(); }
451  double GetLatitude(void) const { return VState.vLocation.GetLatitude(); }
452 
453  double GetGeodLatitudeRad(void) const { return VState.vLocation.GetGeodLatitudeRad(); }
454  double GetGeodLatitudeDeg(void) const { return VState.vLocation.GetGeodLatitudeDeg(); }
455 
456  double GetGeodeticAltitude(void) const { return VState.vLocation.GetGeodAltitude(); }
457  double GetGeodeticAltitudeKm(void) const { return VState.vLocation.GetGeodAltitude()*0.0003048; }
458 
459  double GetLongitudeDeg(void) const { return VState.vLocation.GetLongitudeDeg(); }
460  double GetLatitudeDeg(void) const { return VState.vLocation.GetLatitudeDeg(); }
461  const FGLocation& GetLocation(void) const { return VState.vLocation; }
462  double GetLocation(int i) const { return VState.vLocation(i); }
463 
468  const FGMatrix33& GetTl2b(void) const { return Tl2b; }
469 
474  const FGMatrix33& GetTb2l(void) const { return Tb2l; }
475 
478  const FGMatrix33& GetTec2b(void) const { return Tec2b; }
479 
482  const FGMatrix33& GetTb2ec(void) const { return Tb2ec; }
483 
486  const FGMatrix33& GetTi2b(void) const { return Ti2b; }
487 
490  const FGMatrix33& GetTb2i(void) const { return Tb2i; }
491 
494  const FGMatrix33& GetTec2i(void) const { return Tec2i; }
495 
498  const FGMatrix33& GetTi2ec(void) const { return Ti2ec; }
499 
504  const FGMatrix33& GetTec2l(void) const { return Tec2l; }
505 
510  const FGMatrix33& GetTl2ec(void) const { return Tl2ec; }
511 
514  const FGMatrix33& GetTl2i(void) const { return Tl2i; }
515 
518  const FGMatrix33& GetTi2l(void) const { return Ti2l; }
519 
520  const VehicleState& GetVState(void) const { return VState; }
521 
522  void SetVState(const VehicleState& vstate);
523 
524  void SetEarthPositionAngle(double epa) {VState.vLocation.SetEarthPositionAngle(epa);}
525 
526  void SetInertialOrientation(const FGQuaternion& Qi);
527  void SetInertialVelocity(const FGColumnVector3& Vi);
528  void SetInertialRates(const FGColumnVector3& vRates);
529 
531  const FGQuaternion GetQuaternion(void) const { return VState.qAttitudeLocal; }
532 
534  const FGQuaternion GetQuaternionECI(void) const { return VState.qAttitudeECI; }
535 
537  const FGQuaternion GetQuaternionECEF(void) const { return Qec2b; }
538 
539  void SetPQR(unsigned int i, double val) {
540  VState.vPQR(i) = val;
541  VState.vPQRi = VState.vPQR + Ti2b * in.vOmegaPlanet;
542  }
543 
544  void SetUVW(unsigned int i, double val) {
545  VState.vUVW(i) = val;
546  CalculateInertialVelocity();
547  }
548 
549 // SET functions
550 
551  void SetLongitude(double lon)
552  {
553  VState.vLocation.SetLongitude(lon);
554  UpdateVehicleState();
555  }
556  void SetLongitudeDeg(double lon) { SetLongitude(lon*degtorad); }
557  void SetLatitude(double lat)
558  {
559  VState.vLocation.SetLatitude(lat);
560  UpdateVehicleState();
561  }
562  void SetLatitudeDeg(double lat) { SetLatitude(lat*degtorad); }
563  void SetRadius(double r)
564  {
565  VState.vLocation.SetRadius(r);
566  VState.vInertialPosition = Tec2i * VState.vLocation;
567  }
568 
569  void SetAltitudeASL(double altASL)
570  {
571  VState.vLocation.SetAltitudeASL(altASL);
572  UpdateVehicleState();
573  }
574  void SetAltitudeASLmeters(double altASL) { SetAltitudeASL(altASL/fttom); }
575 
576  void SetSeaLevelRadius(double tt);
577  void SetTerrainElevation(double tt);
578  void SetDistanceAGL(double tt);
579  void SetDistanceAGLKm(double tt);
580 
581  void SetInitialState(const FGInitialCondition*);
582  void SetLocation(const FGLocation& l);
583  void SetLocation(const FGColumnVector3& lv)
584  {
585  FGLocation l = FGLocation(lv);
586  SetLocation(l);
587  }
588  void SetPosition(const double Lon, const double Lat, const double Radius)
589  {
590  FGLocation l = FGLocation(Lon, Lat, Radius);
591  SetLocation(l);
592  }
593 
594  void NudgeBodyLocation(const FGColumnVector3& deltaLoc) {
595  VState.vInertialPosition -= Tb2i*deltaLoc;
596  VState.vLocation -= Tb2ec*deltaLoc;
597  }
598 
603  void SetHoldDown(bool hd);
604 
605  void DumpState(void);
606 
607  struct Inputs {
608  FGColumnVector3 vPQRidot;
609  FGColumnVector3 vUVWidot;
610  FGColumnVector3 vOmegaPlanet;
611  double SemiMajor;
612  double SemiMinor;
613  double DeltaT;
614  } in;
615 
616 private:
617 
618 // state vector
619 
620  struct VehicleState VState;
621 
622  FGColumnVector3 vVel;
623  FGMatrix33 Tec2b;
624  FGMatrix33 Tb2ec;
625  FGMatrix33 Tl2b; // local to body frame matrix copy for immediate local use
626  FGMatrix33 Tb2l; // body to local frame matrix copy for immediate local use
627  FGMatrix33 Tl2ec; // local to ECEF matrix copy for immediate local use
628  FGMatrix33 Tec2l; // ECEF to local frame matrix copy for immediate local use
629  FGMatrix33 Tec2i; // ECEF to ECI frame matrix copy for immediate local use
630  FGMatrix33 Ti2ec; // ECI to ECEF frame matrix copy for immediate local use
631  FGMatrix33 Ti2b; // ECI to body frame rotation matrix
632  FGMatrix33 Tb2i; // body to ECI frame rotation matrix
633  FGMatrix33 Ti2l;
634  FGMatrix33 Tl2i;
635 
636  FGQuaternion Qec2b;
637 
638  FGColumnVector3 LocalTerrainVelocity, LocalTerrainAngularVelocity;
639 
640  eIntegrateType integrator_rotational_rate;
641  eIntegrateType integrator_translational_rate;
642  eIntegrateType integrator_rotational_position;
643  eIntegrateType integrator_translational_position;
644 
645  void CalculateInertialVelocity(void);
646  void CalculateUVW(void);
647  void CalculateQuatdot(void);
648 
649  void Integrate( FGColumnVector3& Integrand,
650  FGColumnVector3& Val,
651  std::deque <FGColumnVector3>& ValDot,
652  double dt,
653  eIntegrateType integration_type);
654 
655  void Integrate( FGQuaternion& Integrand,
656  FGQuaternion& Val,
657  std::deque <FGQuaternion>& ValDot,
658  double dt,
659  eIntegrateType integration_type);
660 
661  void UpdateLocationMatrices(void);
662  void UpdateBodyMatrices(void);
663  void UpdateVehicleState(void);
664 
665  void WriteStateFile(int num);
666  void bind(void);
667  void Debug(int from);
668 };
669 }
670 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 #endif
bool Run(bool Holding)
Runs the state propagation model; called by the Executive Can pass in a value indicating if the execu...
const FGMatrix33 & GetTec2b(void) const
Retrieves the ECEF-to-body transformation matrix.
Definition: FGPropagate.h:478
Models the Quaternion representation of rotations.
Definition: FGQuaternion.h:92
double GetEuler(int axis) const
Retrieves a vehicle Euler angle component.
Definition: FGPropagate.h:382
FGColumnVector3 vPQRi
The angular velocity vector for the vehicle body frame relative to the ECI frame, expressed in the bo...
Definition: FGPropagate.h:126
double GetCosEuler(int idx) const
Retrieves the cosine of a vehicle Euler angle component.
Definition: FGPropagate.h:406
~FGPropagate()
Destructor.
const FGMatrix33 & GetTl2b(void) const
Retrieves the local-to-body transformation matrix.
Definition: FGPropagate.h:468
const FGMatrix33 & GetTl2i(void) const
Retrieves the local-to-inertial transformation matrix.
Definition: FGPropagate.h:514
const FGQuaternion GetQuaternionECI(void) const
Returns the quaternion that goes from ECI to Body.
Definition: FGPropagate.h:534
bool InitModel(void)
Initializes the FGPropagate class after instantiation and prior to first execution.
const FGColumnVector3 & GetPQRi(void) const
Retrieves the body angular rates vector, relative to the ECI (inertial) frame.
Definition: FGPropagate.h:232
double GetNEDVelocityMagnitude(void) const
Retrieves the total local NED velocity in ft/sec.
Definition: FGPropagate.h:311
FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF)...
Definition: FGLocation.h:160
double GetAltitudeASLmeters(void) const
Returns the current altitude above sea level.
Definition: FGPropagate.h:344
FGLocation vLocation
Represents the current location of the vehicle in Earth centered Earth fixed (ECEF) frame...
Definition: FGPropagate.h:111
double GetAltitudeASL(void) const
Returns the current altitude above sea level.
Definition: FGPropagate.h:337
double GetSinEuler(int idx) const
Retrieves the sine of a vehicle Euler angle component.
Definition: FGPropagate.h:418
FGColumnVector3 GetEulerDeg(void) const
Retrieves the Euler angles (in degrees) that define the vehicle orientation.
FGColumnVector3 GetECEFVelocity(void) const
Calculates and retrieves the velocity vector relative to the earth centered earth fixed (ECEF) frame...
Definition: FGPropagate.h:325
const FGMatrix33 & GetTi2l(void) const
Retrieves the inertial-to-local transformation matrix.
Definition: FGPropagate.h:518
const FGMatrix33 & GetTb2ec(void) const
Retrieves the body-to-ECEF transformation matrix.
Definition: FGPropagate.h:482
The current vehicle state vector structure contains the translational and angular position...
Definition: FGPropagate.h:107
const FGMatrix33 & GetTi2ec(void) const
Retrieves the ECI-to-ECEF transformation matrix.
Definition: FGPropagate.h:498
const FGColumnVector3 & GetUVW(void) const
Retrieves the body frame vehicle velocity vector.
Definition: FGPropagate.h:204
const FGColumnVector3 & GetPQR(void) const
Retrieves the body angular rates vector, relative to the ECEF frame.
Definition: FGPropagate.h:218
double GetEulerDeg(int axis) const
Retrieves a vehicle Euler angle component in degrees.
Definition: FGPropagate.h:394
double GetPQRi(int axis) const
Retrieves a body frame angular velocity component relative to the ECI (inertial) frame.
Definition: FGPropagate.h:370
FGQuaternion qAttitudeLocal
The current orientation of the vehicle, that is, the orientation of the body frame relative to the lo...
Definition: FGPropagate.h:130
FGColumnVector3 vPQR
The angular velocity vector for the vehicle relative to the ECEF frame, expressed in the body frame...
Definition: FGPropagate.h:121
Models the EOM and integration/propagation of state.
Definition: FGPropagate.h:102
const FGMatrix33 & GetTec2i(void) const
Retrieves the ECEF-to-ECI transformation matrix.
Definition: FGPropagate.h:494
const FGMatrix33 & GetTb2i(void) const
Retrieves the body-to-ECI transformation matrix.
Definition: FGPropagate.h:490
FGPropagate(FGFDMExec *Executive)
Constructor.
Definition: FGPropagate.cpp:89
double GetLocalTerrainRadius(void) const
Returns the "constant" LocalTerrainRadius.
const FGMatrix33 & GetTec2l(void) const
Retrieves the ECEF-to-local transformation matrix.
Definition: FGPropagate.h:504
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
const FGMatrix33 & GetTb2l(void) const
Retrieves the body-to-local transformation matrix.
Definition: FGPropagate.h:474
const FGColumnVector3 & GetVel(void) const
Retrieves the velocity vector.
Definition: FGPropagate.h:192
const FGQuaternion & GetQuaterniondot(void) const
Retrieves the time derivative of the body orientation quaternion.
Definition: FGPropagate.h:243
const FGColumnVector3 & GetEuler(void) const
Retrieves the Euler angles that define the vehicle orientation.
Definition: FGPropagate.h:260
double GetInertialVelocityMagnitude(void) const
Retrieves the total inertial velocity in ft/sec.
Definition: FGPropagate.h:307
This class implements a 3 element column vector.
const FGMatrix33 & GetTl2ec(void) const
Retrieves the local-to-ECEF transformation matrix.
Definition: FGPropagate.h:510
FGQuaternion qAttitudeECI
The current orientation of the vehicle, that is, the orientation of the body frame relative to the in...
Definition: FGPropagate.h:134
const FGColumnVector3 & GetInertialPosition(void) const
Retrieves the inertial position vector.
Definition: FGPropagate.h:320
const FGQuaternion GetQuaternion(void) const
Returns the quaternion that goes from Local to Body.
Definition: FGPropagate.h:531
Initializes the simulation run.
double Gethdot(void) const
Returns the current altitude rate.
Definition: FGPropagate.h:425
const FGColumnVector3 & GetInertialVelocity(void) const
Retrieves the inertial velocity vector in ft/sec.
Definition: FGPropagate.h:315
Handles matrix math operations.
Definition: FGMatrix33.h:92
double GetVel(int idx) const
Retrieves a Local frame velocity component.
Definition: FGPropagate.h:303
eIntegrateType
These define the indices use to select the various integrators.
Definition: FGPropagate.h:162
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
double GetPQR(int axis) const
Retrieves a body frame angular velocity component relative to the ECEF frame.
Definition: FGPropagate.h:357
double GetECEFVelocity(int idx) const
Calculates and retrieves the velocity vector relative to the earth centered earth fixed (ECEF) frame ...
Definition: FGPropagate.h:330
double GetUVW(int idx) const
Retrieves a body frame velocity component.
Definition: FGPropagate.h:290
FGColumnVector3 vUVW
The velocity vector of the vehicle with respect to the ECEF frame, expressed in the body system...
Definition: FGPropagate.h:116
const FGQuaternion GetQuaternionECEF(void) const
Returns the quaternion that goes from ECEF to Body.
Definition: FGPropagate.h:537
const FGMatrix33 & GetTi2b(void) const
Retrieves the ECI-to-body transformation matrix.
Definition: FGPropagate.h:486
void SetHoldDown(bool hd)
Sets the property forces/hold-down.