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