]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGFilter.cpp
FG_HAVE_STD_INCLUDES -> SG_HAVE_STD_INCLUDES
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGFilter.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGFilter.cpp
4  Author:       Jon S. Berndt
5  Date started: 11/2000
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 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 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 "FGFilter.h"
41
42 static const char *IdSrc = "$Header$";
43 static const char *IdHdr = ID_FILTER;
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 CLASS IMPLEMENTATION
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 FGFilter::FGFilter(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
50                                                        AC_cfg(AC_cfg)
51 {
52   string token;
53
54   Type = AC_cfg->GetValue("TYPE");
55   Name = AC_cfg->GetValue("NAME");
56   AC_cfg->GetNextConfigLine();
57
58   C1 = C2 = C3 = C4 = C5 = C6 = 0.0;
59
60   if      (Type == "LAG_FILTER")          FilterType = eLag        ;
61   else if (Type == "RECT_LAG_FILTER")     FilterType = eRectLag    ;
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 if (Type == "INTEGRATOR")          FilterType = eIntegrator ;
66   else                                    FilterType = eUnknown    ;
67
68   while ((token = AC_cfg->GetValue()) != "/COMPONENT") {
69     *AC_cfg >> token;
70     if (token == "ID") {
71       *AC_cfg >> ID;
72     } else if (token == "INPUT") {
73       token = AC_cfg->GetValue("INPUT");
74       if (token.find("FG_") != token.npos) {
75         *AC_cfg >> token;
76         InputIdx = fcs->GetState()->GetParameterIndex(token);
77         InputType = itPilotAC;
78       } else {
79         *AC_cfg >> InputIdx;
80         InputType = itFCS;
81       }
82     } else if (token == "C1") {
83       *AC_cfg >> C1;
84     } else if (token == "C2") {
85       *AC_cfg >> C2;
86     } else if (token == "C3") {
87       *AC_cfg >> C3;
88     } else if (token == "C4") {
89       *AC_cfg >> C4;
90     } else if (token == "C5") {
91       *AC_cfg >> C5;
92     } else if (token == "C6") {
93       *AC_cfg >> C6;
94     }
95   }
96
97   switch (FilterType) {
98     case eLag:
99       ca = dt*C1 / (2.00 + dt*C1);
100       cb = (2.00 - dt*C1) / (2.00 + dt*C1);
101       break;
102     case eRectLag:
103       break;
104     case eLeadLag:
105       break;
106     case eOrder2:
107       break;
108     case eWashout:
109       break;
110     case eIntegrator:
111       break;
112   }
113
114 }
115
116 // *****************************************************************************
117 //  Function:   Run
118 //  Purpose:
119 //  Parameters: void
120 //  Comments:
121
122 bool FGFilter::Run(void)
123 {
124   FGFCSComponent::Run(); // call the base class for initialization of Input
125
126   switch (FilterType) {
127     case eLag:
128       break;
129     case eRectLag:
130       break;
131     case eLeadLag:
132       break;
133     case eOrder2:
134       break;
135     case eWashout:
136       break;
137     case eIntegrator:
138       break;
139   }
140
141   PreviousOutput2 = PreviousOutput1;
142   PreviousOutput1 = Output;
143   PreviousInput2  = PreviousInput1;
144   PreviousInput1  = Input;
145
146   return true;
147 }
148