]> git.mxchange.org Git - flightgear.git/commitdiff
Put gyro spin into a property so that it can be restored after a save.
authordavid <david>
Sun, 29 Sep 2002 18:26:24 +0000 (18:26 +0000)
committerdavid <david>
Sun, 29 Sep 2002 18:26:24 +0000 (18:26 +0000)
src/Instrumentation/attitude_indicator.cxx
src/Instrumentation/attitude_indicator.hxx
src/Instrumentation/heading_indicator.cxx
src/Instrumentation/heading_indicator.hxx

index 9b6626e8785c6ab6ca3554cab605938dc6699eda..b33f25da89ce813049f6624c26262ce799ec6edb 100644 (file)
@@ -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));
index 81ad86aee97c12d0bbed94ba1951098db054f498..26196eb032170ce753fcec0d75549ea9137a1f29 100644 (file)
@@ -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;
index a5040f95d711676e0918307b4a3f1cc92ce9b214..dc939c5980e11d7bcf02f074608fb4421b704648 100644 (file)
@@ -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;
index 6e414c9c4a2af4120b0a6fb5b2a9849e5be76fe7..7941010fa8b3007133fd8554da2ef5e60c13d7f8 100644 (file)
@@ -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;