]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
Nov. 14, 2000 JSBSim updates
[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 = "$Header$";
60 static const char *IdHdr = "ID_FCS";
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS IMPLEMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) {
67   Name = "FGFCS";
68   for (int i=0; i < MAX_ENGINES; i++) {  // needs to be changed: no limit
69     ThrottleCmd[i] = 0.0;
70     ThrottlePos[i] = 0.0;
71   }
72   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
73   DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
74 }
75
76 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
78 FGFCS::~FGFCS(void) {
79   for(unsigned int i=0;i<Components.size();i++)
80     delete Components[i];
81 }
82
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85 bool FGFCS::Run(void) {
86   if (!FGModel::Run()) {
87
88     for (unsigned int i=0; i<Aircraft->GetNumEngines(); i++) ThrottlePos[i]=ThrottleCmd[i];
89
90     for (unsigned int i=0; i<Components.size(); i++) {
91       Components[i]->Run();
92     }
93
94   } else {}
95
96
97   return false;
98 }
99
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102 void FGFCS::SetThrottleCmd(int engineNum, float setting) {
103   if (engineNum < 0) {
104     for (unsigned int ctr=0;ctr<Aircraft->GetNumEngines();ctr++) ThrottleCmd[ctr] = setting;
105   } else {
106     ThrottleCmd[engineNum] = setting;
107   }
108 }
109
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112 void FGFCS::SetThrottlePos(int engineNum, float setting) {
113   if (engineNum < 0) {
114     for (unsigned int ctr=0;ctr<=Aircraft->GetNumEngines();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
115   } else {
116     ThrottlePos[engineNum] = setting;
117   }
118 }
119
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122 bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) {
123   string token;
124
125   FCSName = AC_cfg->GetValue("NAME");
126   cout << "    Control System Name: " << FCSName << endl;
127   AC_cfg->GetNextConfigLine();
128   while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
129     if (token == "COMPONENT") {
130       token = AC_cfg->GetValue("TYPE");
131       cout << "    Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
132       if ((token == "LAG_FILTER") ||
133           (token == "RECT_LAG_FILTER") ||
134           (token == "LEAD_LAG_FILTER") ||
135           (token == "SECOND_ORDER_FILTER") ||
136           (token == "WASHOUT_FILTER") ||
137           (token == "INTEGRATOR") ) {
138         Components.push_back(new FGFilter(this, AC_cfg));
139       } else if ((token == "PURE_GAIN") ||
140                  (token == "SCHEDULED_GAIN") ||
141                  (token == "AEROSURFACE_SCALE") ) {
142
143         Components.push_back(new FGGain(this, AC_cfg));
144
145       } else if (token == "SUMMER") {
146         Components.push_back(new FGSummer(this, AC_cfg));
147       } else if (token == "DEADBAND") {
148         Components.push_back(new FGDeadBand(this, AC_cfg));
149       } else if (token == "GRADIENT") {
150         Components.push_back(new FGGradient(this, AC_cfg));
151       } else if (token == "SWITCH") {
152         Components.push_back(new FGSwitch(this, AC_cfg));
153       } else if (token == "FLAPS") {
154         Components.push_back(new FGFlaps(this, AC_cfg));
155       }
156       AC_cfg->GetNextConfigLine();
157     }
158   }
159   return true;
160 }
161
162 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163
164 float FGFCS::GetComponentOutput(eParam idx) {
165   return Components[idx]->GetOutput();
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170 string FGFCS::GetComponentName(int idx) {
171   return Components[idx]->GetName();
172 }
173
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
176 float FGFCS::GetBrake(FGLGear::eBrakeGroup bg) {
177   switch (bg) {
178   case FGLGear::bgLeft:
179     return LeftBrake;
180   case FGLGear::bgRight:
181     return RightBrake;
182   case FGLGear::bgCenter:
183     return CenterBrake;
184   default:
185     cerr << "GetBrake asked to return a bogus brake value" << endl;
186   }
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 string FGFCS::GetComponentStrings(void){
192   string CompStrings = "";
193   bool firstime = true;
194
195   for (unsigned int comp = 0; comp < Components.size(); comp++) {
196     if (firstime) firstime = false;
197     else          CompStrings += ", ";
198
199     CompStrings += Components[comp]->GetName();
200   }
201
202   return CompStrings;
203 }
204
205 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206
207 string FGFCS::GetComponentValues(void){
208   string CompValues = "";
209   char buffer[10];
210   bool firstime = true;
211
212   for (unsigned int comp = 0; comp < Components.size(); comp++) {
213     if (firstime) firstime = false;
214     else          CompValues += ", ";
215
216     sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
217     CompValues += string(buffer);
218   }
219
220   return CompValues;
221 }