]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.cxx
Moved random ground cover object management code (userdata.[ch]xx) over
[flightgear.git] / src / Systems / electrical.cxx
index 2559874cace44b644658ab9f3e962a829e44c01f..4905dbeb46e10aa56645339a53031cb796118375 100644 (file)
@@ -56,6 +56,7 @@ FGElectricalSupplier::FGElectricalSupplier ( SGPropertyNode *node ) {
     }
     volts = node->getDoubleValue("volts");
     amps = node->getDoubleValue("amps");
+    rpm_src = node->getStringValue("rpm-source");
 
     int i;
     for ( i = 0; i < node->nChildren(); ++i ) {
@@ -69,7 +70,7 @@ FGElectricalSupplier::FGElectricalSupplier ( SGPropertyNode *node ) {
         }
     }
 
-    _rpm_node = fgGetNode("/engines/engine[0]/rpm", true);
+    _rpm_node = fgGetNode( rpm_src.c_str(), true);
 }  
 
 
@@ -200,7 +201,7 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
 
 // set all switches to the specified state
 void FGElectricalConnector::set_switches( bool state ) {
-    cout << "setting switch state to " << state << endl;
+    // cout << "setting switch state to " << state << endl;
     for ( unsigned int i = 0; i < switches.size(); ++i ) {
         switches[i]->setBoolValue( state );
     }
@@ -236,6 +237,8 @@ void FGElectricalSystem::init () {
     config_props = new SGPropertyNode;
 
     SGPropertyNode *path_n = fgGetNode("/sim/systems/electrical/path");
+    _volts_out = fgGetNode( "/systems/electrical/volts", true );
+    _amps_out = fgGetNode( "/systems/electrical/amps", true );
 
     if (path_n) {
         SGPath config( globals->get_fg_root() );
@@ -280,6 +283,7 @@ void FGElectricalSystem::unbind () {
 
 void FGElectricalSystem::update (double dt) {
     if ( !enabled ) {
+        _amps_out->setDoubleValue(0);
         return;
     }
 
@@ -301,12 +305,53 @@ void FGElectricalSystem::update (double dt) {
         connectors[i]->set_value( 0.0 );
     }
 
-    // for each supplier, propogate the electrical current
+    // for each supplier, propagate the electrical current
     for ( i = 0; i < suppliers.size(); ++i ) {
         // cout << " Updating: " << suppliers[i]->get_name() << endl;
-        propogate( suppliers[i], 0.0, " " );
+        propagate( suppliers[i], 0.0, " " );
     }
 
+    double alt_norm
+        = fgGetDouble("/systems/electrical/suppliers/alternator") / 60.0;
+
+    // impliment an extremely simplistic voltage model (assumes
+    // certain naming conventions in electrical system config)
+    double volts = 0.0;
+    if ( fgGetBool("/controls/switches/master-bat") ) {
+        volts = 24.0;
+    }
+    if ( fgGetBool("/controls/switches/master-alt") &&
+         fgGetDouble("/engines/engine[0]/rpm") > 800 )
+    {
+        double alt_contrib = 28.0;
+        if ( alt_contrib > volts ) {
+            volts = alt_contrib;
+        }
+    }
+    _volts_out->setDoubleValue( volts );
+
+    // impliment an extremely simplistic amps model (assumes certain
+    // naming conventions in the electrical system config) ... FIXME:
+    // make this more generic
+    double amps = 0.0;
+    if ( fgGetBool("/controls/switches/master-bat") ) {
+        if ( fgGetBool("/controls/switches/master-alt") &&
+             fgGetDouble("/engines/engine[0]/rpm") > 800 )
+        {
+            amps += 40.0 * alt_norm;
+        }
+        amps -= 15.0;            // normal load
+        if ( fgGetBool("/controls/switches/flashing-beacon") ) {
+            amps -= 7.5;
+        }
+        if ( fgGetBool("/controls/switches/nav-lights") ) {
+            amps -= 7.5;
+        }
+        if ( amps > 7.0 ) {
+            amps = 7.0;
+        }
+    }
+    _amps_out->setDoubleValue( amps );
 }
 
 
@@ -346,8 +391,8 @@ bool FGElectricalSystem::build () {
 }
 
 
-// propogate the electrical current through the network
-void FGElectricalSystem::propogate( FGElectricalComponent *node, double val,
+// propagate the electrical current through the network
+void FGElectricalSystem::propagate( FGElectricalComponent *node, double val,
                                     string s ) {
     s += " ";
 
@@ -388,9 +433,9 @@ void FGElectricalSystem::propogate( FGElectricalComponent *node, double val,
     }
     // cout << s << node->get_name() << " -> " << node->get_value() << endl;
 
-    // propogate to all children
+    // propagate to all children
     for ( i = 0; i < node->get_num_outputs(); ++i ) {
-        propogate( node->get_output(i), current, s );
+        propagate( node->get_output(i), current, s );
     }
 }