]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.cxx
Don't scale elevator by 0.5.
[flightgear.git] / src / Systems / electrical.cxx
index 4c385b3a3f0e27631ee02382897978ebd641daea..d2bb01c59f51d9bfce75809fb853f4febb192434 100644 (file)
@@ -21,7 +21,7 @@
 // $Id$
 
 
-#include <simgear/misc/exception.hxx>
+#include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 #include <Main/fg_props.hxx>
@@ -62,7 +62,7 @@ FGElectricalSupplier::FGElectricalSupplier ( SGPropertyNode *node ) {
     for ( i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
         // cout << " scanning: " << child->getName() << endl;
-        if ( (string)child->getName() == "prop" ) {
+        if ( !strcmp(child->getName(), "prop") ) {
             string prop = child->getStringValue();
             // cout << "  Adding prop = " << prop << endl;
             add_prop( prop );
@@ -107,7 +107,7 @@ FGElectricalBus::FGElectricalBus ( SGPropertyNode *node ) {
     int i;
     for ( i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
-        if ( (string)child->getName() == "prop" ) {
+        if ( !strcmp(child->getName(), "prop") ) {
             string prop = child->getStringValue();
             add_prop( prop );
         }
@@ -122,7 +122,7 @@ FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) {
     int i;
     for ( i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
-        if ( (string)child->getName() == "prop" ) {
+        if ( !strcmp(child->getName(), "prop") ) {
             string prop = child->getStringValue();
             add_prop( prop );
         }
@@ -201,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 );
     }
@@ -237,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() );
@@ -281,6 +283,7 @@ void FGElectricalSystem::unbind () {
 
 void FGElectricalSystem::update (double dt) {
     if ( !enabled ) {
+        _amps_out->setDoubleValue(0);
         return;
     }
 
@@ -308,6 +311,47 @@ void FGElectricalSystem::update (double dt) {
         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 );
 }