1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Encapsulates an aircraft
9 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 Models the aircraft reactions and forces. This class is instantiated by the
31 FGFDMExec class and scheduled as an FDM entry.
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 COMMENTS, REFERENCES, and NOTES
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include <sys/types.h>
46 #include "FGAircraft.h"
47 #include "FGMassBalance.h"
48 #include "FGInertial.h"
49 #include "FGGroundReactions.h"
50 #include "FGExternalReactions.h"
51 #include "FGBuoyantForces.h"
52 #include "FGAerodynamics.h"
53 #include "FGFDMExec.h"
54 #include "FGPropagate.h"
55 #include "FGPropulsion.h"
56 #include "input_output/FGPropertyManager.h"
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.29 2010/11/18 12:38:06 jberndt Exp $";
71 static const char *IdHdr = ID_AIRCRAFT;
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
81 HTailArea = VTailArea = 0.0;
82 HTailArm = VTailArm = 0.0;
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 FGAircraft::~FGAircraft()
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 bool FGAircraft::InitModel(void)
104 if (!FGModel::InitModel()) return false;
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 bool FGAircraft::Run(void)
113 if (FGModel::Run()) return true;
114 if (FDMExec->Holding()) return false;
118 vForces.InitMatrix();
120 vForces += FDMExec->GetAerodynamics()->GetForces();
121 vForces += FDMExec->GetPropulsion()->GetForces();
122 vForces += FDMExec->GetGroundReactions()->GetForces();
123 vForces += FDMExec->GetExternalReactions()->GetForces();
124 vForces += FDMExec->GetBuoyantForces()->GetForces();
126 const FGMatrix33& mTl2b = FDMExec->GetPropagate()->GetTl2b();
127 vForces = mTl2b * FGColumnVector3(0,0,-FDMExec->GetMassBalance()->GetWeight());
130 vMoments.InitMatrix();
132 vMoments += FDMExec->GetAerodynamics()->GetMoments();
133 vMoments += FDMExec->GetPropulsion()->GetMoments();
134 vMoments += FDMExec->GetGroundReactions()->GetMoments();
135 vMoments += FDMExec->GetExternalReactions()->GetMoments();
136 vMoments += FDMExec->GetBuoyantForces()->GetMoments();
139 vBodyAccel = vForces/FDMExec->GetMassBalance()->GetMass();
141 vNcg = vBodyAccel/FDMExec->GetInertial()->SLgravity();
143 vNwcg = FDMExec->GetAerodynamics()->GetTb2w() * vNcg;
144 vNwcg(3) = 1.0 - vNwcg(3);
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 double FGAircraft::GetNlf(void) const
155 if (FDMExec->GetMassBalance()->GetWeight() != 0)
156 return (-FDMExec->GetAerodynamics()->GetvFw(3))/FDMExec->GetMassBalance()->GetWeight();
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 bool FGAircraft::Load(Element* el)
170 if (el->FindElement("wingarea"))
171 WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
172 if (el->FindElement("wingspan"))
173 WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
174 if (el->FindElement("chord"))
175 cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
176 if (el->FindElement("wing_incidence"))
177 WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
178 if (el->FindElement("htailarea"))
179 HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
180 if (el->FindElement("htailarm"))
181 HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
182 if (el->FindElement("vtailarea"))
183 VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
184 if (el->FindElement("vtailarm"))
185 VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
187 // Find all LOCATION elements that descend from this METRICS branch of the
188 // config file. This would be CG location, eyepoint, etc.
190 element = el->FindElement("location");
192 element_name = element->GetAttributeValue("name");
194 if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
195 else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
196 else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
198 element = el->FindNextElement("location");
201 // calculate some derived parameters
203 lbarh = HTailArm/cbar;
204 lbarv = VTailArm/cbar;
205 if (WingArea != 0.0) {
206 vbarh = HTailArm*HTailArea / (cbar*WingArea);
207 vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
211 PostLoad(el, PropertyManager);
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 void FGAircraft::bind(void)
222 typedef double (FGAircraft::*PMF)(int) const;
223 PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
224 PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
225 PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
226 PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
227 PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
228 PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
229 PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
230 PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
231 PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
232 PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
233 PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
234 PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
235 PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
236 PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp);
237 PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp);
238 PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp);
239 PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
240 PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
241 PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
242 PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
243 PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
244 PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
245 PropertyManager->Tie("forces/fbx-total-lbs", this, eX, (PMF)&FGAircraft::GetForces);
246 PropertyManager->Tie("forces/fby-total-lbs", this, eY, (PMF)&FGAircraft::GetForces);
247 PropertyManager->Tie("forces/fbz-total-lbs", this, eZ, (PMF)&FGAircraft::GetForces);
248 PropertyManager->Tie("forces/load-factor", this, &FGAircraft::GetNlf);
249 PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
250 PropertyManager->Tie("moments/l-total-lbsft", this, eL, (PMF)&FGAircraft::GetMoments);
251 PropertyManager->Tie("moments/m-total-lbsft", this, eM, (PMF)&FGAircraft::GetMoments);
252 PropertyManager->Tie("moments/n-total-lbsft", this, eN, (PMF)&FGAircraft::GetMoments);
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 // The bitmasked value choices are as follows:
257 // unset: In this case (the default) JSBSim would only print
258 // out the normally expected messages, essentially echoing
259 // the config files as they are read. If the environment
260 // variable is not set, debug_lvl is set to 1 internally
261 // 0: This requests JSBSim not to output any messages
263 // 1: This value explicity requests the normal JSBSim
265 // 2: This value asks for a message to be printed out when
266 // a class is instantiated
267 // 4: When this value is set, a message is displayed when a
268 // FGModel object executes its Run() method
269 // 8: When this value is set, various runtime state variables
270 // are printed out periodically
271 // 16: When set various parameters are sanity checked and
272 // a message is printed out when they go out of bounds
274 void FGAircraft::Debug(int from)
276 if (debug_lvl <= 0) return;
278 if (debug_lvl & 1) { // Standard console startup message output
279 if (from == 2) { // Loading
280 cout << endl << " Aircraft Metrics:" << endl;
281 cout << " WingArea: " << WingArea << endl;
282 cout << " WingSpan: " << WingSpan << endl;
283 cout << " Incidence: " << WingIncidence << endl;
284 cout << " Chord: " << cbar << endl;
285 cout << " H. Tail Area: " << HTailArea << endl;
286 cout << " H. Tail Arm: " << HTailArm << endl;
287 cout << " V. Tail Area: " << VTailArea << endl;
288 cout << " V. Tail Arm: " << VTailArm << endl;
289 cout << " Eyepoint (x, y, z): " << vXYZep << endl;
290 cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
291 cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
294 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
295 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
296 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
298 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
300 if (debug_lvl & 8 ) { // Runtime state variables
302 if (debug_lvl & 16) { // Sanity checking
304 if (debug_lvl & 64) {
305 if (from == 0) { // Constructor
306 cout << IdSrc << endl;
307 cout << IdHdr << endl;
312 } // namespace JSBSim