]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Removing files already removed from JSBSim CVS.
[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 #include "FGPropertyManager.h"
40
41 namespace JSBSim {
42
43 static const char *IdSrc = "$Id$";
44 static const char *IdHdr = ID_GROUNDREACTIONS;
45
46 #if defined (__APPLE__)
47 /* Not all systems have the gcvt function */
48 inline char* gcvt (double value, int ndigits, char *buf) {
49     /* note that this is not exactly what gcvt is supposed to do! */
50     snprintf (buf, ndigits+1, "%f", value);
51     return buf;
52 }
53 #endif
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 CLASS IMPLEMENTATION
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59
60 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
61 {
62   Name = "FGGroundReactions";
63   
64   bind();
65
66   Debug(0);
67 }
68
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70
71 FGGroundReactions::~FGGroundReactions(void)
72 {
73   unbind();
74
75   Debug(1);
76 }
77
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 bool FGGroundReactions::Run(void)
81 {
82   if (!FGModel::Run()) {
83     vForces.InitMatrix();
84     vMoments.InitMatrix();
85
86     // Only execute gear force code below 300 feet
87     if ( Position->GetDistanceAGL() < 300.0 ) {
88       vector <FGLGear>::iterator iGear = lGear.begin();
89       // Sum forces and moments for all gear, here.
90       // Some optimizations may be made here - or rather in the gear code itself.
91       // The gear ::Run() method is called several times - once for each gear.
92       // Perhaps there is some commonality for things which only need to be
93       // calculated once.
94       while (iGear != lGear.end()) {
95         vForces  += iGear->Force();
96         vMoments += iGear->Moment();
97         iGear++;
98       }
99
100     } else {
101       // Crash Routine
102     }
103
104     return false;
105   } else {
106     return true;
107   }
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
113 {
114   string token;
115
116   AC_cfg->GetNextConfigLine();
117
118   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
119     lGear.push_back(FGLGear(AC_cfg, FDMExec));
120   }
121
122   return true;
123 }
124
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127 string FGGroundReactions::GetGroundReactionStrings(void)
128 {
129   string GroundReactionStrings = "";
130   bool firstime = true;
131
132   for (unsigned int i=0;i<lGear.size();i++) {
133     if (!firstime) GroundReactionStrings += ", ";
134     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
135     GroundReactionStrings += (lGear[i].GetName() + "_stroke, ");
136     GroundReactionStrings += (lGear[i].GetName() + "_strokeVel, ");
137     GroundReactionStrings += (lGear[i].GetName() + "_CompressForce, ");
138     GroundReactionStrings += (lGear[i].GetName() + "_WhlSideForce, ");
139     GroundReactionStrings += (lGear[i].GetName() + "_WhlVelVecX, ");
140     GroundReactionStrings += (lGear[i].GetName() + "_WhlVelVecY, ");
141     GroundReactionStrings += (lGear[i].GetName() + "_WhlRollForce, ");
142     GroundReactionStrings += (lGear[i].GetName() + "_BodyXForce, ");
143     GroundReactionStrings += (lGear[i].GetName() + "_BodyYForce, ");
144     GroundReactionStrings += (lGear[i].GetName() + "_WhlSlipDegrees");
145
146     firstime = false;
147   }
148
149   GroundReactionStrings += ", TotalGearForce_X, ";
150   GroundReactionStrings += "TotalGearForce_Y, ";
151   GroundReactionStrings += "TotalGearForce_Z, ";
152   GroundReactionStrings += "TotalGearMoment_L, ";
153   GroundReactionStrings += "TotalGearMoment_M, ";
154   GroundReactionStrings += "TotalGearMoment_N";
155
156   return GroundReactionStrings;
157 }
158
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160
161 string FGGroundReactions::GetGroundReactionValues(void)
162 {
163   char buff[20];
164   string GroundReactionValues = "";
165
166   bool firstime = true;
167
168   for (unsigned int i=0;i<lGear.size();i++) {
169     if (!firstime) GroundReactionValues += ", ";
170     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
171     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
172     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
173     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)) + ", ");
174     GroundReactionValues += (string(gcvt(lGear[i].GetWheelVel(eX), 6, buff)) + ", ");
175     GroundReactionValues += (string(gcvt(lGear[i].GetWheelVel(eY), 6, buff)) + ", ");
176     GroundReactionValues += (string(gcvt(lGear[i].GetWheelSideForce(), 6, buff)) + ", ");
177     GroundReactionValues += (string(gcvt(lGear[i].GetWheelRollForce(), 6, buff)) + ", ");
178     GroundReactionValues += (string(gcvt(lGear[i].GetBodyXForce(), 6, buff)) + ", ");
179     GroundReactionValues += (string(gcvt(lGear[i].GetBodyYForce(), 6, buff)) + ", ");
180     GroundReactionValues += (string(gcvt(lGear[i].GetWheelSlipAngle(), 6, buff)));
181
182     firstime = false;
183   }
184
185   GroundReactionValues += (", " + string(gcvt(vForces(eX), 6, buff)) + ", ");
186   GroundReactionValues += (string(gcvt(vForces(eY), 6, buff)) + ", ");
187   GroundReactionValues += (string(gcvt(vForces(eZ), 6, buff)) + ", ");
188   GroundReactionValues += (string(gcvt(vMoments(eX), 6, buff)) + ", ");
189   GroundReactionValues += (string(gcvt(vMoments(eY), 6, buff)) + ", ");
190   GroundReactionValues += (string(gcvt(vMoments(eZ), 6, buff)));
191
192   return GroundReactionValues;
193 }
194
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
197 void FGGroundReactions::bind(void)
198
199   typedef double (FGGroundReactions::*PMF)(int) const;
200   PropertyManager->Tie("gear/num-units", this,
201                        &FGGroundReactions::GetNumGearUnits);  
202   PropertyManager->Tie("moments/l-gear-lbsft", this,1,
203                        (PMF)&FGGroundReactions::GetMoments);
204   PropertyManager->Tie("moments/m-gear-lbsft", this,2,
205                        (PMF)&FGGroundReactions::GetMoments);
206   PropertyManager->Tie("moments/n-gear-lbsft", this,3,
207                        (PMF)&FGGroundReactions::GetMoments);
208   PropertyManager->Tie("forces/fbx-gear-lbs", this,1,
209                        (PMF)&FGGroundReactions::GetForces);
210   PropertyManager->Tie("forces/fby-gear-lbs", this,2,
211                        (PMF)&FGGroundReactions::GetForces);
212   PropertyManager->Tie("forces/fbz-gear-lbs", this,3,
213                        (PMF)&FGGroundReactions::GetForces);
214 }
215
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218 void FGGroundReactions::unbind(void)
219 {
220   PropertyManager->Untie("gear/num-units");
221   PropertyManager->Untie("moments/l-gear-lbsft");
222   PropertyManager->Untie("moments/m-gear-lbsft");
223   PropertyManager->Untie("moments/n-gear-lbsft");
224   PropertyManager->Untie("forces/fbx-gear-lbs");
225   PropertyManager->Untie("forces/fby-gear-lbs");
226   PropertyManager->Untie("forces/fbz-gear-lbs");
227 }
228
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 //    The bitmasked value choices are as follows:
231 //    unset: In this case (the default) JSBSim would only print
232 //       out the normally expected messages, essentially echoing
233 //       the config files as they are read. If the environment
234 //       variable is not set, debug_lvl is set to 1 internally
235 //    0: This requests JSBSim not to output any messages
236 //       whatsoever.
237 //    1: This value explicity requests the normal JSBSim
238 //       startup messages
239 //    2: This value asks for a message to be printed out when
240 //       a class is instantiated
241 //    4: When this value is set, a message is displayed when a
242 //       FGModel object executes its Run() method
243 //    8: When this value is set, various runtime state variables
244 //       are printed out periodically
245 //    16: When set various parameters are sanity checked and
246 //       a message is printed out when they go out of bounds
247
248 void FGGroundReactions::Debug(int from)
249 {
250   if (debug_lvl <= 0) return;
251
252   if (debug_lvl & 1) { // Standard console startup message output
253     if (from == 0) { // Constructor
254
255     }
256   }
257   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
258     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
259     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
260   }
261   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
262   }
263   if (debug_lvl & 8 ) { // Runtime state variables
264   }
265   if (debug_lvl & 16) { // Sanity checking
266   }
267   if (debug_lvl & 64) {
268     if (from == 0) { // Constructor
269       cout << IdSrc << endl;
270       cout << IdHdr << endl;
271     }
272   }
273 }
274 }