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