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