]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_wrapper.cpp
9648e35dfcbcbd925515b35deaadb0f6b1309bbe
[flightgear.git] / src / FDM / UIUCModel / uiuc_wrapper.cpp
1 /********************************************************************** 
2  
3  FILENAME:     uiuc_wrapper.cpp 
4
5 ---------------------------------------------------------------------- 
6
7  DESCRIPTION:  A wrapper(interface) between the UIUC Aeromodel (C++ files) 
8                and the LaRCsim FDM (C files)
9
10 ----------------------------------------------------------------------
11  
12  STATUS:       alpha version
13
14 ----------------------------------------------------------------------
15  
16  REFERENCES:   
17  
18 ----------------------------------------------------------------------
19
20  HISTORY:      01/26/2000   initial release
21  
22 ----------------------------------------------------------------------
23  
24  AUTHOR(S):    Bipin Sehgal       <bsehgal@uiuc.edu>
25  
26 ----------------------------------------------------------------------
27
28  VARIABLES:
29
30 ----------------------------------------------------------------------
31
32  INPUTS:       *
33
34 ----------------------------------------------------------------------
35
36  OUTPUTS:      *
37
38 ----------------------------------------------------------------------
39  
40  CALLED BY:    *
41  
42 ----------------------------------------------------------------------
43  
44  CALLS TO:     *
45  
46 ----------------------------------------------------------------------
47  
48  COPYRIGHT:    (C) 2000 by Michael Selig
49  
50  This program is free software; you can redistribute it and/or
51  modify it under the terms of the GNU General Public License
52  as published by the Free Software Foundation.
53  
54  This program is distributed in the hope that it will be useful,
55  but WITHOUT ANY WARRANTY; without even the implied warranty of
56  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57  GNU General Public License for more details.
58  
59  You should have received a copy of the GNU General Public License
60  along with this program; if not, write to the Free Software
61  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
62  USA or view http://www.gnu.org/copyleft/gpl.html.
63  
64 **********************************************************************/
65
66 #include <simgear/compiler.h>
67
68 #include "uiuc_aircraft.h"
69 #include "uiuc_aircraftdir.h"
70 #include "uiuc_coefficients.h"
71 #include "uiuc_engine.h"
72 #include "uiuc_aerodeflections.h"
73 #include "uiuc_recorder.h"
74 #include "uiuc_menu.h"
75 #include "uiuc_betaprobe.h"
76 #include <FDM/LaRCsim/ls_generic.h>
77
78 SG_USING_STD(cout);
79 SG_USING_STD(endl);
80
81 extern "C" void uiuc_init_aeromodel ();
82 extern "C" void uiuc_force_moment(double dt);
83 extern "C" void uiuc_engine_routine();
84
85 AIRCRAFT *aircraft_ = new AIRCRAFT;
86 AIRCRAFTDIR *aircraftdir_ = new AIRCRAFTDIR;
87
88 void uiuc_init_aeromodel ()
89 {
90   string aircraft;
91
92   if (aircraft_dir != "")
93     aircraft = aircraft_dir + "/";
94
95   aircraft += "aircraft.dat";
96   cout << "We are using "<< aircraft << endl;
97   uiuc_initializemaps(); // Initialize the <string,int> maps
98   uiuc_menu(aircraft);   // Read the specified aircraft file 
99 }
100
101 void uiuc_force_moment(double dt)
102 {
103   double qS = Dynamic_pressure * Sw;
104   double qScbar = qS * cbar;
105   double qSb = qS * bw;
106
107   uiuc_aerodeflections(dt);
108   uiuc_coefficients();
109
110   /* Calculate the wind axis forces */
111   if (CX && CZ)
112     {
113       CD = -CX * cos(Alpha) - CZ * sin(Alpha);
114       CL =  CX * sin(Alpha) - CZ * cos(Alpha);
115     }
116   F_X_wind = -1 * CD * qS;
117   F_Y_wind = CY * qS;
118   F_Z_wind = -1 * CL * qS;
119
120   /* wind-axis to body-axis transformation */
121   F_X_aero = F_X_wind * Cos_alpha * Cos_beta - F_Y_wind * Cos_alpha * Sin_beta - F_Z_wind * Sin_alpha;
122   F_Y_aero = F_X_wind * Sin_beta + F_Y_wind * Cos_beta;
123   F_Z_aero = F_X_wind * Sin_alpha * Cos_beta - F_Y_wind * Sin_alpha * Sin_beta + F_Z_wind * Cos_alpha;
124
125   /* Moment calculations */
126   M_l_aero = Cl * qSb;
127   M_m_aero = Cm * qScbar;
128   M_n_aero = Cn * qSb;
129
130   /* Call fligt data recorder */
131   if (Simtime >= recordStartTime)
132       uiuc_recorder(dt);
133 }
134
135 void uiuc_engine_routine()
136 {
137   uiuc_engine();
138 }
139
140 //end uiuc_wrapper.cpp