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 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 bool FGGroundReactions::Run(void)
65 // double steerAngle = 0.0;
66 // double xForces = 0.0, yForces = 0.0;
68 if (!FGModel::Run()) {
70 vMoments.InitMatrix();
72 // Only execute gear force code below 300 feet
73 if ( Position->GetDistanceAGL() < 300.0 ) {
74 vector <FGLGear>::iterator iGear = lGear.begin();
75 // Sum forces and moments for all gear, here.
76 // Some optimizations may be made here - or rather in the gear code itself.
77 // The gear ::Run() method is called several times - once for each gear.
78 // Perhaps there is some commonality for things which only need to be
80 while (iGear != lGear.end()) {
81 vForces += iGear->Force();
82 vMoments += iGear->Moment();
86 // Only execute this code when the aircraft ground speed is very, very small.
88 if (fabs(Translation->GetUVW(eX)) < 0.1 &&
89 fabs(Translation->GetUVW(eZ)) < 0.1)
91 // Initialize the comparison matrices.
92 vMaxStaticGrip.InitMatrix();
93 vMaxMomentResist.InitMatrix();
94 iGear = lGear.begin();
95 // For each gear that is touching the ground (which had better be all of them!)
96 // calculate the X and Y direction maximum "gripping" power. Also, keep track
97 // of the number of gear that have weight on wheels. This is probably unnecessary.
98 while (iGear != lGear.end()) {
99 // calculate maximum gripping power for each gear here based on brake
100 // and steering settings
101 // also calculate total number of wheels with WOW set true?
102 if (iGear->GetWOW()) {
103 steerAngle = iGear->GetSteerAngle();
104 vMaxStaticGrip(eX) += (iGear->GetBrakeFCoeff()*cos(steerAngle) -
105 iGear->GetstaticFCoeff()*sin(steerAngle))*iGear->GetCompForce();
106 vMaxStaticGrip(eY) += iGear->GetBrakeFCoeff()*sin(steerAngle) +
107 iGear->GetstaticFCoeff()*cos(steerAngle)*iGear->GetCompForce();
108 vMaxStaticGrip(eZ) = 0.0;
109 // vMaxMomentResist += 1;
114 // Calculate the X and Y direction non-gear forces to counteract if needed.
115 xForces = -1.0 * ( Aerodynamics->GetForces(eX)
116 + Propulsion->GetForces(eX)
117 + Inertial->GetForces(eX));
119 yForces = -1.0 * ( Aerodynamics->GetForces(eY)
120 + Propulsion->GetForces(eY)
121 + Inertial->GetForces(eY));
123 // These if statement comparisons probably need some validation and work
124 if (fabs(xForces) < fabs(vMaxStaticGrip(eX))) { // forces exceed gear power
125 vForces(eX) = xForces;
128 if (fabs(yForces) < fabs(vMaxStaticGrip(eY))) { // forces exceed gear power
129 vForces(eY) = yForces;
132 vMoments(eZ) = -(Aerodynamics->GetMoments(eZ) + Propulsion->GetMoments(eZ));
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
151 AC_cfg->GetNextConfigLine();
153 while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
154 lGear.push_back(FGLGear(AC_cfg, FDMExec));
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 string FGGroundReactions::GetGroundReactionStrings(void)
164 string GroundReactionStrings = "";
165 bool firstime = true;
167 for (unsigned int i=0;i<lGear.size();i++) {
168 if (!firstime) GroundReactionStrings += ", ";
169 GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
170 GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
171 GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
172 GroundReactionStrings += (lGear[i].GetName() + "_Force");
177 return GroundReactionStrings;
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 string FGGroundReactions::GetGroundReactionValues(void)
185 string GroundReactionValues = "";
187 bool firstime = true;
189 for (unsigned int i=0;i<lGear.size();i++) {
190 if (!firstime) GroundReactionValues += ", ";
191 GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
192 GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
193 GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
194 GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
199 return GroundReactionValues;
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 // The bitmasked value choices are as follows:
204 // unset: In this case (the default) JSBSim would only print
205 // out the normally expected messages, essentially echoing
206 // the config files as they are read. If the environment
207 // variable is not set, debug_lvl is set to 1 internally
208 // 0: This requests JSBSim not to output any messages
210 // 1: This value explicity requests the normal JSBSim
212 // 2: This value asks for a message to be printed out when
213 // a class is instantiated
214 // 4: When this value is set, a message is displayed when a
215 // FGModel object executes its Run() method
216 // 8: When this value is set, various runtime state variables
217 // are printed out periodically
218 // 16: When set various parameters are sanity checked and
219 // a message is printed out when they go out of bounds
221 void FGGroundReactions::Debug(int from)
223 if (debug_lvl <= 0) return;
225 if (debug_lvl & 1) { // Standard console startup message output
226 if (from == 0) { // Constructor
230 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
231 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
232 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
234 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
236 if (debug_lvl & 8 ) { // Runtime state variables
238 if (debug_lvl & 16) { // Sanity checking
240 if (debug_lvl & 64) {
241 if (from == 0) { // Constructor
242 cout << IdSrc << endl;
243 cout << IdHdr << endl;