1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
53 #include "filtersjb/FGFCSComponent.h"
56 #include "FGConfigFile.h"
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 typedef enum { iDe=0, iDaL, iDaR, iDr, iDsb, iDsp, iDf, NNorm } FcIdx;
71 typedef enum { ofRad=0, ofNorm, ofMag , NForms} OutputForm;
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 /** Encapsulates the Flight Control System (FCS) functionality.
78 This class owns and contains the list of FGFCSComponents
79 that define the control system for this aircraft. The config file for the
80 aircraft contains a description of the control path that starts at an input
81 or command and ends at an effector, e.g. an aerosurface. The FCS components
82 which comprise the control laws for an axis are defined sequentially in
83 the configuration file. For instance, for the X-15:
86 \<FLIGHT_CONTROL NAME="X-15 SAS">
88 \<COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER">
89 INPUT fcs/elevator-cmd-norm
90 INPUT fcs/pitch-trim-cmd-norm
94 \<COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE">
95 INPUT fcs/pitch-trim-sum
100 \<COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN">
101 INPUT fcs/pitch-command-scale
108 In the above case we can see the first few components of the pitch channel
109 defined. The input to the first component, 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. The type of this component is
113 The next component created is an aerosurface scale component - a type of
114 gain (see the LoadFCS() method for insight on how the various types of
115 components map into the actual component classes). This continues until the
116 final component for an axis when the
117 OUTPUT keyword specifies where the output is supposed to go. See the
118 individual components for more information on how they are mechanized.
120 Another option for the flight controls portion of the config file is that in
121 addition to using the "NAME" attribute in,
124 \<FLIGHT_CONTROL NAME="X-15 SAS">
127 one can also supply a filename:
130 \<FLIGHT_CONTROL NAME="X-15 SAS" FILE="X15.xml">
134 In this case, the FCS would be read in from another file.
136 @author Jon S. Berndt
148 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
152 class FGFCS : public FGModel {
156 @param Executive a pointer to the parent executive object */
161 /** Runs the Flight Controls model; called by the Executive
162 @return false if no error */
165 /// @name Pilot input command retrieval
167 /** Gets the aileron command.
168 @return aileron command in percent */
169 inline double GetDaCmd(void) const { return DaCmd; }
171 /** Gets the elevator command.
172 @return elevator command in percent */
173 inline double GetDeCmd(void) const { return DeCmd; }
175 /** Gets the rudder command.
176 @return rudder command in percent */
177 inline double GetDrCmd(void) const { return DrCmd; }
179 /** Gets the steering command.
180 @return steering command in percent */
181 inline double GetDsCmd(void) const { return DsCmd; }
183 /** Gets the flaps command.
184 @return flaps command in percent */
185 inline double GetDfCmd(void) const { return DfCmd; }
187 /** Gets the speedbrake command.
188 @return speedbrake command in percent */
189 inline double GetDsbCmd(void) const { return DsbCmd; }
191 /** Gets the spoiler command.
192 @return spoiler command in percent */
193 inline double GetDspCmd(void) const { return DspCmd; }
195 /** Gets the throttle command.
196 @param engine engine ID number
197 @return throttle command in percent ( 0 - 100) for the given engine */
198 double GetThrottleCmd(int engine) const;
200 /** Gets the mixture command.
201 @param engine engine ID number
202 @return mixture command in percent ( 0 - 100) for the given engine */
203 inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
205 /** Gets the prop pitch command.
206 @param engine engine ID number
207 @return pitch command in percent ( 0.0 - 1.0) for the given engine */
208 inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
210 /** Gets the pitch trim command.
211 @return pitch trim command in percent */
212 inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
214 /** Gets the rudder trim command.
215 @return rudder trim command in percent */
216 inline double GetYawTrimCmd(void) const { return YTrimCmd; }
218 /** Gets the aileron trim command.
219 @return aileron trim command in percent */
220 inline double GetRollTrimCmd(void) const { return RTrimCmd; }
222 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
224 @return the current value of the gear extend/retract command*/
225 inline double GetGearCmd(void) const { return GearCmd; }
228 /// @name AUTOPilot -> FCS effectors command retrieval
230 /** Gets the AUTOPilot aileron command.
231 @return aileron command in radians */
232 inline double GetAPDaCmd(void) const { return AP_DaCmd; }
234 /** Gets the AUTOPilot elevator command.
235 @return elevator command in radians */
236 inline double GetAPDeCmd(void) const { return AP_DeCmd; }
238 /** Gets the AUTOPilot rudder command.
239 @return rudder command in radians */
240 inline double GetAPDrCmd(void) const { return AP_DrCmd; }
242 /** Gets the AUTOPilot throttle (all engines) command.
243 @return throttle command in percent */
244 inline double GetAPThrottleCmd(void) const { return AP_ThrottleCmd; }
247 /// @name AUTOPilot setpoint retrieval
249 /** Gets the autopilot pitch attitude setpoint
250 @return Pitch attitude setpoint in radians */
251 inline double GetAPAttitudeSetPt(void) const {return APAttitudeSetPt;}
253 /** Gets the autopilot altitude setpoint
254 @return Altitude setpoint in feet */
255 inline double GetAPAltitudeSetPt(void) const {return APAltitudeSetPt;}
257 /** Gets the autopilot heading setpoint
258 @return Heading setpoint in radians */
259 inline double GetAPHeadingSetPt(void) const {return APHeadingSetPt;}
261 /** Gets the autopilot airspeed setpoint
262 @return Airspeed setpoint in fps */
263 inline double GetAPAirspeedSetPt(void) const {return APAirspeedSetPt;}
266 /// @name AUTOPilot setpoint setting
268 /// Sets the autopilot pitch attitude setpoint
269 inline void SetAPAttitudeSetPt(double set) {APAttitudeSetPt = set;}
271 /// Sets the autopilot altitude setpoint
272 inline void SetAPAltitudeSetPt(double set) {APAltitudeSetPt = set;}
274 /// Sets the autopilot heading setpoint
275 inline void SetAPHeadingSetPt(double set) {APHeadingSetPt = set;}
277 /// Sets the autopilot airspeed setpoint
278 inline void SetAPAirspeedSetPt(double set) {APAirspeedSetPt = set;}
282 /// @name AUTOPilot mode setting
284 /** Turns on/off the attitude-seeking autopilot.
285 @param set true turns the mode on, false turns it off **/
286 inline void SetAPAcquireAttitude(bool set) {APAcquireAttitude = set;}
288 /** Turns on/off the altitude-seeking autopilot.
289 @param set true turns the mode on, false turns it off **/
290 inline void SetAPAcquireAltitude(bool set) {APAcquireAltitude = set;}
292 /** Turns on/off the heading-seeking autopilot.
293 @param set true turns the mode on, false turns it off **/
294 inline void SetAPAcquireHeading(bool set) {APAcquireHeading = set;}
296 /** Turns on/off the airspeed-seeking autopilot.
297 @param set true turns the mode on, false turns it off **/
298 inline void SetAPAcquireAirspeed(bool set) {APAcquireAirspeed = set;}
300 /** Turns on/off the attitude-holding autopilot.
301 @param set true turns the mode on, false turns it off **/
302 inline void SetAPAttitudeHold(bool set) {APAttitudeHold = set;}
304 /** Turns on/off the altitude-holding autopilot.
305 @param set true turns the mode on, false turns it off **/
306 inline void SetAPAltitudeHold(bool set) {APAltitudeHold = set;}
308 /** Turns on/off the heading-holding autopilot.
309 @param set true turns the mode on, false turns it off **/
310 inline void SetAPHeadingHold(bool set) {APHeadingHold = set;}
312 /** Turns on/off the airspeed-holding autopilot.
313 @param set true turns the mode on, false turns it off **/
314 inline void SetAPAirspeedHold(bool set) {APAirspeedHold = set;}
316 /** Turns on/off the wing-leveler autopilot.
317 @param set true turns the mode on, false turns it off **/
318 inline void SetAPWingsLevelHold(bool set) {APWingsLevelHold = set;}
321 /// @name AUTOPilot mode retrieval
323 /** Retrieves the on/off mode of the autopilot AcquireAttitude mode
324 @return true if on, false if off */
325 inline bool GetAPAcquireAttitude(void) const {return APAcquireAttitude;}
327 /** Retrieves the on/off mode of the autopilot AcquireAltitude mode
328 @return true if on, false if off */
329 inline bool GetAPAcquireAltitude(void) const {return APAcquireAltitude;}
331 /** Retrieves the on/off mode of the autopilot AcquireHeading mode
332 @return true if on, false if off */
333 inline bool GetAPAcquireHeading(void) const {return APAcquireHeading;}
335 /** Retrieves the on/off mode of the autopilot AcquireAirspeed mode
336 @return true if on, false if off */
337 inline bool GetAPAcquireAirspeed(void) const {return APAcquireAirspeed;}
339 /** Retrieves the on/off mode of the autopilot AttitudeHold mode
340 @return true if on, false if off */
341 inline bool GetAPAttitudeHold(void) const {return APAttitudeHold;}
343 /** Retrieves the on/off mode of the autopilot AltitudeHold mode
344 @return true if on, false if off */
345 inline bool GetAPAltitudeHold(void) const {return APAltitudeHold;}
347 /** Retrieves the on/off mode of the autopilot HeadingHold mode
348 @return true if on, false if off */
349 inline bool GetAPHeadingHold(void) const {return APHeadingHold;}
351 /** Retrieves the on/off mode of the autopilot AirspeedHold mode
352 @return true if on, false if off */
353 inline bool GetAPAirspeedHold(void) const {return APAirspeedHold;}
355 /** Retrieves the on/off mode of the autopilot WingsLevelHold mode
356 @return true if on, false if off */
357 inline bool GetAPWingsLevelHold(void) const {return APWingsLevelHold;}
360 /// @name Aerosurface position retrieval
362 /** Gets the left aileron position.
363 @return aileron position in radians */
364 inline double GetDaLPos( int form = ofRad )
365 const { return DaLPos[form]; }
367 /// @name Aerosurface position retrieval
369 /** Gets the right aileron position.
370 @return aileron position in radians */
371 inline double GetDaRPos( int form = ofRad )
372 const { return DaRPos[form]; }
374 /** Gets the elevator position.
375 @return elevator position in radians */
376 inline double GetDePos( int form = ofRad )
377 const { return DePos[form]; }
379 /** Gets the rudder position.
380 @return rudder position in radians */
381 inline double GetDrPos( int form = ofRad )
382 const { return DrPos[form]; }
384 /** Gets the speedbrake position.
385 @return speedbrake position in radians */
386 inline double GetDsbPos( int form = ofRad )
387 const { return DsbPos[form]; }
389 /** Gets the spoiler position.
390 @return spoiler position in radians */
391 inline double GetDspPos( int form = ofRad )
392 const { return DspPos[form]; }
394 /** Gets the flaps position.
395 @return flaps position in radians */
396 inline double GetDfPos( int form = ofRad )
397 const { return DfPos[form]; }
399 /** Gets the throttle position.
400 @param engine engine ID number
401 @return throttle position for the given engine in percent ( 0 - 100)*/
402 double GetThrottlePos(int engine) const;
404 /** Gets the mixture position.
405 @param engine engine ID number
406 @return mixture position for the given engine in percent ( 0 - 100)*/
407 inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
409 /** Gets the steering position.
410 @return steering position in degrees */
411 double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
413 /** Gets the gear position (0 up, 1 down), defaults to down
414 @return gear position (0 up, 1 down) */
415 inline double GetGearPos(void) const { return GearPos; }
417 /** Gets the prop pitch position.
418 @param engine engine ID number
419 @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
420 inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
423 /** Retrieves the State object pointer.
424 This is used by the FGFCS-owned components.
425 @return pointer to the State object */
426 inline FGState* GetState(void) { return State; }
428 /** Retrieves all component names for inclusion in output stream
429 @param delimeter either a tab or comma string depending on output type
430 @return a string containing the descriptive names for all components */
431 string GetComponentStrings(string delimeter);
433 /** Retrieves all component outputs for inclusion in output stream
434 @param delimeter either a tab or comma string depending on output type
435 @return a string containing the numeric values for the current set of
437 string GetComponentValues(string delimeter);
439 /// @name Pilot input command setting
441 /** Sets the aileron command
442 @param cmd aileron command in percent*/
443 inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
445 /** Sets the elevator command
446 @param cmd elevator command in percent*/
447 inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
449 /** Sets the rudder command
450 @param cmd rudder command in percent*/
451 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
453 /** Sets the steering command
454 @param cmd steering command in percent*/
455 inline void SetDsCmd(double cmd) { DsCmd = cmd; }
457 /** Sets the flaps command
458 @param cmd flaps command in percent*/
459 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
461 /** Sets the speedbrake command
462 @param cmd speedbrake command in percent*/
463 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
465 /** Sets the spoilers command
466 @param cmd spoilers command in percent*/
467 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
469 /** Sets the pitch trim command
470 @param cmd pitch trim command in percent*/
471 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
473 /** Sets the rudder trim command
474 @param cmd rudder trim command in percent*/
475 inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
477 /** Sets the aileron trim command
478 @param cmd aileron trim command in percent*/
479 inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
481 /** Sets the throttle command for the specified engine
482 @param engine engine ID number
483 @param cmd throttle command in percent (0 - 100)*/
484 void SetThrottleCmd(int engine, double cmd);
486 /** Sets the mixture command for the specified engine
487 @param engine engine ID number
488 @param cmd mixture command in percent (0 - 100)*/
489 void SetMixtureCmd(int engine, double cmd);
491 /** Set the gear extend/retract command, defaults to down
492 @param gear command 0 for up, 1 for down */
493 void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
495 /** Sets the propeller pitch command for the specified engine
496 @param engine engine ID number
497 @param cmd mixture command in percent (0.0 - 1.0)*/
498 void SetPropAdvanceCmd(int engine, double cmd);
501 /// @name AUTOPilot -> FCS effector command setting
503 /** Sets the AUTOPilot aileron command
504 @param cmd AUTOPilot aileron command in radians*/
505 inline void SetAPDaCmd( double cmd ) { AP_DaCmd = cmd; }
507 /** Sets the AUTOPilot elevator command
508 @param cmd AUTOPilot elevator command in radians*/
509 inline void SetAPDeCmd(double cmd ) { AP_DeCmd = cmd; }
511 /** Sets the AUTOPilot rudder command
512 @param cmd AUTOPilot rudder command in radians*/
513 inline void SetAPDrCmd(double cmd) { AP_DrCmd = cmd; }
515 /** Sets the AUTOPilot throttle command
516 @param cmd AUTOPilot throttle command in percent*/
517 inline void SetAPThrottleCmd(double cmd) { AP_ThrottleCmd = cmd; }
520 /// @name Aerosurface position setting
522 /** Sets the left aileron position
523 @param cmd left aileron position in radians*/
524 inline void SetDaLPos( int form , double pos )
525 { DaLPos[form] = pos; }
527 /** Sets the right aileron position
528 @param cmd right aileron position in radians*/
529 inline void SetDaRPos( int form , double pos )
530 { DaRPos[form] = pos; }
532 /** Sets the elevator position
533 @param cmd elevator position in radians*/
534 inline void SetDePos( int form , double pos )
535 { DePos[form] = pos; }
537 /** Sets the rudder position
538 @param cmd rudder position in radians*/
539 inline void SetDrPos( int form , double pos )
540 { DrPos[form] = pos; }
542 /** Sets the flaps position
543 @param cmd flaps position in radians*/
544 inline void SetDfPos( int form , double pos )
545 { DfPos[form] = pos; }
547 /** Sets the speedbrake position
548 @param cmd speedbrake position in radians*/
549 inline void SetDsbPos( int form , double pos )
550 { DsbPos[form] = pos; }
552 /** Sets the spoiler position
553 @param cmd spoiler position in radians*/
554 inline void SetDspPos( int form , double pos )
555 { DspPos[form] = pos; }
557 /** Sets the actual throttle setting for the specified engine
558 @param engine engine ID number
559 @param cmd throttle setting in percent (0 - 100)*/
560 void SetThrottlePos(int engine, double cmd);
562 /** Sets the actual mixture setting for the specified engine
563 @param engine engine ID number
564 @param cmd mixture setting in percent (0 - 100)*/
565 void SetMixturePos(int engine, double cmd);
567 /** Sets the steering position
568 @param cmd steering position in degrees*/
569 void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
571 /** Set the gear extend/retract position, defaults to down
572 @param gear position 0 up, 1 down */
573 void SetGearPos(double gearpos) { GearPos = gearpos; }
576 /** Sets the actual prop pitch setting for the specified engine
577 @param engine engine ID number
578 @param cmd prop pitch setting in percent (0.0 - 1.0)*/
579 void SetPropAdvance(int engine, double cmd);
582 /// @name Landing Gear brakes
584 /** Sets the left brake group
585 @param cmd brake setting in percent (0.0 - 1.0) */
586 void SetLBrake(double cmd) {LeftBrake = cmd;}
588 /** Sets the right brake group
589 @param cmd brake setting in percent (0.0 - 1.0) */
590 void SetRBrake(double cmd) {RightBrake = cmd;}
592 /** Sets the center brake group
593 @param cmd brake setting in percent (0.0 - 1.0) */
594 void SetCBrake(double cmd) {CenterBrake = cmd;}
596 /** Gets the brake for a specified group.
597 @param bg which brakegroup to retrieve the command for
598 @return the brake setting for the supplied brake group argument */
599 double GetBrake(FGLGear::BrakeGroup bg);
602 /** Loads the Flight Control System.
603 The FGAircraft instance is actually responsible for reading the config file
604 and calling the various Loadxx() methods of the other systems, passing in
605 the config file instance pointer. LoadFCS() is called from FGAircraft.
606 @param AC_cfg pointer to the config file instance
607 @return true if succesful */
608 bool Load(FGConfigFile* AC_cfg);
610 void AddThrottle(void);
613 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
617 void bindModel(void);
618 void unbind(FGPropertyManager *node);
621 double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
622 double AP_DaCmd, AP_DeCmd, AP_DrCmd, AP_ThrottleCmd;
623 double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
624 double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
625 double PTrimCmd, YTrimCmd, RTrimCmd;
626 vector <double> ThrottleCmd;
627 vector <double> ThrottlePos;
628 vector <double> MixtureCmd;
629 vector <double> MixturePos;
630 vector <double> PropAdvanceCmd;
631 vector <double> PropAdvance;
632 vector <double> SteerPosDeg;
633 double LeftBrake, RightBrake, CenterBrake; // Brake settings
634 double GearCmd,GearPos;
636 double APAttitudeSetPt, APAltitudeSetPt, APHeadingSetPt, APAirspeedSetPt;
637 bool APAcquireAttitude, APAcquireAltitude, APAcquireHeading, APAcquireAirspeed;
638 bool APAttitudeHold, APAltitudeHold, APHeadingHold, APAirspeedHold, APWingsLevelHold;
641 void Normalize(void);
643 vector <FGFCSComponent*> FCSComponents;
644 vector <FGFCSComponent*> APComponents;
645 int ToNormalize[NNorm];
646 void Debug(int from);