1 /**********************************************************************
3 FILENAME: uiuc_wrapper.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: A wrapper(interface) between the UIUC Aeromodel (C++ files)
8 and the LaRCsim FDM (C files)
10 ----------------------------------------------------------------------
14 ----------------------------------------------------------------------
18 ----------------------------------------------------------------------
20 HISTORY: 01/26/2000 initial release
21 03/09/2001 (DPM) added support for gear
22 06/18/2001 (RD) Made uiuc_recorder its own routine.
23 07/19/2001 (RD) Added uiuc_vel_init() to initialize
25 08/27/2001 (RD) Added uiuc_initial_init() to help
26 in starting an A/C at an initial condition
28 ----------------------------------------------------------------------
30 AUTHOR(S): Bipin Sehgal <bsehgal@uiuc.edu>
31 Robert Deters <rdeters@uiuc.edu>
32 David Megginson <david@megginson.com>
34 ----------------------------------------------------------------------
38 ----------------------------------------------------------------------
42 ----------------------------------------------------------------------
46 ----------------------------------------------------------------------
50 ----------------------------------------------------------------------
54 ----------------------------------------------------------------------
56 COPYRIGHT: (C) 2000 by Michael Selig
58 This program is free software; you can redistribute it and/or
59 modify it under the terms of the GNU General Public License
60 as published by the Free Software Foundation.
62 This program is distributed in the hope that it will be useful,
63 but WITHOUT ANY WARRANTY; without even the implied warranty of
64 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 GNU General Public License for more details.
67 You should have received a copy of the GNU General Public License
68 along with this program; if not, write to the Free Software
69 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
70 USA or view http://www.gnu.org/copyleft/gpl.html.
72 **********************************************************************/
74 #include <simgear/compiler.h>
75 #include <Aircraft/aircraft.hxx>
77 #ifndef FG_OLD_WEATHER
78 #include <WeatherCM/FGLocalWeatherDatabase.h>
80 #include <Weather/weather.hxx>
83 #include "uiuc_aircraft.h"
84 #include "uiuc_aircraftdir.h"
85 #include "uiuc_coefficients.h"
86 #include "uiuc_engine.h"
87 #include "uiuc_gear.h"
88 #include "uiuc_aerodeflections.h"
89 #include "uiuc_recorder.h"
90 #include "uiuc_menu.h"
91 #include "uiuc_betaprobe.h"
92 #include <FDM/LaRCsim/ls_generic.h>
93 #include "Main/simple_udp.h"
94 #include "uiuc_fog.h" //321654
96 #if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
101 extern "C" void uiuc_init_aeromodel ();
102 extern "C" void uiuc_force_moment(double dt);
103 extern "C" void uiuc_engine_routine();
104 extern "C" void uiuc_gear_routine();
105 extern "C" void uiuc_record_routine(double dt);
106 extern "C" void uiuc_vel_init ();
107 extern "C" void uiuc_initial_init ();
109 AIRCRAFT *aircraft_ = new AIRCRAFT;
110 AIRCRAFTDIR *aircraftdir_ = new AIRCRAFTDIR;
112 SendArray testarray(4950);
114 /* Convert float to string */
115 string ftoa(double in)
117 static char temp[20];
118 sprintf(temp,"%g",in);
122 void uiuc_initial_init ()
124 if (P_body_init_true)
125 P_body = P_body_init;
126 if (Q_body_init_true)
127 Q_body = Q_body_init;
128 if (R_body_init_true)
129 R_body = R_body_init;
138 if (U_body_init_true)
139 U_body = U_body_init;
140 if (V_body_init_true)
141 V_body = V_body_init;
142 if (W_body_init_true)
143 W_body = W_body_init;
147 void uiuc_vel_init ()
149 if (U_body_init_true && V_body_init_true && W_body_init_true)
151 double det_T_l_to_b, cof11, cof12, cof13, cof21, cof22, cof23, cof31, cof32, cof33;
153 det_T_l_to_b = T_local_to_body_11*(T_local_to_body_22*T_local_to_body_33-T_local_to_body_23*T_local_to_body_32) - T_local_to_body_12*(T_local_to_body_21*T_local_to_body_33-T_local_to_body_23*T_local_to_body_31) + T_local_to_body_13*(T_local_to_body_21*T_local_to_body_32-T_local_to_body_22*T_local_to_body_31);
154 cof11 = T_local_to_body_22 * T_local_to_body_33 - T_local_to_body_23 * T_local_to_body_32;
155 cof12 = T_local_to_body_23 * T_local_to_body_31 - T_local_to_body_21 * T_local_to_body_33;
156 cof13 = T_local_to_body_21 * T_local_to_body_32 - T_local_to_body_22 * T_local_to_body_31;
157 cof21 = T_local_to_body_13 * T_local_to_body_32 - T_local_to_body_12 * T_local_to_body_33;
158 cof22 = T_local_to_body_11 * T_local_to_body_33 - T_local_to_body_13 * T_local_to_body_31;
159 cof23 = T_local_to_body_12 * T_local_to_body_31 - T_local_to_body_11 * T_local_to_body_32;
160 cof31 = T_local_to_body_12 * T_local_to_body_23 - T_local_to_body_13 * T_local_to_body_22;
161 cof32 = T_local_to_body_13 * T_local_to_body_21 - T_local_to_body_11 * T_local_to_body_23;
162 cof33 = T_local_to_body_11 * T_local_to_body_22 - T_local_to_body_12 * T_local_to_body_21;
164 V_north = (cof11*U_body+cof21*V_body+cof31*W_body)/det_T_l_to_b;
165 V_east_rel_ground = (cof12*U_body+cof22*V_body+cof32*W_body)/det_T_l_to_b;
166 V_down = (cof13*U_body+cof23*V_body+cof33*W_body)/det_T_l_to_b;
168 V_east = V_east_rel_ground + OMEGA_EARTH*Sea_level_radius*cos(Lat_geocentric);
172 void uiuc_init_aeromodel ()
176 if (aircraft_dir != (string)"")
177 aircraft = aircraft_dir + "/";
179 aircraft += "aircraft.dat";
180 cout << "We are using "<< aircraft << endl;
181 uiuc_initializemaps(); // Initialize the <string,int> maps
182 uiuc_menu(aircraft); // Read the specified aircraft file
185 void uiuc_force_moment(double dt)
187 double qS = Dynamic_pressure * Sw;
188 double qScbar = qS * cbar;
189 double qSb = qS * bw;
191 uiuc_aerodeflections(dt);
194 /* Calculate the wind axis forces */
197 CD = -CX * cos(Alpha) - CZ * sin(Alpha);
198 CL = CX * sin(Alpha) - CZ * cos(Alpha);
200 F_X_wind = -1 * CD * qS;
202 F_Z_wind = -1 * CL * qS;
204 /* wind-axis to body-axis transformation */
205 F_X_aero = F_X_wind * Cos_alpha * Cos_beta - F_Y_wind * Cos_alpha * Sin_beta - F_Z_wind * Sin_alpha;
206 F_Y_aero = F_X_wind * Sin_beta + F_Y_wind * Cos_beta;
207 F_Z_aero = F_X_wind * Sin_alpha * Cos_beta - F_Y_wind * Sin_alpha * Sin_beta + F_Z_wind * Cos_alpha;
209 /* Moment calculations */
211 M_m_aero = Cm * qScbar;
214 /* Call flight data recorder */
215 // if (Simtime >= recordStartTime)
216 // uiuc_recorder(dt);
227 #ifndef FG_OLD_WEATHER
228 vis = WeatherDatabase->getWeatherVisibility();
233 WeatherDatabase->setWeatherVisibility( vis );
235 vis = current_weather->get_visibility();
240 current_weather->set_visibility( vis );
245 /* Send data on the network to the Glass Cockpit */
249 input += " stick_right " + ftoa(Lat_control);
250 input += " rudder_left " + ftoa(-Rudder_pedal);
251 input += " stick_forward " + ftoa(Long_control);
252 input += " stick_trim_forward " + ftoa(Long_trim);
253 input += " vehicle_pitch " + ftoa(Theta * 180.0 / 3.14);
254 input += " vehicle_roll " + ftoa(Phi * 180.0 / 3.14);
255 input += " vehicle_speed " + ftoa(V_rel_wind);
256 input += " throttle_forward " + ftoa(Throttle_pct);
257 input += " altitude " + ftoa(Altitude);
258 input += " climb_rate " + ftoa(-1.0*V_down_rel_ground);
260 testarray.getHello();
261 testarray.sendData(input);
263 /* End of Networking */
267 void uiuc_engine_routine()
272 void uiuc_gear_routine ()
277 void uiuc_record_routine(double dt)
279 if (Simtime >= recordStartTime)
282 //end uiuc_wrapper.cpp