]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cpp
a41a51e275680ca849508461c7f00686a9dc4069
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
1 /*******************************************************************************
2
3  Module:       JSBSim.cpp
4  Author:       Jon S. Berndt
5  Date started: 08/17/99
6  Purpose:      Standalone version of JSBSim.
7  Called by:    The USER.
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
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 General Public License for more
19  details.
20
21  You should have received a copy of the GNU 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.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 This class Handles calling JSBSim standalone. It is set up for compilation under
32 Borland C+Builder or other compiler.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 08/17/99   JSB   Created
37
38 ********************************************************************************
39 INCLUDES
40 *******************************************************************************/
41
42 #if __BCPLUSPLUS__  == 0x0540   // If compiling under Borland C++Builder
43 #pragma hdrstop
44 #include <condefs.h>
45 USEUNIT("FGUtility.cpp");
46 USEUNIT("FGAtmosphere.cpp");
47 USEUNIT("FGAuxiliary.cpp");
48 USEUNIT("FGCoefficient.cpp");
49 USEUNIT("FGConfigFile.cpp");
50 USEUNIT("FGControls.cpp");
51 USEUNIT("FGEngine.cpp");
52 USEUNIT("FGFCS.cpp");
53 USEUNIT("FGFDMExec.cpp");
54 USEUNIT("FGfdmSocket.cpp");
55 USEUNIT("FGInitialCondition.cpp");
56 USEUNIT("FGLGear.cpp");
57 USEUNIT("FGMatrix.cpp");
58 USEUNIT("FGModel.cpp");
59 USEUNIT("FGOutput.cpp");
60 USEUNIT("FGPosition.cpp");
61 USEUNIT("FGRotation.cpp");
62 USEUNIT("FGState.cpp");
63 USEUNIT("FGTank.cpp");
64 USEUNIT("FGTranslation.cpp");
65 USEUNIT("FGAircraft.cpp");
66 USERES("JSBSim.res");
67 USEUNIT("filtersjb\FGfcsComponent.cpp");
68 USEUNIT("filtersjb\FGSwitch.cpp");
69 USEUNIT("filtersjb\FGFilter.cpp");
70 USEUNIT("filtersjb\FGGain.cpp");
71 USEUNIT("filtersjb\FGGradient.cpp");
72 USEUNIT("filtersjb\FGSummer.cpp");
73 USEUNIT("filtersjb\FGDeadBand.cpp");
74 USEUNIT("filtersjb\FGFlaps.cpp");
75 USEFILE("JSBSim.cxx");
76 USEUNIT("FGForce.cpp");
77 USEUNIT("FGInertial.cpp");
78 USEUNIT("FGNozzle.cpp");
79 USEUNIT("FGPropeller.cpp");
80 USEUNIT("FGRotor.cpp");
81 USEUNIT("FGThruster.cpp");
82 USEUNIT("FGMassBalance.cpp");
83 USEUNIT("FGRocket.cpp");
84 USEUNIT("FGTurboJet.cpp");
85 USEUNIT("FGPiston.cpp");
86 USEUNIT("FGTurboShaft.cpp");
87 USEUNIT("FGPropulsion.cpp");
88 USEUNIT("FGGroundReactions.cpp");
89 USEUNIT("FGAerodynamics.cpp");
90 //---------------------------------------------------------------------------
91 #pragma argsused
92 #endif
93
94 #include "FGFDMExec.h"
95 #include "FGRotation.h"
96 #include "FGAtmosphere.h"
97 #include "FGState.h"
98 #include "FGFCS.h"
99 #include "FGAircraft.h"
100 #include "FGTranslation.h"
101 #include "FGPosition.h"
102 #include "FGAuxiliary.h"
103 #include "FGOutput.h"
104 #include "FGInitialCondition.h"
105
106 #ifdef FGFS
107 #include <simgear/compiler.h>
108 #include STL_IOSTREAM
109 #  ifdef FG_HAVE_STD_INCLUDES
110 #    include <ctime>
111 #  else
112 #    include <time.h>
113 #  endif
114 #else
115 #include <iostream>
116 #include <ctime>
117 #endif
118
119 static const char *IdSrc = "$Header$";
120
121 int main(int argc, char** argv)
122 {
123   FGFDMExec* FDMExec;
124   bool result = false;
125
126   if (argc != 3) {
127     cout << endl
128          << "  You must enter the name of a registered aircraft and reset point:"
129          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
130     exit(0);
131   }
132
133   FDMExec = new FGFDMExec();
134
135   result = FDMExec->LoadModel("/home/tony/FlightGear/Aircraft", 
136                                 "/home/tony/FlightGear/Engine", 
137                                   string(argv[1]));
138   
139   if (!result) {
140         cerr << "Aircraft file " << argv[1] << " was not found" << endl;
141           exit(-1);
142   }
143   
144   if ( ! FDMExec->GetState()->Reset("/home/tony/FlightGear/Aircraft", 
145                                        string(argv[1]), string(argv[2])))
146     FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
147   
148   FGInitialCondition *fgic= new FGInitialCondition(FDMExec);
149   fgic->SetUBodyFpsIC(170);
150   fgic->SetTrueHeadingDegIC(275);
151   FDMExec->RunIC(fgic);
152   cout << "FDMExec->GetTranslation()->GetVt(): " << FDMExec->GetTranslation()->GetVt() << endl;
153   cout << "FDMExec->GetPosition()->GetVn(): " << FDMExec->GetPosition()->GetVn() << endl;
154   cout << "FDMExec->GetPosition()->GetVe(): " << FDMExec->GetPosition()->GetVe() << endl;
155   cout << "FDMExec->GetAuxiliary()->GetVcalibratedKTS(): " << FDMExec->GetAuxiliary()->GetVcalibratedKTS() << endl; 
156   fgic->SetVnorthFpsIC(170);
157   cout << "fgic->GetUBodyFpsIC(): " << fgic->GetUBodyFpsIC() << endl;
158   cout << "fgic->GetVBodyFpsIC(): " << fgic->GetVBodyFpsIC() << endl;
159   cout << "fgic->GetWBodyFpsIC(): " << fgic->GetWBodyFpsIC() << endl;
160   FDMExec->RunIC(fgic);
161   cout << "FDMExec->GetTranslation()->GetVt(): " << FDMExec->GetTranslation()->GetVt() << endl;
162   cout << "FDMExec->GetPosition()->GetVn(): " << FDMExec->GetPosition()->GetVn() << endl;
163   cout << "FDMExec->GetPosition()->GetVe(): " << FDMExec->GetPosition()->GetVe() << endl;
164   cout << "FDMExec->GetAuxiliary()->GetVcalibratedKTS(): " << FDMExec->GetAuxiliary()->GetVcalibratedKTS() << endl; 
165   
166   /* float cmd = 0.0;
167
168   while (FDMExec->GetState()->Getsim_time() <= 10.0)
169   {
170     // Fake an elevator ramp here after 1 second, hold for one second, ramp down
171     
172     if (FDMExec->GetState()->Getsim_time() >= 1.00 &&
173         FDMExec->GetState()->Getsim_time() < 2.0)
174     {
175       cmd = -(FDMExec->GetState()->Getsim_time() - 1.00)/2.0;
176     } else if (FDMExec->GetState()->Getsim_time() >= 2.00 &&
177         FDMExec->GetState()->Getsim_time() < 6.0)
178     {
179       cmd = -1.00/2.0;
180     } else if (FDMExec->GetState()->Getsim_time() >= 6.00 &&
181         FDMExec->GetState()->Getsim_time() < 7.0)
182     {
183       cmd = -(7.0 - FDMExec->GetState()->Getsim_time())/2.0;
184     } else {
185       cmd = 0.00;
186     }
187     FDMExec->GetFCS()->SetDeCmd(cmd);    // input between -1 and 1
188     
189     FDMExec->Run();
190   }
191  */
192
193   delete FDMExec;
194
195   return 0;
196 }
197
198