]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
21bb6b232c83215c52f7e968873c305d36471ba1
[flightgear.git] / src / FDM / JSBSim / FGFCS.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Module:       FGFCS.cpp
4  Author:       Jon Berndt
5  Date started: 12/12/98
6  Purpose:      Model the flight controls
7  Called by:    FDMExec
8  
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10  
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15  
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20  
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24  
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27  
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the flight controls for a specific airplane
31  
32 HISTORY
33 --------------------------------------------------------------------------------
34 12/12/98   JSB   Created
35  
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCS.h"
41 #include "FGState.h"
42 #include "FGFDMExec.h"
43 #include "FGAtmosphere.h"
44 #include "FGAircraft.h"
45 #include "FGTranslation.h"
46 #include "FGRotation.h"
47 #include "FGPosition.h"
48 #include "FGAuxiliary.h"
49 #include "FGOutput.h"
50
51 #include "filtersjb/FGFilter.h"
52 #include "filtersjb/FGDeadBand.h"
53 #include "filtersjb/FGGain.h"
54 #include "filtersjb/FGGradient.h"
55 #include "filtersjb/FGSwitch.h"
56 #include "filtersjb/FGSummer.h"
57 #include "filtersjb/FGFlaps.h"
58
59 static const char *IdSrc = "$Id$";
60 static const char *IdHdr = "ID_FCS";
61
62 extern short debug_lvl;
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 CLASS IMPLEMENTATION
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) {
69   Name = "FGFCS";
70
71   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
72   DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
73   LeftBrake = RightBrake = CenterBrake = 0.0;
74
75   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
76 }
77
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 FGFCS::~FGFCS()
81 {
82   ThrottleCmd.clear();
83   ThrottlePos.clear();
84
85   for(unsigned int i=0;i<Components.size();i++) delete Components[i];
86   if (debug_lvl & 2) cout << "Destroyed:    FGFCS" << endl;
87 }
88
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91 bool FGFCS::Run(void)
92 {
93   if (!FGModel::Run()) {
94     for (unsigned int i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
95     for (unsigned int i=0; i<Components.size(); i++)  Components[i]->Run();
96   } else {
97   }
98
99   return false;
100 }
101
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104 void FGFCS::SetThrottleCmd(int engineNum, float setting) {
105   if (engineNum < 0) {
106     for (unsigned int ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
107   } else {
108     ThrottleCmd[engineNum] = setting;
109   }
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 void FGFCS::SetThrottlePos(int engineNum, float setting) {
115   if (engineNum < 0) {
116     for (unsigned int ctr=0;ctr<=ThrottleCmd.size();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
117   } else {
118     ThrottlePos[engineNum] = setting;
119   }
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) {
125   string token;
126
127   FCSName = AC_cfg->GetValue("NAME");
128   cout << "    Control System Name: " << FCSName << endl;
129   AC_cfg->GetNextConfigLine();
130   while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
131     if (token == "COMPONENT") {
132       token = AC_cfg->GetValue("TYPE");
133       cout << "    Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
134       if ((token == "LAG_FILTER") ||
135           (token == "LEAD_LAG_FILTER") ||
136           (token == "SECOND_ORDER_FILTER") ||
137           (token == "WASHOUT_FILTER") ||
138           (token == "INTEGRATOR") ) {
139         Components.push_back(new FGFilter(this, AC_cfg));
140       } else if ((token == "PURE_GAIN") ||
141                  (token == "SCHEDULED_GAIN") ||
142                  (token == "AEROSURFACE_SCALE") ) {
143
144         Components.push_back(new FGGain(this, AC_cfg));
145
146       } else if (token == "SUMMER") {
147         Components.push_back(new FGSummer(this, AC_cfg));
148       } else if (token == "DEADBAND") {
149         Components.push_back(new FGDeadBand(this, AC_cfg));
150       } else if (token == "GRADIENT") {
151         Components.push_back(new FGGradient(this, AC_cfg));
152       } else if (token == "SWITCH") {
153         Components.push_back(new FGSwitch(this, AC_cfg));
154       } else if (token == "FLAPS") {
155         Components.push_back(new FGFlaps(this, AC_cfg));
156       } else {
157         cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
158         return false;
159       }
160       AC_cfg->GetNextConfigLine();
161     }
162   }
163   return true;
164 }
165
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167
168 float FGFCS::GetComponentOutput(eParam idx) {
169   return Components[idx]->GetOutput();
170 }
171
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173
174 string FGFCS::GetComponentName(int idx) {
175   return Components[idx]->GetName();
176 }
177
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
180 float FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
181   switch (bg) {
182   case FGLGear::bgLeft:
183     return LeftBrake;
184   case FGLGear::bgRight:
185     return RightBrake;
186   case FGLGear::bgCenter:
187     return CenterBrake;
188   default:
189     cerr << "GetBrake asked to return a bogus brake value" << endl;
190   }
191   return 0.0;
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 string FGFCS::GetComponentStrings(void){
197   string CompStrings = "";
198   bool firstime = true;
199
200   for (unsigned int comp = 0; comp < Components.size(); comp++) {
201     if (firstime) firstime = false;
202     else          CompStrings += ", ";
203
204     CompStrings += Components[comp]->GetName();
205   }
206
207   return CompStrings;
208 }
209
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
212 string FGFCS::GetComponentValues(void)
213 {
214   string CompValues = "";
215   char buffer[10];
216   bool firstime = true;
217
218   for (unsigned int comp = 0; comp < Components.size(); comp++) {
219     if (firstime) firstime = false;
220     else          CompValues += ", ";
221
222     sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
223     CompValues += string(buffer);
224   }
225
226   return CompValues;
227 }
228
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231 void FGFCS::AddThrottle(void)
232 {
233   ThrottleCmd.push_back(0.0);
234   ThrottlePos.push_back(0.0);
235 }
236
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238
239 void FGFCS::Debug(void)
240 {
241     //TODO: Add your source code here
242 }
243