54 C[1] = C[2] = C[3] = C[4] = C[5] = C[6] =
nullptr;
58 for (
int i=1;
i<7;
i++)
59 ReadFilterCoefficients(element,
i);
61 if (
Type ==
"LAG_FILTER") FilterType = eLag ;
62 else if (
Type ==
"LEAD_LAG_FILTER") FilterType = eLeadLag ;
63 else if (
Type ==
"SECOND_ORDER_FILTER") FilterType = eOrder2 ;
64 else if (
Type ==
"WASHOUT_FILTER") FilterType = eWashout ;
65 else FilterType = eUnknown ;
67 CalculateDynamicFilters();
87 Input = 0.0; Initialize =
true;
92void FGFilter::ReadFilterCoefficients(
Element* element,
int index)
96 string coefficient =
"c0";
97 coefficient[1] +=
index;
102 DynamicFilter |= !
C[
index]->IsConstant();
108void FGFilter::CalculateDynamicFilters(
void)
112 switch (FilterType) {
114 denom = 2.0 +
dt*C[1];
115 ca =
dt*C[1] / denom;
116 cb = (2.0 -
dt*C[1]) / denom;
120 denom = 2.0*C[3] +
dt*C[4];
121 ca = (2.0*C[1] +
dt*C[2]) / denom;
122 cb = (
dt*C[2] - 2.0*C[1]) / denom;
123 cc = (2.0*C[3] -
dt*C[4]) / denom;
126 denom = 4.0*C[4] + 2.0*C[5]*
dt + C[6]*
dt*
dt;
127 ca = (4.0*C[1] + 2.0*C[2]*
dt + C[3]*
dt*
dt) / denom;
128 cb = (2.0*C[3]*
dt*
dt - 8.0*C[1]) / denom;
129 cc = (4.0*C[1] - 2.0*C[2]*
dt + C[3]*
dt*
dt) / denom;
130 cd = (2.0*C[6]*
dt*
dt - 8.0*C[4]) / denom;
131 ce = (4.0*C[4] - 2.0*C[5]*
dt + C[6]*
dt*
dt) / denom;
134 denom = 2.0 +
dt*C[1];
136 cb = (2.0 -
dt*C[1]) / denom;
139 cerr <<
"Unknown filter type" << endl;
151 PreviousOutput2 = PreviousInput2 = PreviousOutput1 = PreviousInput1 =
Output =
Input;
158 if (DynamicFilter) CalculateDynamicFilters();
160 switch (FilterType) {
162 Output = (
Input + PreviousInput1) * ca + PreviousOutput1 * cb;
165 Output =
Input * ca + PreviousInput1 * cb + PreviousOutput1 * cc;
168 Output =
Input * ca + PreviousInput1 * cb + PreviousInput2 * cc
169 - PreviousOutput1 * cd - PreviousOutput2 * ce;
172 Output =
Input * ca - PreviousInput1 * ca + PreviousOutput1 * cb;
180 PreviousOutput2 = PreviousOutput1;
182 PreviousInput2 = PreviousInput1;
183 PreviousInput1 =
Input;
210void FGFilter::Debug(
int from)
216 cout <<
" INPUT: " <<
InputNodes[0]->GetName() << endl;
218 for (
int i=1;
i < 7;
i++) {
221 cout <<
" C[" <<
i <<
"]";
222 if (!
C[
i]->IsConstant()) cout <<
" is the value of property";
223 cout <<
": "<<
C[
i]->GetName() << endl;
227 cout <<
" OUTPUT: " << node->getNameString() << endl;
231 if (from == 0) cout <<
"Instantiated: FGFilter" << endl;
232 if (from == 1) cout <<
"Destroyed: FGFilter" << endl;
Element * FindElement(const std::string &el="")
Searches for a specified element.
FGFCSComponent(FGFCS *fcs, Element *el)
Constructor.
std::vector< FGPropertyValue_ptr > InputNodes
void CheckInputNodes(size_t MinNodes, size_t MaxNodes, Element *el)
virtual void ResetPastStates(void)
FGPropertyManager * PropertyManager
virtual void bind(Element *el)
virtual void SetOutput(void)
std::vector< FGPropertyNode_ptr > OutputNodes
void ResetPastStates(void) override
FGFilter(FGFCS *fcs, Element *element)
Represents a either a real value or a property value.