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