]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGForce.cpp
Syncing with most recent JSBSim.
[flightgear.git] / src / FDM / JSBSim / 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 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
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 "FGAircraft.h"
45 #include "FGTranslation.h"
46 #include "FGMatrix33.h"
47 #include "FGColumnVector3.h"
48 #include "FGColumnVector4.h"
49 #include "FGForce.h"
50
51 static const char *IdSrc = "$Id$";
52 static const char *IdHdr = ID_FORCE;
53
54 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
56 FGForce::FGForce(FGFDMExec *FDMExec) :
57                  ttype(tNone),
58                  fdmex(FDMExec)
59 {
60   mT(1,1) = 1; //identity matrix
61   mT(2,2) = 1;
62   mT(3,3) = 1;
63   vSense.InitMatrix(1);
64   if (debug_lvl & 2) cout << "Instantiated: FGForce" << endl;
65 }
66
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69 FGForce::~FGForce()
70 {
71   if (debug_lvl & 2) cout << "Destroyed:    FGForce" << endl;
72 }
73
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 FGColumnVector3& FGForce::GetBodyForces(void)
77 {
78   vFb = Transform()*(vFn.multElementWise(vSense));
79
80   // Find the distance from this vector's acting location to the cg; this
81   // needs to be done like this to convert from structural to body coords.
82   // CG and RP values are in inches
83
84   vDXYZ(eX) = -(vActingXYZn(eX) - fdmex->GetMassBalance()->GetXYZcg(eX))*inchtoft;
85   vDXYZ(eY) =  (vActingXYZn(eY) - fdmex->GetMassBalance()->GetXYZcg(eY))*inchtoft;
86   vDXYZ(eZ) = -(vActingXYZn(eZ) - fdmex->GetMassBalance()->GetXYZcg(eZ))*inchtoft;
87
88   vM = vMn + vDXYZ*vFb;
89
90   return vFb;
91 }
92
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
95 FGMatrix33 FGForce::Transform(void)
96 {
97   switch(ttype) {
98   case tWindBody:
99     return fdmex->GetState()->GetTs2b();
100   case tLocalBody:
101     return fdmex->GetState()->GetTl2b();
102   case tCustom:
103
104   case tNone:
105     return mT;
106   default:
107     cout << "Unrecognized tranform requested from FGForce::Transform()" << endl;
108     exit(1);
109   }
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw)
115 {
116   if (ttype == tCustom) {
117     double cp,sp,cr,sr,cy,sy;
118
119     cp=cos(bpitch); sp=sin(bpitch);
120     cr=cos(broll);  sr=sin(broll);
121     cy=cos(byaw);   sy=sin(byaw);
122
123     mT(1,1)=cp*cy;
124     mT(1,2)=cp*sy;
125     mT(1,3)=-1*sp;
126
127     mT(2,1)=sr*sp*cy-cr*sy;
128     mT(2,2)=sr*sp*sy+cr*cy;
129     mT(2,3)=sr*cp;
130
131     mT(3,1)=cr*sp*cy+sr*sy;
132     mT(3,2)=cr*sp*sy-sr*cy;
133     mT(3,3)=cr*cp;
134   }
135 }
136
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139 void FGForce::Debug(void)
140 {
141     //TODO: Add your source code here
142 }
143