40 #include "FGDeadBand.h" 41 #include "input_output/FGXMLElement.h" 42 #include "input_output/FGPropertyManager.h" 49 IDENT(IdSrc,
"$Id: FGDeadBand.cpp,v 1.14 2014/01/13 10:46:07 ehofman Exp $");
50 IDENT(IdHdr,ID_DEADBAND);
58 FGDeadBand::FGDeadBand(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
62 WidthPropertyNode = 0;
63 WidthPropertySign = 1.0;
67 if ( element->FindElement(
"width") ) {
68 width_string = element->FindElementValue(
"width");
69 if (!is_number(width_string)) {
70 if (width_string[0] ==
'-') {
71 WidthPropertySign = -1.0;
72 width_string.erase(0,1);
74 WidthPropertyNode = PropertyManager->GetNode(width_string);
76 width = element->FindElementValueAsNumber(
"width");
80 if (element->FindElement(
"gain")) {
81 gain = element->FindElementValueAsNumber(
"gain");
84 FGFCSComponent::bind();
90 FGDeadBand::~FGDeadBand()
97 bool FGDeadBand::Run(
void )
99 Input = InputNodes[0]->getDoubleValue() * InputSigns[0];
101 if (WidthPropertyNode != 0) {
102 width = WidthPropertyNode->getDoubleValue() * WidthPropertySign;
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;
114 if (IsOutput) SetOutput();
138 void FGDeadBand::Debug(
int from)
140 if (debug_lvl <= 0)
return;
144 cout <<
" INPUT: " << InputNodes[0]->GetName() << endl;
145 if (WidthPropertyNode != 0) {
146 cout <<
" DEADBAND WIDTH: " << WidthPropertyNode->GetName() << endl;
148 cout <<
" DEADBAND WIDTH: " << width << endl;
150 cout <<
" GAIN: " << gain << endl;
152 for (
unsigned int i=0; i<OutputNodes.size(); i++)
153 cout <<
" OUTPUT: " << OutputNodes[i]->getName() << endl;
157 if (debug_lvl & 2 ) {
158 if (from == 0) cout <<
"Instantiated: FGDeadBand" << endl;
159 if (from == 1) cout <<
"Destroyed: FGDeadBand" << endl;
161 if (debug_lvl & 4 ) {
163 if (debug_lvl & 8 ) {
165 if (debug_lvl & 16) {
167 if (debug_lvl & 64) {
169 cout << IdSrc << endl;
170 cout << IdHdr << endl;