]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGForce.cpp
Sync with current JSBSim devel code.
[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 "FGMatrix.h"
47 #include "FGDefs.h"
48 #include "FGForce.h"
49
50 static const char *IdSrc = "$Header$";
51 static const char *IdHdr = "ID_FORCE";
52
53 FGForce::FGForce(FGFDMExec *FDMExec) :
54     vFn(3),
55     vMn(3),
56     vFb(3),
57     vM(3),
58     vXYZn(3),
59     vDXYZ(3),
60     mT(3,3),
61     vSense(3),
62     fdmex(FDMExec),
63     ttype(tNone) 
64 {
65   mT(1,1)=1; //identity matrix
66   mT(2,2)=1;
67   mT(3,3)=1;
68   vSense.InitMatrix(1);
69 }
70
71 FGForce::~FGForce(void) {}
72
73 FGColumnVector FGForce::GetBodyForces(void) {
74   
75   
76   vFb=Transform()*(vFn.multElementWise(vSense));
77
78   //find the distance from this vector's location to the cg
79   //needs to be done like this to convert from structural to body coords
80   vDXYZ(1) = -(vXYZn(1) - fdmex->GetAircraft()->GetXYZcg()(1))*INCHTOFT;
81   vDXYZ(2) =  (vXYZn(2) - fdmex->GetAircraft()->GetXYZcg()(2))*INCHTOFT;  //cg and rp values are in inches
82   vDXYZ(3) = -(vXYZn(3) - fdmex->GetAircraft()->GetXYZcg()(3))*INCHTOFT;
83
84   vM=vMn +vDXYZ*vFb;
85   
86   return vFb;
87 }
88
89
90
91 FGMatrix FGForce::Transform(void) {
92   switch(ttype) {
93   case tWindBody:
94     return fdmex->GetState()->GetTs2b(fdmex->GetTranslation()->Getalpha(),fdmex->GetTranslation()->Getbeta());
95   case tLocalBody:
96     return fdmex->GetState()->GetTl2b();
97   case tCustom:
98     
99   case tNone:
100     return mT; 
101   default:
102     cout << "Unrecognized tranform requested from FGForce::Transform()" << endl;
103     exit(1);
104   }
105 }
106
107 void FGForce::SetAnglesToBody(float broll, float bpitch, float byaw) {
108
109   if(ttype == tCustom) {
110     float cp,sp,cr,sr,cy,sy;
111
112     cp=cos(bpitch); sp=sin(bpitch);
113     cr=cos(broll);  sr=sin(broll);
114     cy=cos(byaw);   sy=sin(byaw);
115
116     mT(1,1)=cp*cy;
117     mT(1,2)=cp*sy;
118     mT(1,3)=-1*sp;
119
120     mT(2,1)=sr*sp*cy-cr*sy;
121     mT(2,2)=sr*sp*sy+cr*cy;
122     mT(2,3)=sr*cp;
123
124     mT(3,1)=cr*sp*cy+sr*sy;
125     mT(3,2)=cr*sp*sy-sr*cy;
126     mT(3,3)=cr*cp;
127   }
128
129 }
130
131