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