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