]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGFCS.h
Merge branch 'maint' into next
[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 fcs/wing-fold-pos-norm
166     @property gear/gear-pos-norm
167     @property gear/tailhook-pos-norm
168
169     @author Jon S. Berndt
170     @version $Revision$
171     @see FGActuator
172     @see FGDeadBand
173     @see FGFCSFunction
174     @see FGFilter
175     @see FGGain
176     @see FGKinemat
177     @see FGPID
178     @see FGSensor
179     @see FGSummer
180     @see FGSwitch
181     @see FGFCSComponent
182     @see Element
183 */
184
185 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 CLASS DECLARATION
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
188
189 class FGFCS : public FGModel, public FGXMLFileRead
190 {
191
192 public:
193   /** Constructor
194       @param Executive a pointer to the parent executive object */
195   FGFCS(FGFDMExec*);
196   /// Destructor
197   ~FGFCS();
198
199   bool InitModel(void);
200
201   /** Runs the Flight Controls model; called by the Executive
202       @return false if no error */
203   bool Run(void);
204
205   /// @name Pilot input command retrieval
206   //@{
207   /** Gets the aileron command.
208       @return aileron command in range from -1.0 - 1.0 */
209   double GetDaCmd(void) const { return DaCmd; }
210
211   /** Gets the elevator command.
212       @return elevator command in range from -1.0 - 1.0 */
213   double GetDeCmd(void) const { return DeCmd; }
214
215   /** Gets the rudder command.
216       @return rudder command in range from -1.0 - 1.0 */
217   double GetDrCmd(void) const { return DrCmd; }
218
219   /** Gets the steering command.
220       @return steering command in range from -1.0 - 1.0 */
221   double GetDsCmd(void) const { return DsCmd; }
222
223   /** Gets the flaps command.
224       @return flaps command in range from 0 to 1.0 */
225   double GetDfCmd(void) const { return DfCmd; }
226
227   /** Gets the speedbrake command.
228       @return speedbrake command in range from 0 to 1.0 */
229   double GetDsbCmd(void) const { return DsbCmd; }
230
231   /** Gets the spoiler command.
232       @return spoiler command in range from 0 to 1.0 */
233   double GetDspCmd(void) const { return DspCmd; }
234
235   /** Gets the throttle command.
236       @param engine engine ID number
237       @return throttle command in range from 0 - 1.0 for the given engine */
238   double GetThrottleCmd(int engine) const;
239
240   /** Gets the mixture command.
241       @param engine engine ID number
242       @return mixture command in range from 0 - 1.0 for the given engine */
243   double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
244
245   /** Gets the prop pitch command.
246       @param engine engine ID number
247       @return pitch command in range from 0.0 - 1.0 for the given engine */
248   double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
249
250   /** Gets the prop feather command.
251       @param engine engine ID number
252       @return feather command for the given engine (on / off)*/
253   bool GetFeatherCmd(int engine) const { return PropFeatherCmd[engine]; }
254
255   /** Gets the pitch trim command.
256       @return pitch trim command in range from -1.0 to 1.0 */
257   double GetPitchTrimCmd(void) const { return PTrimCmd; }
258
259   /** Gets the rudder trim command.
260       @return rudder trim command in range from -1.0 - 1.0 */
261   double GetYawTrimCmd(void) const { return YTrimCmd; }
262
263   /** Gets the aileron trim command.
264       @return aileron trim command in range from -1.0 - 1.0 */
265   double GetRollTrimCmd(void) const { return RTrimCmd; }
266
267   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
268       defaults to down.
269       @return the current value of the gear extend/retract command*/
270   double GetGearCmd(void) const { return GearCmd; }
271   //@}
272
273   /// @name Aerosurface position retrieval
274   //@{
275   /** Gets the left aileron position.
276       @return aileron position in radians */
277   double GetDaLPos( int form = ofRad )
278                          const { return DaLPos[form]; }
279
280   /// @name Aerosurface position retrieval
281   //@{
282   /** Gets the right aileron position.
283       @return aileron position in radians */
284   double GetDaRPos( int form = ofRad )
285                          const { return DaRPos[form]; }
286
287   /** Gets the elevator position.
288       @return elevator position in radians */
289   double GetDePos( int form = ofRad )
290                          const { return DePos[form]; }
291
292   /** Gets the rudder position.
293       @return rudder position in radians */
294   double GetDrPos( int form = ofRad )
295                          const { return DrPos[form]; }
296
297   /** Gets the speedbrake position.
298       @return speedbrake position in radians */
299   double GetDsbPos( int form = ofRad )
300                          const { return DsbPos[form]; }
301
302   /** Gets the spoiler position.
303       @return spoiler position in radians */
304   double GetDspPos( int form = ofRad )
305                          const { return DspPos[form]; }
306
307   /** Gets the flaps position.
308       @return flaps position in radians */
309   double GetDfPos( int form = ofRad )
310                          const { return DfPos[form]; }
311
312   /** Gets the throttle position.
313       @param engine engine ID number
314       @return throttle position for the given engine in range from 0 - 1.0 */
315   double GetThrottlePos(int engine) const;
316
317   /** Gets the mixture position.
318       @param engine engine ID number
319       @return mixture position for the given engine in range from 0 - 1.0 */
320   double GetMixturePos(int engine) const { return MixturePos[engine]; }
321
322   /** Gets the steering position.
323       @return steering position in degrees */
324   double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
325
326   /** Gets the gear position (0 up, 1 down), defaults to down
327       @return gear position (0 up, 1 down) */
328   double GetGearPos(void) const { return GearPos; }
329
330   /** Gets the tailhook position (0 up, 1 down)
331       @return tailhook position (0 up, 1 down) */
332   double GetTailhookPos(void) const { return TailhookPos; }
333
334   /** Gets the wing fold position (0 unfolded, 1 folded)
335       @return wing fold position (0 unfolded, 1 folded) */
336   double GetWingFoldPos(void) const { return WingFoldPos; }
337
338   /** Gets the prop pitch position.
339       @param engine engine ID number
340       @return prop pitch position for the given engine in range from 0 - 1.0 */
341   double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
342
343   /** Gets the prop feather position.
344       @param engine engine ID number
345       @return prop fether for the given engine (on / off)*/
346   bool GetPropFeather(int engine) const { return PropFeather[engine]; }
347   //@}
348
349   /** Retrieves the State object pointer.
350       This is used by the FGFCS-owned components.
351       @return pointer to the State object */
352   FGState* GetState(void) { return State; }
353
354   /** Retrieves all component names for inclusion in output stream
355       @param delimeter either a tab or comma string depending on output type
356       @return a string containing the descriptive names for all components */
357   string GetComponentStrings(string delimeter);
358
359   /** Retrieves all component outputs for inclusion in output stream
360       @param delimeter either a tab or comma string depending on output type
361       @return a string containing the numeric values for the current set of
362       component outputs */
363   string GetComponentValues(string delimeter);
364
365   /// @name Pilot input command setting
366   //@{
367   /** Sets the aileron command
368       @param cmd aileron command */
369   void SetDaCmd( double cmd ) { DaCmd = cmd; }
370
371   /** Sets the elevator command
372       @param cmd elevator command in percent*/
373   void SetDeCmd(double cmd ) { DeCmd = cmd; }
374
375   /** Sets the rudder command
376       @param cmd rudder command in percent*/
377   void SetDrCmd(double cmd) { DrCmd = cmd; }
378
379   /** Sets the steering command
380       @param cmd steering command in percent*/
381   void SetDsCmd(double cmd) { DsCmd = cmd; }
382
383   /** Sets the flaps command
384       @param cmd flaps command in percent*/
385   void SetDfCmd(double cmd) { DfCmd = cmd; }
386
387   /** Sets the speedbrake command
388       @param cmd speedbrake command in percent*/
389   void SetDsbCmd(double cmd) { DsbCmd = cmd; }
390
391   /** Sets the spoilers command
392       @param cmd spoilers command in percent*/
393   void SetDspCmd(double cmd) { DspCmd = cmd; }
394
395   /** Sets the pitch trim command
396       @param cmd pitch trim command in percent*/
397   void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
398
399   /** Sets the rudder trim command
400       @param cmd rudder trim command in percent*/
401   void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
402
403   /** Sets the aileron trim command
404       @param cmd aileron trim command in percent*/
405   void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
406
407   /** Sets the throttle command for the specified engine
408       @param engine engine ID number
409       @param cmd throttle command in percent (0 - 100)*/
410   void SetThrottleCmd(int engine, double cmd);
411
412   /** Sets the mixture command for the specified engine
413       @param engine engine ID number
414       @param cmd mixture command in percent (0 - 100)*/
415   void SetMixtureCmd(int engine, double cmd);
416
417   /** Set the gear extend/retract command, defaults to down
418       @param gear command 0 for up, 1 for down */
419    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
420
421   /** Sets the propeller pitch command for the specified engine
422       @param engine engine ID number
423       @param cmd mixture command in percent (0.0 - 1.0)*/
424   void SetPropAdvanceCmd(int engine, double cmd);
425
426    /** Sets the propeller feather command for the specified engine
427       @param engine engine ID number
428       @param cmd feather (bool)*/
429   void SetFeatherCmd(int engine, bool cmd);
430   //@}
431
432   /// @name Aerosurface position setting
433   //@{
434   /** Sets the left aileron position
435       @param cmd left aileron position in radians*/
436   void SetDaLPos( int form , double pos );
437
438   /** Sets the right aileron position
439       @param cmd right aileron position in radians*/
440   void SetDaRPos( int form , double pos );
441
442   /** Sets the elevator position
443       @param cmd elevator position in radians*/
444   void SetDePos( int form , double pos );
445
446   /** Sets the rudder position
447       @param cmd rudder position in radians*/
448   void SetDrPos( int form , double pos );
449
450    /** Sets the flaps position
451       @param cmd flaps position in radians*/
452   void SetDfPos( int form , double pos );
453
454   /** Sets the speedbrake position
455       @param cmd speedbrake position in radians*/
456   void SetDsbPos( int form , double pos );
457
458   /** Sets the spoiler position
459       @param cmd spoiler position in radians*/
460   void SetDspPos( int form , double pos );
461
462   /** Sets the actual throttle setting for the specified engine
463       @param engine engine ID number
464       @param cmd throttle setting in percent (0 - 100)*/
465   void SetThrottlePos(int engine, double cmd);
466
467   /** Sets the actual mixture setting for the specified engine
468       @param engine engine ID number
469       @param cmd mixture setting in percent (0 - 100)*/
470   void SetMixturePos(int engine, double cmd);
471
472   /** Sets the steering position
473       @param cmd steering position in degrees*/
474   void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
475
476   /** Set the gear extend/retract position, defaults to down
477       @param gear position 0 up, 1 down       */
478    void SetGearPos(double gearpos) { GearPos = gearpos; }
479
480   /** Set the tailhook position
481       @param tailhook position 0 up, 1 down       */
482    void SetTailhookPos(double hookpos) { TailhookPos = hookpos; }
483
484   /** Set the wing fold position
485       @param wing fold position 0 unfolded, 1 folded  */
486    void SetWingFoldPos(double foldpos) { WingFoldPos = foldpos; }
487
488   /** Sets the actual prop pitch setting for the specified engine
489       @param engine engine ID number
490       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
491   void SetPropAdvance(int engine, double cmd);
492
493   /** Sets the actual prop feather setting for the specified engine
494       @param engine engine ID number
495       @param cmd prop fether setting (bool)*/
496   void SetPropFeather(int engine, bool cmd);
497   //@}
498
499     /// @name Landing Gear brakes
500   //@{
501   /** Sets the left brake group
502       @param cmd brake setting in percent (0.0 - 1.0) */
503   void SetLBrake(double cmd) {LeftBrake = cmd;}
504
505   /** Sets the right brake group
506       @param cmd brake setting in percent (0.0 - 1.0) */
507   void SetRBrake(double cmd) {RightBrake = cmd;}
508
509   /** Sets the center brake group
510       @param cmd brake setting in percent (0.0 - 1.0) */
511   void SetCBrake(double cmd) {CenterBrake = cmd;}
512
513   /** Gets the brake for a specified group.
514       @param bg which brakegroup to retrieve the command for
515       @return the brake setting for the supplied brake group argument */
516   double GetBrake(FGLGear::BrakeGroup bg);
517
518   /** Gets the left brake.
519       @return the left brake setting. */
520   double GetLBrake(void) const {return LeftBrake;}
521
522   /** Gets the right brake.
523       @return the right brake setting. */
524   double GetRBrake(void) const {return RightBrake;}
525
526   /** Gets the center brake.
527       @return the center brake setting. */
528   double GetCBrake(void) const {return CenterBrake;}
529   //@}
530
531   enum SystemType { stFCS, stSystem, stAutoPilot }; 
532
533   /** Loads the Flight Control System.
534       Load() is called from FGFDMExec.
535       @param el pointer to the Element instance
536       @param systype type of system (FCS, Autopilot, System) 
537       @return true if succesful */
538   bool Load(Element* el, SystemType systype);
539
540   ifstream* FindSystemFile(string system_filename);
541   string FindSystemFullPathname(string system_filename);
542
543   void AddThrottle(void);
544   void AddGear(void);
545   double GetDt(void);
546
547   FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
548
549 private:
550   double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
551   double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
552   double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
553   double PTrimCmd, YTrimCmd, RTrimCmd;
554   vector <double> ThrottleCmd;
555   vector <double> ThrottlePos;
556   vector <double> MixtureCmd;
557   vector <double> MixturePos;
558   vector <double> PropAdvanceCmd;
559   vector <double> PropAdvance;
560   vector <bool> PropFeatherCmd;
561   vector <bool> PropFeather;
562   vector <double> SteerPosDeg;
563   double LeftBrake, RightBrake, CenterBrake; // Brake settings
564   double GearCmd,GearPos;
565   double TailhookPos, WingFoldPos;
566
567   typedef vector <FGFCSComponent*> FCSCompVec;
568   FCSCompVec Systems;
569   FCSCompVec FCSComponents;
570   FCSCompVec APComponents;
571   FCSCompVec sensors;
572   vector <double*> interface_properties;
573   void bind(void);
574   void bindModel(void);
575   void bindThrottle(unsigned int);
576   void Debug(int from);
577 };
578 }
579
580 #endif
581