1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGAccelerations.h
7 ------------- Copyright (C) 2011 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGACCELERATIONS_H
35 #define FGACCELERATIONS_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "models/FGModel.h"
44 #include "math/FGColumnVector3.h"
45 #include "math/LagrangeMultiplier.h"
46 #include "math/FGMatrix33.h"
47 #include "math/FGQuaternion.h"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 #define ID_ACCELERATIONS "$Id: FGAccelerations.h,v 1.8 2011/10/31 14:54:41 bcoconni Exp $"
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 /** Handles the calculation of accelerations.
67 -Calculate the angular accelerations
68 -Calculate the translational accelerations
69 -Calculate the angular rate
70 -Calculate the translational velocity
72 @author Jon S. Berndt, Mathias Froehlich, Bertrand Coconnier
73 @version $Id: FGAccelerations.h,v 1.8 2011/10/31 14:54:41 bcoconni Exp $
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 class FGAccelerations : public FGModel {
83 @param Executive a pointer to the parent executive object */
84 FGAccelerations(FGFDMExec* Executive);
89 /// These define the indices use to select the gravitation models.
90 enum eGravType {gtStandard, gtWGS84};
92 /** Initializes the FGAccelerations class after instantiation and prior to first execution.
93 The base class FGModel::InitModel is called first, initializing pointers to the
94 other FGModel objects (and others). */
97 /** Runs the state propagation model; called by the Executive
98 Can pass in a value indicating if the executive is directing the simulation to Hold.
99 @param Holding if true, the executive has been directed to hold the sim from
100 advancing time. Some models may ignore this flag, such as the Input
101 model, which may need to be active to listen on a socket for the
102 "Resume" command to be given.
103 @return false if no error */
104 bool Run(bool Holding);
106 const FGQuaternion& GetQuaterniondot(void) const {return vQtrndot;}
108 /** Retrieves the body axis acceleration.
109 Retrieves the computed body axis accelerations based on the
110 applied forces and accounting for a rotating body frame.
111 The vector returned is represented by an FGColumnVector reference. The vector
112 for the acceleration in Body frame is organized (Ax, Ay, Az). The vector
113 is 1-based, so that the first element can be retrieved using the "()" operator.
114 In other words, vUVWdot(1) is Ax. Various convenience enumerators are defined
115 in FGJSBBase. The relevant enumerators for the vector returned by this call are,
118 @return Body axis translational acceleration in ft/sec^2.
120 const FGColumnVector3& GetUVWdot(void) const { return vUVWdot; }
122 const FGColumnVector3& GetUVWidot(void) const { return vUVWidot; }
124 /** Retrieves the body axis angular acceleration vector.
125 Retrieves the body axis angular acceleration vector in rad/sec^2. The
126 angular acceleration vector is determined from the applied forces and
127 accounts for a rotating frame.
128 The vector returned is represented by an FGColumnVector reference. The vector
129 for the angular acceleration in Body frame is organized (Pdot, Qdot, Rdot). The vector
130 is 1-based, so that the first element can be retrieved using the "()" operator.
131 In other words, vPQRdot(1) is Pdot. Various convenience enumerators are defined
132 in FGJSBBase. The relevant enumerators for the vector returned by this call are,
135 @return The angular acceleration vector.
137 const FGColumnVector3& GetPQRdot(void) const {return vPQRdot;}
139 const FGColumnVector3& GetPQRidot(void) const {return vPQRidot;}
141 /** Retrieves a body frame acceleration component.
142 Retrieves a body frame acceleration component. The acceleration returned
143 is extracted from the vUVWdot vector (an FGColumnVector). The vector for
144 the acceleration in Body frame is organized (Ax, Ay, Az). The vector is
145 1-based. In other words, GetUVWdot(1) returns Ax. Various convenience
146 enumerators are defined in FGJSBBase. The relevant enumerators for the
147 acceleration returned by this call are, eX=1, eY=2, eZ=3.
149 @param idx the index of the acceleration component desired (1-based).
150 @return The body frame acceleration component.
152 double GetUVWdot(int idx) const { return vUVWdot(idx); }
154 const FGColumnVector3& GetBodyAccel(void) const { return vBodyAccel; }
156 double GetBodyAccel(int idx) const { return vBodyAccel(idx); }
158 /** Retrieves a body frame angular acceleration component.
159 Retrieves a body frame angular acceleration component. The angular
160 acceleration returned is extracted from the vPQRdot vector (an
161 FGColumnVector). The vector for the angular acceleration in Body frame
162 is organized (Pdot, Qdot, Rdot). The vector is 1-based. In other words,
163 GetPQRdot(1) returns Pdot (roll acceleration). Various convenience
164 enumerators are defined in FGJSBBase. The relevant enumerators for the
165 angular acceleration returned by this call are, eP=1, eQ=2, eR=3.
167 @param axis the index of the angular acceleration component desired (1-based).
168 @return The body frame angular acceleration component.
170 double GetPQRdot(int axis) const {return vPQRdot(axis);}
172 double GetMoments(int idx) const { return in.Moment(idx) + vFrictionMoments(idx); }
173 double GetForces(int idx) const { return in.Force(idx) + vFrictionForces(idx); }
174 double GetGroundMoments(int idx) const { return in.GroundMoment(idx) + vFrictionMoments(idx); }
175 double GetGroundForces(int idx) const { return in.GroundForce(idx) + vFrictionForces(idx); }
177 void InitializeDerivatives(void);
179 void DumpState(void);
188 FGQuaternion qAttitudeECI;
189 FGColumnVector3 Moment;
190 FGColumnVector3 GroundMoment;
191 FGColumnVector3 Force;
192 FGColumnVector3 GroundForce;
193 FGColumnVector3 J2Grav;
194 FGColumnVector3 vPQRi;
195 FGColumnVector3 vPQR;
196 FGColumnVector3 vUVW;
197 FGColumnVector3 vInertialPosition;
198 FGColumnVector3 vOmegaPlanet;
199 FGColumnVector3 TerrainVelocity;
200 FGColumnVector3 TerrainAngularVel;
204 std::vector<LagrangeMultiplier*> *MultipliersList;
209 FGColumnVector3 vPQRdot, vPQRidot;
210 FGColumnVector3 vUVWdot, vUVWidot;
211 FGQuaternion vQtrndot;
212 FGColumnVector3 vBodyAccel;
213 FGColumnVector3 vGravAccel;
214 FGColumnVector3 vFrictionForces;
215 FGColumnVector3 vFrictionMoments;
219 void CalculatePQRdot(void);
220 void CalculateQuatdot(void);
221 void CalculateUVWdot(void);
223 void ResolveFrictionForces(double dt);
226 void Debug(int from);
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%