]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAccelerations.h
Merge branch 'next' into comm-subsystem
[flightgear.git] / src / FDM / JSBSim / models / FGAccelerations.h
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 (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 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 <vector>
42
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"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 DEFINITIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 #define ID_ACCELERATIONS "$Id: FGAccelerations.h,v 1.7 2011/08/21 15:46:48 bcoconni Exp $"
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 FORWARD DECLARATIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 namespace JSBSim {
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 CLASS DOCUMENTATION
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 /** Handles the calculation of accelerations.
66
67     -Calculate the angular accelerations
68     -Calculate the translational accelerations
69     -Calculate the angular rate
70     -Calculate the translational velocity
71
72     @author Jon S. Berndt, Mathias Froehlich, Bertrand Coconnier
73     @version $Id: FGAccelerations.h,v 1.7 2011/08/21 15:46:48 bcoconni Exp $
74   */
75
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 CLASS DECLARATION
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79
80 class FGAccelerations : public FGModel {
81 public:
82   /** Constructor.
83       @param Executive a pointer to the parent executive object */
84   FGAccelerations(FGFDMExec* Executive);
85
86   /// Destructor
87   ~FGAccelerations();
88   
89   /// These define the indices use to select the gravitation models.
90   enum eGravType {gtStandard, gtWGS84}; 
91
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).  */
95   bool InitModel(void);
96
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);
105
106   const FGQuaternion& GetQuaterniondot(void) const {return vQtrndot;}
107
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,
116       eX=1, eY=2, eZ=3.
117       units ft/sec^2
118       @return Body axis translational acceleration in ft/sec^2.
119   */
120   const FGColumnVector3& GetUVWdot(void) const { return vUVWdot; }
121
122   const FGColumnVector3& GetUVWidot(void) const { return vUVWidot; }
123
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,
133       eP=1, eQ=2, eR=3.
134       units rad/sec^2
135       @return The angular acceleration vector.
136   */
137   const FGColumnVector3& GetPQRdot(void) const {return vPQRdot;}
138   
139   const FGColumnVector3& GetPQRidot(void) const {return vPQRidot;}
140
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.
148       units ft/sec^2
149       @param idx the index of the acceleration component desired (1-based).
150       @return The body frame acceleration component.
151   */
152   double GetUVWdot(int idx) const { return vUVWdot(idx); }
153
154   FGColumnVector3& GetBodyAccel(void) { return vBodyAccel; }
155
156   double GetBodyAccel(int idx) const { return vBodyAccel(idx); }
157
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.
166       units rad/sec^2
167       @param axis the index of the angular acceleration component desired (1-based).
168       @return The body frame angular acceleration component.
169   */
170   double GetPQRdot(int axis) const {return vPQRdot(axis);}
171
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); }
176
177   void InitializeDerivatives(void);
178
179   void DumpState(void);
180
181   struct Inputs {
182     FGMatrix33 J;
183     FGMatrix33 Jinv;
184     FGMatrix33 Ti2b;
185     FGMatrix33 Tb2i;
186     FGMatrix33 Tec2b;
187     FGMatrix33 Tl2b;
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;
201     double DeltaT;
202     double Mass;
203     double GAccel;
204     std::vector<LagrangeMultiplier*> *MultipliersList;
205   } in;
206
207 private:
208
209   FGColumnVector3 vPQRdot, vPQRidot;
210   FGColumnVector3 vUVWdot, vUVWidot;
211   FGQuaternion vQtrndot;
212   FGColumnVector3 vBodyAccel;
213   FGColumnVector3 vGravAccel;
214   FGColumnVector3 vFrictionForces;
215   FGColumnVector3 vFrictionMoments;
216
217   int gravType;
218
219   void CalculatePQRdot(void);
220   void CalculateQuatdot(void);
221   void CalculateUVWdot(void);
222
223   void ResolveFrictionForces(double dt);
224
225   void bind(void);
226   void Debug(int from);
227 };
228 }
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 #endif