JSBSim Flight Dynamics Model 1.3.3 (16 Oct 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGGroundReactions.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGGroundReactions.cpp
4 Author: Jon S. Berndt
5 Date started: 09/13/00
6 Purpose: Encapsulates the ground reaction forces (gear and collision)
7
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 2 of the License, or (at your option) any
13 later version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18 details.
19
20 You should have received a copy of the GNU Lesser General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 Further information about the GNU Lesser General Public License can also be
25 found on the world wide web at http://www.gnu.org.
26
27FUNCTIONAL DESCRIPTION
28--------------------------------------------------------------------------------
29
30HISTORY
31--------------------------------------------------------------------------------
3209/13/00 JSB Created
33
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35INCLUDES
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38#include <iomanip>
39
40#include "FGFDMExec.h"
41#include "FGGroundReactions.h"
42#include "FGAccelerations.h"
43#include "input_output/FGXMLElement.h"
44#include "input_output/FGLog.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS IMPLEMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) :
55 FGModel(fgex, "FGGroundReactions"),
56 FGSurface(fgex),
57 DsCmd(0.0)
58{
59 bind();
60
61 Debug(0);
62}
63
64//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
66bool FGGroundReactions::InitModel(void)
67{
68 if (!FGModel::InitModel()) return false;
69
70 vForces.InitMatrix();
71 vMoments.InitMatrix();
72 DsCmd = 0.0;
73
74 multipliers.clear();
75
76 for (auto& gear: lGear)
77 gear->ResetToIC();
78
79 return true;
80}
81
82//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84bool FGGroundReactions::Run(bool Holding)
85{
86 if (FGModel::Run(Holding)) return true;
87 if (Holding) return false;
88
89 RunPreFunctions();
90
91 vForces.InitMatrix();
92 vMoments.InitMatrix();
93
94 multipliers.clear();
95
96 // Sum forces and moments for all gear, here.
97 // Some optimizations may be made here - or rather in the gear code itself.
98 // The gear ::Run() method is called several times - once for each gear.
99 // Perhaps there is some commonality for things which only need to be
100 // calculated once.
101 for (auto& gear:lGear) {
102 vForces += gear->GetBodyForces();
103 vMoments += gear->GetMoments();
104 }
105
106 RunPostFunctions();
107
108 return false;
109}
110
111//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112
113bool FGGroundReactions::GetWOW(void) const
114{
115 for (auto& gear:lGear) {
116 if (gear->IsBogey() && gear->GetWOW())
117 return true;
118 }
119 return false;
120}
121
122//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124void FGGroundReactions::SetDsCmd(double cmd)
125{
126 DsCmd = cmd;
127 for (auto& gear:lGear)
128 gear->SetSteerCmd(cmd);
129}
130
131//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133bool FGGroundReactions::Load(Element* document)
134{
135 int num=0;
136
137 Name = "Ground Reactions Model: " + document->GetAttributeValue("name");
138
139 Debug(2);
140
141 // Perform base class Pre-Load
142 if (!FGModel::Upload(document, true))
143 return false;
144
145 Element* contact_element = document->FindElement("contact");
146 while (contact_element) {
147 lGear.push_back(make_shared<FGLGear>(contact_element, FDMExec, num++, in));
148 contact_element = document->FindNextElement("contact");
149 }
150
151 PostLoad(document, FDMExec);
152
153 return true;
154}
155
156//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158string FGGroundReactions::GetGroundReactionStrings(string delimeter) const
159{
160 std::ostringstream buf;
161
162 for (auto& gear:lGear) {
163 string name = gear->GetName();
164 if (gear->IsBogey()) {
165 buf << name << " WOW" << delimeter
166 << name << " stroke (ft)" << delimeter
167 << name << " stroke velocity (ft/sec)" << delimeter
168 << name << " compress force (lbs)" << delimeter
169 << name << " wheel side force (lbs)" << delimeter
170 << name << " wheel roll force (lbs)" << delimeter
171 << name << " body X force (lbs)" << delimeter
172 << name << " body Y force (lbs)" << delimeter
173 << name << " wheel velocity vec X (ft/sec)" << delimeter
174 << name << " wheel velocity vec Y (ft/sec)" << delimeter
175 << name << " wheel rolling velocity (ft/sec)" << delimeter
176 << name << " wheel side velocity (ft/sec)" << delimeter
177 << name << " wheel slip (deg)" << delimeter;
178 } else {
179 buf << name << " WOW" << delimeter
180 << name << " stroke (ft)" << delimeter
181 << name << " stroke velocity (ft/sec)" << delimeter
182 << name << " compress force (lbs)" << delimeter;
183 }
184 }
185
186 buf << " Total Gear Force_X (lbs)" << delimeter
187 << " Total Gear Force_Y (lbs)" << delimeter
188 << " Total Gear Force_Z (lbs)" << delimeter
189 << " Total Gear Moment_L (ft-lbs)" << delimeter
190 << " Total Gear Moment_M (ft-lbs)" << delimeter
191 << " Total Gear Moment_N (ft-lbs)";
192
193 return buf.str();
194}
195
196//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197
198string FGGroundReactions::GetGroundReactionValues(string delimeter) const
199{
200 std::ostringstream buf;
201
202 for (auto& gear: lGear) {
203 if (gear->IsBogey()) {
204 buf << (gear->GetWOW() ? "1" : "0") << delimeter
205 << setprecision(5) << gear->GetCompLen() << delimeter
206 << setprecision(6) << gear->GetCompVel() << delimeter
207 << setprecision(10) << gear->GetCompForce() << delimeter
208 << gear->GetWheelSideForce() << delimeter
209 << gear->GetWheelRollForce() << delimeter
210 << gear->GetBodyXForce() << delimeter
211 << gear->GetBodyYForce() << delimeter
212 << setprecision(6) << gear->GetWheelVel(eX) << delimeter
213 << gear->GetWheelVel(eY) << delimeter
214 << gear->GetWheelRollVel() << delimeter
215 << gear->GetWheelSideVel() << delimeter
216 << gear->GetWheelSlipAngle() << delimeter;
217 } else {
218 buf << (gear->GetWOW() ? "1" : "0") << delimeter
219 << setprecision(5) << gear->GetCompLen() << delimeter
220 << setprecision(6) << gear->GetCompVel() << delimeter
221 << setprecision(10) << gear->GetCompForce() << delimeter;
222 }
223 }
224
225 auto Accelerations = FDMExec->GetAccelerations();
226
227 buf << Accelerations->GetGroundForces(eX) << delimeter
228 << Accelerations->GetGroundForces(eY) << delimeter
229 << Accelerations->GetGroundForces(eZ) << delimeter
230 << Accelerations->GetGroundMoments(eX) << delimeter
231 << Accelerations->GetGroundMoments(eY) << delimeter
232 << Accelerations->GetGroundMoments(eZ);
233
234 return buf.str();
235}
236
237//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238
239void FGGroundReactions::bind(void)
240{
241 FGSurface::bind(PropertyManager.get());
242
243 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
244 PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW);
245 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGGroundReactions::GetDsCmd,
246 &FGGroundReactions::SetDsCmd);
247}
248
249//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250// The bitmasked value choices are as follows:
251// unset: In this case (the default) JSBSim would only print
252// out the normally expected messages, essentially echoing
253// the config files as they are read. If the environment
254// variable is not set, debug_lvl is set to 1 internally
255// 0: This requests JSBSim not to output any messages
256// whatsoever.
257// 1: This value explicity requests the normal JSBSim
258// startup messages
259// 2: This value asks for a message to be printed out when
260// a class is instantiated
261// 4: When this value is set, a message is displayed when a
262// FGModel object executes its Run() method
263// 8: When this value is set, various runtime state variables
264// are printed out periodically
265// 16: When set various parameters are sanity checked and
266// a message is printed out when they go out of bounds
267
268void FGGroundReactions::Debug(int from)
269{
270 if (debug_lvl <= 0) return;
271
272 if (debug_lvl & 1) { // Standard console startup message output
273 if (from == 2) { // Loading
274 FGLogging log(LogLevel::DEBUG);
275 log << "\n Ground Reactions: \n";
276 }
277 }
278 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
279 FGLogging log(LogLevel::DEBUG);
280 if (from == 0) log << "Instantiated: FGGroundReactions\n";
281 if (from == 1) log << "Destroyed: FGGroundReactions\n";
282 }
283 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
284 }
285 if (debug_lvl & 8 ) { // Runtime state variables
286 }
287 if (debug_lvl & 16) { // Sanity checking
288 }
289 if (debug_lvl & 64) {
290 if (from == 0) { // Constructor
291 }
292 }
293}
294}
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
std::shared_ptr< FGAccelerations > GetAccelerations(void) const
Returns the FGAccelerations pointer.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:73