Debian Codegraph @

src/FDM/JSBSim/models/FGInertial.h

raw symbols SCIP
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 ([email protected]) -------------
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
57 /** Models inertial forces (e.g. centripetal and coriolis accelerations).
58 Starting conversion to WGS84.
59 */
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 CLASS DECLARATION
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 class JSBSIM_API FGInertial : public FGModel {
66
67 public:
68 explicit FGInertial(FGFDMExec*);
69 ~FGInertial(void);
70
71 /** Runs the Inertial model; called by the Executive
72 Can pass in a value indicating if the executive is directing the
73 simulation to Hold.
74 @param Holding if true, the executive has been directed to hold the sim
75 from advancing time. Some models may ignore this flag, such
76 as the Input model, which may need to be active to listen
77 on a socket for the "Resume" command to be given.
78 @return false if no error */
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
89 /** @name Functions that rely on the ground callback
90 The following functions allow to set and get the vehicle position above
91 the ground. The ground level is obtained by interrogating an instance of
92 FGGroundCallback. A ground callback must therefore be set with
93 SetGroundCallback() before calling any of these functions. */
94 ///@{
95 /** Get terrain contact point information below the current location.
96 @param location Location at which the contact point is evaluated.
97 @param contact Contact point location
98 @param normal Terrain normal vector in contact point (ECEF frame)
99 @param velocity Terrain linear velocity in contact point (ECEF frame)
100 @param ang_velocity Terrain angular velocity in contact point (ECEF frame)
101 @return Location altitude above contact point (AGL) in feet.
102 @see SetGroundCallback */
103 double GetContactPoint(const FGLocation& location, FGLocation& contact,
104 FGColumnVector3& normal, FGColumnVector3& velocity,
105 FGColumnVector3& ang_velocity) const
106 {
107 return GroundCallback->GetAGLevel(location, contact, normal, velocity,
108 ang_velocity); }
109
110 /** Get the altitude above ground level.
111 @return the altitude AGL in feet.
112 @param location Location at which the AGL is evaluated.
113 @see SetGroundCallback */
114 double GetAltitudeAGL(const FGLocation& location) const {
115 FGLocation lDummy;
116 FGColumnVector3 vDummy;
117 return GroundCallback->GetAGLevel(location, lDummy, vDummy, vDummy,
118 vDummy);
119 }
120
121 /** Set the altitude above ground level.
122 @param location Location at which the AGL is set.
123 @param altitudeAGL Altitude above Ground Level in feet.
124 @see SetGroundCallback */
125 void SetAltitudeAGL(FGLocation& location, double altitudeAGL);
126
127 /** Set the terrain elevation above sea level.
128 @param h Terrain elevation in ft.
129 @see SetGroundcallback */
130 void SetTerrainElevation(double h) {
131 GroundCallback->SetTerrainElevation(h);
132 }
133
134 /** Set the simulation time.
135 The elapsed time can be used by the ground callback to assess the planet
136 rotation or the movement of objects.
137 @param time elapsed time in seconds since the simulation started.
138 */
139 void SetTime(double time) {
140 GroundCallback->SetTime(time);
141 }
142 ///@}
143
144 /** Sets the ground callback pointer.
145 FGInertial will take ownership of the pointer which must therefore be
146 located in the heap.
147 @param gc A pointer to a ground callback object
148 @see FGGroundCallback
149 */
150 void SetGroundCallback(FGGroundCallback* gc) { GroundCallback.reset(gc); }
151
152 /// These define the indices use to select the gravitation models.
153 enum eGravType {
154 /// Evaluate gravity using Newton's classical formula assuming the Earth is
155 /// spherical
156 gtStandard,
157 /// Evaluate gravity using WGS84 formulas that take the Earth oblateness
158 /// into account
159 gtWGS84
160 };
161
162 /// Get the gravity type.
163 int GetGravityType(void) const { return gravType; }
164
165 /// Set the gravity type.
166 void SetGravityType(int gt);
167
168 /** Transform matrix from the local horizontal frame to earth centered.
169 The local frame is the NED (North-East-Down) frame. Since the Down
170 direction depends on the gravity so is the local frame.
171 The East direction is tangent to the spheroid with a null component along
172 the Z axis.
173 The North direction is obtained from the cross product between East and
174 Down.
175 @param location The location at which the transform matrix must be
176 evaluated.
177 @return a rotation matrix of the transform from the earth centered frame
178 to the local horizontal frame.
179 */
180 FGMatrix33 GetTl2ec(const FGLocation& location) const;
181
182 /** Transform matrix from the earth centered to local horizontal frame.
183 The local frame is the NED (North-East-Down) frame. Since the Down
184 direction depends on the gravity so is the local frame.
185 The East direction is tangent to the spheroid with a null component along
186 the Z axis.
187 The North direction is obtained from the cross product between East and
188 Down.
189 @param location The location at which the transform matrix must be
190 evaluated.
191 @return a rotation matrix of the transform from the earth centered frame
192 to the local horizontal frame.
193 */
194 FGMatrix33 GetTec2l(const FGLocation& location) const
195 { return GetTl2ec(location).Transposed(); }
196
197 struct Inputs {
198 FGLocation Position;
199 } in;
200
201 bool Load(Element* el) override;
202
203 private:
204 // Standard gravity (9.80665 m/s^2) in ft/s^2 which is the gravity at 45 deg.
205 // of latitude (see ISA 1976 and Steven & Lewis)
206 // It includes the centripetal acceleration.
207 static constexpr double gAccelReference = 9.80665 / fttom;
208
209 FGColumnVector3 vOmegaPlanet;
210 FGColumnVector3 vGravAccel;
211 double GM;
212 double J2; // WGS84 value for J2
213 double a; // WGS84 semimajor axis length in feet
214 double b; // WGS84 semiminor axis length in feet
215 int gravType;
216 std::unique_ptr<FGGroundCallback> GroundCallback;
217
218 double GetGAccel(double r) const;
219 FGColumnVector3 GetGravityJ2(const FGLocation& position) const;
220 void bind(void);
221 void Debug(int from) override;
222 };
223 }
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 #endif