1 /*****************************************************************************
3 Module: BalloonSimInterface.cxx
4 Author: Christian Mayer
8 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Interface to the hot air balloon simulator
32 ------------------------------------------------------------------------------
33 01.09.1999 Christian Mayer Created
34 *****************************************************************************/
36 /****************************************************************************/
38 /****************************************************************************/
40 #include <Include/compiler.h>
42 #ifdef FG_MATH_EXCEPTION_CLASH
48 #include <Aircraft/aircraft.hxx>
49 #include <Controls/controls.hxx>
50 #include <Debug/logstream.hxx>
51 #include <Include/fg_constants.h>
52 #include <Main/options.hxx>
53 #include <Math/fg_geodesy.hxx>
54 #include <Misc/fgpath.hxx>
58 /****************************************************************************/
59 /********************************** CODE ************************************/
60 /****************************************************************************/
63 // Initialize the BalloonSim flight model, dt is the time increment for
64 // each subsequent iteration through the EOM
65 int FGBalloonSim::init( double dt ) {
68 FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing BalloonSim" );
70 FG_LOG( FG_FLIGHT, FG_INFO, " created a balloon" );
72 //set the dt of the model
73 current_balloon.set_dt(dt);
79 get_Altitude() * FEET_TO_METER);
80 current_balloon.setPosition( temp );
82 //set Euler angles (?)
87 current_balloon.setHPR( temp );
91 current_options.get_uBody(),
92 current_options.get_vBody(),
93 current_options.get_wBody() );
94 current_balloon.setVelocity( temp );
96 FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing BalloonSim" );
102 // Run an iteration of the EOM (equations of motion)
103 int FGBalloonSim::update( int multiloop ) {
104 double save_alt = 0.0;
106 // lets try to avoid really screwing up the BalloonSim model
107 if ( get_Altitude() < -9000 ) {
108 save_alt = get_Altitude();
112 // set control positions
113 current_balloon.set_burner_strength ( controls.get_throttle(0) );
114 //not more implemented yet
116 // Inform BalloonSim of the local terrain altitude
117 current_balloon.setGroundLevel ( get_Runway_altitude() * FEET_TO_METER);
119 // old -- FGInterface_2_JSBsim() not needed except for Init()
120 // translate FG to JSBsim structure
121 // FGInterface_2_JSBsim(f);
122 // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
123 // printf("Altitude = %.2f\n", Altitude * 0.3048);
124 // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
126 /* FDMExec.GetState()->Setsim_time(State->Getsim_time()
127 + State->Getdt() * multiloop); */
129 for ( int i = 0; i < multiloop; i++ ) {
130 current_balloon.update();
133 // translate BalloonSim back to FG structure so that the
134 // autopilot (and the rest of the sim can use the updated
137 copy_from_BalloonSim();
139 /*sgVec3 temp, temp2;
140 current_balloon.getPosition( temp );
141 current_balloon.getVelocity( temp2 );
142 FG_LOG( FG_FLIGHT, FG_INFO, "T: " << current_balloon.getTemperature() <<
143 " alt: " << temp[2] <<
144 " gr_alt: " << get_Runway_altitude() <<
145 " burner: " << controls.get_elevator() <<
146 " v[2]: " << temp2[2]); */
148 // but lets restore our original bogus altitude when we are done
149 if ( save_alt < -9000.0 ) {
150 set_Altitude( save_alt );
157 // Convert from the FGInterface struct to the BalloonSim
158 int FGBalloonSim::copy_to_BalloonSim() {
163 // Convert from the BalloonSim to the FGInterface struct
164 int FGBalloonSim::copy_from_BalloonSim() {
169 current_balloon.getVelocity( temp );
170 set_Velocities_Local( temp[0], temp[1], temp[2] );
172 /* ***FIXME*** */ set_V_equiv_kts( sgLengthVec3 ( temp ) );
174 set_Omega_Body( 0.0, 0.0, 0.0 );
177 current_balloon.getPosition( temp );
178 double lat_geoc = temp[0];
179 double lon = temp[1];
180 double alt = temp[2] * METER_TO_FEET;
182 double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
183 fgGeocToGeod( lat_geoc, EQUATORIAL_RADIUS_M + alt * FEET_TO_METER,
184 &lat_geod, &tmp_alt, &sl_radius1 );
185 fgGeodToGeoc( lat_geod, alt * FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
187 FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << lon << " lat_geod = " << lat_geod
188 << " lat_geoc = " << lat_geoc
189 << " alt = " << alt << " tmp_alt = " << tmp_alt * METER_TO_FEET
190 << " sl_radius1 = " << sl_radius1 * METER_TO_FEET
191 << " sl_radius2 = " << sl_radius2 * METER_TO_FEET
192 << " Equator = " << EQUATORIAL_RADIUS_FT );
194 set_Geocentric_Position( lat_geoc, lon,
195 sl_radius2 * METER_TO_FEET + alt );
196 set_Geodetic_Position( lat_geod, lon, alt );
198 current_balloon.getHPR( temp );
199 set_Euler_Angles( temp[0], temp[1], temp[2] );
202 set_Alpha( 0.0/*FDMExec.GetTranslation()->Getalpha()*/ );
203 set_Beta( 0.0/*FDMExec.GetTranslation()->Getbeta()*/ );
205 /* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
206 /* **FIXME*** */ set_Earth_position_angle( 0.0 );
208 /* ***FIXME*** */ set_Runway_altitude( 0.0 );
210 set_sin_lat_geocentric( lat_geoc );
211 set_cos_lat_geocentric( lat_geoc );
212 set_sin_cos_longitude( lon );
213 set_sin_cos_latitude( lat_geod );