]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp
745f8ad281d5804fa14fa14ae82b0c2009ea7c35
[flightgear.git] / src / FDM / JSBSim / models / flight_control / 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
42 namespace JSBSim {
43
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_DEADBAND;
46
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 CLASS IMPLEMENTATION
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
53 FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
54 {
55   string width_string;
56
57   WidthPropertyNode = 0;
58   WidthPropertySign = 1.0;
59   gain = 1.0;
60   width = 0.0;
61
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);
68       }
69       WidthPropertyNode = PropertyManager->GetNode(width_string);
70     } else {
71       width = element->FindElementValueAsNumber("width");
72     }
73   }
74
75   if (element->FindElement("gain")) {
76     gain = element->FindElementValueAsNumber("gain");
77   }
78
79   FGFCSComponent::bind();
80   Debug(0);
81 }
82
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85 FGDeadBand::~FGDeadBand()
86 {
87   Debug(1);
88 }
89
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92 bool FGDeadBand::Run(void )
93 {
94   Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
95
96   if (WidthPropertyNode != 0) {
97     width = WidthPropertyNode->getDoubleValue() * WidthPropertySign;
98   }
99
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;
104   } else {
105     Output = 0.0;
106   }
107
108   Clip();
109
110   if (IsOutput) SetOutput();
111
112   return true;
113 }
114
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
122 //       whatsoever.
123 //    1: This value explicity requests the normal JSBSim
124 //       startup messages
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
133
134 void FGDeadBand::Debug(int from)
135 {
136   if (debug_lvl <= 0) return;
137
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;
143       } else {
144         cout << "      DEADBAND WIDTH: " << width << endl;
145       }
146       cout << "      GAIN: " << gain << endl;
147       if (IsOutput) cout << "      OUTPUT: " << OutputNode->getName() << endl;
148     }
149   }
150   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
151     if (from == 0) cout << "Instantiated: FGDeadBand" << endl;
152     if (from == 1) cout << "Destroyed:    FGDeadBand" << endl;
153   }
154   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
155   }
156   if (debug_lvl & 8 ) { // Runtime state variables
157   }
158   if (debug_lvl & 16) { // Sanity checking
159   }
160   if (debug_lvl & 64) {
161     if (from == 0) { // Constructor
162       cout << IdSrc << endl;
163       cout << IdHdr << endl;
164     }
165   }
166 }
167 }