1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
5 Date started: 6/10/00
\r
7 ------------- Copyright (C) 1999 Anthony K. Peden (apeden@earthlink.net) -------------
\r
9 This program is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License as published by the Free Software
\r
11 Foundation; either version 2 of the License, or (at your option) any later
\r
14 This program is distributed in the hope that it will be useful, but WITHOUT
\r
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
19 You should have received a copy of the GNU General Public License along with
\r
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
\r
21 Place - Suite 330, Boston, MA 02111-1307, USA.
\r
23 Further information about the GNU General Public License can also be found on
\r
24 the world wide web at http://www.gnu.org.
\r
28 --------------------------------------------------------------------------------
\r
32 FUNCTIONAL DESCRIPTION
\r
33 --------------------------------------------------------------------------------
\r
35 The purpose of this class is to provide storage for computed forces and
\r
36 encapsulate all the functionality associated with transforming those
\r
37 forces from their native coord system to the body system. This includes
\r
38 computing the moments due to the difference between the point of application
\r
43 #include "FGFDMExec.h"
\r
44 #include "FGAircraft.h"
\r
45 #include "FGTranslation.h"
\r
46 #include "FGMassBalance.h"
\r
47 #include "FGState.h"
\r
48 #include "FGForce.h"
\r
52 static const char *IdSrc = "$Id$";
\r
53 static const char *IdHdr = ID_FORCE;
\r
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
57 FGForce::FGForce(FGFDMExec *FDMExec) :
\r
61 mT(1,1) = 1; //identity matrix
\r
64 vSense.InitMatrix(1);
\r
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
77 FGColumnVector3& FGForce::GetBodyForces(void)
\r
79 vFb = Transform()*(vFn.multElementWise(vSense));
\r
81 // Find the distance from this vector's acting location to the cg; this
\r
82 // needs to be done like this to convert from structural to body coords.
\r
83 // CG and RP values are in inches
\r
85 vDXYZ = fdmex->GetMassBalance()->StructuralToBody(vActingXYZn);
\r
87 vM = vMn + vDXYZ*vFb;
\r
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
94 FGMatrix33 FGForce::Transform(void)
\r
98 return fdmex->GetState()->GetTs2b();
\r
100 return fdmex->GetState()->GetTl2b();
\r
105 cout << "Unrecognized tranform requested from FGForce::Transform()" << endl;
\r
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
112 void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw)
\r
114 if (ttype == tCustom) {
\r
115 double cp,sp,cr,sr,cy,sy;
\r
117 cp=cos(bpitch); sp=sin(bpitch);
\r
118 cr=cos(broll); sr=sin(broll);
\r
119 cy=cos(byaw); sy=sin(byaw);
\r
125 mT(2,1)=sr*sp*cy-cr*sy;
\r
126 mT(2,2)=sr*sp*sy+cr*cy;
\r
129 mT(3,1)=cr*sp*cy+sr*sy;
\r
130 mT(3,2)=cr*sp*sy-sr*cy;
\r
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
136 // The bitmasked value choices are as follows:
\r
137 // unset: In this case (the default) JSBSim would only print
\r
138 // out the normally expected messages, essentially echoing
\r
139 // the config files as they are read. If the environment
\r
140 // variable is not set, debug_lvl is set to 1 internally
\r
141 // 0: This requests JSBSim not to output any messages
\r
143 // 1: This value explicity requests the normal JSBSim
\r
144 // startup messages
\r
145 // 2: This value asks for a message to be printed out when
\r
146 // a class is instantiated
\r
147 // 4: When this value is set, a message is displayed when a
\r
148 // FGModel object executes its Run() method
\r
149 // 8: When this value is set, various runtime state variables
\r
150 // are printed out periodically
\r
151 // 16: When set various parameters are sanity checked and
\r
152 // a message is printed out when they go out of bounds
\r
154 void FGForce::Debug(int from)
\r
156 if (debug_lvl <= 0) return;
\r
158 if (debug_lvl & 1) { // Standard console startup message output
\r
159 if (from == 0) { // Constructor
\r
163 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
\r
164 if (from == 0) cout << "Instantiated: FGForce" << endl;
\r
165 if (from == 1) cout << "Destroyed: FGForce" << endl;
\r
167 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
\r
169 if (debug_lvl & 8 ) { // Runtime state variables
\r
171 if (debug_lvl & 16) { // Sanity checking
\r
173 if (debug_lvl & 64) {
\r
174 if (from == 0) { // Constructor
\r
175 cout << IdSrc << endl;
\r
176 cout << IdHdr << endl;
\r