JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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
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"
41#include "models/FGFCS.h"
42#include "math/FGParameterValue.h"
43#include "input_output/FGLog.h"
44
45using namespace std;
46
47namespace JSBSim {
48
49/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50CLASS IMPLEMENTATION
51%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element)
56 : FGFCSComponent(fcs, element)
57{
58 Width = nullptr;
59 gain = 1.0;
60
61 CheckInputNodes(1, 1, element);
62
63 auto PropertyManager = fcs->GetPropertyManager();
64 Element* width_element = element->FindElement("width");
65 if (width_element)
66 Width = new FGParameterValue(width_element, PropertyManager);
67 else
68 Width = new FGRealValue(0.0);
69
70 if (element->FindElement("gain"))
71 gain = element->FindElementValueAsNumber("gain");
72
73 bind(element, PropertyManager.get());
74 Debug(0);
75}
76
77//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79FGDeadBand::~FGDeadBand()
80{
81 Debug(1);
82}
83
84//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86bool FGDeadBand::Run(void)
87{
88 Input = InputNodes[0]->getDoubleValue();
89
90 double HalfWidth = 0.5*Width;
91
92 if (Input < -HalfWidth) {
93 Output = (Input + HalfWidth)*gain;
94 } else if (Input > HalfWidth) {
95 Output = (Input - HalfWidth)*gain;
96 } else {
97 Output = 0.0;
98 }
99
100 Clip();
101 SetOutput();
102
103 return true;
104}
105
106//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107// The bitmasked value choices are as follows:
108// unset: In this case (the default) JSBSim would only print
109// out the normally expected messages, essentially echoing
110// the config files as they are read. If the environment
111// variable is not set, debug_lvl is set to 1 internally
112// 0: This requests JSBSim not to output any messages
113// whatsoever.
114// 1: This value explicitly requests the normal JSBSim
115// startup messages
116// 2: This value asks for a message to be printed out when
117// a class is instantiated
118// 4: When this value is set, a message is displayed when a
119// FGModel object executes its Run() method
120// 8: When this value is set, various runtime state variables
121// are printed out periodically
122// 16: When set various parameters are sanity checked and
123// a message is printed out when they go out of bounds
124
125void FGDeadBand::Debug(int from)
126{
127 if (debug_lvl <= 0) return;
128
129 if (debug_lvl & 1) { // Standard console startup message output
130 if (from == 0) { // Constructor
131 FGLogging log(LogLevel::DEBUG);
132 log << " INPUT: " << InputNodes[0]->GetName() << "\n";
133 log << " DEADBAND WIDTH: " << Width->GetName() << "\n";
134 log << " GAIN: " << fixed << setprecision(4) << gain << "\n";
135
136 for (auto node: OutputNodes)
137 log << " OUTPUT: " << node->getNameString() << "\n";
138 }
139 }
140 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
141 FGLogging log(LogLevel::DEBUG);
142 if (from == 0) log << "Instantiated: FGDeadBand\n";
143 if (from == 1) log << "Destroyed: FGDeadBand\n";
144 }
145 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
146 }
147 if (debug_lvl & 8 ) { // Runtime state variables
148 }
149 if (debug_lvl & 16) { // Sanity checking
150 }
151 if (debug_lvl & 64) {
152 if (from == 0) { // Constructor
153 }
154 }
155}
156}
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71