]> git.mxchange.org Git - flightgear.git/blob - src/FDM/Balloon.cxx
Updates from the Jon and Tony show.
[flightgear.git] / src / FDM / Balloon.cxx
1 /*****************************************************************************
2
3  Module:       BalloonSimInterface.cxx
4  Author:       Christian Mayer
5  Date started: 07.10.99
6  Called by:    
7
8  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Interface to the hot air balloon simulator
30
31 HISTORY
32 ------------------------------------------------------------------------------
33 01.09.1999 Christian Mayer      Created
34 *****************************************************************************/
35
36 /****************************************************************************/
37 /* INCLUDES                                                                 */
38 /****************************************************************************/
39
40 #include <Include/compiler.h>
41
42 #ifdef FG_MATH_EXCEPTION_CLASH
43 #  include <math.h>
44 #endif
45
46 #include STL_STRING
47
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>
55
56 #include "Balloon.h"
57
58 /****************************************************************************/
59 /********************************** CODE ************************************/
60 /****************************************************************************/
61
62
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 ) {
66     sgVec3 temp;
67
68     FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing BalloonSim" );
69
70     FG_LOG( FG_FLIGHT, FG_INFO, "  created a balloon" );
71
72     //set the dt of the model
73     current_balloon.set_dt(dt);
74
75     //set position
76     sgSetVec3( temp,
77         get_Latitude(), 
78         get_Longitude(), 
79         get_Altitude() * FEET_TO_METER);
80     current_balloon.setPosition( temp );
81
82     //set Euler angles (?)
83     sgSetVec3( temp,
84         get_Phi(), 
85         get_Theta(), 
86         get_Psi() );
87     current_balloon.setHPR( temp );
88
89     //set velocities
90     sgSetVec3( temp,
91         current_options.get_uBody(), 
92         current_options.get_vBody(), 
93         current_options.get_wBody() );
94     current_balloon.setVelocity( temp );
95
96     FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing BalloonSim" );
97
98     return 1;
99 }
100
101
102 // Run an iteration of the EOM (equations of motion)
103 int FGBalloonSim::update( int multiloop ) {
104     double save_alt = 0.0;
105
106     // lets try to avoid really screwing up the BalloonSim model
107     if ( get_Altitude() < -9000 ) {
108         save_alt = get_Altitude();
109         set_Altitude( 0.0 );
110     }
111
112     // set control positions
113     current_balloon.set_burner_strength ( controls.get_throttle(0) );
114     //not more implemented yet
115
116     // Inform BalloonSim of the local terrain altitude
117     current_balloon.setGroundLevel ( get_Runway_altitude() * FEET_TO_METER);
118
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);
125
126     /* FDMExec.GetState()->Setsim_time(State->Getsim_time() 
127                                     + State->Getdt() * multiloop); */
128
129     for ( int i = 0; i < multiloop; i++ ) {
130         current_balloon.update(); 
131     }
132
133     // translate BalloonSim back to FG structure so that the
134     // autopilot (and the rest of the sim can use the updated
135     // values
136
137     copy_from_BalloonSim();
138     
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]); */                      
147
148     // but lets restore our original bogus altitude when we are done
149     if ( save_alt < -9000.0 ) {
150         set_Altitude( save_alt );
151     }
152
153     return 1;
154 }
155
156
157 // Convert from the FGInterface struct to the BalloonSim
158 int FGBalloonSim::copy_to_BalloonSim() {
159     return 1;
160 }
161
162
163 // Convert from the BalloonSim to the FGInterface struct
164 int FGBalloonSim::copy_from_BalloonSim() {
165
166     sgVec3 temp;
167
168     // Velocities
169     current_balloon.getVelocity( temp );
170     set_Velocities_Local( temp[0], temp[1], temp[2] );
171
172     /* ***FIXME*** */ set_V_equiv_kts( sgLengthVec3 ( temp ) );
173
174     set_Omega_Body( 0.0, 0.0, 0.0 );
175
176     // Positions
177     current_balloon.getPosition( temp );
178     double lat_geoc = temp[0];
179     double lon      = temp[1];
180     double alt      = temp[2] * METER_TO_FEET;
181
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 );
186
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 );
193             
194     set_Geocentric_Position( lat_geoc, lon, 
195                                sl_radius2 * METER_TO_FEET + alt );
196     set_Geodetic_Position( lat_geod, lon, alt );
197
198     current_balloon.getHPR( temp );
199     set_Euler_Angles( temp[0], temp[1], temp[2] );
200
201
202     set_Alpha( 0.0/*FDMExec.GetTranslation()->Getalpha()*/ );
203     set_Beta( 0.0/*FDMExec.GetTranslation()->Getbeta()*/ );
204
205     /* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
206     /* **FIXME*** */ set_Earth_position_angle( 0.0 );
207
208     /* ***FIXME*** */ set_Runway_altitude( 0.0 );
209
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 );
214
215     return 0;
216 }
217
218