]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/steam.cxx
0d8ca2547bc70b574933cff4607815ac716a81d2
[flightgear.git] / src / Cockpit / steam.cxx
1 // steam.cxx - Steam Gauge Calculations
2 //
3 // Copyright (C) 2000  Alexander Perry - alex.perry@ieee.org
4 //
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.
9 //
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.
14 //
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.
18 //
19 // $Id$
20
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
27 #  include <iostream.h>
28 #else
29 #  include <iostream>
30 #endif
31
32 #include <simgear/constants.h>
33 #include <simgear/math/fg_types.hxx>
34 #include <Main/options.hxx>
35 #include <Main/bfi.hxx>
36
37 FG_USING_NAMESPACE(std);
38
39 #include "steam.hxx"
40
41
42 \f
43 ////////////////////////////////////////////////////////////////////////
44 // Declare the functions that read the variables
45 ////////////////////////////////////////////////////////////////////////
46
47 // Anything that reads the BFI directly is not implemented at all!
48
49
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; }
53
54 double FGSteam::get_ASI_kias() { return FGBFI::getAirspeed(); }
55
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; }
59
60 double FGSteam::get_MH_deg () { return FGBFI::getHeading (); }
61 double FGSteam::get_DG_deg () { return FGBFI::getHeading (); }
62
63 double FGSteam::get_TC_rad   () { return FGBFI::getSideSlip (); }
64 double FGSteam::get_TC_radps () { return FGBFI::getRoll (); }
65
66
67 \f
68 ////////////////////////////////////////////////////////////////////////
69 // Recording the current time
70 ////////////////////////////////////////////////////////////////////////
71
72
73 int FGSteam::_UpdatesPending = 9999;  /* Forces filter to reset */
74
75
76 void FGSteam::update ( int timesteps )
77 {
78         _UpdatesPending += timesteps;
79 }
80
81
82 void FGSteam::set_lowpass ( double *outthe, double inthe, double tc )
83 {
84         if ( tc < 0.0 )
85         {       if ( tc < -1.0 )
86                 {       /* time went backwards; kill the filter */
87                         (*outthe) = inthe;
88                 } else
89                 {       /* ignore mildly negative time */
90                 }
91         } else
92         if ( tc < 0.2 )
93         {       /* Normal mode of operation */
94                 (*outthe) = (*outthe) * ( 1.0 - tc )
95                           +    inthe  * tc;
96         } else
97         if ( tc > 5 )
98         {       /* Huge time step; assume filter has settled */
99                 (*outthe) = inthe;
100         } else
101         {       /* Moderate time step; non linear response */
102                 tc = exp ( -tc );
103                 (*outthe) = (*outthe) * ( 1.0 - tc )
104                           +    inthe  * tc;
105         }
106 }
107
108
109 \f
110 ////////////////////////////////////////////////////////////////////////
111 // Here the fun really begins
112 ////////////////////////////////////////////////////////////////////////
113
114
115 void FGSteam::_CatchUp()
116 { if ( _UpdatesPending != 0 )
117   {     double dt = _UpdatesPending * 1.0 / current_options.get_model_hz();
118         int i,j;
119         double d;
120         /*
121         Someone has called our update function and we haven't
122         incorporated this into our instrument modelling yet
123         */
124
125         /**************************
126         This is just temporary
127         */
128         the_ALT_ft = FGBFI::getAltitude();
129
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.
133         */
134         the_STATIC_inhg = 29.92; 
135         i = (int) the_ALT_ft;
136         while ( i > 18000 )
137         {       the_STATIC_inhg /= 2;
138                 i -= 18000;
139         }
140         the_STATIC_inhg /= ( 1.0 + i / 18000.0 );
141
142         /*
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.
146         */
147
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.
154         */
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 */       
158
159         /**************************
160         Finished updates, now clear the timer 
161         */
162         _UpdatesPending = 0;
163   }
164 }
165
166
167 // end of steam.cxx