]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/flight_control/FGGain.cpp
sync with JSB JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGGain.cpp
index b46e7721e2134f5980f70cbe6b8dd122fa658d32..fb864e06bba13feff4df23913d702df2c328b100 100644 (file)
@@ -7,20 +7,20 @@
  ------------- Copyright (C) 2000 -------------
 
  This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
+ the terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
 
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  details.
 
- You should have received a copy of the GNU General Public License along with
+ You should have received a copy of the GNU Lesser General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
 
- Further information about the GNU General Public License can also be found on
+ Further information about the GNU Lesser General Public License can also be found on
  the world wide web at http://www.gnu.org.
 
 FUNCTIONAL DESCRIPTION
@@ -38,10 +38,16 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGGain.h"
+#include "input_output/FGXMLElement.h"
+#include <iostream>
+#include <string>
+#include <cstdlib>
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGGain.cpp,v 1.23 2011/04/18 08:51:12 andgi Exp $";
 static const char *IdHdr = ID_GAIN;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -54,6 +60,7 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
   string strScheduledBy, gain_string, sZeroCentered;
 
   GainPropertyNode = 0;
+  GainPropertySign = 1.0;
   Gain = 1.000;
   Rows = 0;
   Table = 0;
@@ -63,13 +70,17 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
 
   if (Type == "PURE_GAIN") {
     if ( !element->FindElement("gain") ) {
-      cout << highint << "      No GAIN specified (default: 1.0)" << normint << endl;
+      cerr << highint << "      No GAIN specified (default: 1.0)" << normint << endl;
     }
   }
 
   if ( element->FindElement("gain") ) {
     gain_string = element->FindElementValue("gain");
-    if (gain_string.find_first_not_of("+-.0123456789") != string::npos) { // property
+    if (!is_number(gain_string)) { // property
+      if (gain_string[0] == '-') {
+       GainPropertySign = -1.0;
+       gain_string.erase(0,1);
+      }
       GainPropertyNode = PropertyManager->GetNode(gain_string);
     } else {
       Gain = element->FindElementValueAsNumber("gain");
@@ -98,8 +109,9 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
     }
     ZeroCentered = true;
     zero_centered = element->FindElement("zero_centered");
+    //ToDo if zero centered, then mins must be <0 and max's must be >0
     if (zero_centered) {
-      sZeroCentered = zero_centered->FindElementValue("zero_centered");
+      sZeroCentered = element->FindElementValue("zero_centered");
       if (sZeroCentered == string("0") || sZeroCentered == string("false")) {
         ZeroCentered = false;
       }
@@ -124,6 +136,8 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
 
 FGGain::~FGGain()
 {
+  delete Table;
+
   Debug(1);
 }
 
@@ -135,7 +149,7 @@ bool FGGain::Run(void )
 
   Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
 
-  if (GainPropertyNode != 0) Gain = GainPropertyNode->getDoubleValue();
+  if (GainPropertyNode != 0) Gain = GainPropertyNode->getDoubleValue() * GainPropertySign;
 
   if (Type == "PURE_GAIN") {                       // PURE_GAIN
 
@@ -195,12 +209,19 @@ void FGGain::Debug(int from)
   if (debug_lvl & 1) { // Standard console startup message output
     if (from == 0) { // Constructor
       if (InputSigns[0] < 0)
-        cout << "      INPUT: -" << InputNodes[0]->getName() << endl;
+        cout << "      INPUT: -" << InputNodes[0]->GetName() << endl;
       else
-        cout << "      INPUT: " << InputNodes[0]->getName() << endl;
+        cout << "      INPUT: " << InputNodes[0]->GetName() << endl;
 
-      cout << "      GAIN: " << Gain << endl;
-      if (IsOutput) cout << "      OUTPUT: " << OutputNode->getName() << endl;
+      if (GainPropertyNode != 0) {
+        cout << "      GAIN: " << GainPropertyNode->GetName() << endl;
+      } else {
+        cout << "      GAIN: " << Gain << endl;
+      }
+      if (IsOutput) {
+        for (unsigned int i=0; i<OutputNodes.size(); i++)
+          cout << "      OUTPUT: " << OutputNodes[i]->getName() << endl;
+      }
       if (Type == "AEROSURFACE_SCALE") {
         cout << "      In/Out Mapping:" << endl;
         cout << "        Input MIN: " << InMin << endl;