]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.h
Updates. Includes property tree additions and fixes. Also Jon's first cut at
[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 typedef enum { iDe=0, iDaL, iDaR, iDr, iDsb, iDsp, iDf } FcIdx;
69 int const NNorm=7;
70 typedef enum { ofRad=0, ofNorm, ofMag } OutputForm;
71 int const NForms=3;
72
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 CLASS DOCUMENTATION
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80
81 /** Encapsulates the Flight Control System (FCS) functionality.
82     <ul><li>\URL[Source Code]{FGFCS.cpp.html}</li>
83     <li>\URL[Header File]{FGFCS.h.html}</li></ul>
84     This class owns and contains the list of \URL[components]{FGFCSComponent.html}
85     that define the control system for this aircraft. The config file for the
86     aircraft contains a description of the control path that starts at an input
87     or command and ends at an effector, e.g. an aerosurface. The FCS components
88     which comprise the control laws for an axis are defined sequentially in
89     the configuration file. For instance, for the X-15:
90     
91     <pre>
92     &lt FLIGHT_CONTROL NAME="X-15 SAS"&gt
93
94     &lt COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER"&gt
95       ID            0
96       INPUT        FG_ELEVATOR_CMD
97       INPUT        FG_PITCH_TRIM_CMD
98       CLIPTO       -1 1
99     &lt/COMPONENT&gt
100
101     &lt COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE"&gt
102       ID           1
103       INPUT        0
104       MIN         -50
105       MAX          50
106     &lt/COMPONENT&gt
107
108     &lt COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN"&gt
109       ID           2
110       INPUT        1
111       GAIN         -0.36
112     &lt/COMPONENT&gt
113
114     &lt COMPONENT NAME="Pitch Scheduled Gain 1" TYPE="SCHEDULED_GAIN"&gt
115       ID           3
116       INPUT        2
117       GAIN         0.017
118       SCHEDULED_BY FG_ELEVATOR_POS
119       -0.35  -6.0
120       -0.17  -3.0
121        0.00  -2.0
122        0.09  -3.0
123        0.17  -5.0
124        0.60 -12.0
125     &lt/COMPONENT&gt
126
127     ... etc.
128     </pre>
129     
130     In the above case we can see the first few components of the pitch channel
131     defined. The input to the first component, as can be seen in the "Pitch trim
132     sum" component, is really the sum of two parameters: elevator command (from
133     the stick - a pilot input), and pitch trim. The type of this component is
134     "Summer". Its ID is 0 - the ID is used by other components to reference it.
135     The next component created is an aerosurface scale component - a type of
136     gain (see the LoadFCS() method for insight on how the various types of
137     components map into the actual component classes). You can see the input of
138     the "Pitch Command Scale" component takes "0" as input. When a number is
139     specified as an input, it refers to the ID of another FCS component. In this
140     case, ID 0 refers to the previously defined and discussed "Pitch Trim Sum"
141     component. This continues until the final component for an axis when the
142     OUTPUT keyword specifies where the output is supposed to go. See the
143     individual components for more information on how they are mechanized.
144     
145     @author Jon S. Berndt
146     @version $Id$
147     @see FGFCSComponent
148     @see FGConfigFile
149     @see FGGain
150     @see FGSummer
151     @see FGSwitch
152     @see FGGradient
153     @see FGFilter
154     @see FGDeadBand
155 */
156
157 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 CLASS DECLARATION
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
160
161 class FGFCS : public FGModel {
162
163 public:
164   /** Constructor
165       @param Executive a pointer to the parent executive object */
166   FGFCS(FGFDMExec*);
167   /// Destructor
168   ~FGFCS();
169
170   /** Runs the Flight Controls model; called by the Executive
171       @return false if no error */
172   bool Run(void);
173
174   /// @name Pilot input command retrieval
175   //@{
176   /** Gets the aileron command.
177       @return aileron command in percent */
178   inline double GetDaCmd(void) const { return DaCmd; }
179   
180   /** Gets the elevator command.
181       @return elevator command in percent */
182   inline double GetDeCmd(void) const { return DeCmd; }
183
184   /** Gets the rudder command.
185       @return rudder command in percent */
186   inline double GetDrCmd(void) const { return DrCmd; }
187
188   /** Gets the flaps command.
189       @return flaps command in percent */
190   inline double GetDfCmd(void) const { return DfCmd; }
191
192   /** Gets the speedbrake command.
193       @return speedbrake command in percent */
194   inline double GetDsbCmd(void) const { return DsbCmd; }
195
196   /** Gets the spoiler command.
197       @return spoiler command in percent */
198   inline double GetDspCmd(void) const { return DspCmd; }
199
200   /** Gets the throttle command.
201       @param engine engine ID number
202       @return throttle command in percent ( 0 - 100) for the given engine */
203   double GetThrottleCmd(int engine);
204
205   /** Gets the mixture command.
206       @param engine engine ID number
207       @return mixture command in percent ( 0 - 100) for the given engine */
208   inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
209
210   /** Gets the prop pitch command.
211       @param engine engine ID number
212       @return pitch command in percent ( 0.0 - 1.0) for the given engine */
213   inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
214
215   /** Gets the pitch trim command.
216       @return pitch trim command in percent */
217   inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
218   
219   /** Gets the rudder trim command.
220       @return rudder trim command in percent */
221   inline double GetYawTrimCmd(void) const { return YTrimCmd; }
222   
223   /** Gets the aileron trim command.
224       @return aileron trim command in percent */
225   inline double GetRollTrimCmd(void) const { return RTrimCmd; }
226   
227   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
228       defaults to down.
229       @return the current value of the gear extend/retract command*/
230   inline double GetGearCmd(void) const { return GearCmd; }    
231   //@}
232
233   /// @name Aerosurface position retrieval
234   //@{
235   /** Gets the left aileron position.
236       @return aileron position in radians */
237   inline double GetDaLPos( int form = ofRad ) 
238                          const { return DaLPos[form]; }
239
240   /// @name Aerosurface position retrieval
241   //@{
242   /** Gets the right aileron position.
243       @return aileron position in radians */
244   inline double GetDaRPos( int form = ofRad ) 
245                          const { return DaRPos[form]; }
246
247   /** Gets the elevator position.
248       @return elevator position in radians */
249   inline double GetDePos( int form = ofRad ) 
250                          const { return DePos[form]; }
251  
252   /** Gets the rudder position.
253       @return rudder position in radians */
254   inline double GetDrPos( int form = ofRad ) 
255                          const { return DrPos[form]; }
256
257   /** Gets the speedbrake position.
258       @return speedbrake position in radians */
259   inline double GetDsbPos( int form = ofRad ) 
260                          const { return DsbPos[form]; }
261
262   /** Gets the spoiler position.
263       @return spoiler position in radians */
264   inline double GetDspPos( int form = ofRad ) 
265                          const { return DspPos[form]; }
266   
267   /** Gets the flaps position.
268       @return flaps position in radians */
269   inline double GetDfPos( int form = ofRad ) 
270                          const { return DfPos[form]; }
271                          
272   /** Gets the throttle position.
273       @param engine engine ID number
274       @return throttle position for the given engine in percent ( 0 - 100)*/
275   double GetThrottlePos(int engine);
276
277   /** Gets the mixture position.
278       @param engine engine ID number
279       @return mixture position for the given engine in percent ( 0 - 100)*/
280   inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
281   
282   /** Gets the gear position (0 up, 1 down), defaults to down
283       @return gear position (0 up, 1 down) */
284   inline double GetGearPos(void) const { return GearPos; }    
285
286   /** Gets the prop pitch position.
287       @param engine engine ID number
288       @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
289   inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
290   //@}
291
292   /** Retrieves the State object pointer.
293       This is used by the FGFCS-owned components.
294       @return pointer to the State object */
295   inline FGState* GetState(void) { return State; }
296
297   /** Retrieves a components output value
298       @param idx the index of the component (the component ID)
299       @return output value from the component */
300   double GetComponentOutput(eParam idx);
301
302   /** Retrieves the component name
303       @param idx the index of the component (the component ID)
304       @return name of the component */
305   string GetComponentName(int idx);
306
307   /** Retrieves all component names for inclusion in output stream */
308   string GetComponentStrings(void);
309
310   /** Retrieves all component outputs for inclusion in output stream */
311   string GetComponentValues(void);
312
313   /// @name Pilot input command setting
314   //@{
315   /** Sets the aileron command
316       @param cmd aileron command in percent*/
317   inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
318
319   /** Sets the elevator command
320       @param cmd elevator command in percent*/
321   inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
322
323   /** Sets the rudder command
324       @param cmd rudder command in percent*/
325   inline void SetDrCmd(double cmd) { DrCmd = cmd; }
326
327   /** Sets the flaps command
328       @param cmd flaps command in percent*/
329   inline void SetDfCmd(double cmd) { DfCmd = cmd; }
330
331   /** Sets the speedbrake command
332       @param cmd speedbrake command in percent*/
333   inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
334
335   /** Sets the spoilers command
336       @param cmd spoilers command in percent*/
337   inline void SetDspCmd(double cmd) { DspCmd = cmd; }
338
339   /** Sets the pitch trim command
340       @param cmd pitch trim command in percent*/
341   inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
342
343   /** Sets the rudder trim command
344       @param cmd rudder trim command in percent*/
345   inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
346
347   /** Sets the aileron trim command
348       @param cmd aileron trim command in percent*/
349   inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
350
351   /** Sets the throttle command for the specified engine
352       @param engine engine ID number
353       @param cmd throttle command in percent (0 - 100)*/
354   void SetThrottleCmd(int engine, double cmd);
355
356   /** Sets the mixture command for the specified engine
357       @param engine engine ID number
358       @param cmd mixture command in percent (0 - 100)*/
359   void SetMixtureCmd(int engine, double cmd);
360   
361   /** Set the gear extend/retract command, defaults to down
362       @param gear command 0 for up, 1 for down */
363    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }   
364
365   /** Sets the propeller pitch command for the specified engine
366       @param engine engine ID number
367       @param cmd mixture command in percent (0.0 - 1.0)*/
368   void SetPropAdvanceCmd(int engine, double cmd);
369   //@}
370
371   /// @name Aerosurface position setting
372   //@{
373   /** Sets the left aileron position
374       @param cmd left aileron position in radians*/
375   inline void SetDaLPos( int form , double pos ) 
376                                       { DaLPos[form] = pos; }
377
378   /** Sets the right aileron position
379       @param cmd right aileron position in radians*/
380   inline void SetDaRPos( int form , double pos ) 
381                                       { DaRPos[form] = pos; }
382
383   /** Sets the elevator position
384       @param cmd elevator position in radians*/
385   inline void SetDePos( int form , double pos ) 
386                                       { DePos[form] = pos; }
387
388   /** Sets the rudder position
389       @param cmd rudder position in radians*/
390   inline void SetDrPos( int form , double pos ) 
391                                       { DrPos[form] = pos; }
392  
393    /** Sets the flaps position
394       @param cmd flaps position in radians*/
395   inline void SetDfPos( int form , double pos ) 
396                                       { DfPos[form] = pos; }
397   
398   /** Sets the speedbrake position
399       @param cmd speedbrake position in radians*/
400   inline void SetDsbPos( int form , double pos ) 
401                                       { DsbPos[form] = pos; }
402
403   /** Sets the spoiler position
404       @param cmd spoiler position in radians*/
405   inline void SetDspPos( int form , double pos ) 
406                                       { DspPos[form] = pos; }
407  
408   /** Sets the actual throttle setting for the specified engine
409       @param engine engine ID number
410       @param cmd throttle setting in percent (0 - 100)*/
411   void SetThrottlePos(int engine, double cmd);
412
413   /** Sets the actual mixture setting for the specified engine
414       @param engine engine ID number
415       @param cmd mixture setting in percent (0 - 100)*/
416   void SetMixturePos(int engine, double cmd);
417   
418   /** Set the gear extend/retract position, defaults to down
419       @param gear position 0 up, 1 down       */
420    void SetGearPos(double gearpos) { GearPos = gearpos; }   
421
422
423   /** Sets the actual prop pitch setting for the specified engine
424       @param engine engine ID number
425       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
426   void SetPropAdvance(int engine, double cmd);
427   //@}
428
429   /// @name Landing Gear brakes
430   //@{
431   /** Sets the left brake group
432       @param cmd brake setting in percent (0.0 - 1.0) */
433   void SetLBrake(double cmd) {LeftBrake = cmd;}
434
435   /** Sets the right brake group
436       @param cmd brake setting in percent (0.0 - 1.0) */
437   void SetRBrake(double cmd) {RightBrake = cmd;}
438
439   /** Sets the center brake group
440       @param cmd brake setting in percent (0.0 - 1.0) */
441   void SetCBrake(double cmd) {CenterBrake = cmd;}
442
443   /** Gets the brake for a specified group.
444       @param bg which brakegroup to retrieve the command for
445       @return the brake setting for the supplied brake group argument */
446   double GetBrake(FGLGear::BrakeGroup bg);
447   //@}
448
449   /** Loads the Flight Control System.
450       The FGAircraft instance is actually responsible for reading the config file
451       and calling the various Loadxx() methods of the other systems, passing in
452       the config file instance pointer. LoadFCS() is called from FGAircraft.
453       @param AC_cfg pointer to the config file instance
454       @return true if succesful */
455   bool Load(FGConfigFile* AC_cfg);
456
457   void AddThrottle(void);
458   
459   void bind(void);
460   void unbind(void);
461
462   
463 private:
464   double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
465   double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];  
466   double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
467   double PTrimCmd, YTrimCmd, RTrimCmd;
468   vector <double> ThrottleCmd;
469   vector <double> ThrottlePos;
470   vector <double> MixtureCmd;
471   vector <double> MixturePos;
472   vector <double> PropAdvanceCmd;
473   vector <double> PropAdvance;
474   double LeftBrake, RightBrake, CenterBrake; // Brake settings
475   double GearCmd,GearPos;
476   
477   bool DoNormalize;
478   void Normalize(void);
479
480   vector <FGFCSComponent*> Components;
481   int ToNormalize[NNorm];
482   void Debug(int from);
483 };
484
485 #include "FGState.h"
486
487 #endif
488