1 /*****************************************************************************
3 Module: BalloonSimInterface.cxx
4 Author: Christian Mayer
8 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Interface to the hot air balloon simulator
32 ------------------------------------------------------------------------------
33 01.09.1999 Christian Mayer Created
34 *****************************************************************************/
36 /****************************************************************************/
38 /****************************************************************************/
40 #include <simgear/compiler.h>
42 #ifdef FG_MATH_EXCEPTION_CLASH
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/math/sg_geodesy.hxx>
51 #include <simgear/misc/fgpath.hxx>
53 #include <Aircraft/aircraft.hxx>
54 #include <Controls/controls.hxx>
55 #include <Main/globals.hxx>
56 #include <Main/fg_props.hxx>
60 /****************************************************************************/
61 /********************************** CODE ************************************/
62 /****************************************************************************/
65 FGBalloonSim::FGBalloonSim( double dt ) {
66 //set the dt of the model
67 current_balloon.set_dt(dt);
71 FGBalloonSim::~FGBalloonSim() {
75 // Initialize the BalloonSim flight model, dt is the time increment for
76 // each subsequent iteration through the EOM
77 void FGBalloonSim::init() {
80 FG_LOG( FG_FLIGHT, FG_INFO, "Starting initializing BalloonSim" );
82 FG_LOG( FG_FLIGHT, FG_INFO, " created a balloon" );
88 get_Altitude() * FEET_TO_METER);
89 current_balloon.setPosition( temp );
91 //set Euler angles (?)
96 current_balloon.setHPR( temp );
100 fgGetDouble("/velocities/uBody"),
101 fgGetDouble("/velocities/vBody"),
102 fgGetDouble("/velocities/wBody") );
103 current_balloon.setVelocity( temp );
105 FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing BalloonSim" );
109 // Run an iteration of the EOM (equations of motion)
110 bool FGBalloonSim::update( int multiloop ) {
111 double save_alt = 0.0;
113 // lets try to avoid really screwing up the BalloonSim model
114 if ( get_Altitude() < -9000 ) {
115 save_alt = get_Altitude();
119 // set control positions
120 current_balloon.set_burner_strength ( controls.get_throttle(0) );
121 //not more implemented yet
123 // Inform BalloonSim of the local terrain altitude
124 current_balloon.setGroundLevel ( get_Runway_altitude() * FEET_TO_METER);
126 // old -- FGInterface_2_JSBsim() not needed except for Init()
127 // translate FG to JSBsim structure
128 // FGInterface_2_JSBsim(f);
129 // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
130 // printf("Altitude = %.2f\n", Altitude * 0.3048);
131 // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
133 /* FDMExec.GetState()->Setsim_time(State->Getsim_time()
134 + State->Getdt() * multiloop); */
136 for ( int i = 0; i < multiloop; i++ ) {
137 current_balloon.update();
140 // translate BalloonSim back to FG structure so that the
141 // autopilot (and the rest of the sim can use the updated
144 copy_from_BalloonSim();
146 /*sgVec3 temp, temp2;
147 current_balloon.getPosition( temp );
148 current_balloon.getVelocity( temp2 );
149 FG_LOG( FG_FLIGHT, FG_INFO, "T: " << current_balloon.getTemperature() <<
150 " alt: " << temp[2] <<
151 " gr_alt: " << get_Runway_altitude() <<
152 " burner: " << controls.get_elevator() <<
153 " v[2]: " << temp2[2]); */
155 // but lets restore our original bogus altitude when we are done
156 if ( save_alt < -9000.0 ) {
157 set_Altitude( save_alt );
164 // Convert from the FGInterface struct to the BalloonSim
165 bool FGBalloonSim::copy_to_BalloonSim() {
170 // Convert from the BalloonSim to the FGInterface struct
171 bool FGBalloonSim::copy_from_BalloonSim() {
176 current_balloon.getVelocity( temp );
177 _set_Velocities_Local( temp[0], temp[1], temp[2] );
179 /* ***FIXME*** */ _set_V_equiv_kts( sgLengthVec3 ( temp ) );
181 _set_Omega_Body( 0.0, 0.0, 0.0 );
184 current_balloon.getPosition( temp );
185 //temp[0]: geocentric latitude
187 //temp[2]: altitude (meters)
189 _updatePosition( temp[0], temp[1], temp[2] * METER_TO_FEET );
191 current_balloon.getHPR( temp );
192 set_Euler_Angles( temp[0], temp[1], temp[2] );