]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Latest JSBSim changes, including some gear tweaking from Jon and some
[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
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_GROUNDREACTIONS;
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 CLASS IMPLEMENTATION
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47
48 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
49 {
50   Name = "FGGroundReactions";
51
52   Debug(0);
53 }
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 FGGroundReactions::~FGGroundReactions(void)
58 {
59   Debug(1);
60 }
61
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 bool FGGroundReactions::Run(void)
65 {
66   if (!FGModel::Run()) {
67     vForces.InitMatrix();
68     vMoments.InitMatrix();
69
70     // Only execute gear force code below 300 feet
71     if ( Position->GetDistanceAGL() < 300.0 ) {
72       vector <FGLGear>::iterator iGear = lGear.begin();
73       // Sum forces and moments for all gear, here.
74       // Some optimizations may be made here - or rather in the gear code itself.
75       // The gear ::Run() method is called several times - once for each gear.
76       // Perhaps there is some commonality for things which only need to be
77       // calculated once.
78       while (iGear != lGear.end()) {
79         vForces  += iGear->Force();
80         vMoments += iGear->Moment();
81         iGear++;
82       }
83
84     } else {
85       // Crash Routine
86     }
87
88     return false;
89   } else {
90     return true;
91   }
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
97 {
98   string token;
99
100   AC_cfg->GetNextConfigLine();
101
102   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
103     lGear.push_back(FGLGear(AC_cfg, FDMExec));
104   }
105
106   return true;
107 }
108
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111 string FGGroundReactions::GetGroundReactionStrings(void)
112 {
113   string GroundReactionStrings = "";
114   bool firstime = true;
115
116   for (unsigned int i=0;i<lGear.size();i++) {
117     if (!firstime) GroundReactionStrings += ", ";
118     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
119     GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
120     GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
121     GroundReactionStrings += (lGear[i].GetName() + "_Force");
122
123     firstime = false;
124   }
125
126   return GroundReactionStrings;
127 }
128
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130
131 string FGGroundReactions::GetGroundReactionValues(void)
132 {
133   char buff[20];
134   string GroundReactionValues = "";
135
136   bool firstime = true;
137
138   for (unsigned int i=0;i<lGear.size();i++) {
139     if (!firstime) GroundReactionValues += ", ";
140     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
141     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
142     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
143     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
144
145     firstime = false;
146   }
147
148   return GroundReactionValues;
149 }
150
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 //    The bitmasked value choices are as follows:
153 //    unset: In this case (the default) JSBSim would only print
154 //       out the normally expected messages, essentially echoing
155 //       the config files as they are read. If the environment
156 //       variable is not set, debug_lvl is set to 1 internally
157 //    0: This requests JSBSim not to output any messages
158 //       whatsoever.
159 //    1: This value explicity requests the normal JSBSim
160 //       startup messages
161 //    2: This value asks for a message to be printed out when
162 //       a class is instantiated
163 //    4: When this value is set, a message is displayed when a
164 //       FGModel object executes its Run() method
165 //    8: When this value is set, various runtime state variables
166 //       are printed out periodically
167 //    16: When set various parameters are sanity checked and
168 //       a message is printed out when they go out of bounds
169
170 void FGGroundReactions::Debug(int from)
171 {
172   if (debug_lvl <= 0) return;
173
174   if (debug_lvl & 1) { // Standard console startup message output
175     if (from == 0) { // Constructor
176
177     }
178   }
179   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
180     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
181     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
182   }
183   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
184   }
185   if (debug_lvl & 8 ) { // Runtime state variables
186   }
187   if (debug_lvl & 16) { // Sanity checking
188   }
189   if (debug_lvl & 64) {
190     if (from == 0) { // Constructor
191       cout << IdSrc << endl;
192       cout << IdHdr << endl;
193     }
194   }
195 }
196