1 // inst_vertical_speed_indicator.cxx
2 // -- Instantaneous VSI (emulation calibrated to standard atmosphere).
4 // Started September 2004.
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <simgear/math/interpolater.hxx>
25 #include "inst_vertical_speed_indicator.hxx"
26 #include <Main/fg_props.hxx>
27 #include <Main/util.hxx>
30 // Altitude based on pressure difference from sea level.
32 // See http://www.pdas.com/programs/atmos.f90, the tables match exactly
33 // environment.cxx (Standard 1976).
35 // - at 27900 m the level is 20 km :
36 // geopotential altitude 27.9 x 6369 / ( 27.9 + 6369) = 27.778 km.
37 // - deltah = 27.778 - 20 = 7.778 km and tbase 216.65 degK.
38 // - delta = 5.403295E-2 x exp( -34.163195 x 7.778 / 216.65 ) = 0.016.
39 // - pressure = (1 - delta ) x 29.92 = 29.44 inhg.
40 // - to construct the tables, round delta to 3 digits.
42 // altitude ft, pressure step inHG
43 static double pressure_data[][2] = {
44 { 0.00, 3.33 }, // guess !
82 // pressure difference inHG, altitude ft
83 static double altitude_data[][2] = {
118 { 29.62, 100393.70 },
124 #define SEA_LEVEL_INHG 29.92
126 // A higher number means more responsive.
127 #define RESPONSIVENESS 5.0
129 // External environment
130 #define MAX_INHG_PER_S 0.0002
133 InstVerticalSpeedIndicator::InstVerticalSpeedIndicator ( SGPropertyNode *node ) :
134 _name(node->getStringValue("name", "inst-vertical-speed-indicator")),
135 _num(node->getIntValue("number", 0)),
136 _internal_pressure_inhg( SEA_LEVEL_INHG ),
137 _internal_sea_inhg( SEA_LEVEL_INHG ),
138 _speed_ft_per_s( 0 ),
139 _pressure_table(new SGInterpTable),
140 _altitude_table(new SGInterpTable)
143 for ( i = 0; pressure_data[i][0] != -1; i++)
144 _pressure_table->addEntry( pressure_data[i][0], pressure_data[i][1] );
146 for ( i = 0; altitude_data[i][0] != -1; i++)
147 _altitude_table->addEntry( altitude_data[i][0], altitude_data[i][1] );
151 InstVerticalSpeedIndicator::~InstVerticalSpeedIndicator ()
153 delete _pressure_table;
154 delete _altitude_table;
158 void InstVerticalSpeedIndicator::init ()
160 SGPropertyNode *node = fgGetNode("/instrumentation", true)->getChild(_name, _num, true);
163 node->getNode("serviceable", true);
165 fgGetNode("/sim/freeze/master", true);
167 // A real IVSI is operated by static pressure changes.
168 // It operates like a conventional VSI, except that an internal sensor
169 // detects load factors, to momentarily alters the static pressure
171 // It appears lag free at subsonic speed; at high altitude indication may
172 // be less than 1/3 of actual conditions.
174 fgGetNode("/environment/pressure-inhg", true);
176 fgGetNode("/environment/pressure-sea-level-inhg", true);
178 fgGetNode("/sim/speed-up", true);
180 node->getNode("indicated-speed-fps", true);
182 node->getNode("indicated-speed-fpm", true);
184 // Initialize at ambient pressure
185 _internal_pressure_inhg = _pressure_node->getDoubleValue();
189 void InstVerticalSpeedIndicator::update (double dt)
191 if (_serviceable_node->getBoolValue())
193 // avoids hang, when freeze
194 if( !_freeze_node->getBoolValue() )
196 double pressure_inhg = _pressure_node->getDoubleValue();
197 double sea_inhg = _sea_node->getDoubleValue();
198 double speed_up = _speed_up_node->getDoubleValue();
200 // must work by speed up
206 // limit effect of external environment
207 double rate_sea_inhg_per_s = ( sea_inhg - _internal_sea_inhg ) / dt;
209 if( rate_sea_inhg_per_s > - MAX_INHG_PER_S && rate_sea_inhg_per_s < MAX_INHG_PER_S )
211 double rate_inhg_per_s = ( pressure_inhg - _internal_pressure_inhg ) / dt;
213 // IVSI determines alone the current altitude, without altimeter setting.
214 // Altimeter setting is 29.92 above 10000 or 18000 ft.
215 // Below this level, the slope is slightly wrong.
216 double altitude_ft = _altitude_table->interpolate( SEA_LEVEL_INHG - pressure_inhg );
217 double slope_inhg = _pressure_table->interpolate( altitude_ft );
220 double last_speed_ft_per_s = _speed_ft_per_s;
223 _speed_ft_per_s = - rate_inhg_per_s * 2952.75591 / slope_inhg;
226 _speed_ft_per_s = fgGetLowPass( last_speed_ft_per_s, _speed_ft_per_s,
227 dt * RESPONSIVENESS );
230 _speed_node->setDoubleValue( _speed_ft_per_s );
231 _speed_min_node->setDoubleValue( _speed_ft_per_s * 60.0 );
234 _internal_pressure_inhg = pressure_inhg;
235 _internal_sea_inhg = sea_inhg;
240 // end of inst_vertical_speed_indicator.cxx