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