1 /*******************************************************************************
6 Purpose: Model the flight controls
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the flight controls for a specific airplane
33 --------------------------------------------------------------------------------
36 ********************************************************************************
38 *******************************************************************************/
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"
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"
59 /*******************************************************************************
60 ************************************ CODE **************************************
61 *******************************************************************************/
63 char const *Id = "$Header$";
65 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) {
67 for (int i=0; i < MAX_ENGINES; i++) { // needs to be changed: no limit
71 DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0;
72 DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
75 /******************************************************************************/
78 for(unsigned int i=0;i<Components.size();i++)
82 /******************************************************************************/
84 bool FGFCS::Run(void) {
85 if (!FGModel::Run()) {
87 for (unsigned int i=0; i<Aircraft->GetNumEngines(); i++) ThrottlePos[i]=ThrottleCmd[i];
89 for (unsigned int i=0; i<Components.size(); i++) Components[i]->Run();
97 /******************************************************************************/
99 void FGFCS::SetThrottleCmd(int engineNum, float setting) {
101 for (unsigned int ctr=0;ctr<Aircraft->GetNumEngines();ctr++) ThrottleCmd[ctr] = setting;
103 ThrottleCmd[engineNum] = setting;
107 /******************************************************************************/
109 void FGFCS::SetThrottlePos(int engineNum, float setting) {
111 for (unsigned int ctr=0;ctr<=Aircraft->GetNumEngines();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
113 ThrottlePos[engineNum] = setting;
117 /******************************************************************************/
119 void FGFCS::SetLBrake(float setting) {
123 /******************************************************************************/
125 void FGFCS::SetRBrake(float setting) {
128 /******************************************************************************/
129 void FGFCS::SetCBrake(float setting) {
132 /******************************************************************************/
133 bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) {
136 FCSName = AC_cfg->GetValue("NAME");
137 cout << " Control System Name: " << FCSName << endl;
138 AC_cfg->GetNextConfigLine();
139 while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
140 if (token == "COMPONENT") {
141 token = AC_cfg->GetValue("TYPE");
142 cout << " Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
143 if ((token == "LAG_FILTER") ||
144 (token == "RECT_LAG_FILTER") ||
145 (token == "LEAD_LAG_FILTER") ||
146 (token == "SECOND_ORDER_FILTER") ||
147 (token == "WASHOUT_FILTER") ||
148 (token == "INTEGRATOR") ) {
149 Components.push_back(new FGFilter(this, AC_cfg));
150 } else if ((token == "PURE_GAIN") ||
151 (token == "SCHEDULED_GAIN") ||
152 (token == "AEROSURFACE_SCALE") ) {
154 Components.push_back(new FGGain(this, AC_cfg));
156 } else if (token == "SUMMER") {
157 Components.push_back(new FGSummer(this, AC_cfg));
158 } else if (token == "DEADBAND") {
159 Components.push_back(new FGDeadBand(this, AC_cfg));
160 } else if (token == "GRADIENT") {
161 Components.push_back(new FGGradient(this, AC_cfg));
162 } else if (token == "SWITCH") {
163 Components.push_back(new FGSwitch(this, AC_cfg));
164 } else if (token == "FLAPS") {
165 Components.push_back(new FGFlaps(this, AC_cfg));
167 AC_cfg->GetNextConfigLine();
173 /******************************************************************************/
175 float FGFCS::GetComponentOutput(eParam idx) {
176 return Components[idx]->GetOutput();
179 /******************************************************************************/
181 string FGFCS::GetComponentName(int idx) {
182 return Components[idx]->GetName();