1 // steam.cxx - Steam Gauge Calculations
3 // Copyright (C) 2000 Alexander Perry - alex.perry@ieee.org
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
27 # include <iostream.h>
32 #include <simgear/constants.h>
33 #include <simgear/math/fg_types.hxx>
34 #include <Main/options.hxx>
35 #include <Main/bfi.hxx>
37 FG_USING_NAMESPACE(std);
43 ////////////////////////////////////////////////////////////////////////
44 // Declare the functions that read the variables
45 ////////////////////////////////////////////////////////////////////////
47 // Anything that reads the BFI directly is not implemented at all!
50 double FGSteam::the_STATIC_inhg = 29.92;
51 double FGSteam::the_ALT_ft = 0.0;
52 double FGSteam::get_ALT_ft() { _CatchUp(); return the_ALT_ft; }
54 double FGSteam::get_ASI_kias() { return FGBFI::getAirspeed(); }
56 double FGSteam::the_VSI_case = 29.92;
57 double FGSteam::the_VSI_fps = 0.0;
58 double FGSteam::get_VSI_fps() { _CatchUp(); return the_VSI_fps; }
60 double FGSteam::the_VACUUM_inhg = 0.0;
61 double FGSteam::get_VACUUM_inhg() { _CatchUp(); return the_VACUUM_inhg; }
63 double FGSteam::get_MH_deg () { return FGBFI::getHeading (); }
64 double FGSteam::get_DG_deg () { return FGBFI::getHeading (); }
66 double FGSteam::get_TC_rad () { return FGBFI::getSideSlip (); }
67 double FGSteam::get_TC_radps () { return FGBFI::getRoll (); }
71 ////////////////////////////////////////////////////////////////////////
72 // Recording the current time
73 ////////////////////////////////////////////////////////////////////////
76 int FGSteam::_UpdatesPending = 9999; /* Forces filter to reset */
79 void FGSteam::update ( int timesteps )
81 _UpdatesPending += timesteps;
85 void FGSteam::set_lowpass ( double *outthe, double inthe, double tc )
89 { /* time went backwards; kill the filter */
92 { /* ignore mildly negative time */
96 { /* Normal mode of operation */
97 (*outthe) = (*outthe) * ( 1.0 - tc )
101 { /* Huge time step; assume filter has settled */
104 { /* Moderate time step; non linear response */
105 double keep = exp ( -tc );
106 printf ( "ARP: Keep is %f\n", keep );
107 (*outthe) = (*outthe) * keep
108 + inthe * ( 1.0 - keep );
114 ////////////////////////////////////////////////////////////////////////
115 // Here the fun really begins
116 ////////////////////////////////////////////////////////////////////////
119 void FGSteam::_CatchUp()
120 { if ( _UpdatesPending != 0 )
121 { double dt = _UpdatesPending * 1.0 / current_options.get_model_hz();
123 double d, the_ENGINE_rpm;
125 Someone has called our update function and
126 it turns out that we are running somewhat behind.
127 Here, we recalculate everything for a 'dt' second step.
130 /**************************
131 This is not actually correct, but provides a
132 scaling capability for the vacuum pump later on.
133 When we have a real engine model, we can ask it.
135 the_ENGINE_rpm = FGBFI::getThrottle() * 26.0;
137 /**************************
138 This is just temporary, until the static source works,
139 so we just filter the actual value by one second to
140 account for the line impedance of the plumbing.
142 set_lowpass ( & the_ALT_ft, FGBFI::getAltitude(), dt );
144 /**************************
145 First, we need to know what the static line is reporting,
146 which is a whole simulation area in itself. For now, we cheat.
148 the_STATIC_inhg = 29.92;
149 i = (int) the_ALT_ft;
151 { the_STATIC_inhg *= 0.707;
154 the_STATIC_inhg *= ( 1.0 - 0.293 * i / 9000.0 );
157 NO alternate static source error (student feature),
158 NO possibility of blockage (instructor feature),
159 NO slip-induced error, important for C172 for example.
162 /**************************
163 The VSI case is a low-pass filter of the static line pressure.
164 The instrument reports the difference, scaled to approx ft.
165 NO option for student to break glass when static source fails.
166 NO capability for a fixed non-zero reading when level.
167 NO capability to have a scaling error of maybe a factor of two.
169 the_VSI_fps = ( the_VSI_case - the_STATIC_inhg )
170 * 7000.0; /* manual scaling factor */
171 set_lowpass ( & the_VSI_case, the_STATIC_inhg, dt/9.0 );
173 /**************************
174 The engine driven vacuum pump is directly attached
175 to the engine shaft, so each engine rotation pumps
176 a fixed volume. The amount of air in that volume
177 is determined by the vacuum line's internal pressure.
178 The instruments are essentially leaking air like
179 a fixed source impedance from atmospheric pressure.
180 The regulator provides a digital limit setting,
181 which is open circuit unless the pressure drop is big.
182 Thus, we can compute the vacuum line pressure directly.
183 We assume that there is negligible reservoir space.
184 NO failure of the pump supported (yet)
186 the_VACUUM_inhg = the_STATIC_inhg *
187 the_ENGINE_rpm / ( the_ENGINE_rpm + 10000.0 );
188 if ( the_VACUUM_inhg > 5.0 )
189 the_VACUUM_inhg = 5.0;
192 > I was merely going to do the engine rpm driven vacuum pump for both
193 > the AI and DG, have the gyros spin down down in power off descents,
194 > have it tumble when you exceed the usual pitch or bank limits,
195 > put in those insidious turning errors ... for now anyway.
198 /**************************
199 Finished updates, now clear the timer