]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGDeadBand.cpp
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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 #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 static const char *IdSrc = "$Id: FGDeadBand.cpp,v 1.9 2009/10/24 22:59:30 jberndt Exp $";
50 static const char *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
115   if (IsOutput) SetOutput();
116
117   return true;
118 }
119
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 //    The bitmasked value choices are as follows:
122 //    unset: In this case (the default) JSBSim would only print
123 //       out the normally expected messages, essentially echoing
124 //       the config files as they are read. If the environment
125 //       variable is not set, debug_lvl is set to 1 internally
126 //    0: This requests JSBSim not to output any messages
127 //       whatsoever.
128 //    1: This value explicity requests the normal JSBSim
129 //       startup messages
130 //    2: This value asks for a message to be printed out when
131 //       a class is instantiated
132 //    4: When this value is set, a message is displayed when a
133 //       FGModel object executes its Run() method
134 //    8: When this value is set, various runtime state variables
135 //       are printed out periodically
136 //    16: When set various parameters are sanity checked and
137 //       a message is printed out when they go out of bounds
138
139 void FGDeadBand::Debug(int from)
140 {
141   if (debug_lvl <= 0) return;
142
143   if (debug_lvl & 1) { // Standard console startup message output
144     if (from == 0) { // Constructor
145       cout << "      INPUT: " << InputNodes[0]->GetName() << endl;
146       if (WidthPropertyNode != 0) {
147         cout << "      DEADBAND WIDTH: " << WidthPropertyNode->GetName() << endl;
148       } else {
149         cout << "      DEADBAND WIDTH: " << width << endl;
150       }
151       cout << "      GAIN: " << gain << endl;
152       if (IsOutput) {
153         for (unsigned int i=0; i<OutputNodes.size(); i++)
154           cout << "      OUTPUT: " << OutputNodes[i]->getName() << endl;
155       }
156     }
157   }
158   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
159     if (from == 0) cout << "Instantiated: FGDeadBand" << endl;
160     if (from == 1) cout << "Destroyed:    FGDeadBand" << endl;
161   }
162   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
163   }
164   if (debug_lvl & 8 ) { // Runtime state variables
165   }
166   if (debug_lvl & 16) { // Sanity checking
167   }
168   if (debug_lvl & 64) {
169     if (from == 0) { // Constructor
170       cout << IdSrc << endl;
171       cout << IdHdr << endl;
172     }
173   }
174 }
175 }