]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
515eed5e371eb40a730f6b7b25f9058963aa2085
[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
58 /*******************************************************************************
59 ************************************ CODE **************************************
60 *******************************************************************************/
61
62
63 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
64 {
65   Name = "FGFCS";
66 }
67
68 /******************************************************************************/
69
70 FGFCS::~FGFCS(void)
71 {
72 }
73
74 /******************************************************************************/
75
76 bool FGFCS::Run(void)
77 {
78   if (!FGModel::Run()) {
79
80     for (unsigned int i=0; i<Components.size(); i++) Components[i]->Run();
81
82   } else {
83   }
84   return false;
85 }
86
87 /******************************************************************************/
88
89 void FGFCS::SetThrottleCmd(int engineNum, float setting)
90 {
91   if (engineNum < 0) {
92     for (int ctr=0;ctr<Aircraft->GetNumEngines();ctr++) ThrottleCmd[ctr] = setting;
93   } else {
94     ThrottlePos[engineNum] = setting;
95   }
96 }
97
98 /******************************************************************************/
99
100 void FGFCS::SetThrottlePos(int engineNum, float setting)
101 {
102   if (engineNum < 0) {
103     for (int ctr=0;ctr<Aircraft->GetNumEngines();ctr++)
104       ThrottlePos[ctr] = ThrottleCmd[ctr];
105   } else {
106     ThrottlePos[engineNum] = setting;
107   }
108 }
109
110 /******************************************************************************/
111
112 bool FGFCS::LoadFCS(FGConfigFile* AC_cfg)
113 {
114   string token;
115
116   FCSName = AC_cfg->GetValue("NAME");
117   AC_cfg->GetNextConfigLine();
118   while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
119     if (token == "COMPONENT") {
120
121       if (((token = AC_cfg->GetValue("TYPE")) == "LAG_FILTER") ||
122           (token == "RECT_LAG_FILTER") ||
123           (token == "LEAD_LAG_FILTER") ||
124           (token == "SECOND_ORDER_FILTER") ||
125           (token == "WASHOUT_FILTER") ||
126           (token == "INTEGRATOR") )
127       {
128        Components.push_back(new FGFilter(this, AC_cfg));
129       } else if ((token == "PURE_GAIN") ||
130                 (token == "SCHEDULED_GAIN") ||
131                 (token == "AEROSURFACE_SCALE") )
132       {
133        Components.push_back(new FGGain(this, AC_cfg));
134       } else if (token == "SUMMER") {
135        Components.push_back(new FGSummer(this, AC_cfg));
136       } else if (token == "DEADBAND") {
137        Components.push_back(new FGDeadBand(this, AC_cfg));
138       } else if (token == "GRADIENT") {
139        Components.push_back(new FGGradient(this, AC_cfg));
140       } else if (token == "SWITCH") {
141        Components.push_back(new FGSwitch(this, AC_cfg));
142       }
143       AC_cfg->GetNextConfigLine();
144     }
145   }
146   return true;
147 }
148
149 /******************************************************************************/
150
151 float FGFCS::GetComponentOutput(int idx)
152 {
153   return Components[idx]->GetOutput();
154 }
155
156 /******************************************************************************/
157
158 string FGFCS::GetComponentName(int idx)
159 {
160   return Components[idx]->GetName();
161 }
162
163