]> git.mxchange.org Git - flightgear.git/blob - src/FDM/Balloon.cxx
More property manager interface updates.
[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 <simgear/compiler.h>
41
42 #ifdef FG_MATH_EXCEPTION_CLASH
43 #  include <math.h>
44 #endif
45
46 #include STL_STRING
47
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/math/sg_geodesy.hxx>
51 #include <simgear/misc/fgpath.hxx>
52
53 #include <Aircraft/aircraft.hxx>
54 #include <Controls/controls.hxx>
55 #include <Main/globals.hxx>
56 #include <Main/fg_props.hxx>
57
58 #include "Balloon.h"
59
60 /****************************************************************************/
61 /********************************** CODE ************************************/
62 /****************************************************************************/
63
64
65 // Initialize the BalloonSim flight model, dt is the time increment for
66 // each subsequent iteration through the EOM
67 bool FGBalloonSim::init( double dt ) {
68     sgVec3 temp;
69
70     FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing BalloonSim" );
71
72     FG_LOG( FG_FLIGHT, FG_INFO, "  created a balloon" );
73
74     //set the dt of the model
75     current_balloon.set_dt(dt);
76
77     //set position
78     sgSetVec3( temp,
79         get_Latitude(), 
80         get_Longitude(), 
81         get_Altitude() * FEET_TO_METER);
82     current_balloon.setPosition( temp );
83
84     //set Euler angles (?)
85     sgSetVec3( temp,
86         get_Phi(), 
87         get_Theta(), 
88         get_Psi() );
89     current_balloon.setHPR( temp );
90
91     //set velocities
92     sgSetVec3( temp,
93                fgGetDouble("/velocities/uBody"),
94                fgGetDouble("/velocities/vBody"),
95                fgGetDouble("/velocities/wBody") );
96     current_balloon.setVelocity( temp );
97
98     FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing BalloonSim" );
99
100     return true;
101 }
102
103
104 // Run an iteration of the EOM (equations of motion)
105 bool FGBalloonSim::update( int multiloop ) {
106     double save_alt = 0.0;
107
108     // lets try to avoid really screwing up the BalloonSim model
109     if ( get_Altitude() < -9000 ) {
110         save_alt = get_Altitude();
111         set_Altitude( 0.0 );
112     }
113
114     // set control positions
115     current_balloon.set_burner_strength ( controls.get_throttle(0) );
116     //not more implemented yet
117
118     // Inform BalloonSim of the local terrain altitude
119     current_balloon.setGroundLevel ( get_Runway_altitude() * FEET_TO_METER);
120
121     // old -- FGInterface_2_JSBsim() not needed except for Init()
122     // translate FG to JSBsim structure
123     // FGInterface_2_JSBsim(f);
124     // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
125     // printf("Altitude = %.2f\n", Altitude * 0.3048);
126     // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
127
128     /* FDMExec.GetState()->Setsim_time(State->Getsim_time() 
129                                     + State->Getdt() * multiloop); */
130
131     for ( int i = 0; i < multiloop; i++ ) {
132         current_balloon.update(); 
133     }
134
135     // translate BalloonSim back to FG structure so that the
136     // autopilot (and the rest of the sim can use the updated
137     // values
138
139     copy_from_BalloonSim();
140     
141     /*sgVec3 temp, temp2;
142     current_balloon.getPosition( temp );
143     current_balloon.getVelocity( temp2 );
144     FG_LOG( FG_FLIGHT, FG_INFO, "T: " << current_balloon.getTemperature() <<
145                                 " alt: " << temp[2] <<
146                                 " gr_alt: " << get_Runway_altitude() << 
147                                 " burner: " << controls.get_elevator() <<
148                                 " v[2]: " << temp2[2]); */                      
149
150     // but lets restore our original bogus altitude when we are done
151     if ( save_alt < -9000.0 ) {
152         set_Altitude( save_alt );
153     }
154
155     return true;
156 }
157
158
159 // Convert from the FGInterface struct to the BalloonSim
160 bool FGBalloonSim::copy_to_BalloonSim() {
161     return true;
162 }
163
164
165 // Convert from the BalloonSim to the FGInterface struct
166 bool FGBalloonSim::copy_from_BalloonSim() {
167
168     sgVec3 temp;
169
170     // Velocities
171     current_balloon.getVelocity( temp );
172     _set_Velocities_Local( temp[0], temp[1], temp[2] );
173
174     /* ***FIXME*** */ _set_V_equiv_kts( sgLengthVec3 ( temp ) );
175
176     _set_Omega_Body( 0.0, 0.0, 0.0 );
177
178     // Positions
179     current_balloon.getPosition( temp );
180     //temp[0]: geocentric latitude
181     //temp[1]: longitude
182     //temp[2]: altitude (meters)
183
184     _updatePosition( temp[0], temp[1], temp[2] * METER_TO_FEET  );
185     
186     current_balloon.getHPR( temp );
187     set_Euler_Angles( temp[0], temp[1], temp[2] );
188     
189     return true;
190 }
191
192