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