Debian Codegraph @

src/FDM/JSBSim/models/FGAccelerations.h

raw symbols SCIP
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Header: FGAccelerations.h
4 Author: Jon S. Berndt
5 Date started: 07/12/11
6
7 ------------- Copyright (C) 2011 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 07/12/11 JSB Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGACCELERATIONS_H
35 #define FGACCELERATIONS_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "models/FGModel.h"
42 #include "math/FGColumnVector3.h"
43 #include "math/LagrangeMultiplier.h"
44 #include "math/FGMatrix33.h"
45
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 FORWARD DECLARATIONS
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50 namespace JSBSim {
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS DOCUMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 /** Handles the calculation of accelerations.
57
58 - Calculate the angular accelerations
59 - Calculate the translational accelerations
60
61 This class is collecting all the forces and the moments acting on the body
62 to calculate the corresponding accelerations according to Newton's second
63 law. This is also where the friction forces related to the ground reactions
64 are evaluated.
65
66 JSBSim provides several ways to calculate the influence of the gravity on
67 the vehicle. The different options can be selected via the following
68 properties :
69 @property simulation/gravity-model (read/write) Selects the gravity model.
70 Two options are available : 0 (Standard gravity assuming the Earth
71 is spherical) or 1 (WGS84 gravity taking the Earth oblateness into
72 account). WGS84 gravity is the default.
73 @property simulation/gravitational-torque (read/write) Enables/disables the
74 calculations of the gravitational torque on the vehicle. This is
75 mainly relevant for spacecrafts that are orbiting at low altitudes.
76 Gravitational torque calculations are disabled by default.
77
78 Special care is taken in the calculations to obtain maximum fidelity in
79 JSBSim results. In FGAccelerations, this is obtained by avoiding as much as
80 possible the transformations from one frame to another. As a consequence,
81 the frames in which the accelerations are primarily evaluated are dictated
82 by the frames in which FGPropagate resolves the equations of movement (the
83 ECI frame for the translations and the body frame for the rotations).
84
85 @see Mark Harris and Robert Lyle, "Spacecraft Gravitational Torques",
86 NASA SP-8024, May 1969
87
88 @author Jon S. Berndt, Mathias Froehlich, Bertrand Coconnier
89 */
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 CLASS DECLARATION
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 class FGAccelerations : public FGModel {
96 public:
97 /** Constructor.
98 @param Executive a pointer to the parent executive object */
99 explicit FGAccelerations(FGFDMExec* Executive);
100
101 /// Destructor
102 ~FGAccelerations();
103
104 /** Initializes the FGAccelerations class after instantiation and prior to first execution.
105 The base class FGModel::InitModel is called first, initializing pointers to the
106 other FGModel objects (and others). */
107 bool InitModel(void) override;
108
109 /** Runs the state propagation model; called by the Executive
110 Can pass in a value indicating if the executive is directing the simulation to Hold.
111 @param Holding if true, the executive has been directed to hold the sim from
112 advancing time. Some models may ignore this flag, such as the Input
113 model, which may need to be active to listen on a socket for the
114 "Resume" command to be given.
115 @return false if no error */
116 bool Run(bool Holding) override;
117
118 /** Retrieves the body axis acceleration.
119 Retrieves the computed body axis accelerations based on the
120 applied forces and accounting for a rotating body frame.
121 The vector returned is represented by an FGColumnVector3 reference. The vector
122 for the acceleration in Body frame is organized (Ax, Ay, Az). The vector
123 is 1-based, so that the first element can be retrieved using the "()" operator.
124 In other words, vUVWdot(1) is Ax. Various convenience enumerators are defined
125 in FGJSBBase. The relevant enumerators for the vector returned by this call are,
126 eX=1, eY=2, eZ=3.
127 units ft/sec^2
128 @return Body axis translational acceleration in ft/sec^2.
129 */
130 const FGColumnVector3& GetUVWdot(void) const { return vUVWdot; }
131
132 /** Retrieves the body axis acceleration in the ECI frame.
133 Retrieves the computed body axis accelerations based on the applied forces.
134 The ECI frame being an inertial frame this vector does not contain the
135 Coriolis and centripetal accelerations. The vector is expressed in the
136 Body frame.
137 The vector returned is represented by an FGColumnVector3 reference. The
138 vector for the acceleration in Body frame is organized (Aix, Aiy, Aiz). The
139 vector is 1-based, so that the first element can be retrieved using the
140 "()" operator. In other words, vUVWidot(1) is Aix. Various convenience
141 enumerators are defined in FGJSBBase. The relevant enumerators for the
142 vector returned by this call are, eX=1, eY=2, eZ=3.
143 units ft/sec^2
144 @return Body axis translational acceleration in ft/sec^2.
145 */
146 const FGColumnVector3& GetUVWidot(void) const { return vUVWidot; }
147
148 /** Retrieves the body axis angular acceleration vector.
149 Retrieves the body axis angular acceleration vector in rad/sec^2. The
150 angular acceleration vector is determined from the applied moments and
151 accounts for a rotating frame.
152 The vector returned is represented by an FGColumnVector3 reference. The vector
153 for the angular acceleration in Body frame is organized (Pdot, Qdot, Rdot). The vector
154 is 1-based, so that the first element can be retrieved using the "()" operator.
155 In other words, vPQRdot(1) is Pdot. Various convenience enumerators are defined
156 in FGJSBBase. The relevant enumerators for the vector returned by this call are,
157 eP=1, eQ=2, eR=3.
158 units rad/sec^2
159 @return The angular acceleration vector.
160 */
161 const FGColumnVector3& GetPQRdot(void) const {return vPQRdot;}
162
163 /** Retrieves the axis angular acceleration vector in the ECI frame.
164 Retrieves the body axis angular acceleration vector measured in the ECI
165 frame and expressed in the body frame. The angular acceleration vector is
166 determined from the applied moments.
167 The vector returned is represented by an FGColumnVector3 reference. The
168 vector for the angular acceleration in Body frame is organized (Pidot,
169 Qidot, Ridot). The vector is 1-based, so that the first element can be
170 retrieved using the "()" operator. In other words, vPQRidot(1) is Pidot.
171 Various convenience enumerators are defined in FGJSBBase. The relevant
172 enumerators for the vector returned by this call are, eP=1, eQ=2, eR=3.
173 units rad/sec^2
174 @return The angular acceleration vector.
175 */
176 const FGColumnVector3& GetPQRidot(void) const {return vPQRidot;}
177
178 /** Retrieves a body frame acceleration component.
179 Retrieves a body frame acceleration component. The acceleration returned
180 is extracted from the vUVWdot vector (an FGColumnVector3). The vector for
181 the acceleration in Body frame is organized (Ax, Ay, Az). The vector is
182 1-based. In other words, GetUVWdot(1) returns Ax. Various convenience
183 enumerators are defined in FGJSBBase. The relevant enumerators for the
184 acceleration returned by this call are, eX=1, eY=2, eZ=3.
185 units ft/sec^2
186 @param idx the index of the acceleration component desired (1-based).
187 @return The body frame acceleration component.
188 */
189 double GetUVWdot(int idx) const { return vUVWdot(idx); }
190
191 /** Retrieves the acceleration resulting from the applied forces.
192 Retrieves the ratio of the sum of all forces applied on the craft to its
193 mass. This does include the friction forces but not the gravity.
194 The vector returned is represented by an FGColumnVector3 reference. The
195 vector for the acceleration in Body frame is organized (Ax, Ay, Az). The
196 vector is 1-based, so that the first element can be retrieved using the
197 "()" operator. In other words, vBodyAccel(1) is Ax. Various convenience
198 enumerators are defined in FGJSBBase. The relevant enumerators for the
199 vector returned by this call are, eX=1, eY=2, eZ=3.
200 units ft/sec^2
201 @return The acceleration resulting from the applied forces.
202 */
203 const FGColumnVector3& GetBodyAccel(void) const { return vBodyAccel; }
204
205 double GetGravAccelMagnitude(void) const { return in.vGravAccel.Magnitude(); }
206
207 /** Retrieves a component of the acceleration resulting from the applied forces.
208 Retrieves a component of the ratio between the sum of all forces applied
209 on the craft to its mass. The value returned is extracted from the vBodyAccel
210 vector (an FGColumnVector3). The vector for the acceleration in Body frame
211 is organized (Ax, Ay, Az). The vector is 1-based. In other words,
212 GetBodyAccel(1) returns Ax. Various convenience enumerators are defined
213 in FGJSBBase. The relevant enumerators for the vector returned by this
214 call are, eX=1, eY=2, eZ=3.
215 units ft/sec^2
216 @param idx the index of the acceleration component desired (1-based).
217 @return The component of the acceleration resulting from the applied forces.
218 */
219 double GetBodyAccel(int idx) const { return vBodyAccel(idx); }
220
221 /** Retrieves a body frame angular acceleration component.
222 Retrieves a body frame angular acceleration component. The angular
223 acceleration returned is extracted from the vPQRdot vector (an
224 FGColumnVector3). The vector for the angular acceleration in Body frame
225 is organized (Pdot, Qdot, Rdot). The vector is 1-based. In other words,
226 GetPQRdot(1) returns Pdot (roll acceleration). Various convenience
227 enumerators are defined in FGJSBBase. The relevant enumerators for the
228 angular acceleration returned by this call are, eP=1, eQ=2, eR=3.
229 units rad/sec^2
230 @param axis the index of the angular acceleration component desired (1-based).
231 @return The body frame angular acceleration component.
232 */
233 double GetPQRdot(int axis) const {return vPQRdot(axis);}
234
235 /** Retrieves a component of the total moments applied on the body.
236 Retrieves a component of the total moments applied on the body. This does
237 include the moments generated by friction forces and the gravitational
238 torque (if the property \e simulation/gravitational-torque is set to true).
239 The vector for the total moments in the body frame is organized (Mx, My
240 , Mz). The vector is 1-based. In other words, GetMoments(1) returns Mx.
241 Various convenience enumerators are defined in FGJSBBase. The relevant
242 enumerators for the moments returned by this call are, eX=1, eY=2, eZ=3.
243 units lbs*ft
244 @param idx the index of the moments component desired (1-based).
245 @return The total moments applied on the body.
246 */
247 double GetMoments(int idx) const { return in.Moment(idx) + vFrictionMoments(idx); }
248 FGColumnVector3 GetMoments(void) const { return in.Moment + vFrictionMoments; }
249
250 /** Retrieves the total forces applied on the body.
251 Retrieves the total forces applied on the body. This does include the
252 friction forces but not the gravity.
253 The vector for the total forces in the body frame is organized (Fx, Fy
254 , Fz). The vector is 1-based. In other words, GetForces(1) returns Fx.
255 Various convenience enumerators are defined in FGJSBBase. The relevant
256 enumerators for the forces returned by this call are, eX=1, eY=2, eZ=3.
257 units lbs
258 @param idx the index of the forces component desired (1-based).
259 @return The total forces applied on the body.
260 */
261 double GetForces(int idx) const { return in.Force(idx) + vFrictionForces(idx); }
262 FGColumnVector3 GetForces(void) const { return in.Force + vFrictionForces; }
263
264 /** Retrieves the ground moments applied on the body.
265 Retrieves the ground moments applied on the body. This does include the
266 ground normal reaction and friction moments.
267 The vector for the ground moments in the body frame is organized (Mx, My
268 , Mz). The vector is 1-based. In other words, GetGroundMoments(1) returns
269 Mx. Various convenience enumerators are defined in FGJSBBase. The relevant
270 enumerators for the moments returned by this call are, eX=1, eY=2, eZ=3.
271 units lbs*ft
272 @param idx the index of the moments component desired (1-based).
273 @return The ground moments applied on the body.
274 */
275 double GetGroundMoments(int idx) const { return in.GroundMoment(idx) + vFrictionMoments(idx); }
276 FGColumnVector3 GetGroundMoments(void) const { return in.GroundMoment + vFrictionMoments; }
277
278 /** Retrieves the ground forces applied on the body.
279 Retrieves the ground forces applied on the body. This does include the
280 ground normal reaction and friction forces.
281 The vector for the ground forces in the body frame is organized (Fx, Fy
282 , Fz). The vector is 1-based. In other words, GetGroundForces(1) returns
283 Fx. Various convenience enumerators are defined in FGJSBBase. The relevant
284 enumerators for the forces returned by this call are, eX=1, eY=2, eZ=3.
285 units lbs.
286 @param idx the index of the forces component desired (1-based).
287 @return The ground forces applied on the body.
288 */
289 double GetGroundForces(int idx) const { return in.GroundForce(idx) + vFrictionForces(idx); }
290 FGColumnVector3 GetGroundForces(void) const { return in.GroundForce + vFrictionForces; }
291
292 /** Retrieves the weight applied on the body.
293 Retrieves the weight applied on the body i.e. the force that results from
294 the gravity applied to the body mass.
295 The vector for the weight forces in the body frame is organized (Fx, Fy ,
296 Fz). The vector is 1-based. In other words, GetWeight(1) returns
297 Fx. Various convenience enumerators are defined in FGJSBBase. The relevant
298 enumerators for the forces returned by this call are, eX=1, eY=2, eZ=3.
299 units lbs.
300 @param idx the index of the forces component desired (1-based).
301 @return The ground forces applied on the body.
302 */
303 double GetWeight(int idx) const { return in.Mass * (in.Tec2b * in.vGravAccel)(idx); }
304 FGColumnVector3 GetWeight(void) const { return in.Mass * in.Tec2b * in.vGravAccel; }
305
306 /** Initializes the FGAccelerations class prior to a new execution.
307 Initializes the class prior to a new execution when the input data stored
308 in the Inputs structure have been set to their initial values.
309 */
310 void InitializeDerivatives(void);
311
312 /** Sets the property forces/hold-down. This allows to do hard 'hold-down'
313 such as for rockets on a launch pad with engines ignited.
314 @param hd enables the 'hold-down' function if non-zero
315 */
316 void SetHoldDown(bool hd);
317
318 struct Inputs {
319 /// The body inertia matrix expressed in the body frame
320 FGMatrix33 J;
321 /// The inverse of the inertia matrix J
322 FGMatrix33 Jinv;
323 /// Transformation matrix from the ECI to the Body frame
324 FGMatrix33 Ti2b;
325 /// Transformation matrix from the Body to the ECI frame
326 FGMatrix33 Tb2i;
327 /// Transformation matrix from the ECEF to the Body frame
328 FGMatrix33 Tec2b;
329 /// Transformation matrix from the ECEF to the ECI frame
330 FGMatrix33 Tec2i;
331 /// Total moments applied to the body except friction and gravity (expressed in the body frame)
332 FGColumnVector3 Moment;
333 /// Moments generated by the ground normal reactions expressed in the body frame. Does not account for friction.
334 FGColumnVector3 GroundMoment;
335 /// Total forces applied to the body except friction and gravity (expressed in the body frame)
336 FGColumnVector3 Force;
337 /// Forces generated by the ground normal reactions expressed in the body frame. Does not account for friction.
338 FGColumnVector3 GroundForce;
339 /// Gravity intensity vector (expressed in the ECEF frame).
340 FGColumnVector3 vGravAccel;
341 /// Angular velocities of the body with respect to the ECI frame (expressed in the body frame).
342 FGColumnVector3 vPQRi;
343 /// Angular velocities of the body with respect to the local frame (expressed in the body frame).
344 FGColumnVector3 vPQR;
345 /// Velocities of the body with respect to the local frame (expressed in the body frame).
346 FGColumnVector3 vUVW;
347 /// Body position (X,Y,Z) measured in the ECI frame.
348 FGColumnVector3 vInertialPosition;
349 /// Earth rotating vector (expressed in the ECI frame).
350 FGColumnVector3 vOmegaPlanet;
351 /// Terrain velocities with respect to the local frame (expressed in the ECEF frame).
352 FGColumnVector3 TerrainVelocity;
353 /// Terrain angular velocities with respect to the local frame (expressed in the ECEF frame).
354 FGColumnVector3 TerrainAngularVel;
355 /// Time step
356 double DeltaT;
357 /// Body mass
358 double Mass;
359 /// List of Lagrange multipliers set by FGLGear for friction forces calculations.
360 std::vector<LagrangeMultiplier*> *MultipliersList;
361 } in;
362
363 private:
364
365 FGColumnVector3 vPQRdot, vPQRidot;
366 FGColumnVector3 vUVWdot, vUVWidot;
367 FGColumnVector3 vBodyAccel;
368 FGColumnVector3 vFrictionForces;
369 FGColumnVector3 vFrictionMoments;
370
371 bool gravTorque;
372
373 void CalculatePQRdot(void);
374 void CalculateUVWdot(void);
375
376 void CalculateFrictionForces(double dt);
377
378 void bind(void);
379 void Debug(int from) override;
380 };
381 }
382 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 #endif