1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGGroundReactions.cpp
6 Purpose: Encapsulates the ground reaction forces (gear and collision)
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
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 Software
12 Foundation; either version 2 of the License, or (at your option) any later
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
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "FGGroundReactions.h"
43 #include "input_output/FGPropertyManager.h"
49 static const char *IdSrc = "$Id: FGGroundReactions.cpp,v 1.31 2010/11/18 12:38:06 jberndt Exp $";
50 static const char *IdHdr = ID_GROUNDREACTIONS;
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS IMPLEMENTATION for MultiplierIterator (See below for FGGroundReactions)
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 MultiplierIterator::MultiplierIterator(FGGroundReactions* GndReactions)
57 : GroundReactions(GndReactions),
62 for (int i=0; i < GroundReactions->GetNumGearUnits(); i++) {
63 FGLGear* gear = GroundReactions->GetGearUnit(i);
65 if (!gear->GetWOW()) continue;
68 multiplier = gear->GetMultiplierEntry(0);
73 MultiplierIterator& MultiplierIterator::operator++()
75 for (int i=gearNum; i < GroundReactions->GetNumGearUnits(); i++) {
76 FGLGear* gear = GroundReactions->GetGearUnit(i);
78 if (!gear->GetWOW()) continue;
80 multiplier = gear->GetMultiplierEntry(++entry);
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
98 Name = "FGGroundReactions";
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 FGGroundReactions::~FGGroundReactions(void)
109 for (unsigned int i=0; i<lGear.size();i++) delete lGear[i];
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 bool FGGroundReactions::InitModel(void)
119 if (!FGModel::InitModel()) return false;
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 bool FGGroundReactions::Run(void)
128 if (FGModel::Run()) return true;
129 if (FDMExec->Holding()) return false;
133 vForces.InitMatrix();
134 vMoments.InitMatrix();
136 // Sum forces and moments for all gear, here.
137 // Some optimizations may be made here - or rather in the gear code itself.
138 // The gear ::Run() method is called several times - once for each gear.
139 // Perhaps there is some commonality for things which only need to be
141 for (unsigned int i=0; i<lGear.size(); i++) {
142 vForces += lGear[i]->GetBodyForces();
143 vMoments += lGear[i]->GetMoments();
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 bool FGGroundReactions::GetWOW(void) const
156 for (unsigned int i=0; i<lGear.size(); i++) {
157 if (lGear[i]->IsBogey() && lGear[i]->GetWOW()) {
165 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 // This function must be called after friction forces are resolved in order to
167 // include them in the ground reactions total force and moment.
168 void FGGroundReactions::UpdateForcesAndMoments(void)
170 vForces.InitMatrix();
171 vMoments.InitMatrix();
173 for (unsigned int i=0; i<lGear.size(); i++) {
174 vForces += lGear[i]->UpdateForces();
175 vMoments += lGear[i]->GetMoments();
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 bool FGGroundReactions::Load(Element* el)
187 Element* contact_element = el->FindElement("contact");
188 while (contact_element) {
189 lGear.push_back(new FGLGear(contact_element, FDMExec, num++));
190 FDMExec->GetFCS()->AddGear(); // make the FCS aware of the landing gear
191 contact_element = el->FindNextElement("contact");
194 FGModel::Load(el); // Perform base class Load
196 for (unsigned int i=0; i<lGear.size();i++) lGear[i]->bind();
198 PostLoad(el, PropertyManager);
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 string FGGroundReactions::GetGroundReactionStrings(string delimeter) const
207 std::ostringstream buf;
209 for (unsigned int i=0;i<lGear.size();i++) {
210 if (lGear[i]->IsBogey()) {
211 string name = lGear[i]->GetName();
212 buf << name << " WOW" << delimeter
213 << name << " stroke (ft)" << delimeter
214 << name << " stroke velocity (ft/sec)" << delimeter
215 << name << " compress force (lbs)" << delimeter
216 << name << " wheel side force (lbs)" << delimeter
217 << name << " wheel roll force (lbs)" << delimeter
218 << name << " body X force (lbs)" << delimeter
219 << name << " body Y force (lbs)" << delimeter
220 << name << " wheel velocity vec X (ft/sec)" << delimeter
221 << name << " wheel velocity vec Y (ft/sec)" << delimeter
222 << name << " wheel rolling velocity (ft/sec)" << delimeter
223 << name << " wheel side velocity (ft/sec)" << delimeter
224 << name << " wheel slip (deg)" << delimeter;
228 buf << " Total Gear Force_X (lbs)" << delimeter
229 << " Total Gear Force_Y (lbs)" << delimeter
230 << " Total Gear Force_Z (lbs)" << delimeter
231 << " Total Gear Moment_L (ft-lbs)" << delimeter
232 << " Total Gear Moment_M (ft-lbs)" << delimeter
233 << " Total Gear Moment_N (ft-lbs)";
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 string FGGroundReactions::GetGroundReactionValues(string delimeter) const
242 std::ostringstream buf;
244 for (unsigned int i=0;i<lGear.size();i++) {
245 if (lGear[i]->IsBogey()) {
246 FGLGear *gear = lGear[i];
247 buf << (gear->GetWOW() ? "1" : "0") << delimeter
248 << setprecision(5) << gear->GetCompLen() << delimeter
249 << setprecision(6) << gear->GetCompVel() << delimeter
250 << setprecision(10) << gear->GetCompForce() << delimeter
251 << gear->GetWheelSideForce() << delimeter
252 << gear->GetWheelRollForce() << delimeter
253 << gear->GetBodyXForce() << delimeter
254 << gear->GetBodyYForce() << delimeter
255 << setprecision(6) << gear->GetWheelVel(eX) << delimeter
256 << gear->GetWheelVel(eY) << delimeter
257 << gear->GetWheelRollVel() << delimeter
258 << gear->GetWheelSideVel() << delimeter
259 << gear->GetWheelSlipAngle() << delimeter;
263 buf << vForces(eX) << delimeter
264 << vForces(eY) << delimeter
265 << vForces(eZ) << delimeter
266 << vMoments(eX) << delimeter
267 << vMoments(eY) << delimeter
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 void FGGroundReactions::bind(void)
277 typedef double (FGGroundReactions::*PMF)(int) const;
278 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
279 PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW);
280 PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
281 PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
282 PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
283 PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
284 PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
285 PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
288 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 // The bitmasked value choices are as follows:
290 // unset: In this case (the default) JSBSim would only print
291 // out the normally expected messages, essentially echoing
292 // the config files as they are read. If the environment
293 // variable is not set, debug_lvl is set to 1 internally
294 // 0: This requests JSBSim not to output any messages
296 // 1: This value explicity requests the normal JSBSim
298 // 2: This value asks for a message to be printed out when
299 // a class is instantiated
300 // 4: When this value is set, a message is displayed when a
301 // FGModel object executes its Run() method
302 // 8: When this value is set, various runtime state variables
303 // are printed out periodically
304 // 16: When set various parameters are sanity checked and
305 // a message is printed out when they go out of bounds
307 void FGGroundReactions::Debug(int from)
309 if (debug_lvl <= 0) return;
311 if (debug_lvl & 1) { // Standard console startup message output
312 if (from == 2) { // Loading
313 cout << endl << " Ground Reactions: " << endl;
316 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
317 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
318 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
320 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
322 if (debug_lvl & 8 ) { // Runtime state variables
324 if (debug_lvl & 16) { // Sanity checking
326 if (debug_lvl & 64) {
327 if (from == 0) { // Constructor
328 cout << IdSrc << endl;
329 cout << IdHdr << endl;