]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGFCS.h
9a99aded1560e8b71af172756d0ba9948251a19d
[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 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 <models/flight_control/FGFCSComponent.h>
54 #include <models/FGModel.h>
55 #include <models/FGLGear.h>
56 #include <input_output/FGXMLElement.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     <pre>
85     \<flight_control name="X-15 SAS">
86       \<channel>
87         \<component name="Pitch Trim Sum" type="SUMMER">
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         \</component>
95
96         \<component name="Pitch Command Scale" TYPE="AEROSURFACE_SCALE">
97           <input> fcs/pitch-trim-sum </input>
98           <limit>
99             <min> -50 </min>
100             <max>  50 </max>
101           </limit>
102         \</component>
103
104         ... etc.
105     </pre>
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, 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. The type of this component is
111     "Summer".
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 specifies 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     <pre>
123     \<flight_control name="X-15 SAS">
124     </pre>
125
126     one can also supply a filename:
127
128     <pre>
129     \<flight_control name="X-15 SAS" file="X15.xml">
130     \</flight_control>
131     </pre>
132
133     In this case, the FCS would be read in from another file.
134
135     @author Jon S. Berndt
136     @version $Id$
137     @see FGFCSComponent
138     @see FGXMLElement
139     @see FGGain
140     @see FGSummer
141     @see FGSwitch
142     @see FGGradient
143     @see FGFilter
144     @see FGDeadBand
145 */
146
147 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 CLASS DECLARATION
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
150
151 class FGFCS : public FGModel {
152
153 public:
154   /** Constructor
155       @param Executive a pointer to the parent executive object */
156   FGFCS(FGFDMExec*);
157   /// Destructor
158   ~FGFCS();
159
160   /** Runs the Flight Controls model; called by the Executive
161       @return false if no error */
162   bool Run(void);
163
164   /// @name Pilot input command retrieval
165   //@{
166   /** Gets the aileron command.
167       @return aileron command in range from -1.0 - 1.0 */
168   inline double GetDaCmd(void) const { return DaCmd; }
169
170   /** Gets the elevator command.
171       @return elevator command in range from -1.0 - 1.0 */
172   inline double GetDeCmd(void) const { return DeCmd; }
173
174   /** Gets the rudder command.
175       @return rudder command in range from -1.0 - 1.0 */
176   inline double GetDrCmd(void) const { return DrCmd; }
177
178   /** Gets the steering command.
179       @return steering command in range from -1.0 - 1.0 */
180   inline double GetDsCmd(void) const { return DsCmd; }
181
182   /** Gets the flaps command.
183       @return flaps command in range from 0 to 1.0 */
184   inline double GetDfCmd(void) const { return DfCmd; }
185
186   /** Gets the speedbrake command.
187       @return speedbrake command in range from 0 to 1.0 */
188   inline double GetDsbCmd(void) const { return DsbCmd; }
189
190   /** Gets the spoiler command.
191       @return spoiler command in range from 0 to 1.0 */
192   inline double GetDspCmd(void) const { return DspCmd; }
193
194   /** Gets the throttle command.
195       @param engine engine ID number
196       @return throttle command in range from 0 - 1.0 for the given engine */
197   double GetThrottleCmd(int engine) const;
198
199   /** Gets the mixture command.
200       @param engine engine ID number
201       @return mixture command in range from 0 - 1.0 for the given engine */
202   inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
203
204   /** Gets the prop pitch command.
205       @param engine engine ID number
206       @return pitch command in range from 0.0 - 1.0 for the given engine */
207   inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
208
209   /** Gets the prop feather command.
210       @param engine engine ID number
211       @return feather command for the given engine (on / off)*/
212   inline bool GetFeatherCmd(int engine) const { return PropFeatherCmd[engine]; }
213
214   /** Gets the pitch trim command.
215       @return pitch trim command in range from -1.0 to 1.0 */
216   inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
217
218   /** Gets the rudder trim command.
219       @return rudder trim command in range from -1.0 - 1.0 */
220   inline double GetYawTrimCmd(void) const { return YTrimCmd; }
221
222   /** Gets the aileron trim command.
223       @return aileron trim command in range from -1.0 - 1.0 */
224   inline double GetRollTrimCmd(void) const { return RTrimCmd; }
225
226   /** Get the gear extend/retract command. 0 commands gear up, 1 down.
227       defaults to down.
228       @return the current value of the gear extend/retract command*/
229   inline double GetGearCmd(void) const { return GearCmd; }
230   //@}
231
232   /// @name Aerosurface position retrieval
233   //@{
234   /** Gets the left aileron position.
235       @return aileron position in radians */
236   inline double GetDaLPos( int form = ofRad )
237                          const { return DaLPos[form]; }
238
239   /// @name Aerosurface position retrieval
240   //@{
241   /** Gets the right aileron position.
242       @return aileron position in radians */
243   inline double GetDaRPos( int form = ofRad )
244                          const { return DaRPos[form]; }
245
246   /** Gets the elevator position.
247       @return elevator position in radians */
248   inline double GetDePos( int form = ofRad )
249                          const { return DePos[form]; }
250
251   /** Gets the rudder position.
252       @return rudder position in radians */
253   inline double GetDrPos( int form = ofRad )
254                          const { return DrPos[form]; }
255
256   /** Gets the speedbrake position.
257       @return speedbrake position in radians */
258   inline double GetDsbPos( int form = ofRad )
259                          const { return DsbPos[form]; }
260
261   /** Gets the spoiler position.
262       @return spoiler position in radians */
263   inline double GetDspPos( int form = ofRad )
264                          const { return DspPos[form]; }
265
266   /** Gets the flaps position.
267       @return flaps position in radians */
268   inline double GetDfPos( int form = ofRad )
269                          const { return DfPos[form]; }
270
271   /** Gets the throttle position.
272       @param engine engine ID number
273       @return throttle position for the given engine in range from 0 - 1.0 */
274   double GetThrottlePos(int engine) const;
275
276   /** Gets the mixture position.
277       @param engine engine ID number
278       @return mixture position for the given engine in range from 0 - 1.0 */
279   inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
280
281   /** Gets the steering position.
282       @return steering position in degrees */
283   double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
284
285   /** Gets the gear position (0 up, 1 down), defaults to down
286       @return gear position (0 up, 1 down) */
287   inline double GetGearPos(void) const { return GearPos; }
288
289   /** Gets the prop pitch position.
290       @param engine engine ID number
291       @return prop pitch position for the given engine in range from 0 - 1.0 */
292   inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
293
294   /** Gets the prop feather position.
295       @param engine engine ID number
296       @return prop fether for the given engine (on / off)*/
297   inline bool GetPropFeather(int engine) const { return PropFeather[engine]; }
298   //@}
299
300   /** Retrieves the State object pointer.
301       This is used by the FGFCS-owned components.
302       @return pointer to the State object */
303   inline FGState* GetState(void) { return State; }
304
305   /** Retrieves all component names for inclusion in output stream
306       @param delimeter either a tab or comma string depending on output type
307       @return a string containing the descriptive names for all components */
308   string GetComponentStrings(string delimeter);
309
310   /** Retrieves all component outputs for inclusion in output stream
311       @param delimeter either a tab or comma string depending on output type
312       @return a string containing the numeric values for the current set of
313       component outputs */
314   string GetComponentValues(string delimeter);
315
316   /// @name Pilot input command setting
317   //@{
318   /** Sets the aileron command
319       @param cmd aileron command */
320   inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
321
322   /** Sets the elevator command
323       @param cmd elevator command in percent*/
324   inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
325
326   /** Sets the rudder command
327       @param cmd rudder command in percent*/
328   inline void SetDrCmd(double cmd) { DrCmd = cmd; }
329
330   /** Sets the steering command
331       @param cmd steering command in percent*/
332   inline void SetDsCmd(double cmd) { DsCmd = cmd; }
333
334   /** Sets the flaps command
335       @param cmd flaps command in percent*/
336   inline void SetDfCmd(double cmd) { DfCmd = cmd; }
337
338   /** Sets the speedbrake command
339       @param cmd speedbrake command in percent*/
340   inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
341
342   /** Sets the spoilers command
343       @param cmd spoilers command in percent*/
344   inline void SetDspCmd(double cmd) { DspCmd = cmd; }
345
346   /** Sets the pitch trim command
347       @param cmd pitch trim command in percent*/
348   inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
349
350   /** Sets the rudder trim command
351       @param cmd rudder trim command in percent*/
352   inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
353
354   /** Sets the aileron trim command
355       @param cmd aileron trim command in percent*/
356   inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
357
358   /** Sets the throttle command for the specified engine
359       @param engine engine ID number
360       @param cmd throttle command in percent (0 - 100)*/
361   void SetThrottleCmd(int engine, double cmd);
362
363   /** Sets the mixture command for the specified engine
364       @param engine engine ID number
365       @param cmd mixture command in percent (0 - 100)*/
366   void SetMixtureCmd(int engine, double cmd);
367
368   /** Set the gear extend/retract command, defaults to down
369       @param gear command 0 for up, 1 for down */
370    void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
371
372   /** Sets the propeller pitch command for the specified engine
373       @param engine engine ID number
374       @param cmd mixture command in percent (0.0 - 1.0)*/
375   void SetPropAdvanceCmd(int engine, double cmd);
376
377    /** Sets the propeller feather command for the specified engine
378       @param engine engine ID number
379       @param cmd feather (bool)*/
380   void SetFeatherCmd(int engine, bool cmd);
381   //@}
382
383   /// @name Aerosurface position setting
384   //@{
385   /** Sets the left aileron position
386       @param cmd left aileron position in radians*/
387   inline void SetDaLPos( int form , double pos );
388
389   /** Sets the right aileron position
390       @param cmd right aileron position in radians*/
391   inline void SetDaRPos( int form , double pos );
392
393   /** Sets the elevator position
394       @param cmd elevator position in radians*/
395   inline void SetDePos( int form , double pos );
396
397   /** Sets the rudder position
398       @param cmd rudder position in radians*/
399   inline void SetDrPos( int form , double pos );
400
401    /** Sets the flaps position
402       @param cmd flaps position in radians*/
403   inline void SetDfPos( int form , double pos );
404
405   /** Sets the speedbrake position
406       @param cmd speedbrake position in radians*/
407   inline void SetDsbPos( int form , double pos );
408
409   /** Sets the spoiler position
410       @param cmd spoiler position in radians*/
411   inline void SetDspPos( int form , double pos );
412
413   /** Sets the actual throttle setting for the specified engine
414       @param engine engine ID number
415       @param cmd throttle setting in percent (0 - 100)*/
416   void SetThrottlePos(int engine, double cmd);
417
418   /** Sets the actual mixture setting for the specified engine
419       @param engine engine ID number
420       @param cmd mixture setting in percent (0 - 100)*/
421   void SetMixturePos(int engine, double cmd);
422
423   /** Sets the steering position
424       @param cmd steering position in degrees*/
425   void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
426
427   /** Set the gear extend/retract position, defaults to down
428       @param gear position 0 up, 1 down       */
429    void SetGearPos(double gearpos) { GearPos = gearpos; }
430
431
432   /** Sets the actual prop pitch setting for the specified engine
433       @param engine engine ID number
434       @param cmd prop pitch setting in percent (0.0 - 1.0)*/
435   void SetPropAdvance(int engine, double cmd);
436
437   /** Sets the actual prop feather setting for the specified engine
438       @param engine engine ID number
439       @param cmd prop fether setting (bool)*/
440   void SetPropFeather(int engine, bool cmd);
441   //@}
442
443     /// @name Landing Gear brakes
444   //@{
445   /** Sets the left brake group
446       @param cmd brake setting in percent (0.0 - 1.0) */
447   void SetLBrake(double cmd) {LeftBrake = cmd;}
448
449   /** Sets the right brake group
450       @param cmd brake setting in percent (0.0 - 1.0) */
451   void SetRBrake(double cmd) {RightBrake = cmd;}
452
453   /** Sets the center brake group
454       @param cmd brake setting in percent (0.0 - 1.0) */
455   void SetCBrake(double cmd) {CenterBrake = cmd;}
456
457   /** Gets the brake for a specified group.
458       @param bg which brakegroup to retrieve the command for
459       @return the brake setting for the supplied brake group argument */
460   double GetBrake(FGLGear::BrakeGroup bg);
461   //@}
462
463   /** Loads the Flight Control System.
464       The FGAircraft instance is actually responsible for reading the config file
465       and calling the various Load() methods of the other systems, passing in
466       the XML Element instance pointer. Load() is called from FGAircraft.
467       @param el pointer to the Element instance
468       @return true if succesful */
469   bool Load(Element* el);
470
471   void AddThrottle(void);
472   void AddGear(void);
473
474   FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
475
476 private:
477   double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
478   double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
479   double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
480   double PTrimCmd, YTrimCmd, RTrimCmd;
481   vector <double> ThrottleCmd;
482   vector <double> ThrottlePos;
483   vector <double> MixtureCmd;
484   vector <double> MixturePos;
485   vector <double> PropAdvanceCmd;
486   vector <double> PropAdvance;
487   vector <bool> PropFeatherCmd;
488   vector <bool> PropFeather;
489   vector <double> SteerPosDeg;
490   double LeftBrake, RightBrake, CenterBrake; // Brake settings
491   double GearCmd,GearPos;
492
493   vector <FGFCSComponent*> FCSComponents;
494   vector <FGFCSComponent*> APComponents;
495   vector <double*> interface_properties;
496   vector <FGFCSComponent*> sensors;
497   void bind(void);
498   void bindModel(void);
499   void bindThrottle(unsigned int);
500   void unbind(FGPropertyManager *node);
501   void Debug(int from);
502 };
503 }
504
505 #endif
506