JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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--------------------------------------------------------------------------------
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"
44#include "models/FGAuxiliary.h"
45#include "input_output/FGLog.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
81const 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
98const 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 tInertialBody:
106 return fdmex->GetPropagate()->GetTi2b();
107 case tCustom:
108 case tNone:
109 return mT;
110 default:
111 {
112 LogException err;
113 err << "Unrecognized tranform requested from FGForce::Transform()\n";
114 throw err;
115 }
116 }
117}
118
119//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121void FGForce::UpdateCustomTransformMatrix(void)
122{
123 double cp,sp,cr,sr,cy,sy;
124 double srsp, crcy, crsy;
125
126 cp=cos(vOrient(ePitch)); sp=sin(vOrient(ePitch));
127 cr=cos(vOrient(eRoll)); sr=sin(vOrient(eRoll));
128 cy=cos(vOrient(eYaw)); sy=sin(vOrient(eYaw));
129
130 srsp = sr*sp;
131 crcy = cr*cy;
132 crsy = cr*sy;
133
134 mT(1,1) = cp*cy;
135 mT(2,1) = cp*sy;
136 mT(3,1) = -sp;
137
138 mT(1,2) = srsp*cy - crsy;
139 mT(2,2) = srsp*sy + crcy;
140 mT(3,2) = sr*cp;
141
142 mT(1,3) = crcy*sp + sr*sy;
143 mT(2,3) = crsy*sp - sr*cy;
144 mT(3,3) = cr*cp;
145}
146
147//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw)
150{
151 if (ttype == tCustom) {
152 vOrient(ePitch) = bpitch;
153 vOrient(eRoll) = broll;
154 vOrient(eYaw) = byaw;
155
156 UpdateCustomTransformMatrix();
157 }
158}
159
160//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161// The bitmasked value choices are as follows:
162// unset: In this case (the default) JSBSim would only print
163// out the normally expected messages, essentially echoing
164// the config files as they are read. If the environment
165// variable is not set, debug_lvl is set to 1 internally
166// 0: This requests JSBSim not to output any messages
167// whatsoever.
168// 1: This value explicity requests the normal JSBSim
169// startup messages
170// 2: This value asks for a message to be printed out when
171// a class is instantiated
172// 4: When this value is set, a message is displayed when a
173// FGModel object executes its Run() method
174// 8: When this value is set, various runtime state variables
175// are printed out periodically
176// 16: When set various parameters are sanity checked and
177// a message is printed out when they go out of bounds
178
179void FGForce::Debug(int from)
180{
181 if (debug_lvl <= 0) return;
182
183 if (debug_lvl & 1) { // Standard console startup message output
184 if (from == 0) { // Constructor
185 }
186 }
187 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
188 FGLogging log(LogLevel::DEBUG);
189 if (from == 0) log << "Instantiated: FGForce\n";
190 if (from == 1) log << "Destroyed: FGForce\n";
191 }
192 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
193 }
194 if (debug_lvl & 8 ) { // Runtime state variables
195 }
196 if (debug_lvl & 16) { // Sanity checking
197 }
198 if (debug_lvl & 64) {
199 if (from == 0) { // Constructor
200 }
201 }
202}
203}
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
std::shared_ptr< FGPropagate > GetPropagate(void) const
Returns the FGPropagate pointer.
std::shared_ptr< FGAuxiliary > GetAuxiliary(void) const
Returns the FGAuxiliary pointer.
virtual ~FGForce()
Destructor.
Definition FGForce.cpp:74
FGForce(FGFDMExec *FDMExec)
Constructor.
Definition FGForce.cpp:53
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71