~ubuntu-branches/debian/sid/flightgear/sid

« back to all changes in this revision

Viewing changes to src/Instrumentation/airspeed_indicator.cxx

  • Committer: Package Import Robot
  • Author(s): Markus Wanner, Markus Wanner, Rebecca Palmer
  • Date: 2014-01-21 22:31:02 UTC
  • mfrom: (1.3.1) (15.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140121223102-cjw7g9le25acd119
Tags: 3.0.0~git20140204+c99ea4-1
[ Markus Wanner ]
* Upload to unstable.
* Adjust B-D to allow building on kfreebsd-*. Closes: #724686.
* Add a lintian-overrides on autotools; we use cmake.
* Upstream corrected the fgfs manpage. Closes: #556362.
* Drop unnecessary man page for gl-info. Closes: #698308.
* Drop README.Linux: it's outdated to the point of uselessness.
  Closes: #574173.
* Add an upper limit of libsimgear-dev versions that flightgear can be
  built with. Closes: #738436.
* Drop the libsvn-dev dependency, neither flightgear nor simgear depend
  on libsvn, anymore. Closes: #682947.
* List icons in debian/install rather than copying around from rules.
* Update menu entry for flightgear, add one for fgcom; add .xpm icons.
  Closes: #713924.
* flightgear.desktop: add German translation
* Bump Standards-Version to 3.9.5; no changes needed.

[ Rebecca Palmer ]
* New upstream release.
* Install the icons (based on code by Saikrishna Arcot).  (Not a
  complete fix for LP908153 as it only sets the menu/Dash icon, not the
  running window's icon, but better than nothing).
* Disable screensaver while running. Closes: LP#793599. Add required
  libdbus-1-dev dependency.
* Remove outdated README.Debian.
* Terrasync now works after just ticking the box. Closes: #252899.
* Always set Terrasync directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
2
2
// Written by David Megginson, started 2002.
 
3
// Last modified by Eric van den Berg, 09 Dec 2012
3
4
//
4
5
// This file is in the Public Domain and comes with no warranty.
5
6
 
9
10
 
10
11
#include <math.h>
11
12
 
 
13
#include <simgear/constants.h>
12
14
#include <simgear/math/interpolater.hxx>
13
15
 
14
16
#include "airspeed_indicator.hxx"
15
17
#include <Main/fg_props.hxx>
16
18
#include <Main/util.hxx>
 
19
#include <Environment/environment_mgr.hxx>
 
20
#include <Environment/environment.hxx>
17
21
 
18
22
 
19
23
// A higher number means more responsive.
31
35
    _mach_limit(node->getDoubleValue("mach-limit", 0.48)),
32
36
    _alt_threshold(node->getDoubleValue("alt-threshold", 13200))
33
37
{
 
38
  _environmentManager = NULL;
34
39
}
35
40
 
36
41
AirspeedIndicator::~AirspeedIndicator ()
40
45
void
41
46
AirspeedIndicator::init ()
42
47
{
43
 
    string branch;
 
48
    std::string branch;
44
49
    branch = "/instrumentation/" + _name;
45
50
 
46
51
    SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
48
53
    _total_pressure_node = fgGetNode(_total_pressure.c_str(), true);
49
54
    _static_pressure_node = fgGetNode(_static_pressure.c_str(), true);
50
55
    _density_node = fgGetNode("/environment/density-slugft3", true);
51
 
    
52
 
    _sea_level_pressure_node = fgGetNode("/environment/pressure-sea-level-inhg", true);
53
 
    _oat_celsius_node = fgGetNode("/environment/temperature-degc", true);
54
 
  
55
56
    _speed_node = node->getChild("indicated-speed-kt", 0, true);
56
57
    _tas_node = node->getChild("true-speed-kt", 0, true);
57
58
    _mach_node = node->getChild("indicated-mach", 0, true);
77
78
        _airspeed_limit = node->getChild("airspeed-limit-kt", 0, true);
78
79
        _pressure_alt = fgGetNode(_pressure_alt_source.c_str(), true);
79
80
    }
 
81
    
 
82
    _environmentManager = (FGEnvironmentMgr*) globals->get_subsystem("environment");
80
83
}
81
84
 
82
85
void
85
88
    _speed_node->setDoubleValue(0.0);
86
89
}
87
90
 
88
 
#ifndef FPSTOKTS
89
 
# define FPSTOKTS 0.592484
90
 
#endif
91
 
 
92
 
#ifndef INHGTOPSF
93
 
# define INHGTOPSF (2116.217/29.9212)
94
 
#endif
95
 
 
96
91
void
97
92
AirspeedIndicator::update (double dt)
98
93
{
100
95
        return;
101
96
    }
