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