]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGFCS.h
b07800fb71345ead5b440dbaa7464c02544343d4
[flightgear.git] / src / FDM / JSBSim / models / 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 Lesser 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 Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser 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 Lesser 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 <models/flight_control/FGFCSComponent.h>
54 #include <models/FGModel.h>
55 #include <models/FGLGear.h>
56 #include <input_output/FGXMLFileRead.h>
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 DEFINITIONS
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 #define ID_FCS "$Id$"
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 FORWARD DECLARATIONS
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 namespace JSBSim {
69
70 typedef enum { ofRad=0, ofDeg, ofNorm, ofMag , NForms} OutputForm;
71
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 CLASS DOCUMENTATION
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75
76 /** Encapsulates the Flight Control System (FCS) functionality.
77     This class owns and contains the list of FGFCSComponents
78     that define the control system for this aircraft. The config file for the
79     aircraft contains a description of the control path that starts at an input
80     or command and ends at an effector, e.g. an aerosurface. The FCS components
81     which comprise the control laws for an axis are defined sequentially in
82     the configuration file. For instance, for the X-15:
83
84     @code
85     <flight_control name="X-15 SAS">
86       <channel>
87         <summer name="Pitch Trim Sum">
88            <input> fcs/elevator-cmd-norm </input>
89            <input> fcs/pitch-trim-cmd-norm </input>
90            <clipto>
91              <min>-1</min>
92              <max>1</max>
93            </clipto>
94         </summer>
95
96         <aerosurface_scale name="Pitch Command Scale">
97           <input> fcs/pitch-trim-sum </input>
98           <range>
99             <min> -50 </min>
100             <max>  50 </max>
101           </range>
102         </aerosurface_scale>
103
104         ... etc.
105     @endcode
106
107     In the above case we can see the first few components of the pitch channel
108     defined. The input to the first component (a summer), as can be seen in the "Pitch trim
109     sum" component, is really the sum of two parameters: elevator command (from
110     the stick - a pilot input), and pitch trim.
111     The next component created is an aerosurface scale component - a type of
112     gain (see the LoadFCS() method for insight on how the various types of
113     components map into the actual component classes).  This continues until the
114     final component for an axis when the
115     \<output> element is usually used to specify where the output is supposed to go. See the
116     individual components for more information on how they are mechanized.
117
118     Another option for the flight controls portion of the config file is that in
119     addition to using the "NAME" attribute in,
120
121     @code
122     \<flight_control name="X-15 SAS">
123     @endcode
124
125     one can also supply a filename:
126
127     @code
128     \<flight_control name="X-15 SAS" file="X15.xml">
129     \</flight_control>
130     @endcode
131
132     In this case, the FCS would be read in from another file.
133
134     <h2>Properties</h2>
135     @property fcs/aileron-cmd-norm normalized aileron command
136     @property fcs/elevator-cmd-norm normalized elevator command
137     @property fcs/rudder-cmd-norm
138     @property fcs/steer-cmd-norm
139     @property fcs/flap-cmd-norm
140     @property fcs/speedbrake-cmd-norm
141     @property fcs/spoiler-cmd-norm
142     @property fcs/pitch-trim-cmd-norm
143     @property fcs/roll-trim-cmd-norm
144     @property fcs/yaw-trim-cmd-norm
145     @property gear/gear-cmd-norm
146     @property fcs/left-aileron-pos-rad
147     @property fcs/left-aileron-pos-deg
148     @property fcs/left-aileron-pos-norm
149     @property fcs/mag-left-aileron-pos-rad
150     @property fcs/right-aileron-pos-rad
151     @property fcs/right-aileron-pos-deg
152     @property fcs/right-aileron-pos-norm
153     @property fcs/mag-right-aileron-pos-rad
154     @property fcs/elevator-pos-rad
155     @property fcs/elevator-pos-deg
156     @property fcs/elevator-pos-norm
157     @property fcs/mag-elevator-pos-rad
158     @property fcs/rudder-pos-rad
159     @property fcs/rudder-pos-deg
160     @property fcs/rudder-pos-norm
161     @property fcs/mag-rudder-pos-rad
162     @property fcs/flap-pos-rad
163     @property fcs/flap-pos-deg
164     @property fcs/flap-pos-norm
165     @property fcs/speedbrake-pos-rad
166     @property fcs/speedbrake-pos-deg
167     @property fcs/speedbrake-pos-norm
168     @property fcs/mag-speedbrake-pos-rad
169     @property fcs/spoiler-pos-rad
170     @property fcs/spoiler-pos-deg
171     @property fcs/spoiler-pos-norm
172     @property fcs/mag-spoiler-pos-rad
173     @property gear/gear-pos-norm
174
175     @author Jon S. Berndt
176     @version $Revision$
177     @see FGFCSComponent
178     @see FGXMLElement
179     @see FGGain
180     @see FGSummer
181     @see FGSwitch
182     @see FGFCSFunction
183     @see FGCondition
184     @see FGGradient
185     @see FGFilter
186     @see FGDeadBand
187     @see FGKinemat
188 */
189
190 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 CLASS DECLARATION
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
193
194 class FGFCS : public FGModel, public FGXMLFileRead
195 {
196
197 public:
198   /** Constructor
199       @param Executive a pointer to the parent executive object */
200   FGFCS(FGFDMExec*);
201   /// Destructor
202   ~FGFCS();
203
204   /** Runs the Flight Controls model; called by the Executive
205       @return false if no error */
206   bool Run(void);
207
208   /// @name Pilot input command retrieval
209   //@{
210   /** Gets the aileron command.
211       @return aileron command in range from -1.0 - 1.0 */
212   inline double GetDaCmd(void) const { return DaCmd; }
213
214   /** Gets the elevator command.
215       @return elevator command in range from -1.0 - 1.0 */
216   inline double GetDeCmd(void) const { return DeCmd; }
217
218   /** Gets the rudder command.
219       @return rudder command in range from -1.0 - 1.0 */
220   inline double GetDrCmd(void) const { return DrCmd; }
221
222   /** Gets the steering command.
223       @return steering command in range from -1.0 - 1.0 */
224   inline double GetDsCmd(void) const { return DsCmd; }
225
226   /** Gets the flaps command.
227       @return flaps command in range from 0 to 1.0 */
228   inline double GetDfCmd(void) const { return DfCmd; }
229
230   /** Gets the speedbrake command.
231       @return speedbrake command in range from 0 to 1.0 */
232   inline double GetDsbCmd(void) const { return DsbCmd; }
233
234   /** Gets the spoiler command.
235       @return spoiler command in range from 0 to 1.0 */
236   inline double GetDspCmd(void) const { return DspCmd; }
237
238   /** Gets the throttle command.
239       @param engine engine ID number
240       @return throttle command in range from 0 - 1.0 for the given engine */
241   double GetThrottleCmd(int engine) const;
242
243   /** Gets the mixture command.
244       @param engine engine ID number
245       @return mixture command in range from 0 - 1.0 for the given engine */
246   inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
247
248   /** Gets the prop pitch command.
249       @param engine engine ID number
250       @return pitch command in range from 0.0 - 1.0 for the given engine */
251   inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
252
253   /** Gets the prop feather command.
254       @param engine engine ID number
255       @return feather command for the given engine (on / off)*/
256   inline bool GetFeatherCmd(int engine) const { return PropFeatherCmd[engine]; }
257
258   /** Gets the pitch trim command.
259       @return pitch trim command in range from -1.0 to 1.0 */
260   inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
261
262   /** Gets the rudder trim command.
263       @return rudder trim command in range from -1.0 - 1.0 */
264   inline double GetYawTrimCmd(void) const { return YTrimCmd; }
265
266   /** Gets the aileron trim command.
267       @return aileron trim command in range from -1.0 - 1.0 */
268   inline double GetRollTrimCmd(void) const { return RTrimCmd; }
269
270   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
271       defaults to down.
272       @return the current value of the gear extend/retract command*/
273   inline double GetGearCmd(void) const { return GearCmd; }
274   //@}
275
276   /// @name Aerosurface position retrieval
277   //@{
278   /** Gets the left aileron position.
279       @return aileron position in radians */
280   inline double GetDaLPos( int form = ofRad )
281                          const { return DaLPos[form]; }
282
283   /// @name Aerosurface position retrieval
284   //@{
285   /** Gets the right aileron position.
286       @return aileron position in radians */
287   inline double GetDaRPos( int form = ofRad )
288                          const { return DaRPos[form]; }
289
290   /** Gets the elevator position.
291       @return elevator position in radians */
292   inline double GetDePos( int form = ofRad )
293                          const { return DePos[form]; }
294
295   /** Gets the rudder position.
296       @return rudder position in radians */
297   inline double GetDrPos( int form = ofRad )
298                          const { return DrPos[form]; }
299
300   /** Gets the speedbrake position.
301       @return speedbrake position in radians */
302   inline double GetDsbPos( int form = ofRad )
303                          const { return DsbPos[form]; }
304
305   /** Gets the spoiler position.
306       @return spoiler position in radians */
307   inline double GetDspPos( int form = ofRad )
308                          const { return DspPos[form]; }
309
310   /** Gets the flaps position.
311       @return flaps position in radians */
312   inline double GetDfPos( int form = ofRad )
313                          const { return DfPos[form]; }
314
315   /** Gets the throttle position.
316       @param engine engine ID number
317       @return throttle position for the given engine in range from 0 - 1.0 */
318   double GetThrottlePos(int engine) const;
319
320   /** Gets the mixture position.
321       @param engine engine ID number
322       @return mixture position for the given engine in range from 0 - 1.0 */
323   inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
324
325   /** Gets the steering position.
326       @return steering position in degrees */
327   double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
328
329   /** Gets the gear position (0 up, 1 down), defaults to down
330       @return gear position (0 up, 1 down) */
331   inline double GetGearPos(void) const { return GearPos; }
332
333   /** Gets the prop pitch position.
334       @param engine engine ID number
335       @return prop pitch position for the given engine in range from 0 - 1.0 */
336   inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
337
338   /** Gets the prop feather position.
339       @param engine engine ID number
340       @return prop fether for the given engine (on / off)*/
341   inline bool GetPropFeather(int engine) const { return PropFeather[engine]; }
342   //@}
343
344   /** Retrieves the State object pointer.
345       This is used by the FGFCS-owned components.
346       @return pointer to the State object */
347   inline FGState* GetState(void) { return State; }
348
349   /** Retrieves all component names for inclusion in output stream
350       @param delimeter either a tab or comma string depending on output type
351       @return a string containing the descriptive names for all components */
352   string GetComponentStrings(string delimeter);
353
354   /** Retrieves all component outputs for inclusion in output stream
355       @param delimeter either a tab or comma string depending on output type
356       @return a string containing the numeric values for the current set of
357       component outputs */
358   string GetComponentValues(string delimeter);
359
360   /// @name Pilot input command setting
361   //@{
362   /** Sets the aileron command
363       @param cmd aileron command */
364   inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
365
366   /** Sets the elevator command
367       @param cmd elevator command in percent*/
368   inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
369
370   /** Sets the rudder command
371       @param cmd rudder command in percent*/
372   inline void SetDrCmd(double cmd) { DrCmd = cmd; }
373
374   /** Sets the steering command
375       @param cmd steering command in percent*/
376   inline void SetDsCmd(double cmd) { DsCmd = cmd; }
377
378   /** Sets the flaps command
379       @param cmd flaps command in percent*/
380   inline void SetDfCmd(double cmd) { DfCmd = cmd; }
381
382   /** Sets the speedbrake command
383       @param cmd speedbrake command in percent*/
384   inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
385
386   /** Sets the spoilers command
387       @param cmd spoilers command in percent*/
388   inline void SetDspCmd(double cmd) { DspCmd = cmd; }
389
390   /** Sets the pitch trim command
391       @param cmd pitch trim command in percent*/
392   inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
393
394   /** Sets the rudder trim command
395       @param cmd rudder trim command in percent*/
396   inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
397
398   /** Sets the aileron trim command
399       @param cmd aileron trim command in percent*/
400   inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
401
402   /** Sets the throttle command for the specified engine
403       @param engine engine ID number
404       @param cmd throttle command in percent (0 - 100)*/
405   void SetThrottleCmd(int engine, double cmd);
406
407   /** Sets the mixture command for the specified engine
408       @param engine engine ID number
409       @param cmd mixture command in percent (0 - 100)*/
410   void SetMixtureCmd(int engine, double cmd);
411
412   /** Set the gear extend/retract command, defaults to down
413       @param gear command 0 for up, 1 for down */
414    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
415
416   /** Sets the propeller pitch command for the specified engine
417       @param engine engine ID number
418       @param cmd mixture command in percent (0.0 - 1.0)*/
419   void SetPropAdvanceCmd(int engine, double cmd);
420
421    /** Sets the propeller feather command for the specified engine
422       @param engine engine ID number
423       @param cmd feather (bool)*/
424   void SetFeatherCmd(int engine, bool cmd);
425   //@}
426
427   /// @name Aerosurface position setting
428   //@{
429   /** Sets the left aileron position
430       @param cmd left aileron position in radians*/
431   inline void SetDaLPos( int form , double pos );
432
433   /** Sets the right aileron position
434       @param cmd right aileron position in radians*/
435   inline void SetDaRPos( int form , double pos );
436
437   /** Sets the elevator position
438       @param cmd elevator position in radians*/
439   inline void SetDePos( int form , double pos );
440
441   /** Sets the rudder position
442       @param cmd rudder position in radians*/
443   inline void SetDrPos( int form , double pos );
444
445    /** Sets the flaps position
446       @param cmd flaps position in radians*/
447   inline void SetDfPos( int form , double pos );
448
449   /** Sets the speedbrake position
450       @param cmd speedbrake position in radians*/
451   inline void SetDsbPos( int form , double pos );
452
453   /** Sets the spoiler position
454       @param cmd spoiler position in radians*/
455   inline void SetDspPos( int form , double pos );
456
457   /** Sets the actual throttle setting for the specified engine
458       @param engine engine ID number
459       @param cmd throttle setting in percent (0 - 100)*/
460   void SetThrottlePos(int engine, double cmd);
461
462   /** Sets the actual mixture setting for the specified engine
463       @param engine engine ID number
464       @param cmd mixture setting in percent (0 - 100)*/
465   void SetMixturePos(int engine, double cmd);
466
467   /** Sets the steering position
468       @param cmd steering position in degrees*/
469   void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
470
471   /** Set the gear extend/retract position, defaults to down
472       @param gear position 0 up, 1 down       */
473    void SetGearPos(double gearpos) { GearPos = gearpos; }
474
475
476   /** Sets the actual prop pitch setting for the specified engine
477       @param engine engine ID number
478       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
479   void SetPropAdvance(int engine, double cmd);
480
481   /** Sets the actual prop feather setting for the specified engine
482       @param engine engine ID number
483       @param cmd prop fether setting (bool)*/
484   void SetPropFeather(int engine, bool cmd);
485   //@}
486
487     /// @name Landing Gear brakes
488   //@{
489   /** Sets the left brake group
490       @param cmd brake setting in percent (0.0 - 1.0) */
491   void SetLBrake(double cmd) {LeftBrake = cmd;}
492
493   /** Sets the right brake group
494       @param cmd brake setting in percent (0.0 - 1.0) */
495   void SetRBrake(double cmd) {RightBrake = cmd;}
496
497   /** Sets the center brake group
498       @param cmd brake setting in percent (0.0 - 1.0) */
499   void SetCBrake(double cmd) {CenterBrake = cmd;}
500
501   /** Gets the brake for a specified group.
502       @param bg which brakegroup to retrieve the command for
503       @return the brake setting for the supplied brake group argument */
504   double GetBrake(FGLGear::BrakeGroup bg);
505
506   /** Gets the left brake.
507       @return the left brake setting. */
508   double GetLBrake(void) const {return LeftBrake;}
509
510   /** Gets the right brake.
511       @return the right brake setting. */
512   double GetRBrake(void) const {return RightBrake;}
513
514   /** Gets the center brake.
515       @return the center brake setting. */
516   double GetCBrake(void) const {return CenterBrake;}
517   //@}
518
519   /** Loads the Flight Control System.
520       Load() is called from FGFDMExec.
521       @param el pointer to the Element instance
522       @return true if succesful */
523   bool Load(Element* el);
524
525   void AddThrottle(void);
526   void AddGear(void);
527   double GetDt(void);
528
529   FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
530
531 private:
532   double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
533   double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
534   double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
535   double PTrimCmd, YTrimCmd, RTrimCmd;
536   vector <double> ThrottleCmd;
537   vector <double> ThrottlePos;
538   vector <double> MixtureCmd;
539   vector <double> MixturePos;
540   vector <double> PropAdvanceCmd;
541   vector <double> PropAdvance;
542   vector <bool> PropFeatherCmd;
543   vector <bool> PropFeather;
544   vector <double> SteerPosDeg;
545   double LeftBrake, RightBrake, CenterBrake; // Brake settings
546   double GearCmd,GearPos;
547
548   vector <FGFCSComponent*> FCSComponents;
549   vector <FGFCSComponent*> APComponents;
550   vector <double*> interface_properties;
551   vector <FGFCSComponent*> sensors;
552   void bind(void);
553   void bindModel(void);
554   void bindThrottle(unsigned int);
555   void unbind(FGPropertyManager *node);
556   void Debug(int from);
557 };
558 }
559
560 #endif
561