1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Integrates the rotational EOM
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class integrates the rotational EOM.
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES, and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 [1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
40 Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
42 [2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
44 [3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
45 NASA-Ames", NASA CR-2497, January 1975
46 [4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
47 Wiley & Sons, 1979 ISBN 0-471-03032-5
48 [5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
49 1982 ISBN 0-471-08936-2
51 The order of rotations used in this class corresponds to a 3-2-1 sequence,
52 or Y-P-R, or Z-Y-X, if you prefer.
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 #include "FGRotation.h"
59 #include "FGAtmosphere.h"
61 #include "FGFDMExec.h"
63 #include "FGAircraft.h"
64 #include "FGMassBalance.h"
65 #include "FGTranslation.h"
66 #include "FGPosition.h"
67 #include "FGAuxiliary.h"
69 #include "FGPropertyManager.h"
74 static const char *IdSrc = "$Id$";
75 static const char *IdHdr = ID_ROTATION;
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex)
85 cTht = cPhi = cPsi = 1.0;
86 sTht = sPhi = sPsi = 0.0;
89 vPQRdot_prev[0].InitMatrix();
90 vPQRdot_prev[1].InitMatrix();
91 vPQRdot_prev[2].InitMatrix();
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 FGRotation::~FGRotation()
106 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 bool FGRotation::Run(void)
113 if (!FGModel::Run()) {
116 L2 = vMoments(eL) + Ixz*vPQR(eP)*vPQR(eQ) - (Izz-Iyy)*vPQR(eR)*vPQR(eQ);
117 N1 = vMoments(eN) - (Iyy-Ixx)*vPQR(eP)*vPQR(eQ) - Ixz*vPQR(eR)*vPQR(eQ);
119 vPQRdot(eP) = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz);
120 vPQRdot(eQ) = (vMoments(eM) - (Ixx-Izz)*vPQR(eP)*vPQR(eR)
121 - Ixz*(vPQR(eP)*vPQR(eP) - vPQR(eR)*vPQR(eR)))/Iyy;
122 vPQRdot(eR) = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz);
124 vPQR += State->Integrate(FGState::TRAPZ, dt*rate, vPQRdot, vPQRdot_prev);
126 vAeroPQR = vPQR + Atmosphere->GetTurbPQR();
128 State->IntegrateQuat(vPQR, rate);
129 State->CalcMatrices();
130 vEuler = State->CalcEuler();
132 cTht = cos(vEuler(eTht)); sTht = sin(vEuler(eTht));
133 cPhi = cos(vEuler(ePhi)); sPhi = sin(vEuler(ePhi));
134 cPsi = cos(vEuler(ePsi)); sPsi = sin(vEuler(ePsi));
136 vEulerRates(eTht) = vPQR(2)*cPhi - vPQR(3)*sPhi;
138 tTheta = sTht/cTht; // what's cheaper: / or tan() ?
139 vEulerRates(ePhi) = vPQR(1) + (vPQR(2)*sPhi + vPQR(3)*cPhi)*tTheta;
140 vEulerRates(ePsi) = (vPQR(2)*sPhi + vPQR(3)*cPhi)/cTht;
143 if (debug_lvl > 1) Debug(2);
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 void FGRotation::GetState(void)
156 vMoments = Aircraft->GetMoments();
158 Ixx = MassBalance->GetIxx();
159 Iyy = MassBalance->GetIyy();
160 Izz = MassBalance->GetIzz();
161 Ixz = MassBalance->GetIxz();
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 void FGRotation::bind(void)
168 typedef double (FGRotation::*PMF)(int) const;
169 PropertyManager->Tie("velocities/p-rad_sec", this,1,
170 (PMF)&FGRotation::GetPQR);
171 PropertyManager->Tie("velocities/q-rad_sec", this,2,
172 (PMF)&FGRotation::GetPQR);
173 PropertyManager->Tie("velocities/r-rad_sec", this,3,
174 (PMF)&FGRotation::GetPQR);
175 PropertyManager->Tie("velocities/p-aero-rad_sec", this,1,
176 (PMF)&FGRotation::GetAeroPQR);
177 PropertyManager->Tie("velocities/q-aero-rad_sec", this,2,
178 (PMF)&FGRotation::GetAeroPQR);
179 PropertyManager->Tie("velocities/r-aero-rad_sec", this,3,
180 (PMF)&FGRotation::GetAeroPQR);
181 PropertyManager->Tie("accelerations/pdot-rad_sec", this,1,
182 (PMF)&FGRotation::GetPQRdot);
183 PropertyManager->Tie("accelerations/qdot-rad_sec", this,2,
184 (PMF)&FGRotation::GetPQRdot);
185 PropertyManager->Tie("accelerations/rdot-rad_sec", this,3,
186 (PMF)&FGRotation::GetPQRdot);
187 PropertyManager->Tie("attitude/roll-rad", this,1,
188 (PMF)&FGRotation::GetEuler);
189 PropertyManager->Tie("attitude/pitch-rad", this,2,
190 (PMF)&FGRotation::GetEuler);
191 PropertyManager->Tie("attitude/heading-true-rad", this,3,
192 (PMF)&FGRotation::GetEuler);
193 PropertyManager->Tie("velocities/phidot-rad_sec", this,1,
194 (PMF)&FGRotation::GetEulerRates);
195 PropertyManager->Tie("velocities/thetadot-rad_sec", this,2,
196 (PMF)&FGRotation::GetEulerRates);
197 PropertyManager->Tie("velocities/psidot-rad_sec", this,3,
198 (PMF)&FGRotation::GetEulerRates);
199 PropertyManager->Tie("attitude/phi-rad", this,
200 &FGRotation::Getphi);
201 PropertyManager->Tie("attitude/theta-rad", this,
202 &FGRotation::Gettht);
203 PropertyManager->Tie("attitude/psi-true-rad", this,
204 &FGRotation::Getpsi);
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 void FGRotation::unbind(void)
211 PropertyManager->Untie("velocities/p-rad_sec");
212 PropertyManager->Untie("velocities/q-rad_sec");
213 PropertyManager->Untie("velocities/r-rad_sec");
214 PropertyManager->Untie("velocities/p-aero-rad_sec");
215 PropertyManager->Untie("velocities/q-aero-rad_sec");
216 PropertyManager->Untie("velocities/r-aero-rad_sec");
217 PropertyManager->Untie("accelerations/pdot-rad_sec");
218 PropertyManager->Untie("accelerations/qdot-rad_sec");
219 PropertyManager->Untie("accelerations/rdot-rad_sec");
220 PropertyManager->Untie("attitude/roll-rad");
221 PropertyManager->Untie("attitude/pitch-rad");
222 PropertyManager->Untie("attitude/heading-true-rad");
223 PropertyManager->Untie("velocities/phidot-rad_sec");
224 PropertyManager->Untie("velocities/thetadot-rad_sec");
225 PropertyManager->Untie("velocities/psidot-rad_sec");
226 PropertyManager->Untie("attitude/phi-rad");
227 PropertyManager->Untie("attitude/theta-rad");
228 PropertyManager->Untie("attitude/psi-true-rad");
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 // The bitmasked value choices are as follows:
233 // unset: In this case (the default) JSBSim would only print
234 // out the normally expected messages, essentially echoing
235 // the config files as they are read. If the environment
236 // variable is not set, debug_lvl is set to 1 internally
237 // 0: This requests JSBSim not to output any messages
239 // 1: This value explicity requests the normal JSBSim
241 // 2: This value asks for a message to be printed out when
242 // a class is instantiated
243 // 4: When this value is set, a message is displayed when a
244 // FGModel object executes its Run() method
245 // 8: When this value is set, various runtime state variables
246 // are printed out periodically
247 // 16: When set various parameters are sanity checked and
248 // a message is printed out when they go out of bounds
250 void FGRotation::Debug(int from)
252 if (debug_lvl <= 0) return;
254 if (debug_lvl & 1) { // Standard console startup message output
255 if (from == 0) { // Constructor
259 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
260 if (from == 0) cout << "Instantiated: FGRotation" << endl;
261 if (from == 1) cout << "Destroyed: FGRotation" << endl;
263 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
265 if (debug_lvl & 8 ) { // Runtime state variables
267 if (debug_lvl & 16) { // Sanity check variables
269 if (fabs(vPQR(eP)) > 100)
270 cout << "FGRotation::P (Roll Rate) out of bounds: " << vPQR(eP) << endl;
271 if (fabs(vPQR(eQ)) > 100)
272 cout << "FGRotation::Q (Pitch Rate) out of bounds: " << vPQR(eQ) << endl;
273 if (fabs(vPQR(eR)) > 100)
274 cout << "FGRotation::R (Yaw Rate) out of bounds: " << vPQR(eR) << endl;
277 if (debug_lvl & 64) {
278 if (from == 0) { // Constructor
279 cout << IdSrc << endl;
280 cout << IdHdr << endl;