From: david Date: Sun, 29 Sep 2002 18:26:24 +0000 (+0000) Subject: Put gyro spin into a property so that it can be restored after a save. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b0afca93d5f8877f03fb7ca83eff1d3f486c7375;p=flightgear.git Put gyro spin into a property so that it can be restored after a save. --- diff --git a/src/Instrumentation/attitude_indicator.cxx b/src/Instrumentation/attitude_indicator.cxx index 9b6626e87..b33f25da8 100644 --- a/src/Instrumentation/attitude_indicator.cxx +++ b/src/Instrumentation/attitude_indicator.cxx @@ -26,6 +26,7 @@ AttitudeIndicator::init () // to be configured. _serviceable_node = fgGetNode("/instrumentation/attitude-indicator/serviceable", true); + _spin_node = fgGetNode("/instrumentation/attitude-indicator/spin", true); _pitch_in_node = fgGetNode("/orientation/pitch-deg", true); _roll_in_node = fgGetNode("/orientation/roll-deg", true); _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true); @@ -53,7 +54,8 @@ AttitudeIndicator::update (double dt) // First, calculate the bogo-spin from 0 to 1. // All numbers are made up. - _spin -= 0.005 * dt; // spin decays every 0.5% every second. + double spin = _spin_node->getDoubleValue(); + spin -= 0.005 * dt; // spin decays every 0.5% every second. // spin increases up to 25% every second // if suction is available and the gauge @@ -61,17 +63,18 @@ AttitudeIndicator::update (double dt) if (_serviceable_node->getBoolValue()) { double suction = _suction_node->getDoubleValue(); double step = 0.25 * (suction / 5.0) * dt; - if ((_spin + step) <= (suction / 5.0)) - _spin += step; + if ((spin + step) <= (suction / 5.0)) + spin += step; } - if (_spin > 1.0) - _spin = 1.0; - else if (_spin < 0.0) - _spin = 0.0; + if (spin > 1.0) + spin = 1.0; + else if (spin < 0.0) + spin = 0.0; + _spin_node->setDoubleValue(spin); // Next, calculate the indicated roll // and pitch, introducing errors. - double factor = 1.0 - ((1.0 - _spin) * (1.0 - _spin)); + double factor = 1.0 - ((1.0 - spin) * (1.0 - spin)); double roll = _roll_in_node->getDoubleValue(); double pitch = _pitch_in_node->getDoubleValue(); roll = 35 + (factor * (roll - 35)); diff --git a/src/Instrumentation/attitude_indicator.hxx b/src/Instrumentation/attitude_indicator.hxx index 81ad86aee..26196eb03 100644 --- a/src/Instrumentation/attitude_indicator.hxx +++ b/src/Instrumentation/attitude_indicator.hxx @@ -23,6 +23,7 @@ * Input properties: * * /instrumentation/attitude-indicator/serviceable + * /instrumentation/attitude-indicator/spin * /orientation/pitch-deg * /orientation/roll-deg * /systems/vacuum[0]/suction-inhg @@ -47,9 +48,8 @@ public: private: - double _spin; - SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _spin_node; SGPropertyNode_ptr _pitch_in_node; SGPropertyNode_ptr _roll_in_node; SGPropertyNode_ptr _suction_node; diff --git a/src/Instrumentation/heading_indicator.cxx b/src/Instrumentation/heading_indicator.cxx index a5040f95d..dc939c598 100644 --- a/src/Instrumentation/heading_indicator.cxx +++ b/src/Instrumentation/heading_indicator.cxx @@ -21,6 +21,8 @@ HeadingIndicator::init () { _serviceable_node = fgGetNode("/instrumentation/heading-indicator/serviceable", true); + _spin_node = + fgGetNode("/instrumentation/heading-indicator/spin", true); _offset_node = fgGetNode("/instrumentation/heading-indicator/offset-deg", true); _heading_in_node = fgGetNode("/orientation/heading-deg", true); @@ -48,7 +50,8 @@ HeadingIndicator::update (double dt) // First, calculate the bogo-spin from 0 to 1. // All numbers are made up. - _spin -= 0.005 * dt; // spin decays every 0.5% every second. + double spin = _spin_node->getDoubleValue(); + spin -= 0.005 * dt; // spin decays every 0.5% every second. // spin increases up to 25% every second // if suction is available and the gauge @@ -56,13 +59,14 @@ HeadingIndicator::update (double dt) if (_serviceable_node->getBoolValue()) { double suction = _suction_node->getDoubleValue(); double step = 0.25 * (suction / 5.0) * dt; - if ((_spin + step) <= (suction / 5.0)) - _spin += step; + if ((spin + step) <= (suction / 5.0)) + spin += step; } - if (_spin > 1.0) - _spin = 1.0; - else if (_spin < 0.0) - _spin = 0.0; + if (spin > 1.0) + spin = 1.0; + else if (spin < 0.0) + spin = 0.0; + _spin_node->setDoubleValue(spin); // Next, calculate time-based precession double offset = _offset_node->getDoubleValue(); @@ -77,7 +81,7 @@ HeadingIndicator::update (double dt) // Next, calculate the indicated heading, // introducing errors. - double factor = 0.01 / (_spin * _spin * _spin * _spin * _spin * _spin); + double factor = 0.01 / (spin * spin * spin * spin * spin * spin); double heading = _heading_in_node->getDoubleValue(); heading = fgGetLowPass(_last_heading_deg, heading, dt/factor); _last_heading_deg = heading; diff --git a/src/Instrumentation/heading_indicator.hxx b/src/Instrumentation/heading_indicator.hxx index 6e414c9c4..7941010fa 100644 --- a/src/Instrumentation/heading_indicator.hxx +++ b/src/Instrumentation/heading_indicator.hxx @@ -23,6 +23,7 @@ * Input properties: * * /instrumentation/heading-indicator/serviceable + * /instrumentation/heading-indicator/spin * /instrumentation/heading-indicator/offset-deg * /orientation/heading-deg * /systems/vacuum[0]/suction-inhg @@ -46,10 +47,10 @@ public: private: - double _spin; double _last_heading_deg; SGPropertyNode_ptr _serviceable_node; + SGPropertyNode_ptr _spin_node; SGPropertyNode_ptr _offset_node; SGPropertyNode_ptr _heading_in_node; SGPropertyNode_ptr _suction_node;