]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.h
Add support for normalized control surface positions and right and left ailerons
[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 FGDeadBand
150 */
151
152 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 CLASS DECLARATION
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
155
156 typedef enum { iNDe=0, iNDaL, iNDaR, iNDr, iNDsb, iNDsp, iNDf } NormalizeIdx;
157
158 class FGFCS : public FGModel {
159
160 public:
161   /** Constructor
162       @param Executive a pointer to the parent executive object */
163   FGFCS(FGFDMExec*);
164   /// Destructor
165   ~FGFCS();
166
167   /** Runs the Flight Controls model; called by the Executive
168       @return false if no error */
169   bool Run(void);
170
171   /// @name Pilot input command retrieval
172   //@{
173   /** Gets the aileron command.
174       @return aileron command in percent */
175   inline double GetDaCmd(void) { return DaCmd; }
176   
177   /** Gets the elevator command.
178       @return elevator command in percent */
179   inline double GetDeCmd(void) { return DeCmd; }
180
181   /** Gets the rudder command.
182       @return rudder command in percent */
183   inline double GetDrCmd(void) { return DrCmd; }
184
185   /** Gets the flaps command.
186       @return flaps command in percent */
187   inline double GetDfCmd(void) { return DfCmd; }
188
189   /** Gets the speedbrake command.
190       @return speedbrake command in percent */
191   inline double GetDsbCmd(void) { return DsbCmd; }
192
193   /** Gets the spoiler command.
194       @return spoiler command in percent */
195   inline double GetDspCmd(void) { return DspCmd; }
196
197   /** Gets the throttle command.
198       @param engine engine ID number
199       @return throttle command in percent ( 0 - 100) for the given engine */
200   double GetThrottleCmd(int engine);
201
202   /** Gets the mixture command.
203       @param engine engine ID number
204       @return mixture command in percent ( 0 - 100) for the given engine */
205   inline double GetMixtureCmd(int engine) { return MixtureCmd[engine]; }
206
207   /** Gets the prop pitch command.
208       @param engine engine ID number
209       @return pitch command in percent ( 0.0 - 1.0) for the given engine */
210   inline double GetPropAdvanceCmd(int engine) { return PropAdvanceCmd[engine]; }
211
212   /** Gets the pitch trim command.
213       @return pitch trim command in percent */
214   inline double GetPitchTrimCmd(void) { return PTrimCmd; }
215   
216   /** Gets the rudder trim command.
217       @return rudder trim command in percent */
218   inline double GetYawTrimCmd(void) { return YTrimCmd; }
219   
220   /** Gets the aileron trim command.
221       @return aileron trim command in percent */
222   inline double GetRollTrimCmd(void) { return RTrimCmd; }
223   
224   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
225       defaults to down.
226       @return the current value of the gear extend/retract command*/
227   inline double GetGearCmd(void) { return GearCmd; }    
228   //@}
229
230   /// @name Aerosurface position retrieval
231   //@{
232   /** Gets the left aileron position.
233       @return aileron position in radians */
234   inline double GetDaLPos(void) { return DaLPos; }
235
236   /// @name Aerosurface position retrieval
237   //@{
238   /** Gets the normalized left aileron position.
239       @return aileron position in radians */
240   inline double GetDaLPosN(void) { return DaLPosN; }
241
242   /// @name Aerosurface position retrieval
243   //@{
244   /** Gets the right aileron position.
245       @return aileron position in radians */
246   inline double GetDaRPos(void) { return DaRPos; }
247
248   /// @name Aerosurface position retrieval
249   //@{
250   /** Gets the normalized right aileron position.
251       @return right aileron position in percent (-1..1) */
252   inline double GetDaRPosN(void) { return DaRPosN; }
253
254   /** Gets the elevator position.
255       @return elevator position in radians */
256   inline double GetDePos(void) { return DePos; }
257  
258   /** Gets the normalized elevator position.
259       @return  elevator position in percent (-1..1) */
260   inline double GetDePosN(void) { return DePosN; }
261
262   /** Gets the rudder position.
263       @return rudder position in radians */
264   inline double GetDrPos(void) { return DrPos; }
265
266   /** Gets the normalized rudder position.
267       @return rudder position in percent (-1..1) */
268   inline double GetDrPosN(void) { return DrPosN; }
269
270   /** Gets the flaps position.
271       @return flaps position in radians */
272   inline double GetDfPos(void) { return DfPos; }
273
274   /** Gets the normalized flaps position.
275       @return flaps position in percent (-1..1) */
276   inline double GetDfPosN(void) { return DfPosN; }
277
278   /** Gets the speedbrake position.
279       @return speedbrake position in radians */
280   inline double GetDsbPos(void) { return DsbPos; }
281
282   /** Gets the normalized speedbrake position.
283       @return speedbrake position in percent (-1..1) */
284   inline double GetDsbPosN(void) { return DsbPosN; }
285
286   /** Gets the spoiler position.
287       @return spoiler position in radians */
288   inline double GetDspPos(void) { return DspPos; }
289   
290   /** Gets the normalized spoiler position.
291       @return spoiler position in percent (-1..1) */
292   inline double GetDspPosN(void) { return DspPosN; }
293
294   /** Gets the throttle position.
295       @param engine engine ID number
296       @return throttle position for the given engine in percent ( 0 - 100)*/
297   double GetThrottlePos(int engine);
298
299   /** Gets the mixture position.
300       @param engine engine ID number
301       @return mixture position for the given engine in percent ( 0 - 100)*/
302   inline double GetMixturePos(int engine) { return MixturePos[engine]; }
303   
304   /** Gets the gear position (0 up, 1 down), defaults to down
305       @return gear position (0 up, 1 down) */
306   inline double GetGearPos(void) { return GearPos; }    
307
308   /** Gets the prop pitch position.
309       @param engine engine ID number
310       @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
311   inline double GetPropAdvance(int engine) { return PropAdvance[engine]; }
312   //@}
313
314   /** Retrieves the State object pointer.
315       This is used by the FGFCS-owned components.
316       @return pointer to the State object */
317   inline FGState* GetState(void) { return State; }
318
319   /** Retrieves a components output value
320       @param idx the index of the component (the component ID)
321       @return output value from the component */
322   double GetComponentOutput(eParam idx);
323
324   /** Retrieves the component name
325       @param idx the index of the component (the component ID)
326       @return name of the component */
327   string GetComponentName(int idx);
328
329   /** Retrieves all component names for inclusion in output stream */
330   string GetComponentStrings(void);
331
332   /** Retrieves all component outputs for inclusion in output stream */
333   string GetComponentValues(void);
334
335   /// @name Pilot input command setting
336   //@{
337   /** Sets the aileron command
338       @param cmd aileron command in percent*/
339   inline void SetDaCmd(double cmd) { DaCmd = cmd; }
340
341   /** Sets the elevator command
342       @param cmd elevator command in percent*/
343   inline void SetDeCmd(double cmd) { DeCmd = cmd; }
344
345   /** Sets the rudder command
346       @param cmd rudder command in percent*/
347   inline void SetDrCmd(double cmd) { DrCmd = cmd; }
348
349   /** Sets the flaps command
350       @param cmd flaps command in percent*/
351   inline void SetDfCmd(double cmd) { DfCmd = cmd; }
352
353   /** Sets the speedbrake command
354       @param cmd speedbrake command in percent*/
355   inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
356
357   /** Sets the spoilers command
358       @param cmd spoilers command in percent*/
359   inline void SetDspCmd(double cmd) { DspCmd = cmd; }
360
361   /** Sets the pitch trim command
362       @param cmd pitch trim command in percent*/
363   inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
364
365   /** Sets the rudder trim command
366       @param cmd rudder trim command in percent*/
367   inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
368
369   /** Sets the aileron trim command
370       @param cmd aileron trim command in percent*/
371   inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
372
373   /** Sets the throttle command for the specified engine
374       @param engine engine ID number
375       @param cmd throttle command in percent (0 - 100)*/
376   void SetThrottleCmd(int engine, double cmd);
377
378   /** Sets the mixture command for the specified engine
379       @param engine engine ID number
380       @param cmd mixture command in percent (0 - 100)*/
381   void SetMixtureCmd(int engine, double cmd);
382   
383   /** Set the gear extend/retract command, defaults to down
384       @param gear command 0 for up, 1 for down */
385    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }   
386
387   /** Sets the propeller pitch command for the specified engine
388       @param engine engine ID number
389       @param cmd mixture command in percent (0.0 - 1.0)*/
390   void SetPropAdvanceCmd(int engine, double cmd);
391   //@}
392
393   /// @name Aerosurface position setting
394   //@{
395   /** Sets the left aileron position
396       @param cmd left aileron position in radians*/
397   inline void SetDaLPos(double cmd) { DaLPos = cmd; }
398
399   /** Sets the normalized left aileron position
400       @param cmd left aileron position in percent (-1..1)*/
401   inline void SetDaLPosN(double cmd) { DaLPosN = cmd; }
402
403   /** Sets the right aileron position
404       @param cmd right aileron position in radians*/
405   inline void SetDaRPos(double cmd) { DaRPos = cmd; }
406
407   /** Sets the normalized right aileron position
408       @param cmd right aileron position in percent (-1..1)*/
409   inline void SetDaRPosN(double cmd) { DaRPosN = cmd; }
410
411   /** Sets the elevator position
412       @param cmd elevator position in radians*/
413   inline void SetDePos(double cmd) { DePos = cmd; }
414
415   /** Sets the normalized elevator position
416       @param cmd elevator position in percent (-1..1) */
417   inline void SetDePosN(double cmd) { DePosN = cmd; }
418
419   /** Sets the rudder position
420       @param cmd rudder position in radians*/
421   inline void SetDrPos(double cmd) { DrPos = cmd; }
422  
423   /** Sets the normalized rudder position
424       @param cmd rudder position in percent (-1..1)*/
425   inline void SetDrPosN(double cmd) { DrPosN = cmd; }
426
427   /** Sets the flaps position
428       @param cmd flaps position in radians*/
429   inline void SetDfPos(double cmd) { DfPos = cmd; }
430   
431   /** Sets the flaps position
432       @param cmd flaps position in radians*/
433   inline void SetDfPosN(double cmd) { DfPosN = cmd; }
434
435   /** Sets the speedbrake position
436       @param cmd speedbrake position in radians*/
437   inline void SetDsbPos(double cmd) { DsbPos = cmd; }
438  
439   /** Sets the normalized speedbrake position
440       @param cmd normalized speedbrake position in percent (-1..1)*/
441   inline void SetDsbPosN(double cmd) { DsbPosN = cmd; }
442
443   /** Sets the spoiler position
444       @param cmd spoiler position in radians*/
445   inline void SetDspPos(double cmd) { DspPos = cmd; }
446  
447   /** Sets the normalized spoiler position
448       @param cmd normalized spoiler position in percent (-1..1)*/
449   inline void SetDspPosN(double cmd) { DspPosN = cmd; }
450
451   /** Sets the actual throttle setting for the specified engine
452       @param engine engine ID number
453       @param cmd throttle setting in percent (0 - 100)*/
454   void SetThrottlePos(int engine, double cmd);
455
456   /** Sets the actual mixture setting for the specified engine
457       @param engine engine ID number
458       @param cmd mixture setting in percent (0 - 100)*/
459   void SetMixturePos(int engine, double cmd);
460   
461   /** Set the gear extend/retract position, defaults to down
462       @param gear position 0 up, 1 down       */
463    void SetGearPos(double gearpos) { GearPos = gearpos; }   
464
465
466   /** Sets the actual prop pitch setting for the specified engine
467       @param engine engine ID number
468       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
469   void SetPropAdvance(int engine, double cmd);
470   //@}
471
472   /// @name Landing Gear brakes
473   //@{
474   /** Sets the left brake group
475       @param cmd brake setting in percent (0.0 - 1.0) */
476   void SetLBrake(double cmd) {LeftBrake = cmd;}
477
478   /** Sets the right brake group
479       @param cmd brake setting in percent (0.0 - 1.0) */
480   void SetRBrake(double cmd) {RightBrake = cmd;}
481
482   /** Sets the center brake group
483       @param cmd brake setting in percent (0.0 - 1.0) */
484   void SetCBrake(double cmd) {CenterBrake = cmd;}
485
486   /** Gets the brake for a specified group.
487       @param bg which brakegroup to retrieve the command for
488       @return the brake setting for the supplied brake group argument */
489   double GetBrake(FGLGear::BrakeGroup bg);
490   //@}
491
492   /** Loads the Flight Control System.
493       The FGAircraft instance is actually responsible for reading the config file
494       and calling the various Loadxx() methods of the other systems, passing in
495       the config file instance pointer. LoadFCS() is called from FGAircraft.
496       @param AC_cfg pointer to the config file instance
497       @return true if succesful */
498   bool Load(FGConfigFile* AC_cfg);
499
500   void AddThrottle(void);
501
502 private:
503   double DaCmd,   DeCmd,   DrCmd,  DfCmd,  DsbCmd, DspCmd;
504   double DaLPos,  DaRPos,  DePos,  DrPos,  DfPos,  DsbPos,  DspPos;
505   double DaLPosN, DaRPosN, DePosN, DrPosN, DfPosN, DsbPosN, DspPosN;
506   double PTrimCmd, YTrimCmd, RTrimCmd;
507   vector <double> ThrottleCmd;
508   vector <double> ThrottlePos;
509   vector <double> MixtureCmd;
510   vector <double> MixturePos;
511   vector <double> PropAdvanceCmd;
512   vector <double> PropAdvance;
513   double LeftBrake, RightBrake, CenterBrake; // Brake settings
514   double GearCmd,GearPos;
515   
516   bool DoNormalize;
517   void Normalize(void);
518
519   vector <FGFCSComponent*> Components;
520   int ToNormalize[7];
521   void Debug(int from);
522 };
523
524 #include "FGState.h"
525
526 #endif
527