]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.h
Latest JSBSim changes to support yaw and roll trim.
[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 SG_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 double GetDaCmd(void) { return DaCmd; }
175
176   /** Gets the elevator command.
177       @return elevator command in radians */
178   inline double GetDeCmd(void) { return DeCmd; }
179
180   /** Gets the rudder command.
181       @return rudder command in radians */
182   inline double GetDrCmd(void) { return DrCmd; }
183
184   /** Gets the flaps command.
185       @return flaps command in radians */
186   inline double GetDfCmd(void) { return DfCmd; }
187
188   /** Gets the speedbrake command.
189       @return speedbrake command in radians */
190   inline double GetDsbCmd(void) { return DsbCmd; }
191
192   /** Gets the spoiler command.
193       @return spoiler command in radians */
194   inline double GetDspCmd(void) { return DspCmd; }
195
196   /** Gets the throttle command.
197       @param engine engine ID number
198       @return throttle command in percent ( 0 - 100) for the given engine */
199   double GetThrottleCmd(int engine);
200
201   /** Gets the mixture command.
202       @param engine engine ID number
203       @return mixture command in percent ( 0 - 100) for the given engine */
204   inline double GetMixtureCmd(int engine) { return MixtureCmd[engine]; }
205
206   /** Gets the prop pitch command.
207       @param engine engine ID number
208       @return pitch command in percent ( 0.0 - 1.0) for the given engine */
209   inline double GetPropAdvanceCmd(int engine) { return PropAdvanceCmd[engine]; }
210
211   /** Gets the pitch trim command.
212       @return pitch trim command in radians */
213   inline double GetPitchTrimCmd(void) { return PTrimCmd; }
214   
215   /** Gets the rudder trim command.
216       @return rudder trim command in radians */
217   inline double GetYawTrimCmd(void) { return YTrimCmd; }
218   
219   /** Gets the aileron trim command.
220       @return aileron trim command in radians */
221   inline double GetRollTrimCmd(void) { return RTrimCmd; }
222   
223   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
224       defaults to down.
225       @return the current value of the gear extend/retract command*/
226   inline double GetGearCmd(void) { return GearCmd; }    
227   //@}
228
229   /// @name Aerosurface position retrieval
230   //@{
231   /** Gets the aileron position.
232       @return aileron position in radians */
233   inline double GetDaPos(void) { return DaPos; }
234
235   /** Gets the elevator position.
236       @return elevator position in radians */
237   inline double GetDePos(void) { return DePos; }
238
239   /** Gets the rudder position.
240       @return rudder position in radians */
241   inline double GetDrPos(void) { return DrPos; }
242
243   /** Gets the flaps position.
244       @return flaps position in radians */
245   inline double GetDfPos(void) { return DfPos; }
246
247   /** Gets the speedbrake position.
248       @return speedbrake position in radians */
249   inline double GetDsbPos(void) { return DsbPos; }
250
251   /** Gets the spoiler position.
252       @return spoiler position in radians */
253   inline double GetDspPos(void) { return DspPos; }
254
255   /** Gets the throttle position.
256       @param engine engine ID number
257       @return throttle position for the given engine in percent ( 0 - 100)*/
258   double GetThrottlePos(int engine);
259
260   /** Gets the mixture position.
261       @param engine engine ID number
262       @return mixture position for the given engine in percent ( 0 - 100)*/
263   inline double GetMixturePos(int engine) { return MixturePos[engine]; }
264   
265   /** Gets the gear position (0 up, 1 down), defaults to down
266       @return gear position (0 up, 1 down) */
267   inline double GetGearPos(void) { return GearPos; }    
268
269   /** Gets the prop pitch position.
270       @param engine engine ID number
271       @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
272   inline double GetPropAdvance(int engine) { return PropAdvance[engine]; }
273   //@}
274
275   /** Retrieves the State object pointer.
276       This is used by the FGFCS-owned components.
277       @return pointer to the State object */
278   inline FGState* GetState(void) { return State; }
279
280   /** Retrieves a components output value
281       @param idx the index of the component (the component ID)
282       @return output value from the component */
283   double GetComponentOutput(eParam idx);
284
285   /** Retrieves the component name
286       @param idx the index of the component (the component ID)
287       @return name of the component */
288   string GetComponentName(int idx);
289
290   /** Retrieves all component names for inclusion in output stream */
291   string GetComponentStrings(void);
292
293   /** Retrieves all component outputs for inclusion in output stream */
294   string GetComponentValues(void);
295
296   /// @name Pilot input command setting
297   //@{
298   /** Sets the aileron command
299       @param cmd aileron command in radians*/
300   inline void SetDaCmd(double cmd) { DaCmd = cmd; }
301
302   /** Sets the elevator command
303       @param cmd elevator command in radians*/
304   inline void SetDeCmd(double cmd) { DeCmd = cmd; }
305
306   /** Sets the rudder command
307       @param cmd rudder command in radians*/
308   inline void SetDrCmd(double cmd) { DrCmd = cmd; }
309
310   /** Sets the flaps command
311       @param cmd flaps command in radians*/
312   inline void SetDfCmd(double cmd) { DfCmd = cmd; }
313
314   /** Sets the speedbrake command
315       @param cmd speedbrake command in radians*/
316   inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
317
318   /** Sets the spoilers command
319       @param cmd spoilers command in radians*/
320   inline void SetDspCmd(double cmd) { DspCmd = cmd; }
321
322   /** Sets the pitch trim command
323       @param cmd pitch trim command in radians*/
324   inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
325
326   /** Sets the rudder trim command
327       @param cmd rudder trim command in radians*/
328   inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
329
330   /** Sets the aileron trim command
331       @param cmd aileron trim command in radians*/
332   inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
333
334   /** Sets the throttle command for the specified engine
335       @param engine engine ID number
336       @param cmd throttle command in percent (0 - 100)*/
337   void SetThrottleCmd(int engine, double cmd);
338
339   /** Sets the mixture command for the specified engine
340       @param engine engine ID number
341       @param cmd mixture command in percent (0 - 100)*/
342   void SetMixtureCmd(int engine, double cmd);
343   
344   /** Set the gear extend/retract command, defaults to down
345       @param gear command 0 for up, 1 for down */
346    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }   
347
348   /** Sets the propeller pitch command for the specified engine
349       @param engine engine ID number
350       @param cmd mixture command in percent (0.0 - 1.0)*/
351   void SetPropAdvanceCmd(int engine, double cmd);
352   //@}
353
354   /// @name Aerosurface position setting
355   //@{
356   /** Sets the aileron position
357       @param cmd aileron position in radians*/
358   inline void SetDaPos(double cmd) { DaPos = cmd; }
359
360   /** Sets the elevator position
361       @param cmd elevator position in radians*/
362   inline void SetDePos(double cmd) { DePos = cmd; }
363
364   /** Sets the rudder position
365       @param cmd rudder position in radians*/
366   inline void SetDrPos(double cmd) { DrPos = cmd; }
367
368   /** Sets the flaps position
369       @param cmd flaps position in radians*/
370   inline void SetDfPos(double cmd) { DfPos = cmd; }
371
372   /** Sets the speedbrake position
373       @param cmd speedbrake position in radians*/
374   inline void SetDsbPos(double cmd) { DsbPos = cmd; }
375
376   /** Sets the spoiler position
377       @param cmd spoiler position in radians*/
378   inline void SetDspPos(double cmd) { DspPos = cmd; }
379
380   /** Sets the actual throttle setting for the specified engine
381       @param engine engine ID number
382       @param cmd throttle setting in percent (0 - 100)*/
383   void SetThrottlePos(int engine, double cmd);
384
385   /** Sets the actual mixture setting for the specified engine
386       @param engine engine ID number
387       @param cmd mixture setting in percent (0 - 100)*/
388   void SetMixturePos(int engine, double cmd);
389   
390   /** Set the gear extend/retract position, defaults to down
391       @param gear position 0 up, 1 down       */
392    void SetGearPos(double gearpos) { GearPos = gearpos; }   
393
394
395   /** Sets the actual prop pitch setting for the specified engine
396       @param engine engine ID number
397       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
398   void SetPropAdvance(int engine, double cmd);
399   //@}
400
401   /// @name Landing Gear brakes
402   //@{
403   /** Sets the left brake group
404       @param cmd brake setting in percent (0.0 - 1.0) */
405   void SetLBrake(double cmd) {LeftBrake = cmd;}
406
407   /** Sets the right brake group
408       @param cmd brake setting in percent (0.0 - 1.0) */
409   void SetRBrake(double cmd) {RightBrake = cmd;}
410
411   /** Sets the center brake group
412       @param cmd brake setting in percent (0.0 - 1.0) */
413   void SetCBrake(double cmd) {CenterBrake = cmd;}
414
415   /** Gets the brake for a specified group.
416       @param bg which brakegroup to retrieve the command for
417       @return the brake setting for the supplied brake group argument */
418   double GetBrake(FGLGear::BrakeGroup bg);
419   //@}
420
421   /** Loads the Flight Control System.
422       The FGAircraft instance is actually responsible for reading the config file
423       and calling the various Loadxx() methods of the other systems, passing in
424       the config file instance pointer. LoadFCS() is called from FGAircraft.
425       @param AC_cfg pointer to the config file instance
426       @return true if succesful */
427   bool Load(FGConfigFile* AC_cfg);
428
429   void AddThrottle(void);
430
431 private:
432   double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
433   double DaPos, DePos, DrPos, DfPos, DsbPos, DspPos;
434   double PTrimCmd, YTrimCmd, RTrimCmd;
435   vector <double> ThrottleCmd;
436   vector <double> ThrottlePos;
437   vector <double> MixtureCmd;
438   vector <double> MixturePos;
439   vector <double> PropAdvanceCmd;
440   vector <double> PropAdvance;
441   double LeftBrake, RightBrake, CenterBrake; // Brake settings
442   double GearCmd,GearPos;
443
444   vector <FGFCSComponent*> Components;
445   void Debug(int from);
446 };
447
448 #include "FGState.h"
449
450 #endif
451