FlightGear next
FGDeadBand.cpp
Go to the documentation of this file.
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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26FUNCTIONAL DESCRIPTION
27--------------------------------------------------------------------------------
28
29HISTORY
30--------------------------------------------------------------------------------
31
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33COMMENTS, REFERENCES, and NOTES
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37INCLUDES
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40#include "FGDeadBand.h"
42
43using namespace std;
44
45namespace JSBSim {
46
47/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48CLASS IMPLEMENTATION
49%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
54 : FGFCSComponent(fcs, element)
55{
56 Width = nullptr;
57 gain = 1.0;
58
59 CheckInputNodes(1, 1, element);
60
61 Element* width_element = element->FindElement("width");
62 if (width_element)
63 Width = new FGParameterValue(width_element, PropertyManager);
64 else
65 Width = new FGRealValue(0.0);
66
67 if (element->FindElement("gain"))
68 gain = element->FindElementValueAsNumber("gain");
69
70 bind(element);
71 Debug(0);
72}
73
74//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
77{
78 Debug(1);
79}
80
81//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
84{
85 Input = InputNodes[0]->getDoubleValue();
86
87 double HalfWidth = 0.5*Width;
88
89 if (Input < -HalfWidth) {
90 Output = (Input + HalfWidth)*gain;
91 } else if (Input > HalfWidth) {
92 Output = (Input - HalfWidth)*gain;
93 } else {
94 Output = 0.0;
95 }
96
97 Clip();
98 SetOutput();
99
100 return true;
101}
102
103//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104// The bitmasked value choices are as follows:
105// unset: In this case (the default) JSBSim would only print
106// out the normally expected messages, essentially echoing
107// the config files as they are read. If the environment
108// variable is not set, debug_lvl is set to 1 internally
109// 0: This requests JSBSim not to output any messages
110// whatsoever.
111// 1: This value explicity requests the normal JSBSim
112// startup messages
113// 2: This value asks for a message to be printed out when
114// a class is instantiated
115// 4: When this value is set, a message is displayed when a
116// FGModel object executes its Run() method
117// 8: When this value is set, various runtime state variables
118// are printed out periodically
119// 16: When set various parameters are sanity checked and
120// a message is printed out when they go out of bounds
121
122void FGDeadBand::Debug(int from)
123{
124 if (debug_lvl <= 0) return;
125
126 if (debug_lvl & 1) { // Standard console startup message output
127 if (from == 0) { // Constructor
128 cout << " INPUT: " << InputNodes[0]->GetName() << endl;
129 cout << " DEADBAND WIDTH: " << Width->GetName() << endl;
130 cout << " GAIN: " << gain << endl;
131
132 for (auto node: OutputNodes)
133 cout << " OUTPUT: " << node->getNameString() << endl;
134 }
135 }
136 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
137 if (from == 0) cout << "Instantiated: FGDeadBand" << endl;
138 if (from == 1) cout << "Destroyed: FGDeadBand" << endl;
139 }
140 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
141 }
142 if (debug_lvl & 8 ) { // Runtime state variables
143 }
144 if (debug_lvl & 16) { // Sanity checking
145 }
146 if (debug_lvl & 64) {
147 if (from == 0) { // Constructor
148 }
149 }
150}
151}
double FindElementValueAsNumber(const std::string &el="")
Searches for the named element and returns the data belonging to it as a number.
Element * FindElement(const std::string &el="")
Searches for a specified element.
bool Run(void) override
FGDeadBand(FGFCS *fcs, Element *element)
FGFCSComponent(FGFCS *fcs, Element *el)
Constructor.
std::vector< FGPropertyValue_ptr > InputNodes
void CheckInputNodes(size_t MinNodes, size_t MaxNodes, Element *el)
FGPropertyManager * PropertyManager
virtual void bind(Element *el)
virtual void SetOutput(void)
std::vector< FGPropertyNode_ptr > OutputNodes
static short debug_lvl
Definition FGJSBBase.h:190
Represents a either a real value or a property value.
Represents a real value.
Definition FGRealValue.h:58
short debug_lvl