]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cpp
20010710 sync with JSBSim.
[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 #include "FGFDMExec.h"
43 #include "FGRotation.h"
44 #include "FGAtmosphere.h"
45 #include "FGState.h"
46 #include "FGFCS.h"
47 #include "FGAircraft.h"
48 #include "FGTranslation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51 #include "FGOutput.h"
52 #include "FGConfigFile.h"
53
54 #ifdef FGFS
55 #include <simgear/compiler.h>
56 #include STL_IOSTREAM
57 #  ifdef SG_HAVE_STD_INCLUDES
58 #    include <ctime>
59 #  else
60 #    include <time.h>
61 #  endif
62 #else
63 #include <iostream>
64 #include <ctime>
65 #endif
66
67 #if __BORLANDC__ > 0x540
68 #include <condefs.h>
69 USEUNIT("FGUtility.cpp");
70 USEUNIT("FGAircraft.cpp");
71 USEUNIT("FGAtmosphere.cpp");
72 USEUNIT("FGAuxiliary.cpp");
73 USEUNIT("FGCoefficient.cpp");
74 USEUNIT("FGConfigFile.cpp");
75 USEUNIT("FGEngine.cpp");
76 USEUNIT("FGFCS.cpp");
77 USEUNIT("FGFDMExec.cpp");
78 USEUNIT("FGfdmSocket.cpp");
79 USEUNIT("FGForce.cpp");
80 USEUNIT("FGGroundReactions.cpp");
81 USEUNIT("FGInertial.cpp");
82 USEUNIT("FGInitialCondition.cpp");
83 USEUNIT("FGLGear.cpp");
84 USEUNIT("FGMassBalance.cpp");
85 USEUNIT("FGMatrix.cpp");
86 USEUNIT("FGModel.cpp");
87 USEUNIT("FGNozzle.cpp");
88 USEUNIT("FGOutput.cpp");
89 USEUNIT("FGPiston.cpp");
90 USEUNIT("FGPosition.cpp");
91 USEUNIT("FGJSBBase.cpp");
92 USEUNIT("FGPropulsion.cpp");
93 USEUNIT("FGRocket.cpp");
94 USEUNIT("FGRotation.cpp");
95 USEUNIT("FGRotor.cpp");
96 USEUNIT("FGState.cpp");
97 USEUNIT("FGTable.cpp");
98 USEUNIT("FGTank.cpp");
99 USEUNIT("FGThruster.cpp");
100 USEUNIT("FGTranslation.cpp");
101 USEUNIT("FGTrim.cpp");
102 USEUNIT("FGTrimAxis.cpp");
103 USEUNIT("FGTurboJet.cpp");
104 USEUNIT("FGTurboProp.cpp");
105 USEUNIT("FGTurboShaft.cpp");
106 USEUNIT("FGAerodynamics.cpp");
107 USEUNIT("filtersjb\FGSwitch.cpp");
108 USEUNIT("filtersjb\FGFCSComponent.cpp");
109 USEUNIT("filtersjb\FGFilter.cpp");
110 USEUNIT("filtersjb\FGFlaps.cpp");
111 USEUNIT("filtersjb\FGGain.cpp");
112 USEUNIT("filtersjb\FGGradient.cpp");
113 USEUNIT("filtersjb\FGSummer.cpp");
114 USEUNIT("filtersjb\FGDeadBand.cpp");
115 USEUNIT("FGPropeller.cpp");
116 //---------------------------------------------------------------------------
117 #endif
118
119 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 DEFINITIONS
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
122
123 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 GLOBAL DATA
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
126
127 static const char *IdSrc = "$Id$";
128
129 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132
133 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 DOCUMENTATION
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
136
137 /** Standalone JSBSim main program
138     This is the wrapper program used to instantiate the JSBSim system and control
139     it. Use this program to build a version of JSBSim that can be run from the
140     command line. To get any use out of this, you will have to create a script
141     to run a test case and specify what kind of output you would like.
142     @author Jon S. Berndt
143     @version $Id$
144     @see -
145 */
146
147 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 IMPLEMENTATION
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
150
151 int main(int argc, char** argv)
152 {
153   FGFDMExec* FDMExec;
154   float cmd = 0.0;
155   bool result = false;
156   bool scripted = false;
157
158   if (argc == 2) {
159     FGConfigFile testFile(argv[1]);
160
161     if (!testFile.IsOpen()) {
162       cout << "Script file not opened" << endl;
163       exit(-1); 
164     }
165
166     testFile.GetNextConfigLine();
167     if (testFile.GetValue("runscript").length() <= 0) {
168       cout << "File: " << argv[1] << " is not a script file" << endl;
169       exit(-1); 
170     }
171     scripted = true;
172   } else if (argc != 3) {
173     cout << endl
174          << "  You must enter the name of a registered aircraft and reset point:"
175          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
176     cout << endl << "  Alternatively, you may specify only the name of a script file:"
177          << endl << endl << "  FDM <script file>" << endl << endl;
178     exit(0);
179   }
180
181   FDMExec = new FGFDMExec();
182
183   if (scripted) {
184     result = FDMExec->LoadScript(argv[1]);
185     if (!result) {
186       cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
187       exit(-1);
188     }
189   } else {
190     result = FDMExec->LoadModel("aircraft", "engine", string(argv[1]));
191     if (!result) {
192         cerr << "Aircraft file " << argv[1] << " was not found" << endl;
193             exit(-1);
194     }
195     if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2])))
196                    FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
197   }
198
199   while (FDMExec->Run()) {}
200
201   delete FDMExec;
202
203   return 0;
204 }