]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.cxx
Add a *really* crude model of ITT, Oil Temp, and Oil Pressure. This
[flightgear.git] / src / Systems / electrical.cxx
index 41396cc51b5c55f7e675b9d89c30c53f1da0a639..db2dce22328786b37a2c18a7846d68696c85d519 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started September 2002.
 //
-// Copyright (C) 2002  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -118,9 +118,15 @@ FGElectricalBus::FGElectricalBus ( SGPropertyNode *node ) {
 
 FGElectricalOutput::FGElectricalOutput ( SGPropertyNode *node ) {
     kind = FG_OUTPUT;
-    output_amps = 0.1;
+    output_amps = 0.1;          // arbitrary default value
 
     name = node->getStringValue("name");
+    SGPropertyNode *draw = node->getNode("rated-draw");
+    if ( draw != NULL ) {
+        output_amps = draw->getDoubleValue();
+    }
+    // cout << "rated draw = " << output_amps << endl;
+
     int i;
     for ( i = 0; i < node->nChildren(); ++i ) {
         SGPropertyNode *child = node->getChild(i);
@@ -145,17 +151,21 @@ FGElectricalSwitch::FGElectricalSwitch( SGPropertyNode *node ) :
         string cval = child->getStringValue();
         if ( cname == "prop" ) {
             switch_node = fgGetNode( cval.c_str(), true );
-            cout << "switch node = " << cval << endl;
+            // cout << "switch node = " << cval << endl;
         } else if ( cname == "initial-state" ) {
             if ( cval == "off" || cval == "false" ) {
                 initial_state = false;
             }
-            cout << "initial state = " << initial_state << endl;
+            // cout << "initial state = " << initial_state << endl;
+        } else if ( cname == "rating-amps" ) {
+            rating_amps = atof( cval.c_str() );
+            circuit_breaker = true;
+            // cout << "initial state = " << initial_state << endl;
         }            
     }
 
     switch_node->setBoolValue( initial_state );
-    cout << "  value = " << switch_node->getBoolValue() << endl;
+    // cout << "  value = " << switch_node->getBoolValue() << endl;
 }
 
 
@@ -204,13 +214,8 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
                         << child->getStringValue() );
             }
         } else if ( cname == "switch" ) {
-            // set default value of switch to true
-            // cout << "Switch = " << child->getStringValue() << endl;
+             // cout << "Switch = " << child->getStringValue() << endl;
             FGElectricalSwitch s( child );
-            // FGElectricalSwitch s( fgGetNode(child->getStringValue(), true),
-            //                       100.0f,
-            //                       false );
-            // fgSetBool( child->getStringValue(), true );
             add_switch( s );
         }
     }
@@ -262,7 +267,7 @@ void FGElectricalSystem::init () {
         SGPath config( globals->get_fg_root() );
         config.append( path_n->getStringValue() );
 
-        SG_LOG( SG_ALL, SG_ALERT, "Reading electrical system model from "
+        SG_LOG( SG_ALL, SG_INFO, "Reading electrical system model from "
                 << config.str() );
         try {
             readProperties( config.str(), config_props );
@@ -283,9 +288,10 @@ void FGElectricalSystem::init () {
                     << config.str() );
         }
 
-    } else
-        SG_LOG( SG_ALL, SG_ALERT,
+    } else {
+        SG_LOG( SG_ALL, SG_WARN,
                 "No electrical model specified for this model!");
+    }
 
     delete config_props;
 }
@@ -338,16 +344,23 @@ void FGElectricalSystem::update (double dt) {
 
     // impliment an extremely simplistic voltage model (assumes
     // certain naming conventions in electrical system config)
+    // FIXME: we probably want to be able to feed power from all
+    // engines if they are running and the master-alt is switched on
     double volts = 0.0;
-    if ( fgGetBool("/controls/switches/master-bat") ) {
+    if ( fgGetBool("/controls/engines/engine[0]/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;
+    if ( fgGetBool("/controls/engines/engine[0]/master-alt") ) {
+        if ( fgGetDouble("/engines/engine[0]/rpm") > 800 ) {
+            double alt_contrib = 28.0;
+            if ( alt_contrib > volts ) {
+                volts = alt_contrib;
+            }
+        } else if ( fgGetDouble("/engines/engine[0]/rpm") > 200 ) {
+            double alt_contrib = 20.0;
+            if ( alt_contrib > volts ) {
+                volts = alt_contrib;
+            }
         }
     }
     _volts_out->setDoubleValue( volts );
@@ -356,8 +369,8 @@ void FGElectricalSystem::update (double dt) {
     // 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") &&
+    if ( fgGetBool("/controls/engines/engine[0]/master-bat") ) {
+        if ( fgGetBool("/controls/engines/engine[0]/master-alt") &&
              fgGetDouble("/engines/engine[0]/rpm") > 800 )
         {
             amps += 40.0 * alt_norm;