![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 00003 Module: FGDeadBand.cpp 00004 Author: Jon S. Berndt 00005 Date started: 11/1999 00006 00007 ------------- Copyright (C) 2000 ------------- 00008 00009 This program is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU Lesser General Public License as published by the Free Software 00011 Foundation; either version 2 of the License, or (at your option) any later 00012 version. 00013 00014 This program is distributed in the hope that it will be useful, but WITHOUT 00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00017 details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00023 Further information about the GNU Lesser General Public License can also be found on 00024 the world wide web at http://www.gnu.org. 00025 00026 FUNCTIONAL DESCRIPTION 00027 -------------------------------------------------------------------------------- 00028 00029 HISTORY 00030 -------------------------------------------------------------------------------- 00031 00032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00033 COMMENTS, REFERENCES, and NOTES 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 00036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00037 INCLUDES 00038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00039 00040 #include "FGDeadBand.h" 00041 #include "input_output/FGXMLElement.h" 00042 #include "input_output/FGPropertyManager.h" 00043 #include <iostream> 00044 00045 using namespace std; 00046 00047 namespace JSBSim { 00048 00049 static const char *IdSrc = "$Id: FGDeadBand.cpp,v 1.12 2012/11/17 18:03:19 jberndt Exp $"; 00050 static const char *IdHdr = ID_DEADBAND; 00051 00052 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00053 CLASS IMPLEMENTATION 00054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00055 00056 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00057 00058 FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) 00059 { 00060 string width_string; 00061 00062 WidthPropertyNode = 0; 00063 WidthPropertySign = 1.0; 00064 gain = 1.0; 00065 width = 0.0; 00066 00067 if ( element->FindElement("width") ) { 00068 width_string = element->FindElementValue("width"); 00069 if (!is_number(width_string)) { // property 00070 if (width_string[0] == '-') { 00071 WidthPropertySign = -1.0; 00072 width_string.erase(0,1); 00073 } 00074 WidthPropertyNode = PropertyManager->GetNode(width_string); 00075 } else { 00076 width = element->FindElementValueAsNumber("width"); 00077 } 00078 } 00079 00080 if (element->FindElement("gain")) { 00081 gain = element->FindElementValueAsNumber("gain"); 00082 } 00083 00084 FGFCSComponent::bind(); 00085 Debug(0); 00086 } 00087 00088 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00089 00090 FGDeadBand::~FGDeadBand() 00091 { 00092 Debug(1); 00093 } 00094 00095 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00096 00097 bool FGDeadBand::Run(void ) 00098 { 00099 Input = InputNodes[0]->getDoubleValue() * InputSigns[0]; 00100 00101 if (WidthPropertyNode != 0) { 00102 width = WidthPropertyNode->getDoubleValue() * WidthPropertySign; 00103 } 00104 00105 if (Input < -width/2.0) { 00106 Output = (Input + width/2.0)*gain; 00107 } else if (Input > width/2.0) { 00108 Output = (Input - width/2.0)*gain; 00109 } else { 00110 Output = 0.0; 00111 } 00112 00113 Clip(); 00114 if (IsOutput) SetOutput(); 00115 00116 return true; 00117 } 00118 00119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00120 // The bitmasked value choices are as follows: 00121 // unset: In this case (the default) JSBSim would only print 00122 // out the normally expected messages, essentially echoing 00123 // the config files as they are read. If the environment 00124 // variable is not set, debug_lvl is set to 1 internally 00125 // 0: This requests JSBSim not to output any messages 00126 // whatsoever. 00127 // 1: This value explicity requests the normal JSBSim 00128 // startup messages 00129 // 2: This value asks for a message to be printed out when 00130 // a class is instantiated 00131 // 4: When this value is set, a message is displayed when a 00132 // FGModel object executes its Run() method 00133 // 8: When this value is set, various runtime state variables 00134 // are printed out periodically 00135 // 16: When set various parameters are sanity checked and 00136 // a message is printed out when they go out of bounds 00137 00138 void FGDeadBand::Debug(int from) 00139 { 00140 if (debug_lvl <= 0) return; 00141 00142 if (debug_lvl & 1) { // Standard console startup message output 00143 if (from == 0) { // Constructor 00144 cout << " INPUT: " << InputNodes[0]->GetName() << endl; 00145 if (WidthPropertyNode != 0) { 00146 cout << " DEADBAND WIDTH: " << WidthPropertyNode->GetName() << endl; 00147 } else { 00148 cout << " DEADBAND WIDTH: " << width << endl; 00149 } 00150 cout << " GAIN: " << gain << endl; 00151 if (IsOutput) { 00152 for (unsigned int i=0; i<OutputNodes.size(); i++) 00153 cout << " OUTPUT: " << OutputNodes[i]->getName() << endl; 00154 } 00155 } 00156 } 00157 if (debug_lvl & 2 ) { // Instantiation/Destruction notification 00158 if (from == 0) cout << "Instantiated: FGDeadBand" << endl; 00159 if (from == 1) cout << "Destroyed: FGDeadBand" << endl; 00160 } 00161 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects 00162 } 00163 if (debug_lvl & 8 ) { // Runtime state variables 00164 } 00165 if (debug_lvl & 16) { // Sanity checking 00166 } 00167 if (debug_lvl & 64) { 00168 if (from == 0) { // Constructor 00169 cout << IdSrc << endl; 00170 cout << IdHdr << endl; 00171 } 00172 } 00173 } 00174 }