]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGRotation.h
Encapsulate the interpolstion version of FGEnvironment and fix some bugs
[flightgear.git] / src / FDM / JSBSim / FGRotation.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGRotation.h
4  Author:       Jon Berndt
5  Date started: 12/02/98
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 12/02/98   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGROTATION_H
35 #define FGROTATION_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  include <math.h>
44 #else
45 #  if defined (sgi) && !defined(__GNUC__)
46 #    include <math.h>
47 #  else
48 #    include <cmath>
49 #  endif
50 #endif
51
52 #include "FGModel.h"
53 #include "FGMatrix33.h"
54 #include "FGColumnVector3.h"
55 #include "FGColumnVector4.h"
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 DEFINITIONS
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 #define ID_ROTATION "$Id$"
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 FORWARD DECLARATIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 namespace JSBSim {
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 CLASS DOCUMENTATION
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 /** Models the rotational portion of the Equations of Motion.
74     Note: The order of rotations used in this class corresponds to a 3-2-1 sequence,
75     or Y-P-R, or Z-Y-X, if you prefer.
76     @see Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
77     Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420  Naval Postgraduate
78     School, January 1994
79     @see D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
80     JSC 12960, July 1977
81     @see Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
82     NASA-Ames", NASA CR-2497, January 1975
83     @see Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
84     Wiley & Sons, 1979 ISBN 0-471-03032-5
85     @see Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
86     1982 ISBN 0-471-08936-2
87 */
88
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 CLASS DECLARATION
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92
93 class FGRotation : public FGModel
94 {
95 public:
96   FGRotation(FGFDMExec*);
97   ~FGRotation();
98
99   bool Run(void);
100
101   inline FGColumnVector3& GetPQR(void) {return vPQR;}
102   inline double GetPQR(int axis) const {return vPQR(axis);}
103   inline FGColumnVector3& GetAeroPQR(void) {return vAeroPQR;}
104   inline double GetAeroPQR(int axis) const {return vAeroPQR(axis);}
105   inline FGColumnVector3& GetPQRdot(void) {return vPQRdot;}
106   inline double GetPQRdot(int idx) const {return vPQRdot(idx);}
107   inline FGColumnVector3& GetEuler(void) {return vEuler;}
108   inline double GetEuler(int axis) const {return vEuler(axis);}
109   inline FGColumnVector3& GetEulerRates(void) { return vEulerRates; }
110   inline double GetEulerRates(int axis) const { return vEulerRates(axis); }
111   inline void SetPQR(FGColumnVector3 tt) {vPQR = tt;}
112   inline void SetPQR(double p, double q, double r) {vPQR(eP)=p;
113                                                     vPQR(eQ)=q;
114                                                     vPQR(eR)=r;}
115   inline void SetAeroPQR(FGColumnVector3 tt) {vAeroPQR = tt;}
116   inline void SetAeroPQR(double p, double q, double r) {vAeroPQR(eP)=p;
117                                                         vAeroPQR(eQ)=q;
118                                                         vAeroPQR(eR)=r;}
119   inline void SetEuler(FGColumnVector3 tt) {vEuler = tt;}
120   
121   inline double Getphi(void) const {return vEuler(1);}
122   inline double Gettht(void) const {return vEuler(2);}
123   inline double Getpsi(void) const {return vEuler(3);}
124   
125   inline double GetCosphi(void) const {return cPhi;}
126   inline double GetCostht(void) const {return cTht;}
127   inline double GetCospsi(void) const {return cPsi;}
128
129   inline double GetSinphi(void) const {return sPhi;}
130   inline double GetSintht(void) const {return sTht;}
131   inline double GetSinpsi(void) const {return sPsi;}
132   
133   void bind(void);
134   void unbind(void);
135
136 private:
137   FGColumnVector3 vPQR;
138   FGColumnVector3 vAeroPQR;
139   FGColumnVector3 vPQRdot;
140   FGColumnVector3 vPQRdot_prev[4];
141   FGColumnVector3 vMoments;
142   FGColumnVector3 vEuler;
143   FGColumnVector3 vEulerRates;
144   
145   double cTht,sTht;
146   double cPhi,sPhi;
147   double cPsi,sPsi;
148   
149   double Ixx, Iyy, Izz, Ixz;
150   double dt;
151
152   void GetState(void);
153
154   void Debug(int from);
155 };
156 }
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 #endif
159