102
97
    
103
 
    double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
104
 
    double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
105
 
    double r = _density_node->getDoubleValue();
106
 
    double q = ( pt - p );  // dynamic pressure
 
98
    double pt = _total_pressure_node->getDoubleValue() ;
 
99
    double p = _static_pressure_node->getDoubleValue() ;
 
100
    double qc = ( pt - p ) * SG_INHG_TO_PA ;  // Impact pressure in Pa, _not_ to be confused with dynamic pressure!!!
107
101
 
108
 
    // Now, reverse the equation (normalize dynamic pressure to
 
102
    // Now, reverse the equation (normalize impact pressure to
109
103
    // avoid "nan" results from sqrt)
110
 
    if ( q < 0 ) { q = 0.0; }
111
 
    double v_fps = sqrt((2 * q) / r);
 
104
    qc = std::max( qc , 0.0 );
 
105
    // Calibrated airspeed (using compressible aerodynamics) based on impact pressure qc in m/s
 
106
    // Using calibrated airspeed as indicated airspeed, neglecting any airspeed indicator errors.
 
107
    double v_cal = sqrt( 7 * SG_p0_Pa/SG_rho0_kg_p_m3 * ( pow( 1 + qc/SG_p0_Pa  , 1/3.5 )  -1 ) );
112
108
 
113
109
                            // Publish the indicated airspeed
114
110
    double last_speed_kt = _speed_node->getDoubleValue();
115
 
    double current_speed_kt = v_fps * FPSTOKTS;
 
111
    double current_speed_kt = v_cal * SG_MPS_TO_KT;
116
112
    double filtered_speed = fgGetLowPass(last_speed_kt,
117
113
                                             current_speed_kt,
118
114
                                             dt * RESPONSIVENESS);
119
115
    _speed_node->setDoubleValue(filtered_speed);
120
 
    computeMach(filtered_speed);
 
116
    computeMach();
121
117
 
122
118
    if (!_has_overspeed) {
123
119
        return;
133
129
}
134
130
 
135
131
void
136
 
AirspeedIndicator::computeMach(double ias)
 
132
AirspeedIndicator::computeMach()
137
133
{
138
 
   
139
 
  // derived from http://williams.best.vwh.net/avform.htm#Mach
140
 
  // names here are picked to be consistent with those formulae!
141
 
 
142
 
  double oatK = _oat_celsius_node->getDoubleValue() + 273.15; // OAT in Kelvin
143
 
  double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude
144
 
  double CS_0 = 661.4786; // speed-of-sound in knots at sea-level
145
 
  double P_0 = _sea_level_pressure_node->getDoubleValue();
146
 
  double P = _static_pressure_node->getDoubleValue();
147
 
  
148
 
  double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1);
149
 
  double mach = pow(5 * ( pow(DP/P + 1, 2.0/7.0) -1) , 0.5);
 
134
  if (!_environmentManager) {
 
135
    return;
 
136
  }
 
137
  
 
138
  FGEnvironment env(_environmentManager->getEnvironment());
 
139
  
 
140
  double oatK = env.get_temperature_degc() + SG_T0_K - 15.0 ;         // OAT in Kelvin
 
141
  oatK = std::max( oatK , 0.001 );                                // should never happen, but just in case someone flies into space...
 
142
  double c = sqrt(SG_gamma * SG_R_m2_p_s2_p_K * oatK);                 // speed-of-sound in m/s at aircraft position
 
143
  double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA;  // total pressure in Pa
 
144
  double p = _static_pressure_node->getDoubleValue() * SG_INHG_TO_PA;  // static pressure in Pa
 
145
  p = std::max( p , 0.001 );                                           // should never happen, but just in case someone flies into space...
 
146
  double rho = _density_node->getDoubleValue() * SG_SLUGFT3_TO_KGPM3;  // air density in kg/m3
 
147
  rho = std::max( rho , 0.001 );                                      // should never happen, but just in case someone flies into space...
 
148
  
 
149
  // true airspeed in m/s
 
150
  pt = std::max( pt , p );
 
151
  double V_true = sqrt( 7 * p/rho * (pow( 1 + (pt-p)/p , 1/3.5 ) -1 ) );
 
152
  // Mach number; _see notes in systems/pitot.cxx_
 
153
  double mach = V_true / c;
150
154
  
151
155
  // publish Mach and TAS
152
156
  _mach_node->setDoubleValue(mach);
153
 
  _tas_node->setDoubleValue(CS * mach);
 
157
  _tas_node->setDoubleValue(V_true * SG_MPS_TO_KT );
154
158
}
155
159
 
156
160
// end of airspeed_indicator.cxx