]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
Oct. 9, 2000 - synced with latest JSBsim code.
[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 /*******************************************************************************
60 ************************************ CODE **************************************
61 *******************************************************************************/
62
63
64 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) {
65   Name = "FGFCS";
66   for (int i=0; i < MAX_ENGINES; i++) {  // needs to be changed: no limit
67     ThrottleCmd[i] = 0.0;
68     ThrottlePos[i] = 0.0;
69   }
70   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0;
71   DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
72 }
73
74 /******************************************************************************/
75
76 FGFCS::~FGFCS(void) {
77   for(unsigned int i=0;i<Components.size();i++)
78     delete Components[i];
79 }
80
81 /******************************************************************************/
82
83 bool FGFCS::Run(void) {
84   if (!FGModel::Run()) {
85
86     for (unsigned int i=0; i<Aircraft->GetNumEngines(); i++) ThrottlePos[i]=ThrottleCmd[i];
87
88     for (unsigned int i=0; i<Components.size(); i++) Components[i]->Run();
89
90   } else {}
91
92
93   return false;
94 }
95
96 /******************************************************************************/
97
98 void FGFCS::SetThrottleCmd(int engineNum, float setting) {
99   if (engineNum < 0) {
100     for (unsigned int ctr=0;ctr<Aircraft->GetNumEngines();ctr++) ThrottleCmd[ctr] = setting;
101   } else {
102     ThrottleCmd[engineNum] = setting;
103   }
104 }
105
106 /******************************************************************************/
107
108 void FGFCS::SetThrottlePos(int engineNum, float setting) {
109   if (engineNum < 0) {
110     for (unsigned int ctr=0;ctr<=Aircraft->GetNumEngines();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
111   } else {
112     ThrottlePos[engineNum] = setting;
113   }
114 }
115
116 /******************************************************************************/
117
118 void FGFCS::SetLBrake(float setting) {
119
120 }
121
122 /******************************************************************************/
123
124 void FGFCS::SetRBrake(float setting) {
125 }
126
127 /******************************************************************************/
128 void FGFCS::SetCBrake(float setting) {
129 }
130
131 /******************************************************************************/
132 bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) {
133   string token;
134
135   FCSName = AC_cfg->GetValue("NAME");
136   cout << "    Control System Name: " << FCSName << endl;
137   AC_cfg->GetNextConfigLine();
138   while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
139     if (token == "COMPONENT") {
140       token = AC_cfg->GetValue("TYPE");
141       cout << "    Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
142       if ((token == "LAG_FILTER") ||
143           (token == "RECT_LAG_FILTER") ||
144           (token == "LEAD_LAG_FILTER") ||
145           (token == "SECOND_ORDER_FILTER") ||
146           (token == "WASHOUT_FILTER") ||
147           (token == "INTEGRATOR") ) {
148         Components.push_back(new FGFilter(this, AC_cfg));
149       } else if ((token == "PURE_GAIN") ||
150                  (token == "SCHEDULED_GAIN") ||
151                  (token == "AEROSURFACE_SCALE") ) {
152
153         Components.push_back(new FGGain(this, AC_cfg));
154
155       } else if (token == "SUMMER") {
156         Components.push_back(new FGSummer(this, AC_cfg));
157       } else if (token == "DEADBAND") {
158         Components.push_back(new FGDeadBand(this, AC_cfg));
159       } else if (token == "GRADIENT") {
160         Components.push_back(new FGGradient(this, AC_cfg));
161       } else if (token == "SWITCH") {
162         Components.push_back(new FGSwitch(this, AC_cfg));
163       } else if (token == "FLAPS") {
164         Components.push_back(new FGFlaps(this, AC_cfg));
165       }
166       AC_cfg->GetNextConfigLine();
167     }
168   }
169   return true;
170 }
171
172 /******************************************************************************/
173
174 float FGFCS::GetComponentOutput(eParam idx) {
175   return Components[idx]->GetOutput();
176 }
177
178 /******************************************************************************/
179
180 string FGFCS::GetComponentName(int idx) {
181   return Components[idx]->GetName();
182 }
183