JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGInertial.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGInertial.h
4  Author: Jon S. Berndt
5  Date started: 09/13/00
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
11  Software Foundation; either version 2 of the License, or (at your option) any
12  later 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
20  with this program; if not, write to the Free Software Foundation, Inc., 59
21  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be
24  found on the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 09/13/00 JSB Created
29 
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 
34 #ifndef FGINERTIAL_H
35 #define FGINERTIAL_H
36 
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include <memory>
42 
43 #include "FGModel.h"
44 #include "math/FGLocation.h"
45 #include "input_output/FGGroundCallback.h"
46 
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 FORWARD DECLARATIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 
51 namespace JSBSim {
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS DOCUMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 CLASS DECLARATION
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 
65 class JSBSIM_API FGInertial : public FGModel {
66 
67 public:
68  explicit FGInertial(FGFDMExec*);
69  ~FGInertial(void);
70 
79  bool Run(bool Holding) override;
80  static constexpr double GetStandardGravity(void) { return gAccelReference; }
81  const FGColumnVector3& GetGravity(void) const {return vGravAccel;}
82  const FGColumnVector3& GetOmegaPlanet() const {return vOmegaPlanet;}
83  void SetOmegaPlanet(double rate) {
84  vOmegaPlanet = FGColumnVector3(0.0, 0.0, rate);
85  }
86  double GetSemimajor(void) const {return a;}
87  double GetSemiminor(void) const {return b;}
88  double GetGM(void) {return GM;}
89 
96 
104  double GetContactPoint(const FGLocation& location, FGLocation& contact,
105  FGColumnVector3& normal, FGColumnVector3& velocity,
106  FGColumnVector3& ang_velocity) const
107  {
108  return GroundCallback->GetAGLevel(location, contact, normal, velocity,
109  ang_velocity); }
110 
115  double GetAltitudeAGL(const FGLocation& location) const {
116  FGLocation lDummy;
117  FGColumnVector3 vDummy;
118  return GroundCallback->GetAGLevel(location, lDummy, vDummy, vDummy,
119  vDummy);
120  }
121 
126  void SetAltitudeAGL(FGLocation& location, double altitudeAGL);
127 
131  void SetTerrainElevation(double h) {
132  GroundCallback->SetTerrainElevation(h);
133  }
134 
140  void SetTime(double time) {
141  GroundCallback->SetTime(time);
142  }
144 
151  void SetGroundCallback(FGGroundCallback* gc) { GroundCallback.reset(gc); }
152 
154  enum eGravType {
160  gtWGS84
161  };
162 
164  int GetGravityType(void) const { return gravType; }
165 
167  void SetGravityType(int gt);
168 
181  FGMatrix33 GetTl2ec(const FGLocation& location) const;
182 
195  FGMatrix33 GetTec2l(const FGLocation& location) const
196  { return GetTl2ec(location).Transposed(); }
197 
198  struct Inputs {
199  FGLocation Position;
200  } in;
201 
202  bool Load(Element* el) override;
203 
204 private:
205  // Standard gravity (9.80665 m/s^2) in ft/s^2 which is the gravity at 45 deg.
206  // of latitude (see ISA 1976 and Steven & Lewis)
207  // It includes the centripetal acceleration.
208  static constexpr double gAccelReference = 9.80665 / fttom;
209 
210  FGColumnVector3 vOmegaPlanet;
211  FGColumnVector3 vGravAccel;
212  double GM; // Gravitation parameter
213  double J2; // WGS84 value for J2
214  double a; // WGS84 semimajor axis length in feet
215  double b; // WGS84 semiminor axis length in feet
216  int gravType;
217  std::unique_ptr<FGGroundCallback> GroundCallback;
218 
219  double GetGAccel(double r) const;
220  FGColumnVector3 GetGravityJ2(const FGLocation& position) const;
221  void bind(void);
222  void Debug(int from) override;
223 };
224 }
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 #endif
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:184
This class provides callback slots to get ground specific data.
Models inertial forces (e.g.
Definition: FGInertial.h:65
double GetContactPoint(const FGLocation &location, FGLocation &contact, FGColumnVector3 &normal, FGColumnVector3 &velocity, FGColumnVector3 &ang_velocity) const
Get terrain contact point information below the current location.
Definition: FGInertial.h:104
double GetAltitudeAGL(const FGLocation &location) const
Get the altitude above ground level.
Definition: FGInertial.h:115
void SetGroundCallback(FGGroundCallback *gc)
Sets the ground callback pointer.
Definition: FGInertial.h:151
FGMatrix33 GetTec2l(const FGLocation &location) const
Transform matrix from the earth centered to local horizontal frame.
Definition: FGInertial.h:195
void SetTerrainElevation(double h)
Set the terrain elevation above sea level.
Definition: FGInertial.h:131
void SetTime(double time)
Set the simulation time.
Definition: FGInertial.h:140
eGravType
These define the indices use to select the gravitation models.
Definition: FGInertial.h:154
@ gtStandard
Evaluate gravity using Newton's classical formula assuming the Earth is spherical.
Definition: FGInertial.h:157
int GetGravityType(void) const
Get the gravity type.
Definition: FGInertial.h:164
FGLocation holds an arbitrary location in the Earth centered Earth fixed reference frame (ECEF).
Definition: FGLocation.h:152
Handles matrix math operations.
Definition: FGMatrix33.h:70
FGMatrix33 Transposed(void) const
Transposed matrix.
Definition: FGMatrix33.h:221
Base class for all scheduled JSBSim models.
Definition: FGModel.h:70