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