]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Latest JSBSim changes, including a kludge from Tony to keep the
[flightgear.git] / src / FDM / JSBSim / FGGroundReactions.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGGroundReactions.cpp
4  Author:       Jon S. Berndt
5  Date started: 09/13/00
6  Purpose:      Encapsulates the ground reaction forces (gear and collision)
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) -------------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 09/13/00   JSB   Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #include "FGGroundReactions.h"
39
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_GROUNDREACTIONS;
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 CLASS IMPLEMENTATION
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47
48 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
49 {
50   Name = "FGGroundReactions";
51
52   Debug(0);
53 }
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 FGGroundReactions::~FGGroundReactions(void)
58 {
59   Debug(1);
60 }
61
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 bool FGGroundReactions::Run(void)
65 {
66   if (!FGModel::Run()) {
67     vForces.InitMatrix();
68     vMoments.InitMatrix();
69
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
77       // calculated once.
78       while (iGear != lGear.end()) {
79         vForces  += iGear->Force();
80         vMoments += iGear->Moment();
81         iGear++;
82       }
83
84     } else {
85       // Crash Routine
86     }
87
88     return false;
89   } else {
90     return true;
91   }
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
97 {
98   string token;
99
100   AC_cfg->GetNextConfigLine();
101
102   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
103     lGear.push_back(FGLGear(AC_cfg, FDMExec));
104   }
105
106   return true;
107 }
108
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111 string FGGroundReactions::GetGroundReactionStrings(void)
112 {
113   string GroundReactionStrings = "";
114   bool firstime = true;
115
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");
127
128     firstime = false;
129   }
130
131   return GroundReactionStrings;
132 }
133
134 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136 string FGGroundReactions::GetGroundReactionValues(void)
137 {
138   char buff[20];
139   string GroundReactionValues = "";
140
141   bool firstime = true;
142
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)));
154
155     firstime = false;
156   }
157
158   return GroundReactionValues;
159 }
160
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
168 //       whatsoever.
169 //    1: This value explicity requests the normal JSBSim
170 //       startup messages
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
179
180 void FGGroundReactions::Debug(int from)
181 {
182   if (debug_lvl <= 0) return;
183
184   if (debug_lvl & 1) { // Standard console startup message output
185     if (from == 0) { // Constructor
186
187     }
188   }
189   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
190     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
191     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
192   }
193   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
194   }
195   if (debug_lvl & 8 ) { // Runtime state variables
196   }
197   if (debug_lvl & 16) { // Sanity checking
198   }
199   if (debug_lvl & 64) {
200     if (from == 0) { // Constructor
201       cout << IdSrc << endl;
202       cout << IdHdr << endl;
203     }
204   }
205 }
206