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::get_MH_deg () { return FGBFI::getHeading (); }
61 double FGSteam::get_DG_deg () { return FGBFI::getHeading (); }
63 double FGSteam::get_TC_rad () { return FGBFI::getSideSlip (); }
64 double FGSteam::get_TC_radps () { return FGBFI::getRoll (); }
68 ////////////////////////////////////////////////////////////////////////
69 // Recording the current time
70 ////////////////////////////////////////////////////////////////////////
73 int FGSteam::_UpdatesPending = 9999; /* Forces filter to reset */
76 void FGSteam::update ( int timesteps )
78 _UpdatesPending += timesteps;
82 void FGSteam::set_lowpass ( double *outthe, double inthe, double tc )
86 { /* time went backwards; kill the filter */
89 { /* ignore mildly negative time */
93 { /* Normal mode of operation */
94 (*outthe) = (*outthe) * ( 1.0 - tc )
98 { /* Huge time step; assume filter has settled */
101 { /* Moderate time step; non linear response */
103 (*outthe) = (*outthe) * ( 1.0 - tc )
110 ////////////////////////////////////////////////////////////////////////
111 // Here the fun really begins
112 ////////////////////////////////////////////////////////////////////////
115 void FGSteam::_CatchUp()
116 { if ( _UpdatesPending != 0 )
117 { double dt = _UpdatesPending * 1.0 / current_options.get_model_hz();
121 Someone has called our update function and we haven't
122 incorporated this into our instrument modelling yet
125 /**************************
126 This is just temporary
128 the_ALT_ft = FGBFI::getAltitude();
130 /**************************
131 First, we need to know what the static line is reporting,
132 which is a whole simulation area in itself. For now, we cheat.
134 the_STATIC_inhg = 29.92;
135 i = (int) the_ALT_ft;
137 { the_STATIC_inhg /= 2;
140 the_STATIC_inhg /= ( 1.0 + i / 18000.0 );
143 NO alternate static source error (student feature),
144 NO possibility of blockage (instructor feature),
145 NO slip-induced error, important for C172 for example.
148 /**************************
149 The VSI case is a low-pass filter of the static line pressure.
150 The instrument reports the difference, scaled to approx ft.
151 NO option for student to break glass when static source fails.
152 NO capability for a fixed non-zero reading when level.
153 NO capability to have a scaling error of maybe a factor of two.
155 set_lowpass ( & the_VSI_case, the_STATIC_inhg, dt/9.0 );
156 the_VSI_fps = ( the_VSI_case - the_STATIC_inhg )
157 * 7000.0; /* manual scaling factor */
159 /**************************
160 Finished updates, now clear the timer