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