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),
54 Name = "FGGroundReactions";
57 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
60 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 bool FGGroundReactions::Run(void)
64 double steerAngle = 0.0;
65 double xForces = 0.0, yForces = 0.0;
67 if (!FGModel::Run()) {
69 vMoments.InitMatrix();
71 // Only execute gear force code below 300 feet
72 if ( !GearUp && Position->GetDistanceAGL() < 300.0 ) {
73 vector <FGLGear>::iterator iGear = lGear.begin();
74 // Sum forces and moments for all gear, here.
75 // Some optimizations may be made here - or rather in the gear code itself.
76 // The gear ::Run() method is called several times - once for each gear.
77 // Perhaps there is some commonality for things which only need to be
79 while (iGear != lGear.end()) {
80 vForces += iGear->Force();
81 vMoments += iGear->Moment();
85 // Only execute this code when the aircraft ground speed is very, very small.
86 if (fabs(Translation->GetUVW(eX)) < 0.1 &&
87 fabs(Translation->GetUVW(eZ)) < 0.1)
89 // Initialize the comparison matrices.
90 vMaxStaticGrip.InitMatrix();
91 vMaxMomentResist.InitMatrix();
92 iGear = lGear.begin();
93 // For each gear that is touching the ground (which had better be all of them!)
94 // calculate the X and Y direction maximum "gripping" power. Also, keep track
95 // of the number of gear that have weight on wheels. This is probably unnecessary.
96 while (iGear != lGear.end()) {
97 // calculate maximum gripping power for each gear here based on brake
98 // and steering settings
99 // also calculate total number of wheels with WOW set true?
100 if (iGear->GetWOW()) {
101 steerAngle = iGear->GetSteerAngle();
102 vMaxStaticGrip(eX) += (iGear->GetBrakeFCoeff()*cos(steerAngle) -
103 iGear->GetstaticFCoeff()*sin(steerAngle))*iGear->GetCompForce();
104 vMaxStaticGrip(eY) += iGear->GetBrakeFCoeff()*sin(steerAngle) +
105 iGear->GetstaticFCoeff()*cos(steerAngle)*iGear->GetCompForce();
106 vMaxStaticGrip(eZ) = 0.0;
107 // vMaxMomentResist += 1;
112 // Calculate the X and Y direction non-gear forces to counteract if needed.
113 xForces = -1.0 * ( Aerodynamics->GetForces(eX)
114 + Propulsion->GetForces(eX)
115 + Inertial->GetForces(eX));
117 yForces = -1.0 * ( Aerodynamics->GetForces(eY)
118 + Propulsion->GetForces(eY)
119 + Inertial->GetForces(eY));
121 // These if statement comparisons probably need some validation and work
122 if (fabs(xForces) < fabs(vMaxStaticGrip(eX))) { // forces exceed gear power
123 vForces(eX) = xForces;
126 if (fabs(yForces) < fabs(vMaxStaticGrip(eY))) { // forces exceed gear power
127 vForces(eY) = yForces;
130 vMoments(eZ) = -(Aerodynamics->GetMoments(eZ) + Propulsion->GetMoments(eZ));
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
148 AC_cfg->GetNextConfigLine();
150 while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
151 lGear.push_back(FGLGear(AC_cfg, FDMExec));
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 string FGGroundReactions::GetGroundReactionStrings(void)
161 string GroundReactionStrings = "";
162 bool firstime = true;
164 for (unsigned int i=0;i<lGear.size();i++) {
165 if (!firstime) GroundReactionStrings += ", ";
166 GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
167 GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
168 GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
169 GroundReactionStrings += (lGear[i].GetName() + "_Force");
174 return GroundReactionStrings;
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 string FGGroundReactions::GetGroundReactionValues(void)
182 string GroundReactionValues = "";
184 bool firstime = true;
186 for (unsigned int i=0;i<lGear.size();i++) {
187 if (!firstime) GroundReactionValues += ", ";
188 GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
189 GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
190 GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
191 GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
196 return GroundReactionValues;
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 void FGGroundReactions::Debug(void)
203 //TODO: Add your source code here