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 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 General Public License for more
20 You should have received a copy of the GNU 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 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 #include "FGGroundReactions.h"
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_GROUNDREACTIONS;
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
50 Name = "FGGroundReactions";
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FGGroundReactions::~FGGroundReactions(void)
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 bool FGGroundReactions::Run(void)
66 if (!FGModel::Run()) {
68 vMoments.InitMatrix();
70 // Only execute gear force code below 300 feet
71 if ( Position->GetDistanceAGL() < 300.0 ) {
72 vector <FGLGear>::iterator iGear = lGear.begin();
73 // Sum forces and moments for all gear, here.
74 // Some optimizations may be made here - or rather in the gear code itself.
75 // The gear ::Run() method is called several times - once for each gear.
76 // Perhaps there is some commonality for things which only need to be
78 while (iGear != lGear.end()) {
79 vForces += iGear->Force();
80 vMoments += iGear->Moment();
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
100 AC_cfg->GetNextConfigLine();
102 while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
103 lGear.push_back(FGLGear(AC_cfg, FDMExec));
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 string FGGroundReactions::GetGroundReactionStrings(void)
113 string GroundReactionStrings = "";
114 bool firstime = true;
116 for (unsigned int i=0;i<lGear.size();i++) {
117 if (!firstime) GroundReactionStrings += ", ";
118 GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
119 GroundReactionStrings += (lGear[i].GetName() + "_stroke, ");
120 GroundReactionStrings += (lGear[i].GetName() + "_strokeVel, ");
121 GroundReactionStrings += (lGear[i].GetName() + "_CompressForce, ");
122 GroundReactionStrings += (lGear[i].GetName() + "_WhlSideForce, ");
123 GroundReactionStrings += (lGear[i].GetName() + "_WhlRollForce, ");
124 GroundReactionStrings += (lGear[i].GetName() + "_BodyXForce, ");
125 GroundReactionStrings += (lGear[i].GetName() + "_BodyYForce, ");
126 GroundReactionStrings += (lGear[i].GetName() + "_WhlSlipDegrees");
131 return GroundReactionStrings;
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 string FGGroundReactions::GetGroundReactionValues(void)
139 string GroundReactionValues = "";
141 bool firstime = true;
143 for (unsigned int i=0;i<lGear.size();i++) {
144 if (!firstime) GroundReactionValues += ", ";
145 GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
146 GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
147 GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
148 GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)) + ", ");
149 GroundReactionValues += (string(gcvt(lGear[i].GetWheelSideForce(), 6, buff)) + ", ");
150 GroundReactionValues += (string(gcvt(lGear[i].GetWheelRollForce(), 6, buff)) + ", ");
151 GroundReactionValues += (string(gcvt(lGear[i].GetBodyXForce(), 6, buff)) + ", ");
152 GroundReactionValues += (string(gcvt(lGear[i].GetBodyYForce(), 6, buff)) + ", ");
153 GroundReactionValues += (string(gcvt(lGear[i].GetWheelSlipAngle(), 6, buff)));
158 return GroundReactionValues;
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 // The bitmasked value choices are as follows:
163 // unset: In this case (the default) JSBSim would only print
164 // out the normally expected messages, essentially echoing
165 // the config files as they are read. If the environment
166 // variable is not set, debug_lvl is set to 1 internally
167 // 0: This requests JSBSim not to output any messages
169 // 1: This value explicity requests the normal JSBSim
171 // 2: This value asks for a message to be printed out when
172 // a class is instantiated
173 // 4: When this value is set, a message is displayed when a
174 // FGModel object executes its Run() method
175 // 8: When this value is set, various runtime state variables
176 // are printed out periodically
177 // 16: When set various parameters are sanity checked and
178 // a message is printed out when they go out of bounds
180 void FGGroundReactions::Debug(int from)
182 if (debug_lvl <= 0) return;
184 if (debug_lvl & 1) { // Standard console startup message output
185 if (from == 0) { // Constructor
189 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
190 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
191 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
193 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
195 if (debug_lvl & 8 ) { // Runtime state variables
197 if (debug_lvl & 16) { // Sanity checking
199 if (debug_lvl & 64) {
200 if (from == 0) { // Constructor
201 cout << IdSrc << endl;
202 cout << IdHdr << endl;