+
+ double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
+ double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
+ double r = _density_node->getDoubleValue();
+ double q = ( pt - p ); // dynamic pressure
+
+ // Now, reverse the equation (normalize dynamic pressure to
+ // avoid "nan" results from sqrt)
+ if ( q < 0 ) { q = 0.0; }
+ double v_fps = sqrt((2 * q) / r);
+
+ // Publish the indicated airspeed
+ double last_speed_kt = _speed_node->getDoubleValue();
+ double current_speed_kt = v_fps * FPSTOKTS;
+ double filtered_speed = fgGetLowPass(last_speed_kt,
+ current_speed_kt,
+ dt * RESPONSIVENESS);
+ _speed_node->setDoubleValue(filtered_speed);
+ computeMach(filtered_speed);
+
+ if (!_has_overspeed) {
+ return;
+ }
+
+ double lmt = _ias_limit_node->getDoubleValue();
+ if (_pressure_alt->getDoubleValue() > _alt_threshold_node->getDoubleValue()) {
+ double mmo = _mach_limit_node->getDoubleValue();
+ lmt = (filtered_speed/_mach_node->getDoubleValue())* mmo;
+ }
+
+ _airspeed_limit->setDoubleValue(lmt);
+}
+
+void
+AirspeedIndicator::computeMach(double ias)
+{
+ if (!_environmentManager) {
+ return;
+ }
+
+ FGEnvironment env(_environmentManager->getEnvironment());
+
+ // derived from http://williams.best.vwh.net/avform.htm#Mach
+ // names here are picked to be consistent with those formulae!
+
+ double oatK = env.get_temperature_degc() + 273.15; // OAT in Kelvin
+ double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude
+ double CS_0 = 661.4786; // speed-of-sound in knots at sea-level
+ double P_0 = env.get_pressure_sea_level_inhg();
+ double P = _static_pressure_node->getDoubleValue();
+
+ double DP = P_0 * (pow(1 + 0.2*pow(ias/CS_0, 2), 3.5) - 1);
+ double mach = pow(5 * ( pow(DP/P + 1, 2.0/7.0) -1) , 0.5);
+
+ // publish Mach and TAS
+ _mach_node->setDoubleValue(mach);
+ _tas_node->setDoubleValue(CS * mach);