]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.h
Latest round of JSBSim updates.
[flightgear.git] / src / FDM / JSBSim / FGFCS.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGGFCS.h
4  Author:       Jon S. Berndt
5  Date started: 12/12/98
6  
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8  
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13  
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18  
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22  
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25  
26 HISTORY
27 --------------------------------------------------------------------------------
28 12/12/98   JSB   Created
29  
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGFCS_H
35 #define FGFCS_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  ifdef FG_HAVE_STD_INCLUDES
44 #    include <vector>
45 #  else
46 #    include <vector.h>
47 #  endif
48 #else
49 #  include <vector>
50 #endif
51
52 #include <string>
53 #include "filtersjb/FGFCSComponent.h"
54 #include "FGModel.h"
55 #include "FGLGear.h"
56 #include "FGConfigFile.h"
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 DEFINITIONS
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 #define ID_FCS "$Id$"
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 FORWARD DECLARATIONS
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 CLASS DOCUMENTATION
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75
76 /** Encapsulates the Flight Control System (FCS) functionality.
77     <ul><li>\URL[Source Code]{FGFCS.cpp.html}</li>
78     <li>\URL[Header File]{FGFCS.h.html}</li></ul>
79     This class owns and contains the list of \URL[components]{FGFCSComponent.html}
80     that define the control system for this aircraft. The config file for the
81     aircraft contains a description of the control path that starts at an input
82     or command and ends at an effector, e.g. an aerosurface. The FCS components
83     which comprise the control laws for an axis are defined sequentially in
84     the configuration file. For instance, for the X-15:
85     
86     <pre>
87     &lt FLIGHT_CONTROL NAME="X-15 SAS"&gt
88
89     &lt COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER"&gt
90       ID            0
91       INPUT        FG_ELEVATOR_CMD
92       INPUT        FG_PITCH_TRIM_CMD
93       CLIPTO       -1 1
94     &lt/COMPONENT&gt
95
96     &lt COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE"&gt
97       ID           1
98       INPUT        0
99       MIN         -50
100       MAX          50
101     &lt/COMPONENT&gt
102
103     &lt COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN"&gt
104       ID           2
105       INPUT        1
106       GAIN         -0.36
107     &lt/COMPONENT&gt
108
109     &lt COMPONENT NAME="Pitch Scheduled Gain 1" TYPE="SCHEDULED_GAIN"&gt
110       ID           3
111       INPUT        2
112       GAIN         0.017
113       SCHEDULED_BY FG_ELEVATOR_POS
114       -0.35  -6.0
115       -0.17  -3.0
116        0.00  -2.0
117        0.09  -3.0
118        0.17  -5.0
119        0.60 -12.0
120     &lt/COMPONENT&gt
121
122     ... etc.
123     </pre>
124     
125     In the above case we can see the first few components of the pitch channel
126     defined. The input to the first component, as can be seen in the "Pitch trim
127     sum" component, is really the sum of two parameters: elevator command (from
128     the stick - a pilot input), and pitch trim. The type of this component is
129     "Summer". Its ID is 0 - the ID is used by other components to reference it.
130     The next component created is an aerosurface scale component - a type of
131     gain (see the LoadFCS() method for insight on how the various types of
132     components map into the actual component classes). You can see the input of
133     the "Pitch Command Scale" component takes "0" as input. When a number is
134     specified as an input, it refers to the ID of another FCS component. In this
135     case, ID 0 refers to the previously defined and discussed "Pitch Trim Sum"
136     component. This continues until the final component for an axis when the
137     OUTPUT keyword specifies where the output is supposed to go. See the
138     individual components for more information on how they are mechanized.
139     
140     @author Jon S. Berndt
141     @version $Id$
142     @see FGFCSComponent
143     @see FGConfigFile
144     @see FGGain
145     @see FGSummer
146     @see FGSwitch
147     @see FGGradient
148     @see FGFilter
149     @see FGFlaps
150     @see FGDeadBand
151 */
152
153 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 CLASS DECLARATION
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
156
157 class FGFCS : public FGModel {
158
159 public:
160   /** Constructor
161       @param Executive a pointer to the parent executive object */
162   FGFCS(FGFDMExec*);
163   /// Destructor
164   ~FGFCS();
165
166   /** Runs the Flight Controls model; called by the Executive
167       @return false if no error */
168   bool Run(void);
169
170   /// @name Pilot input command retrieval
171   //@{
172   /** Gets the aileron command.
173       @return aileron command in radians */
174   inline float GetDaCmd(void) { return DaCmd; }
175   /** Gets the elevator command.
176       @return elevator command in radians */
177   inline float GetDeCmd(void) { return DeCmd; }
178   /** Gets the rudder command.
179       @return rudder command in radians */
180   inline float GetDrCmd(void) { return DrCmd; }
181   /** Gets the flaps command.
182       @return flaps command in radians */
183   inline float GetDfCmd(void) { return DfCmd; }
184   /** Gets the speedbrake command.
185       @return speedbrake command in radians */
186   inline float GetDsbCmd(void) { return DsbCmd; }
187   /** Gets the spoiler command.
188       @return spoiler command in radians */
189   inline float GetDspCmd(void) { return DspCmd; }
190   /** Gets the throttle command.
191       @param engine engine ID number
192       @return throttle command in percent ( 0 - 100) for the given engine */
193   inline float GetThrottleCmd(int engine) { return ThrottleCmd[engine]; }
194   /** Gets the pitch trim command.
195       @return pitch trim command in radians */
196   inline float GetPitchTrimCmd(void) { return PTrimCmd; }
197   //@}
198   
199   /// @name Aerosurface position retrieval
200   //@{
201   /** Gets the aileron position.
202       @return aileron position in radians */
203   inline float GetDaPos(void) { return DaPos; }
204   /** Gets the elevator position.
205       @return elevator position in radians */
206   inline float GetDePos(void) { return DePos; }
207   /** Gets the rudder position.
208       @return rudder position in radians */
209   inline float GetDrPos(void) { return DrPos; }
210   /** Gets the flaps position.
211       @return flaps position in radians */
212   inline float GetDfPos(void) { return DfPos; }
213   /** Gets the speedbrake position.
214       @return speedbrake position in radians */
215   inline float GetDsbPos(void) { return DsbPos; }
216   /** Gets the spoiler position.
217       @return spoiler position in radians */
218   inline float GetDspPos(void) { return DspPos; }
219   /** Gets the throttle position.
220       @param engine engine ID number
221       @return throttle position for the given engine in percent ( 0 - 100)*/
222   inline float GetThrottlePos(int engine) { return ThrottlePos[engine]; }
223   //@}
224
225   /** Retrieves the State object pointer.
226       This is used by the FGFCS-owned components.
227       @return pointer to the State object */
228   inline FGState* GetState(void) { return State; }
229   /** Retrieves a components output value
230       @param idx the index of the component (the component ID)
231       @return output value from the component */
232   float GetComponentOutput(eParam idx);
233   /** Retrieves the component name
234       @param idx the index of the component (the component ID)
235       @return name of the component */
236   string GetComponentName(int idx);
237   /** Retrieves all component names for inclusion in output stream */
238   string GetComponentStrings(void);
239   /** Retrieves all component outputs for inclusion in output stream */
240   string GetComponentValues(void);
241
242   /// @name Pilot input command setting
243   //@{
244   /** Sets the aileron command
245       @param cmd aileron command in radians*/
246   inline void SetDaCmd(float cmd) { DaCmd = cmd; }
247   /** Sets the elevator command
248       @param cmd elevator command in radians*/
249   inline void SetDeCmd(float cmd) { DeCmd = cmd; }
250   /** Sets the rudder command
251       @param cmd rudder command in radians*/
252   inline void SetDrCmd(float cmd) { DrCmd = cmd; }
253   /** Sets the flaps command
254       @param cmd flaps command in radians*/
255   inline void SetDfCmd(float cmd) { DfCmd = cmd; }
256   /** Sets the speedbrake command
257       @param cmd speedbrake command in radians*/
258   inline void SetDsbCmd(float cmd) { DsbCmd = cmd; }
259   /** Sets the spoilers command
260       @param cmd spoilers command in radians*/
261   inline void SetDspCmd(float cmd) { DspCmd = cmd; }
262   /** Sets the pitch trim command
263       @param cmd pitch trim command in radians*/
264   inline void SetPitchTrimCmd(float cmd) { PTrimCmd = cmd; }
265   /** Sets the throttle command for the specified engine
266       @param engine engine ID number 
267       @param cmd throttle command in percent (0 - 100)*/
268   inline void SetThrottleCmd(int engine, float cmd);
269   //@}
270
271   /// @name Aerosurface position setting
272   //@{
273   /** Sets the aileron position
274       @param cmd aileron position in radians*/
275   inline void SetDaPos(float cmd) { DaPos = cmd; }
276   /** Sets the elevator position
277       @param cmd elevator position in radians*/
278   inline void SetDePos(float cmd) { DePos = cmd; }
279   /** Sets the rudder position
280       @param cmd rudder position in radians*/
281   inline void SetDrPos(float cmd) { DrPos = cmd; }
282   /** Sets the flaps position
283       @param cmd flaps position in radians*/
284   inline void SetDfPos(float cmd) { DfPos = cmd; }
285   /** Sets the speedbrake position
286       @param cmd speedbrake position in radians*/
287   inline void SetDsbPos(float cmd) { DsbPos = cmd; }
288   /** Sets the spoiler position
289       @param cmd spoiler position in radians*/
290   inline void SetDspPos(float cmd) { DspPos = cmd; }
291   /** Sets the actual throttle setting for the specified engine
292       @param engine engine ID number 
293       @param cmd throttle setting in percent (0 - 100)*/
294   inline void SetThrottlePos(int engine, float cmd);
295   //@}
296
297   /// @name Landing Gear brakes
298   //@{
299   /** Sets the left brake group
300       @param cmd brake setting in percent (0.0 - 1.0) */
301   void SetLBrake(float cmd) {LeftBrake = cmd;}
302   /** Sets the right brake group
303       @param cmd brake setting in percent (0.0 - 1.0) */
304   void SetRBrake(float cmd) {RightBrake = cmd;}
305   /** Sets the center brake group
306       @param cmd brake setting in percent (0.0 - 1.0) */
307   void SetCBrake(float cmd) {CenterBrake = cmd;}
308   /** Gets the brake for a specified group.
309       @param bg which brakegroup to retrieve the command for
310       @return the brake setting for the supplied brake group argument */
311   float GetBrake(FGLGear::BrakeGroup bg);
312   //@}
313
314   /** Loads the Flight Control System.
315       The FGAircraft instance is actually responsible for reading the config file
316       and calling the various Loadxx() methods of the other systems, passing in
317       the config file instance pointer. LoadFCS() is called from FGAircraft.
318       @param AC_cfg pointer to the config file instance
319       @return true if succesful */
320   bool LoadFCS(FGConfigFile* AC_cfg);
321
322   /** The name of the flight control laws for this aircraft.
323       This is given in the config file, and is not used for anything currently.*/
324   string FCSName;
325
326   void AddThrottle(void);
327
328 private:
329   float DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
330   float DaPos, DePos, DrPos, DfPos, DsbPos, DspPos;
331   float PTrimCmd;
332   vector <float> ThrottleCmd;
333   vector <float> ThrottlePos;
334   float LeftBrake, RightBrake, CenterBrake; // Brake settings
335
336   vector <FGFCSComponent*> Components;
337   void Debug(void);
338 };
339
340 #include "FGState.h"
341
342 #endif
343