]> git.mxchange.org Git - flightgear.git/blob - src/FDM/Balloon.cxx
b) FDM - ada.cxx, ada.hxx have been updated with the faux, daux and iaux arrays that...
[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 SG_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/sg_path.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 FGBalloonSim::FGBalloonSim( double dt ) {
66     //set the dt of the model
67     current_balloon.set_dt(dt);
68 }
69
70
71 FGBalloonSim::~FGBalloonSim() {
72 }
73
74
75 // Initialize the BalloonSim flight model, dt is the time increment for
76 // each subsequent iteration through the EOM
77 void FGBalloonSim::init() {
78                                 // explicitly call the superclass's
79                                 // init method first.
80     FGInterface::init();
81
82     sgVec3 temp;
83
84     SG_LOG( SG_FLIGHT, SG_INFO, "Starting initializing BalloonSim" );
85
86     SG_LOG( SG_FLIGHT, SG_INFO, "  created a balloon" );
87
88     //set position
89     sgSetVec3( temp,
90         get_Latitude(), 
91         get_Longitude(), 
92         get_Altitude() * SG_FEET_TO_METER);
93     current_balloon.setPosition( temp );
94
95     //set Euler angles (?)
96     sgSetVec3( temp,
97         get_Phi(), 
98         get_Theta(), 
99         get_Psi() );
100     current_balloon.setHPR( temp );
101
102     //set velocities
103     sgSetVec3( temp,
104                fgGetDouble("/velocities/uBody-fps"),
105                fgGetDouble("/velocities/vBody-fps"),
106                fgGetDouble("/velocities/wBody-fps") );
107     current_balloon.setVelocity( temp );
108
109     SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing BalloonSim" );
110 }
111
112
113 // Run an iteration of the EOM (equations of motion)
114 bool FGBalloonSim::update( int multiloop ) {
115     double save_alt = 0.0;
116
117     // lets try to avoid really screwing up the BalloonSim model
118     if ( get_Altitude() < -9000 ) {
119         save_alt = get_Altitude();
120         set_Altitude( 0.0 );
121     }
122
123     // set control positions
124     current_balloon.set_burner_strength ( globals->get_controls()->get_throttle(0) );
125     //not more implemented yet
126
127     // Inform BalloonSim of the local terrain altitude
128     current_balloon.setGroundLevel ( get_Runway_altitude() * SG_FEET_TO_METER);
129
130     // old -- FGInterface_2_JSBsim() not needed except for Init()
131     // translate FG to JSBsim structure
132     // FGInterface_2_JSBsim(f);
133     // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
134     // printf("Altitude = %.2f\n", Altitude * 0.3048);
135     // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
136
137     /* FDMExec.GetState()->Setsim_time(State->Getsim_time() 
138                                     + State->Getdt() * multiloop); */
139
140     for ( int i = 0; i < multiloop; i++ ) {
141         current_balloon.update(); 
142     }
143
144     // translate BalloonSim back to FG structure so that the
145     // autopilot (and the rest of the sim can use the updated
146     // values
147
148     copy_from_BalloonSim();
149     
150     /*sgVec3 temp, temp2;
151     current_balloon.getPosition( temp );
152     current_balloon.getVelocity( temp2 );
153     SG_LOG( SG_FLIGHT, SG_INFO, "T: " << current_balloon.getTemperature() <<
154                                 " alt: " << temp[2] <<
155                                 " gr_alt: " << get_Runway_altitude() << 
156                                 " burner: " << controls.get_elevator() <<
157                                 " v[2]: " << temp2[2]); */                      
158
159     // but lets restore our original bogus altitude when we are done
160     if ( save_alt < -9000.0 ) {
161         set_Altitude( save_alt );
162     }
163
164     return true;
165 }
166
167
168 // Convert from the FGInterface struct to the BalloonSim
169 bool FGBalloonSim::copy_to_BalloonSim() {
170     return true;
171 }
172
173
174 // Convert from the BalloonSim to the FGInterface struct
175 bool FGBalloonSim::copy_from_BalloonSim() {
176
177     sgVec3 temp;
178
179     // Velocities
180     current_balloon.getVelocity( temp );
181     _set_Velocities_Local( temp[0], temp[1], temp[2] );
182
183     /* ***FIXME*** */ _set_V_equiv_kts( sgLengthVec3 ( temp ) );
184
185     _set_Omega_Body( 0.0, 0.0, 0.0 );
186
187     // Positions
188     current_balloon.getPosition( temp );
189     //temp[0]: geocentric latitude
190     //temp[1]: longitude
191     //temp[2]: altitude (meters)
192
193     _updatePosition( temp[0], temp[1], temp[2] * SG_METER_TO_FEET  );
194     
195     current_balloon.getHPR( temp );
196     set_Euler_Angles( temp[0], temp[1], temp[2] );
197     
198     return true;
199 }
200
201