]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/JSBSim.cpp
Updates from the Jon and Tony show.
[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("FGTrimLong.cpp");
75 USEUNIT("filtersjb\FGFlaps.cpp");
76 //---------------------------------------------------------------------------
77 #pragma argsused
78 #endif
79
80 #include "FGFDMExec.h"
81 #include "FGRotation.h"
82 #include "FGAtmosphere.h"
83 #include "FGState.h"
84 #include "FGFCS.h"
85 #include "FGAircraft.h"
86 #include "FGTranslation.h"
87 #include "FGPosition.h"
88 #include "FGAuxiliary.h"
89 #include "FGOutput.h"
90
91 #ifdef FGFS
92 #include <simgear/compiler.h>
93 #include STL_IOSTREAM
94 #  ifdef FG_HAVE_STD_INCLUDES
95 #    include <ctime>
96 #  else
97 #    include <time.h>
98 #  endif
99 #else
100 #include <iostream>
101 #include <ctime>
102 #endif
103
104 int main(int argc, char** argv)
105 {
106   FGFDMExec* FDMExec;
107
108   if (argc != 3) {
109     cout << endl
110          << "  You must enter the name of a registered aircraft and reset point:"
111          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
112     exit(0);
113   }
114
115   FDMExec = new FGFDMExec();
116
117   FDMExec->GetAircraft()->LoadAircraft("aircraft", "engine", string(argv[1]));
118   if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2])))
119     FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
120
121   float cmd = 0.0;
122
123   while (FDMExec->GetState()->Getsim_time() <= 5.0)
124   {
125     // Fake an elevator ramp here after 1 second, hold for one second, ramp down
126
127     if (FDMExec->GetState()->Getsim_time() >= 1.00 &&
128         FDMExec->GetState()->Getsim_time() < 2.0)
129     {
130       cmd = FDMExec->GetState()->Getsim_time() - 1.00;
131     } else if (FDMExec->GetState()->Getsim_time() >= 2.00 &&
132         FDMExec->GetState()->Getsim_time() < 3.0)
133     {
134       cmd = 1.00;
135     } else if (FDMExec->GetState()->Getsim_time() >= 3.00 &&
136         FDMExec->GetState()->Getsim_time() < 4.0)
137     {
138       cmd = 4.0 - FDMExec->GetState()->Getsim_time();
139     } else {
140       cmd = 0.00;
141     }
142     FDMExec->GetFCS()->SetDeCmd(cmd);    // input between -1 and 1
143
144     FDMExec->Run();
145   }
146
147   delete FDMExec;
148
149   return 0;
150 }
151