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 "FGFDMExec.h"
48 #include "input_output/FGPropertyManager.h"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.33 2011/08/21 15:06:38 bcoconni Exp $";
63 static const char *IdHdr = ID_AIRCRAFT;
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
75 HTailArea = VTailArea = 0.0;
76 HTailArm = VTailArm = 0.0;
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 FGAircraft::~FGAircraft()
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 bool FGAircraft::InitModel(void)
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 bool FGAircraft::Run(bool Holding)
105 if (FGModel::Run(Holding)) return true;
106 if (Holding) return false;
110 vForces.InitMatrix();
112 vForces += in.AeroForce;
113 vForces += in.PropForce;
114 vForces += in.GroundForce;
115 vForces += in.ExternalForce;
116 vForces += in.BuoyantForce;
118 vForces = in.Tl2b * FGColumnVector3(0,0,-in.Weight);
121 vMoments.InitMatrix();
123 vMoments += in.AeroMoment;
124 vMoments += in.PropMoment;
125 vMoments += in.GroundMoment;
126 vMoments += in.ExternalMoment;
127 vMoments += in.BuoyantMoment;
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 bool FGAircraft::Load(Element* el)
144 if (el->FindElement("wingarea"))
145 WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
146 if (el->FindElement("wingspan"))
147 WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
148 if (el->FindElement("chord"))
149 cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
150 if (el->FindElement("wing_incidence"))
151 WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
152 if (el->FindElement("htailarea"))
153 HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
154 if (el->FindElement("htailarm"))
155 HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
156 if (el->FindElement("vtailarea"))
157 VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
158 if (el->FindElement("vtailarm"))
159 VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
161 // Find all LOCATION elements that descend from this METRICS branch of the
162 // config file. This would be CG location, eyepoint, etc.
164 element = el->FindElement("location");
166 element_name = element->GetAttributeValue("name");
168 if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
169 else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
170 else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
172 element = el->FindNextElement("location");
175 // calculate some derived parameters
177 lbarh = HTailArm/cbar;
178 lbarv = VTailArm/cbar;
179 if (WingArea != 0.0) {
180 vbarh = HTailArm*HTailArea / (cbar*WingArea);
181 vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
185 PostLoad(el, PropertyManager);
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 void FGAircraft::bind(void)
196 typedef double (FGAircraft::*PMF)(int) const;
197 PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
198 PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
199 PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
200 PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
201 PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
202 PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
203 PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
204 PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
205 PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
206 PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
207 PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
208 PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
209 PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
210 PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp);
211 PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp);
212 PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp);
213 PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
214 PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
215 PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
216 PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
217 PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
218 PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
219 PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 // The bitmasked value choices are as follows:
224 // unset: In this case (the default) JSBSim would only print
225 // out the normally expected messages, essentially echoing
226 // the config files as they are read. If the environment
227 // variable is not set, debug_lvl is set to 1 internally
228 // 0: This requests JSBSim not to output any messages
230 // 1: This value explicity requests the normal JSBSim
232 // 2: This value asks for a message to be printed out when
233 // a class is instantiated
234 // 4: When this value is set, a message is displayed when a
235 // FGModel object executes its Run() method
236 // 8: When this value is set, various runtime state variables
237 // are printed out periodically
238 // 16: When set various parameters are sanity checked and
239 // a message is printed out when they go out of bounds
241 void FGAircraft::Debug(int from)
243 if (debug_lvl <= 0) return;
245 if (debug_lvl & 1) { // Standard console startup message output
246 if (from == 2) { // Loading
247 cout << endl << " Aircraft Metrics:" << endl;
248 cout << " WingArea: " << WingArea << endl;
249 cout << " WingSpan: " << WingSpan << endl;
250 cout << " Incidence: " << WingIncidence << endl;
251 cout << " Chord: " << cbar << endl;
252 cout << " H. Tail Area: " << HTailArea << endl;
253 cout << " H. Tail Arm: " << HTailArm << endl;
254 cout << " V. Tail Area: " << VTailArea << endl;
255 cout << " V. Tail Arm: " << VTailArm << endl;
256 cout << " Eyepoint (x, y, z): " << vXYZep << endl;
257 cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
258 cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
261 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
262 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
263 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
265 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
267 if (debug_lvl & 8 ) { // Runtime state variables
269 if (debug_lvl & 16) { // Sanity checking
271 if (debug_lvl & 64) {
272 if (from == 0) { // Constructor
273 cout << IdSrc << endl;
274 cout << IdHdr << endl;
279 } // namespace JSBSim