]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGSummer.cpp
FG_HAVE_STD_INCLUDES -> SG_HAVE_STD_INCLUDES
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGSummer.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGSummer.cpp
4  Author:       Jon S. Berndt
5  Date started: 4/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 "FGSummer.h"            
41
42 static const char *IdSrc = "$Header$";
43 static const char *IdHdr = ID_SUMMER;
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 CLASS IMPLEMENTATION
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 FGSummer::FGSummer(FGFCS* fcs, FGConfigFile* AC_cfg) : FGFCSComponent(fcs),
50                                                        AC_cfg(AC_cfg)
51 {
52   string token;
53   eParam tmpInputIndex;
54
55   clip = false;
56   InputIndices.clear();
57   InputTypes.clear();
58
59   Type = AC_cfg->GetValue("TYPE");
60   Name = AC_cfg->GetValue("NAME");
61   AC_cfg->GetNextConfigLine();
62
63   while ((token = AC_cfg->GetValue()) != "/COMPONENT") {
64     *AC_cfg >> token;
65
66     if (token == "ID") {
67
68       *AC_cfg >> ID;
69       cout << "      ID: " << ID << endl;
70
71     } else if (token == "INPUT") {
72
73       token = AC_cfg->GetValue("INPUT");
74       cout << "      INPUT: " << token << endl;
75       if (token.find("FG_") != token.npos) {
76         *AC_cfg >> token;
77         tmpInputIndex = fcs->GetState()->GetParameterIndex(token);
78         InputIndices.push_back(tmpInputIndex);
79         InputTypes.push_back(itPilotAC);
80       } else {
81         *AC_cfg >> tmpInputIndex;
82         InputIndices.push_back(tmpInputIndex);
83         InputTypes.push_back(itFCS);
84       }
85
86     } else if (token == "CLIPTO") {
87
88       *AC_cfg >> clipmin >> clipmax;
89       if (clipmax > clipmin) {
90         clip = true;
91         cout << "      CLIPTO: " << clipmin << ", " << clipmax << endl;
92       }
93
94     } else if (token == "OUTPUT") {
95
96       IsOutput = true;
97       *AC_cfg >> sOutputIdx;
98       cout << "      OUTPUT: " <<sOutputIdx <<  endl;
99       OutputIdx = fcs->GetState()->GetParameterIndex(sOutputIdx);
100     }
101   }
102 }
103
104 // *****************************************************************************
105 //  Function:   Run
106 //  Purpose:
107 //  Parameters: void
108 //  Comments:
109
110 bool FGSummer::Run(void )
111 {
112   unsigned int idx;
113
114   // The Summer takes several inputs, so do not call the base class Run()
115   // FGFCSComponent::Run();
116
117   Output = 0.0;
118
119   for (idx=0; idx<InputIndices.size(); idx++) {
120     switch (InputTypes[idx]) {
121     case itPilotAC:
122       Output += fcs->GetState()->GetParameter(InputIndices[idx]);
123       break;
124     case itFCS:
125       Output += fcs->GetComponentOutput(InputIndices[idx]);
126       break;
127     }
128   }
129
130   if (clip) {
131     if (Output > clipmax)      Output = clipmax;
132     else if (Output < clipmin) Output = clipmin;
133   }
134
135   if (IsOutput) SetOutput();
136
137   return true;
138 }
139