]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
20010710 sync with JSBSim.
[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 "FGDefs.h"
41
42 #include "FGFCS.h"
43 #include "FGState.h"
44 #include "FGFDMExec.h"
45 #include "FGAtmosphere.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
51 #include "FGOutput.h"
52
53 #include "filtersjb/FGFilter.h"
54 #include "filtersjb/FGDeadBand.h"
55 #include "filtersjb/FGGain.h"
56 #include "filtersjb/FGGradient.h"
57 #include "filtersjb/FGSwitch.h"
58 #include "filtersjb/FGSummer.h"
59 #include "filtersjb/FGFlaps.h"
60
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_FCS;
63
64 extern short debug_lvl;
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS IMPLEMENTATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
71 {
72   Name = "FGFCS";
73
74   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
75   DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
76   LeftBrake = RightBrake = CenterBrake = 0.0;
77
78   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
79 }
80
81 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 FGFCS::~FGFCS()
84 {
85   ThrottleCmd.clear();
86   ThrottlePos.clear();
87
88   unsigned int i;
89
90   for(i=0;i<Components.size();i++) delete Components[i];
91   if (debug_lvl & 2) cout << "Destroyed:    FGFCS" << endl;
92 }
93
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 bool FGFCS::Run(void)
97 {
98   unsigned int i;
99
100   if (!FGModel::Run()) {
101     for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
102     for (i=0; i<Components.size(); i++)  Components[i]->Run();
103   } else {
104   }
105
106   return false;
107 }
108
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111 void FGFCS::SetThrottleCmd(int engineNum, float setting)
112 {
113   unsigned int ctr;
114
115   if (engineNum < 0) {
116     for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
117   } else {
118     ThrottleCmd[engineNum] = setting;
119   }
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 void FGFCS::SetThrottlePos(int engineNum, float setting)
125 {
126   unsigned int ctr;
127
128   if (engineNum < 0) {
129     for (ctr=0;ctr<=ThrottleCmd.size();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
130   } else {
131     ThrottlePos[engineNum] = setting;
132   }
133 }
134
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 bool FGFCS::Load(FGConfigFile* AC_cfg)
138 {
139   string token;
140
141   Name = AC_cfg->GetValue("NAME");
142   if (debug_lvl > 0) cout << "    Control System Name: " << Name << endl;
143   AC_cfg->GetNextConfigLine();
144   while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
145     if (token == "COMPONENT") {
146       token = AC_cfg->GetValue("TYPE");
147       if (debug_lvl > 0) cout << "    Loading Component \""
148                               << AC_cfg->GetValue("NAME")
149                                                 << "\" of type: " << token << endl;
150       if ((token == "LAG_FILTER") ||
151           (token == "LEAD_LAG_FILTER") ||
152           (token == "SECOND_ORDER_FILTER") ||
153           (token == "WASHOUT_FILTER") ||
154           (token == "INTEGRATOR") ) {
155         Components.push_back(new FGFilter(this, AC_cfg));
156       } else if ((token == "PURE_GAIN") ||
157                  (token == "SCHEDULED_GAIN") ||
158                  (token == "AEROSURFACE_SCALE") ) {
159
160         Components.push_back(new FGGain(this, AC_cfg));
161
162       } else if (token == "SUMMER") {
163         Components.push_back(new FGSummer(this, AC_cfg));
164       } else if (token == "DEADBAND") {
165         Components.push_back(new FGDeadBand(this, AC_cfg));
166       } else if (token == "GRADIENT") {
167         Components.push_back(new FGGradient(this, AC_cfg));
168       } else if (token == "SWITCH") {
169         Components.push_back(new FGSwitch(this, AC_cfg));
170       } else if (token == "FLAPS") {
171         Components.push_back(new FGFlaps(this, AC_cfg));
172       } else {
173         cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
174         return false;
175       }
176       AC_cfg->GetNextConfigLine();
177     }
178   }
179   return true;
180 }
181
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 float FGFCS::GetComponentOutput(eParam idx) {
185   return Components[idx]->GetOutput();
186 }
187
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
190 string FGFCS::GetComponentName(int idx) {
191   return Components[idx]->GetName();
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 float FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
197   switch (bg) {
198   case FGLGear::bgLeft:
199     return LeftBrake;
200   case FGLGear::bgRight:
201     return RightBrake;
202   case FGLGear::bgCenter:
203     return CenterBrake;
204   default:
205     cerr << "GetBrake asked to return a bogus brake value" << endl;
206   }
207   return 0.0;
208 }
209
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
212 string FGFCS::GetComponentStrings(void)
213 {
214   unsigned int comp;
215
216   string CompStrings = "";
217   bool firstime = true;
218
219   for (comp = 0; comp < Components.size(); comp++) {
220     if (firstime) firstime = false;
221     else          CompStrings += ", ";
222
223     CompStrings += Components[comp]->GetName();
224   }
225
226   return CompStrings;
227 }
228
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231 string FGFCS::GetComponentValues(void)
232 {
233   unsigned int comp;
234
235   string CompValues = "";
236   char buffer[10];
237   bool firstime = true;
238
239   for (comp = 0; comp < Components.size(); comp++) {
240     if (firstime) firstime = false;
241     else          CompValues += ", ";
242
243     sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
244     CompValues += string(buffer);
245   }
246
247   return CompValues;
248 }
249
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251
252 void FGFCS::AddThrottle(void)
253 {
254   ThrottleCmd.push_back(0.0);
255   ThrottlePos.push_back(0.0);
256 }
257
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259
260 void FGFCS::Debug(void)
261 {
262     //TODO: Add your source code here
263 }
264