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