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
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),
56 FGSurface(fgex),
57 DsCmd(0.0)
58{
59 Name = "FGGroundReactions";
60
61 bind();
62
63 Debug(0);
64}
65
66//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68bool FGGroundReactions::InitModel(void)
69{
70 if (!FGModel::InitModel()) return false;
71
72 vForces.InitMatrix();
73 vMoments.InitMatrix();
74 DsCmd = 0.0;
75
76 multipliers.clear();
77
78 for (auto& gear: lGear)
79 gear->ResetToIC();
80
81 return true;
82}
83
84//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86bool FGGroundReactions::Run(bool Holding)
87{
88 if (FGModel::Run(Holding)) return true;
89 if (Holding) return false;
90
91 RunPreFunctions();
92
93 vForces.InitMatrix();
94 vMoments.InitMatrix();
95
96 multipliers.clear();
97
98 // Sum forces and moments for all gear, here.
99 // Some optimizations may be made here - or rather in the gear code itself.
100 // The gear ::Run() method is called several times - once for each gear.
101 // Perhaps there is some commonality for things which only need to be
102 // calculated once.
103 for (auto& gear:lGear) {
104 vForces += gear->GetBodyForces();
105 vMoments += gear->GetMoments();
106 }
107
108 RunPostFunctions();
109
110 return false;
111}
112
113//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115bool FGGroundReactions::GetWOW(void) const
116{
117 for (auto& gear:lGear) {
118 if (gear->IsBogey() && gear->GetWOW())
119 return true;
120 }
121 return false;
122}
123
124//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125
126void FGGroundReactions::SetDsCmd(double cmd)
127{
128 DsCmd = cmd;
129 for (auto& gear:lGear)
130 gear->SetSteerCmd(cmd);
131}
132
133//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135bool FGGroundReactions::Load(Element* document)
136{
137 int num=0;
138
139 Name = "Ground Reactions Model: " + document->GetAttributeValue("name");
140
141 Debug(2);
142
143 // Perform base class Pre-Load
144 if (!FGModel::Upload(document, true))
145 return false;
146
147 Element* contact_element = document->FindElement("contact");
148 while (contact_element) {
149 lGear.push_back(make_shared<FGLGear>(contact_element, FDMExec, num++, in));
150 contact_element = document->FindNextElement("contact");
151 }
152
153 PostLoad(document, FDMExec);
154
155 return true;
156}
157
158//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
160string FGGroundReactions::GetGroundReactionStrings(string delimeter) const
161{
162 std::ostringstream buf;
163
164 for (auto& gear:lGear) {
165 string name = gear->GetName();
166 if (gear->IsBogey()) {
167 buf << name << " WOW" << delimeter
168 << name << " stroke (ft)" << delimeter
169 << name << " stroke velocity (ft/sec)" << delimeter
170 << name << " compress force (lbs)" << delimeter
171 << name << " wheel side force (lbs)" << delimeter
172 << name << " wheel roll force (lbs)" << delimeter
173 << name << " body X force (lbs)" << delimeter
174 << name << " body Y force (lbs)" << delimeter
175 << name << " wheel velocity vec X (ft/sec)" << delimeter
176 << name << " wheel velocity vec Y (ft/sec)" << delimeter
177 << name << " wheel rolling velocity (ft/sec)" << delimeter
178 << name << " wheel side velocity (ft/sec)" << delimeter
179 << name << " wheel slip (deg)" << delimeter;
180 } else {
181 buf << name << " WOW" << delimeter
182 << name << " stroke (ft)" << delimeter
183 << name << " stroke velocity (ft/sec)" << delimeter
184 << name << " compress force (lbs)" << delimeter;
185 }
186 }
187
188 buf << " Total Gear Force_X (lbs)" << delimeter
189 << " Total Gear Force_Y (lbs)" << delimeter
190 << " Total Gear Force_Z (lbs)" << delimeter
191 << " Total Gear Moment_L (ft-lbs)" << delimeter
192 << " Total Gear Moment_M (ft-lbs)" << delimeter
193 << " Total Gear Moment_N (ft-lbs)";
194
195 return buf.str();
196}
197
198//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199
200string FGGroundReactions::GetGroundReactionValues(string delimeter) const
201{
202 std::ostringstream buf;
203
204 for (auto& gear: lGear) {
205 if (gear->IsBogey()) {
206 buf << (gear->GetWOW() ? "1" : "0") << delimeter
207 << setprecision(5) << gear->GetCompLen() << delimeter
208 << setprecision(6) << gear->GetCompVel() << delimeter
209 << setprecision(10) << gear->GetCompForce() << delimeter
210 << gear->GetWheelSideForce() << delimeter
211 << gear->GetWheelRollForce() << delimeter
212 << gear->GetBodyXForce() << delimeter
213 << gear->GetBodyYForce() << delimeter
214 << setprecision(6) << gear->GetWheelVel(eX) << delimeter
215 << gear->GetWheelVel(eY) << delimeter
216 << gear->GetWheelRollVel() << delimeter
217 << gear->GetWheelSideVel() << delimeter
218 << gear->GetWheelSlipAngle() << delimeter;
219 } else {
220 buf << (gear->GetWOW() ? "1" : "0") << delimeter
221 << setprecision(5) << gear->GetCompLen() << delimeter
222 << setprecision(6) << gear->GetCompVel() << delimeter
223 << setprecision(10) << gear->GetCompForce() << delimeter;
224 }
225 }
226
227 auto Accelerations = FDMExec->GetAccelerations();
228
229 buf << Accelerations->GetGroundForces(eX) << delimeter
230 << Accelerations->GetGroundForces(eY) << delimeter
231 << Accelerations->GetGroundForces(eZ) << delimeter
232 << Accelerations->GetGroundMoments(eX) << delimeter
233 << Accelerations->GetGroundMoments(eY) << delimeter
234 << Accelerations->GetGroundMoments(eZ);
235
236 return buf.str();
237}
238
239//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240
241void FGGroundReactions::bind(void)
242{
243 FGSurface::bind(PropertyManager.get());
244
245 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
246 PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW);
247 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGGroundReactions::GetDsCmd,
248 &FGGroundReactions::SetDsCmd);
249}
250
251//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252// The bitmasked value choices are as follows:
253// unset: In this case (the default) JSBSim would only print
254// out the normally expected messages, essentially echoing
255// the config files as they are read. If the environment
256// variable is not set, debug_lvl is set to 1 internally
257// 0: This requests JSBSim not to output any messages
258// whatsoever.
259// 1: This value explicity requests the normal JSBSim
260// startup messages
261// 2: This value asks for a message to be printed out when
262// a class is instantiated
263// 4: When this value is set, a message is displayed when a
264// FGModel object executes its Run() method
265// 8: When this value is set, various runtime state variables
266// are printed out periodically
267// 16: When set various parameters are sanity checked and
268// a message is printed out when they go out of bounds
269
270void FGGroundReactions::Debug(int from)
271{
272 if (debug_lvl <= 0) return;
273
274 if (debug_lvl & 1) { // Standard console startup message output
275 if (from == 2) { // Loading
276 FGLogging log(LogLevel::DEBUG);
277 log << "\n Ground Reactions: \n";
278 }
279 }
280 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
281 FGLogging log(LogLevel::DEBUG);
282 if (from == 0) log << "Instantiated: FGGroundReactions\n";
283 if (from == 1) log << "Destroyed: FGGroundReactions\n";
284 }
285 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
286 }
287 if (debug_lvl & 8 ) { // Runtime state variables
288 }
289 if (debug_lvl & 16) { // Sanity checking
290 }
291 if (debug_lvl & 64) {
292 if (from == 0) { // Constructor
293 }
294 }
295}
296}
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:71