]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/mrg.cxx
Modified Files:
[flightgear.git] / src / Instrumentation / mrg.cxx
index 918160ae54eaf8053c4a4e293cb8afe4a61a0a24..d890ee266b6a28ffd6097f2779a80560978d0e22 100644 (file)
@@ -1,5 +1,5 @@
-// MRG.cxx - an electrcally powered master reference gyro.
-// Written by Vivian Meazza based on wrok by David Megginson, started 2006.
+// MRG.cxx - an electrically powered master reference gyro.
+// Written by Vivian Meazza based on work by David Megginson, started 2006.
 //
 // This file is in the Public Domain and comes with no warranty.
 
 
 
 MasterReferenceGyro::MasterReferenceGyro ( SGPropertyNode *node ) :
-       name("master-reference-gyro"),
-       num(0)
-{
-       int i;
-       for ( i = 0; i < node->nChildren(); ++i ) {
-               SGPropertyNode *child = node->getChild(i);
-               string cname = child->getName();
-               string cval = child->getStringValue();
-               if ( cname == "name" ) {
-                       name = cval;
-               } else if ( cname == "number" ) {
-                       num = (int) child->getDoubleValue();
-               } else {
-                       SG_LOG( SG_INSTR, SG_WARN, "Error in mrg config logic" );
-                       if ( name.length() ) {
-                               SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
-                       }
-               }
-       }
-}
-
-MasterReferenceGyro::MasterReferenceGyro ()
+       _name(node->getStringValue("name", "master-reference-gyro")),
+       _num(node->getIntValue("number", 0))
 {
 }
 
@@ -63,7 +43,7 @@ MasterReferenceGyro::init ()
        _indicated_pitch_rate = 0;
        
        string branch;
-       branch = "/instrumentation/" + name;
+       branch = "/instrumentation/" + _name;
 
        _pitch_in_node = fgGetNode("/orientation/pitch-deg", true);
        _roll_in_node = fgGetNode("/orientation/roll-deg", true);
@@ -74,7 +54,7 @@ MasterReferenceGyro::init ()
        _g_in_node =   fgGetNode("/accelerations/pilot-g-damped", true);
        _electrical_node = fgGetNode("/systems/electrical/outputs/MRG", true);
        
-       SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+       SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
        _off_node = node->getChild("off-flag", 0, true);
        _pitch_out_node = node->getChild("indicated-pitch-deg", 0, true);
        _roll_out_node = node->getChild("indicated-roll-deg", 0, true);
@@ -95,8 +75,8 @@ MasterReferenceGyro::bind ()
 {
        std::ostringstream temp;
        string branch;
-       temp << num;
-       branch = "/instrumentation/" + name + "[" + temp.str() + "]";
+       temp << _num;
+       branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
 
        fgTie((branch + "/serviceable").c_str(),
                &_gyro, &Gyro::is_serviceable, &Gyro::set_serviceable);
@@ -109,8 +89,8 @@ MasterReferenceGyro::unbind ()
 {
        std::ostringstream temp;
        string branch;
-       temp << num;
-       branch = "/instrumentation/" + name + "[" + temp.str() + "]";
+       temp << _num;
+       branch = "/instrumentation/" + _name + "[" + temp.str() + "]";
 
        fgUntie((branch + "/serviceable").c_str());
        fgUntie((branch + "/spin").c_str());
@@ -167,7 +147,7 @@ MasterReferenceGyro::update (double dt)
        _last_yaw_rate = yaw_rate;
 
        //the gyro only erects inside limits
-       if ( abs ( yaw_rate ) <= 5
+       if ( fabs ( yaw_rate ) <= 5
                        && (_g_in_node->getDoubleValue() <= 1.5
                        || _g_in_node->getDoubleValue() >= -0.5) ) {
                indicated_roll = _last_roll;