]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGForce.cpp
Sync w. JSBSim CVS (merge from PRE_OSG_PLIB_20061029 branch)
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGForce.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Source:       FGForce.cpp
4  Author:       Tony Peden
5  Date started: 6/10/00
6
7  ------------- Copyright (C) 1999  Anthony K. Peden (apeden@earthlink.net) -------------
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
27  HISTORY
28 --------------------------------------------------------------------------------
29 6/10/00  TP   Created
30
31
32 FUNCTIONAL DESCRIPTION
33 --------------------------------------------------------------------------------
34
35 The purpose of this class is to provide storage for computed forces and
36 encapsulate all the functionality associated with transforming those
37 forces from their native coord system to the body system.  This includes
38 computing the moments due to the difference between the point of application
39 and the cg.
40
41 */
42
43 #include <FGFDMExec.h>
44 #include <models/FGAircraft.h>
45 #include <models/FGPropagate.h>
46 #include <models/FGMassBalance.h>
47 #include <FGState.h>
48 #include "FGForce.h"
49
50 namespace JSBSim {
51
52 static const char *IdSrc = "$Id$";
53 static const char *IdHdr = ID_FORCE;
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 FGForce::FGForce(FGFDMExec *FDMExec) :
58                  ttype(tNone),
59                  fdmex(FDMExec)
60 {
61   mT(1,1) = 1; //identity matrix
62   mT(2,2) = 1;
63   mT(3,3) = 1;
64
65   Debug(0);
66 }
67
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70 FGForce::~FGForce()
71 {
72   Debug(1);
73 }
74
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 FGColumnVector3& FGForce::GetBodyForces(void)
78 {
79   vFb = Transform()*vFn;
80
81   // Find the distance from this vector's acting location to the cg; this
82   // needs to be done like this to convert from structural to body coords.
83   // CG and RP values are in inches
84
85   vDXYZ = fdmex->GetMassBalance()->StructuralToBody(vActingXYZn);
86
87   vM = vMn + vDXYZ*vFb;
88
89   return vFb;
90 }
91
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 FGMatrix33 FGForce::Transform(void)
95 {
96   switch(ttype) {
97   case tWindBody:
98     return fdmex->GetState()->GetTs2b();
99   case tLocalBody:
100     return fdmex->GetPropagate()->GetTl2b();
101   case tCustom:
102   case tNone:
103     return mT;
104   default:
105     cout << "Unrecognized tranform requested from FGForce::Transform()" << endl;
106     exit(1);
107   }
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112 void FGForce::UpdateCustomTransformMatrix(void)
113 {
114   double cp,sp,cr,sr,cy,sy;
115
116   cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
117   cr=cos(vOrient(eRoll));  sr=sin(vOrient(eRoll));
118   cy=cos(vOrient(eYaw));   sy=sin(vOrient(eYaw));
119
120   mT(1,1) =  cp*cy;
121   mT(1,2) =  cp*sy;
122   mT(1,3) = -sp;
123
124   mT(2,1) = sr*sp*cy - cr*sy;
125   mT(2,2) = sr*sp*sy + cr*cy;
126   mT(2,3) = sr*cp;
127
128   mT(3,1) = cr*sp*cy + sr*sy;
129   mT(3,2) = cr*sp*sy - sr*cy;
130   mT(3,3) = cr*cp;
131   mT = mT.Inverse();
132 }
133
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136 void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw)
137 {
138   if (ttype == tCustom) {
139     vOrient(ePitch) = bpitch;
140     vOrient(eRoll) = broll;
141     vOrient(eYaw) = byaw;
142
143     UpdateCustomTransformMatrix();
144   }
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 //    The bitmasked value choices are as follows:
149 //    unset: In this case (the default) JSBSim would only print
150 //       out the normally expected messages, essentially echoing
151 //       the config files as they are read. If the environment
152 //       variable is not set, debug_lvl is set to 1 internally
153 //    0: This requests JSBSim not to output any messages
154 //       whatsoever.
155 //    1: This value explicity requests the normal JSBSim
156 //       startup messages
157 //    2: This value asks for a message to be printed out when
158 //       a class is instantiated
159 //    4: When this value is set, a message is displayed when a
160 //       FGModel object executes its Run() method
161 //    8: When this value is set, various runtime state variables
162 //       are printed out periodically
163 //    16: When set various parameters are sanity checked and
164 //       a message is printed out when they go out of bounds
165
166 void FGForce::Debug(int from)
167 {
168   if (debug_lvl <= 0) return;
169
170   if (debug_lvl & 1) { // Standard console startup message output
171     if (from == 0) { // Constructor
172
173     }
174   }
175   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
176     if (from == 0) cout << "Instantiated: FGForce" << endl;
177     if (from == 1) cout << "Destroyed:    FGForce" << endl;
178   }
179   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
180   }
181   if (debug_lvl & 8 ) { // Runtime state variables
182   }
183   if (debug_lvl & 16) { // Sanity checking
184   }
185   if (debug_lvl & 64) {
186     if (from == 0) { // Constructor
187       cout << IdSrc << endl;
188       cout << IdHdr << endl;
189     }
190   }
191 }
192 }