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() + "_compressLength, ");
120 GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
121 GroundReactionStrings += (lGear[i].GetName() + "_Force");
126 return GroundReactionStrings;
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 string FGGroundReactions::GetGroundReactionValues(void)
134 string GroundReactionValues = "";
136 bool firstime = true;
138 for (unsigned int i=0;i<lGear.size();i++) {
139 if (!firstime) GroundReactionValues += ", ";
140 GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
141 GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
142 GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
143 GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
148 return GroundReactionValues;
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 // The bitmasked value choices are as follows:
153 // unset: In this case (the default) JSBSim would only print
154 // out the normally expected messages, essentially echoing
155 // the config files as they are read. If the environment
156 // variable is not set, debug_lvl is set to 1 internally
157 // 0: This requests JSBSim not to output any messages
159 // 1: This value explicity requests the normal JSBSim
161 // 2: This value asks for a message to be printed out when
162 // a class is instantiated
163 // 4: When this value is set, a message is displayed when a
164 // FGModel object executes its Run() method
165 // 8: When this value is set, various runtime state variables
166 // are printed out periodically
167 // 16: When set various parameters are sanity checked and
168 // a message is printed out when they go out of bounds
170 void FGGroundReactions::Debug(int from)
172 if (debug_lvl <= 0) return;
174 if (debug_lvl & 1) { // Standard console startup message output
175 if (from == 0) { // Constructor
179 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
180 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
181 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
183 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
185 if (debug_lvl & 8 ) { // Runtime state variables
187 if (debug_lvl & 16) { // Sanity checking
189 if (debug_lvl & 64) {
190 if (from == 0) { // Constructor
191 cout << IdSrc << endl;
192 cout << IdHdr << endl;