FlightGear next
FGForce.cpp
Go to the documentation of this file.
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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26
27 HISTORY
28--------------------------------------------------------------------------------
296/10/00 TP Created
30
31
32FUNCTIONAL DESCRIPTION
33--------------------------------------------------------------------------------
34
35The purpose of this class is to provide storage for computed forces and
36encapsulate all the functionality associated with transforming those forces from
37their native coord system to the body system. This includes computing the
38moments due to the difference between the point of application and the cg.
39
40*/
41
42#include "FGForce.h"
43#include "FGFDMExec.h"
45#include "models/FGAuxiliary.h"
46
47using namespace std;
48
49namespace JSBSim {
50
51//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
54 : fdmex(FDMExec), MassBalance(fdmex->GetMassBalance()), ttype(tNone)
55{
56 vFn.InitMatrix();
57 vMn.InitMatrix();
58 vOrient.InitMatrix();
59 vXYZn.InitMatrix();
60 vActingXYZn.InitMatrix();
61
62 vFb.InitMatrix();
63 vM.InitMatrix();
64
65 mT = { 1., 0., 0.,
66 0., 1., 0.,
67 0., 0., 1. };
68
69 Debug(0);
70}
71
72//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
75{
76 Debug(1);
77}
78
79//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
82{
83 vFb = Transform()*vFn;
84
85 // Find the distance from this vector's acting location to the cg; this
86 // needs to be done like this to convert from structural to body coords.
87 // CG and RP values are in inches
88
89 FGColumnVector3 vDXYZ = MassBalance->StructuralToBody(vActingXYZn);
90
91 vM = vMn + vDXYZ*vFb;
92
93 return vFb;
94}
95
96//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
99{
100 switch(ttype) {
101 case tWindBody:
102 return fdmex->GetAuxiliary()->GetTw2b();
103 case tLocalBody:
104 return fdmex->GetPropagate()->GetTl2b();
105 case tCustom:
106 case tNone:
107 return mT;
108 default:
109 {
110 const string s("Unrecognized tranform requested from FGForce::Transform()");
111 cout << s << endl;
112 throw BaseException(s);
113 }
114 }
115}
116
117//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
120{
121 double cp,sp,cr,sr,cy,sy;
122 double srsp, crcy, crsy;
123
124 cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
125 cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll));
126 cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw));
127
128 srsp = sr*sp;
129 crcy = cr*cy;
130 crsy = cr*sy;
131
132 mT(1,1) = cp*cy;
133 mT(2,1) = cp*sy;
134 mT(3,1) = -sp;
135
136 mT(1,2) = srsp*cy - crsy;
137 mT(2,2) = srsp*sy + crcy;
138 mT(3,2) = sr*cp;
139
140 mT(1,3) = crcy*sp + sr*sy;
141 mT(2,3) = crsy*sp - sr*cy;
142 mT(3,3) = cr*cp;
143}
144
145//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw)
148{
149 if (ttype == tCustom) {
150 vOrient(ePitch) = bpitch;
151 vOrient(eRoll) = broll;
152 vOrient(eYaw) = byaw;
153
155 }
156}
157
158//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159// The bitmasked value choices are as follows:
160// unset: In this case (the default) JSBSim would only print
161// out the normally expected messages, essentially echoing
162// the config files as they are read. If the environment
163// variable is not set, debug_lvl is set to 1 internally
164// 0: This requests JSBSim not to output any messages
165// whatsoever.
166// 1: This value explicity requests the normal JSBSim
167// startup messages
168// 2: This value asks for a message to be printed out when
169// a class is instantiated
170// 4: When this value is set, a message is displayed when a
171// FGModel object executes its Run() method
172// 8: When this value is set, various runtime state variables
173// are printed out periodically
174// 16: When set various parameters are sanity checked and
175// a message is printed out when they go out of bounds
176
177void FGForce::Debug(int from)
178{
179 if (debug_lvl <= 0) return;
180
181 if (debug_lvl & 1) { // Standard console startup message output
182 if (from == 0) { // Constructor
183
184 }
185 }
186 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
187 if (from == 0) cout << "Instantiated: FGForce" << endl;
188 if (from == 1) cout << "Destroyed: FGForce" << endl;
189 }
190 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
191 }
192 if (debug_lvl & 8 ) { // Runtime state variables
193 }
194 if (debug_lvl & 16) { // Sanity checking
195 }
196 if (debug_lvl & 64) {
197 if (from == 0) { // Constructor
198 }
199 }
200}
201}
JSBSim::FGFDMExec * FDMExec
Definition JSBSim.cpp:88
This class implements a 3 element column vector.
FGColumnVector3 vOrient
Definition FGForce.h:312
virtual const FGColumnVector3 & GetBodyForces(void)
Definition FGForce.cpp:81
const FGMatrix33 & Transform(void) const
Definition FGForce.cpp:98
FGMassBalance * MassBalance
Definition FGForce.h:309
virtual ~FGForce()
Destructor.
Definition FGForce.cpp:74
void UpdateCustomTransformMatrix(void)
Definition FGForce.cpp:119
FGFDMExec * fdmex
Definition FGForce.h:308
FGColumnVector3 vMn
Definition FGForce.h:311
FGColumnVector3 vXYZn
Definition FGForce.h:314
FGMatrix33 mT
Definition FGForce.h:316
FGForce(FGFDMExec *FDMExec)
Constructor.
Definition FGForce.cpp:53
FGColumnVector3 vActingXYZn
Definition FGForce.h:315
void SetAnglesToBody(double broll, double bpitch, double byaw)
Definition FGForce.cpp:147
FGColumnVector3 vFn
Definition FGForce.h:310
TransformType ttype
Definition FGForce.h:313
static short debug_lvl
Definition FGJSBBase.h:190
Handles matrix math operations.
Definition FGMatrix33.h:70
short debug_lvl