]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Latest JSBSim changes.
[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   PropertyManager->Tie("gear/num-units", this,
171                        &FGGroundReactions::GetNumGearUnits);  
172   PropertyManager->Tie("moments/l-gear-lbsft", this,1,
173                        &FGGroundReactions::GetMoments);
174   PropertyManager->Tie("moments/m-gear-lbsft", this,2,
175                        &FGGroundReactions::GetMoments);
176   PropertyManager->Tie("moments/n-gear-lbsft", this,3,
177                        &FGGroundReactions::GetMoments);
178   PropertyManager->Tie("forces/fbx-gear-lbs", this,1,
179                        &FGGroundReactions::GetForces);
180   PropertyManager->Tie("forces/fby-gear-lbs", this,2,
181                        &FGGroundReactions::GetForces);
182   PropertyManager->Tie("forces/fbz-gear-lbs", this,3,
183                        &FGGroundReactions::GetForces);
184 }
185
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187
188 void FGGroundReactions::unbind(void)
189 {
190   PropertyManager->Untie("gear/num-units");
191   PropertyManager->Untie("moments/l-gear-lbsft");
192   PropertyManager->Untie("moments/m-gear-lbsft");
193   PropertyManager->Untie("moments/n-gear-lbsft");
194   PropertyManager->Untie("forces/fbx-gear-lbs");
195   PropertyManager->Untie("forces/fby-gear-lbs");
196   PropertyManager->Untie("forces/fbz-gear-lbs");
197 }
198
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 //    The bitmasked value choices are as follows:
201 //    unset: In this case (the default) JSBSim would only print
202 //       out the normally expected messages, essentially echoing
203 //       the config files as they are read. If the environment
204 //       variable is not set, debug_lvl is set to 1 internally
205 //    0: This requests JSBSim not to output any messages
206 //       whatsoever.
207 //    1: This value explicity requests the normal JSBSim
208 //       startup messages
209 //    2: This value asks for a message to be printed out when
210 //       a class is instantiated
211 //    4: When this value is set, a message is displayed when a
212 //       FGModel object executes its Run() method
213 //    8: When this value is set, various runtime state variables
214 //       are printed out periodically
215 //    16: When set various parameters are sanity checked and
216 //       a message is printed out when they go out of bounds
217
218 void FGGroundReactions::Debug(int from)
219 {
220   if (debug_lvl <= 0) return;
221
222   if (debug_lvl & 1) { // Standard console startup message output
223     if (from == 0) { // Constructor
224
225     }
226   }
227   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
228     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
229     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
230   }
231   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
232   }
233   if (debug_lvl & 8 ) { // Runtime state variables
234   }
235   if (debug_lvl & 16) { // Sanity checking
236   }
237   if (debug_lvl & 64) {
238     if (from == 0) { // Constructor
239       cout << IdSrc << endl;
240       cout << IdHdr << endl;
241     }
242   }
243 }
244