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