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