JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGDeadBand.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGDeadBand.cpp
4  Author: Jon S. Berndt
5  Date started: 11/1999
6 
7  ------------- Copyright (C) 2000 -------------
8 
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
12  version.
13 
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
17  details.
18 
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.
22 
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.
25 
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28 
29 HISTORY
30 --------------------------------------------------------------------------------
31 
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include "FGDeadBand.h"
41 #include "input_output/FGXMLElement.h"
42 #include "input_output/FGPropertyManager.h"
43 #include <iostream>
44 
45 using namespace std;
46 
47 namespace JSBSim {
48 
49 IDENT(IdSrc,"$Id: FGDeadBand.cpp,v 1.14 2014/01/13 10:46:07 ehofman Exp $");
50 IDENT(IdHdr,ID_DEADBAND);
51 
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS IMPLEMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 
58 FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
59 {
60  string width_string;
61 
62  WidthPropertyNode = 0;
63  WidthPropertySign = 1.0;
64  gain = 1.0;
65  width = 0.0;
66 
67  if ( element->FindElement("width") ) {
68  width_string = element->FindElementValue("width");
69  if (!is_number(width_string)) { // property
70  if (width_string[0] == '-') {
71  WidthPropertySign = -1.0;
72  width_string.erase(0,1);
73  }
74  WidthPropertyNode = PropertyManager->GetNode(width_string);
75  } else {
76  width = element->FindElementValueAsNumber("width");
77  }
78  }
79 
80  if (element->FindElement("gain")) {
81  gain = element->FindElementValueAsNumber("gain");
82  }
83 
84  FGFCSComponent::bind();
85  Debug(0);
86 }
87 
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 
90 FGDeadBand::~FGDeadBand()
91 {
92  Debug(1);
93 }
94 
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 
97 bool FGDeadBand::Run(void )
98 {
99  Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
100 
101  if (WidthPropertyNode != 0) {
102  width = WidthPropertyNode->getDoubleValue() * WidthPropertySign;
103  }
104 
105  if (Input < -width/2.0) {
106  Output = (Input + width/2.0)*gain;
107  } else if (Input > width/2.0) {
108  Output = (Input - width/2.0)*gain;
109  } else {
110  Output = 0.0;
111  }
112 
113  Clip();
114  if (IsOutput) SetOutput();
115 
116  return true;
117 }
118 
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 // The bitmasked value choices are as follows:
121 // unset: In this case (the default) JSBSim would only print
122 // out the normally expected messages, essentially echoing
123 // the config files as they are read. If the environment
124 // variable is not set, debug_lvl is set to 1 internally
125 // 0: This requests JSBSim not to output any messages
126 // whatsoever.
127 // 1: This value explicity requests the normal JSBSim
128 // startup messages
129 // 2: This value asks for a message to be printed out when
130 // a class is instantiated
131 // 4: When this value is set, a message is displayed when a
132 // FGModel object executes its Run() method
133 // 8: When this value is set, various runtime state variables
134 // are printed out periodically
135 // 16: When set various parameters are sanity checked and
136 // a message is printed out when they go out of bounds
137 
138 void FGDeadBand::Debug(int from)
139 {
140  if (debug_lvl <= 0) return;
141 
142  if (debug_lvl & 1) { // Standard console startup message output
143  if (from == 0) { // Constructor
144  cout << " INPUT: " << InputNodes[0]->GetName() << endl;
145  if (WidthPropertyNode != 0) {
146  cout << " DEADBAND WIDTH: " << WidthPropertyNode->GetName() << endl;
147  } else {
148  cout << " DEADBAND WIDTH: " << width << endl;
149  }
150  cout << " GAIN: " << gain << endl;
151  if (IsOutput) {
152  for (unsigned int i=0; i<OutputNodes.size(); i++)
153  cout << " OUTPUT: " << OutputNodes[i]->getName() << endl;
154  }
155  }
156  }
157  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
158  if (from == 0) cout << "Instantiated: FGDeadBand" << endl;
159  if (from == 1) cout << "Destroyed: FGDeadBand" << endl;
160  }
161  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
162  }
163  if (debug_lvl & 8 ) { // Runtime state variables
164  }
165  if (debug_lvl & 16) { // Sanity checking
166  }
167  if (debug_lvl & 64) {
168  if (from == 0) { // Constructor
169  cout << IdSrc << endl;
170  cout << IdHdr << endl;
171  }
172  }
173 }
174 }
STL namespace.