1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2000 -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGDeadBand.h"
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_DEADBAND;
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
57 WidthPropertyNode = 0;
58 WidthPropertySign = 1.0;
62 if ( element->FindElement("width") ) {
63 width_string = element->FindElementValue("width");
64 if (!is_number(width_string)) { // property
65 if (width_string[0] == '-') {
66 WidthPropertySign = -1.0;
67 width_string.erase(0,1);
69 WidthPropertyNode = PropertyManager->GetNode(width_string);
71 width = element->FindElementValueAsNumber("width");
75 if (element->FindElement("gain")) {
76 gain = element->FindElementValueAsNumber("gain");
79 FGFCSComponent::bind();
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 FGDeadBand::~FGDeadBand()
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 bool FGDeadBand::Run(void )
94 Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
96 if (WidthPropertyNode != 0) {
97 width = WidthPropertyNode->getDoubleValue() * WidthPropertySign;
100 if (Input < -width/2.0) {
101 Output = (Input + width/2.0)*gain;
102 } else if (Input > width/2.0) {
103 Output = (Input - width/2.0)*gain;
110 if (IsOutput) SetOutput();
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 // The bitmasked value choices are as follows:
117 // unset: In this case (the default) JSBSim would only print
118 // out the normally expected messages, essentially echoing
119 // the config files as they are read. If the environment
120 // variable is not set, debug_lvl is set to 1 internally
121 // 0: This requests JSBSim not to output any messages
123 // 1: This value explicity requests the normal JSBSim
125 // 2: This value asks for a message to be printed out when
126 // a class is instantiated
127 // 4: When this value is set, a message is displayed when a
128 // FGModel object executes its Run() method
129 // 8: When this value is set, various runtime state variables
130 // are printed out periodically
131 // 16: When set various parameters are sanity checked and
132 // a message is printed out when they go out of bounds
134 void FGDeadBand::Debug(int from)
136 if (debug_lvl <= 0) return;
138 if (debug_lvl & 1) { // Standard console startup message output
139 if (from == 0) { // Constructor
140 cout << " INPUT: " << InputNodes[0]->getName() << endl;
141 if (WidthPropertyNode != 0) {
142 cout << " DEADBAND WIDTH: " << WidthPropertyNode->GetName() << endl;
144 cout << " DEADBAND WIDTH: " << width << endl;
146 cout << " GAIN: " << gain << endl;
147 if (IsOutput) cout << " OUTPUT: " << OutputNode->getName() << endl;
150 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
151 if (from == 0) cout << "Instantiated: FGDeadBand" << endl;
152 if (from == 1) cout << "Destroyed: FGDeadBand" << endl;
154 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
156 if (debug_lvl & 8 ) { // Runtime state variables
158 if (debug_lvl & 16) { // Sanity checking
160 if (debug_lvl & 64) {
161 if (from == 0) { // Constructor
162 cout << IdSrc << endl;
163 cout << IdHdr << endl;