JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
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 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 --------------------------------------------------------------------------------
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 forces from
37 their native coord system to the body system. This includes computing the
38 moments due to the difference between the point of application and the cg.
39 
40 */
41 
42 #include "FGForce.h"
43 #include "FGFDMExec.h"
44 #include "models/FGMassBalance.h"
45 #include "models/FGAuxiliary.h"
46 
47 using namespace std;
48 
49 namespace JSBSim {
50 
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 
53 FGForce::FGForce(FGFDMExec *FDMExec)
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 
81 const FGColumnVector3& FGForce::GetBodyForces(void)
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 
98 const FGMatrix33& FGForce::Transform(void) const
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 
119 void FGForce::UpdateCustomTransformMatrix(void)
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 
147 void 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 
154  UpdateCustomTransformMatrix();
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 
177 void 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
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGColumnVector3
This class implements a 3 element column vector.
Definition: FGColumnVector3.h:63
JSBSim::FGMassBalance::StructuralToBody
FGColumnVector3 StructuralToBody(const FGColumnVector3 &r) const
Conversion from the structural frame to the body frame.
Definition: FGMassBalance.cpp:364
JSBSim::FGFDMExec::GetAuxiliary
FGAuxiliary * GetAuxiliary(void)
Returns the FGAuxiliary pointer.
Definition: FGFDMExec.h:379
JSBSim::FGForce::~FGForce
virtual ~FGForce()
Destructor.
Definition: FGForce.cpp:74
JSBSim::FGAuxiliary::GetTw2b
const FGMatrix33 & GetTw2b(void) const
Calculates and returns the wind-to-body axis transformation matrix.
Definition: FGAuxiliary.h:190
JSBSim::FGFDMExec::GetPropagate
FGPropagate * GetPropagate(void)
Returns the FGPropagate pointer.
Definition: FGFDMExec.h:377
JSBSim::FGPropagate::GetTl2b
const FGMatrix33 & GetTl2b(void) const
Retrieves the local-to-body transformation matrix.
Definition: FGPropagate.h:465