1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGGroundReactions.cpp
6 Purpose: Encapsulates the ground reaction forces (gear and collision)
8 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.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"
42 #include <input_output/FGPropertyManager.h>
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_GROUNDREACTIONS;
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
56 Name = "FGGroundReactions";
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 FGGroundReactions::~FGGroundReactions(void)
67 for (unsigned int i=0; i<lGear.size();i++) delete lGear[i];
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 bool FGGroundReactions::InitModel(void)
77 if (!FGModel::InitModel()) return false;
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 bool FGGroundReactions::Run(void)
86 if (FGModel::Run()) return true;
87 if (FDMExec->Holding()) return false;
90 vMoments.InitMatrix();
92 // Sum forces and moments for all gear, here.
93 // Some optimizations may be made here - or rather in the gear code itself.
94 // The gear ::Run() method is called several times - once for each gear.
95 // Perhaps there is some commonality for things which only need to be
97 if ( Propagate->GetDistanceAGL() < 300.0 ) { // Only execute gear code below 300 feet
98 for (unsigned int i=0; i<lGear.size(); i++) {
99 vForces += lGear[i]->Force();
100 vMoments += lGear[i]->Moment();
108 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 bool FGGroundReactions::GetWOW(void)
113 for (unsigned int i=0; i<lGear.size(); i++) {
114 if (lGear[i]->IsBogey() && lGear[i]->GetWOW()) {
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 bool FGGroundReactions::Load(Element* el)
130 Element* contact_element = el->FindElement("contact");
131 while (contact_element) {
132 lGear.push_back(new FGLGear(contact_element, FDMExec, num++));
133 FCS->AddGear(); // make the FCS aware of the landing gear
134 contact_element = el->FindNextElement("contact");
137 for (unsigned int i=0; i<lGear.size();i++) lGear[i]->bind();
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 string FGGroundReactions::GetGroundReactionStrings(string delimeter)
146 std::ostringstream buf;
148 for (unsigned int i=0;i<lGear.size();i++) {
149 if (lGear[i]->IsBogey()) {
150 string name = lGear[i]->GetName();
151 buf << name << " WOW" << delimeter
152 << name << " stroke (ft)" << delimeter
153 << name << " stroke velocity (ft/sec)" << delimeter
154 << name << " compress force (lbs)" << delimeter
155 << name << " wheel side force (lbs)" << delimeter
156 << name << " wheel roll force (lbs)" << delimeter
157 << name << " body X force (lbs)" << delimeter
158 << name << " body Y force (lbs)" << delimeter
159 << name << " wheel velocity vec X (ft/sec)" << delimeter
160 << name << " wheel velocity vec Y (ft/sec)" << delimeter
161 << name << " wheel rolling velocity (ft/sec)" << delimeter
162 << name << " wheel side velocity (ft/sec)" << delimeter
163 << name << " wheel slip (deg)" << delimeter;
167 buf << " Total Gear Force_X (lbs)" << delimeter
168 << " Total Gear Force_Y (lbs)" << delimeter
169 << " Total Gear Force_Z (lbs)" << delimeter
170 << " Total Gear Moment_L (ft-lbs)" << delimeter
171 << " Total Gear Moment_M (ft-lbs)" << delimeter
172 << " Total Gear Moment_N (ft-lbs)";
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 string FGGroundReactions::GetGroundReactionValues(string delimeter)
181 std::ostringstream buf;
183 for (unsigned int i=0;i<lGear.size();i++) {
184 if (lGear[i]->IsBogey()) {
185 FGLGear *gear = lGear[i];
186 buf << (gear->GetWOW() ? "1, " : "0, ")
187 << setprecision(5) << gear->GetCompLen() << delimeter
188 << setprecision(6) << gear->GetCompVel() << delimeter
189 << setprecision(10) << gear->GetCompForce() << delimeter
190 << gear->GetWheelSideForce() << delimeter
191 << gear->GetWheelRollForce() << delimeter
192 << gear->GetBodyXForce() << delimeter
193 << gear->GetBodyYForce() << delimeter
194 << setprecision(6) << gear->GetWheelVel(eX) << delimeter
195 << gear->GetWheelVel(eY) << delimeter
196 << gear->GetWheelRollVel() << delimeter
197 << gear->GetWheelSideVel() << delimeter
198 << gear->GetWheelSlipAngle() << delimeter;
202 buf << vForces(eX) << delimeter
203 << vForces(eY) << delimeter
204 << vForces(eZ) << delimeter
205 << vMoments(eX) << delimeter
206 << vMoments(eY) << delimeter
212 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 void FGGroundReactions::bind(void)
216 typedef double (FGGroundReactions::*PMF)(int) const;
217 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
218 PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
219 PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
220 PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
221 PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
222 PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
223 PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 // The bitmasked value choices are as follows:
228 // unset: In this case (the default) JSBSim would only print
229 // out the normally expected messages, essentially echoing
230 // the config files as they are read. If the environment
231 // variable is not set, debug_lvl is set to 1 internally
232 // 0: This requests JSBSim not to output any messages
234 // 1: This value explicity requests the normal JSBSim
236 // 2: This value asks for a message to be printed out when
237 // a class is instantiated
238 // 4: When this value is set, a message is displayed when a
239 // FGModel object executes its Run() method
240 // 8: When this value is set, various runtime state variables
241 // are printed out periodically
242 // 16: When set various parameters are sanity checked and
243 // a message is printed out when they go out of bounds
245 void FGGroundReactions::Debug(int from)
247 if (debug_lvl <= 0) return;
249 if (debug_lvl & 1) { // Standard console startup message output
250 if (from == 2) { // Loading
251 cout << endl << " Ground Reactions: " << endl;
254 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
255 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
256 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
258 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
260 if (debug_lvl & 8 ) { // Runtime state variables
262 if (debug_lvl & 16) { // Sanity checking
264 if (debug_lvl & 64) {
265 if (from == 0) { // Constructor
266 cout << IdSrc << endl;
267 cout << IdHdr << endl;