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