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 Lesser 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 Lesser General Public License for more
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.
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.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
53 #include <models/flight_control/FGFCSComponent.h>
54 #include <models/FGModel.h>
55 #include <models/FGLGear.h>
56 #include <input_output/FGXMLElement.h>
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 typedef enum { ofRad=0, ofDeg, ofNorm, ofMag , NForms} OutputForm;
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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:
85 <flight_control name="X-15 SAS">
87 <summer name="Pitch Trim Sum">
88 <input> fcs/elevator-cmd-norm </input>
89 <input> fcs/pitch-trim-cmd-norm </input>
96 <aerosurface_scale name="Pitch Command Scale">
97 <input> fcs/pitch-trim-sum </input>
107 In the above case we can see the first few components of the pitch channel
108 defined. The input to the first component (a summer), 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.
111 The next component created is an aerosurface scale component - a type of
112 gain (see the LoadFCS() method for insight on how the various types of
113 components map into the actual component classes). This continues until the
114 final component for an axis when the
115 \<output> element is usually used to specify where the output is supposed to go. See the
116 individual components for more information on how they are mechanized.
118 Another option for the flight controls portion of the config file is that in
119 addition to using the "NAME" attribute in,
122 \<flight_control name="X-15 SAS">
125 one can also supply a filename:
128 \<flight_control name="X-15 SAS" file="X15.xml">
132 In this case, the FCS would be read in from another file.
135 @property fcs/aileron-cmd-norm normalized aileron command
136 @property fcs/elevator-cmd-norm normalized elevator command
137 @property fcs/rudder-cmd-norm
138 @property fcs/steer-cmd-norm
139 @property fcs/flap-cmd-norm
140 @property fcs/speedbrake-cmd-norm
141 @property fcs/spoiler-cmd-norm
142 @property fcs/pitch-trim-cmd-norm
143 @property fcs/roll-trim-cmd-norm
144 @property fcs/yaw-trim-cmd-norm
145 @property gear/gear-cmd-norm
146 @property fcs/left-aileron-pos-rad
147 @property fcs/left-aileron-pos-deg
148 @property fcs/left-aileron-pos-norm
149 @property fcs/mag-left-aileron-pos-rad
150 @property fcs/right-aileron-pos-rad
151 @property fcs/right-aileron-pos-deg
152 @property fcs/right-aileron-pos-norm
153 @property fcs/mag-right-aileron-pos-rad
154 @property fcs/elevator-pos-rad
155 @property fcs/elevator-pos-deg
156 @property fcs/elevator-pos-norm
157 @property fcs/mag-elevator-pos-rad
158 @property fcs/rudder-pos-rad
159 @property fcs/rudder-pos-deg
160 @property fcs/rudder-pos-norm
161 @property fcs/mag-rudder-pos-rad
162 @property fcs/flap-pos-rad
163 @property fcs/flap-pos-deg
164 @property fcs/flap-pos-norm
165 @property fcs/speedbrake-pos-rad
166 @property fcs/speedbrake-pos-deg
167 @property fcs/speedbrake-pos-norm
168 @property fcs/mag-speedbrake-pos-rad
169 @property fcs/spoiler-pos-rad
170 @property fcs/spoiler-pos-deg
171 @property fcs/spoiler-pos-norm
172 @property fcs/mag-spoiler-pos-rad
173 @property gear/gear-pos-norm
175 @author Jon S. Berndt
190 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
194 class FGFCS : public FGModel {
198 @param Executive a pointer to the parent executive object */
203 /** Runs the Flight Controls model; called by the Executive
204 @return false if no error */
207 /// @name Pilot input command retrieval
209 /** Gets the aileron command.
210 @return aileron command in range from -1.0 - 1.0 */
211 inline double GetDaCmd(void) const { return DaCmd; }
213 /** Gets the elevator command.
214 @return elevator command in range from -1.0 - 1.0 */
215 inline double GetDeCmd(void) const { return DeCmd; }
217 /** Gets the rudder command.
218 @return rudder command in range from -1.0 - 1.0 */
219 inline double GetDrCmd(void) const { return DrCmd; }
221 /** Gets the steering command.
222 @return steering command in range from -1.0 - 1.0 */
223 inline double GetDsCmd(void) const { return DsCmd; }
225 /** Gets the flaps command.
226 @return flaps command in range from 0 to 1.0 */
227 inline double GetDfCmd(void) const { return DfCmd; }
229 /** Gets the speedbrake command.
230 @return speedbrake command in range from 0 to 1.0 */
231 inline double GetDsbCmd(void) const { return DsbCmd; }
233 /** Gets the spoiler command.
234 @return spoiler command in range from 0 to 1.0 */
235 inline double GetDspCmd(void) const { return DspCmd; }
237 /** Gets the throttle command.
238 @param engine engine ID number
239 @return throttle command in range from 0 - 1.0 for the given engine */
240 double GetThrottleCmd(int engine) const;
242 /** Gets the mixture command.
243 @param engine engine ID number
244 @return mixture command in range from 0 - 1.0 for the given engine */
245 inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
247 /** Gets the prop pitch command.
248 @param engine engine ID number
249 @return pitch command in range from 0.0 - 1.0 for the given engine */
250 inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
252 /** Gets the prop feather command.
253 @param engine engine ID number
254 @return feather command for the given engine (on / off)*/
255 inline bool GetFeatherCmd(int engine) const { return PropFeatherCmd[engine]; }
257 /** Gets the pitch trim command.
258 @return pitch trim command in range from -1.0 to 1.0 */
259 inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
261 /** Gets the rudder trim command.
262 @return rudder trim command in range from -1.0 - 1.0 */
263 inline double GetYawTrimCmd(void) const { return YTrimCmd; }
265 /** Gets the aileron trim command.
266 @return aileron trim command in range from -1.0 - 1.0 */
267 inline double GetRollTrimCmd(void) const { return RTrimCmd; }
269 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
271 @return the current value of the gear extend/retract command*/
272 inline double GetGearCmd(void) const { return GearCmd; }
275 /// @name Aerosurface position retrieval
277 /** Gets the left aileron position.
278 @return aileron position in radians */
279 inline double GetDaLPos( int form = ofRad )
280 const { return DaLPos[form]; }
282 /// @name Aerosurface position retrieval
284 /** Gets the right aileron position.
285 @return aileron position in radians */
286 inline double GetDaRPos( int form = ofRad )
287 const { return DaRPos[form]; }
289 /** Gets the elevator position.
290 @return elevator position in radians */
291 inline double GetDePos( int form = ofRad )
292 const { return DePos[form]; }
294 /** Gets the rudder position.
295 @return rudder position in radians */
296 inline double GetDrPos( int form = ofRad )
297 const { return DrPos[form]; }
299 /** Gets the speedbrake position.
300 @return speedbrake position in radians */
301 inline double GetDsbPos( int form = ofRad )
302 const { return DsbPos[form]; }
304 /** Gets the spoiler position.
305 @return spoiler position in radians */
306 inline double GetDspPos( int form = ofRad )
307 const { return DspPos[form]; }
309 /** Gets the flaps position.
310 @return flaps position in radians */
311 inline double GetDfPos( int form = ofRad )
312 const { return DfPos[form]; }
314 /** Gets the throttle position.
315 @param engine engine ID number
316 @return throttle position for the given engine in range from 0 - 1.0 */
317 double GetThrottlePos(int engine) const;
319 /** Gets the mixture position.
320 @param engine engine ID number
321 @return mixture position for the given engine in range from 0 - 1.0 */
322 inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
324 /** Gets the steering position.
325 @return steering position in degrees */
326 double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
328 /** Gets the gear position (0 up, 1 down), defaults to down
329 @return gear position (0 up, 1 down) */
330 inline double GetGearPos(void) const { return GearPos; }
332 /** Gets the prop pitch position.
333 @param engine engine ID number
334 @return prop pitch position for the given engine in range from 0 - 1.0 */
335 inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
337 /** Gets the prop feather position.
338 @param engine engine ID number
339 @return prop fether for the given engine (on / off)*/
340 inline bool GetPropFeather(int engine) const { return PropFeather[engine]; }
343 /** Retrieves the State object pointer.
344 This is used by the FGFCS-owned components.
345 @return pointer to the State object */
346 inline FGState* GetState(void) { return State; }
348 /** Retrieves all component names for inclusion in output stream
349 @param delimeter either a tab or comma string depending on output type
350 @return a string containing the descriptive names for all components */
351 string GetComponentStrings(string delimeter);
353 /** Retrieves all component outputs for inclusion in output stream
354 @param delimeter either a tab or comma string depending on output type
355 @return a string containing the numeric values for the current set of
357 string GetComponentValues(string delimeter);
359 /// @name Pilot input command setting
361 /** Sets the aileron command
362 @param cmd aileron command */
363 inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
365 /** Sets the elevator command
366 @param cmd elevator command in percent*/
367 inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
369 /** Sets the rudder command
370 @param cmd rudder command in percent*/
371 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
373 /** Sets the steering command
374 @param cmd steering command in percent*/
375 inline void SetDsCmd(double cmd) { DsCmd = cmd; }
377 /** Sets the flaps command
378 @param cmd flaps command in percent*/
379 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
381 /** Sets the speedbrake command
382 @param cmd speedbrake command in percent*/
383 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
385 /** Sets the spoilers command
386 @param cmd spoilers command in percent*/
387 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
389 /** Sets the pitch trim command
390 @param cmd pitch trim command in percent*/
391 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
393 /** Sets the rudder trim command
394 @param cmd rudder trim command in percent*/
395 inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
397 /** Sets the aileron trim command
398 @param cmd aileron trim command in percent*/
399 inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
401 /** Sets the throttle command for the specified engine
402 @param engine engine ID number
403 @param cmd throttle command in percent (0 - 100)*/
404 void SetThrottleCmd(int engine, double cmd);
406 /** Sets the mixture command for the specified engine
407 @param engine engine ID number
408 @param cmd mixture command in percent (0 - 100)*/
409 void SetMixtureCmd(int engine, double cmd);
411 /** Set the gear extend/retract command, defaults to down
412 @param gear command 0 for up, 1 for down */
413 void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
415 /** Sets the propeller pitch command for the specified engine
416 @param engine engine ID number
417 @param cmd mixture command in percent (0.0 - 1.0)*/
418 void SetPropAdvanceCmd(int engine, double cmd);
420 /** Sets the propeller feather command for the specified engine
421 @param engine engine ID number
422 @param cmd feather (bool)*/
423 void SetFeatherCmd(int engine, bool cmd);
426 /// @name Aerosurface position setting
428 /** Sets the left aileron position
429 @param cmd left aileron position in radians*/
430 inline void SetDaLPos( int form , double pos );
432 /** Sets the right aileron position
433 @param cmd right aileron position in radians*/
434 inline void SetDaRPos( int form , double pos );
436 /** Sets the elevator position
437 @param cmd elevator position in radians*/
438 inline void SetDePos( int form , double pos );
440 /** Sets the rudder position
441 @param cmd rudder position in radians*/
442 inline void SetDrPos( int form , double pos );
444 /** Sets the flaps position
445 @param cmd flaps position in radians*/
446 inline void SetDfPos( int form , double pos );
448 /** Sets the speedbrake position
449 @param cmd speedbrake position in radians*/
450 inline void SetDsbPos( int form , double pos );
452 /** Sets the spoiler position
453 @param cmd spoiler position in radians*/
454 inline void SetDspPos( int form , double pos );
456 /** Sets the actual throttle setting for the specified engine
457 @param engine engine ID number
458 @param cmd throttle setting in percent (0 - 100)*/
459 void SetThrottlePos(int engine, double cmd);
461 /** Sets the actual mixture setting for the specified engine
462 @param engine engine ID number
463 @param cmd mixture setting in percent (0 - 100)*/
464 void SetMixturePos(int engine, double cmd);
466 /** Sets the steering position
467 @param cmd steering position in degrees*/
468 void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
470 /** Set the gear extend/retract position, defaults to down
471 @param gear position 0 up, 1 down */
472 void SetGearPos(double gearpos) { GearPos = gearpos; }
475 /** Sets the actual prop pitch setting for the specified engine
476 @param engine engine ID number
477 @param cmd prop pitch setting in percent (0.0 - 1.0)*/
478 void SetPropAdvance(int engine, double cmd);
480 /** Sets the actual prop feather setting for the specified engine
481 @param engine engine ID number
482 @param cmd prop fether setting (bool)*/
483 void SetPropFeather(int engine, bool cmd);
486 /// @name Landing Gear brakes
488 /** Sets the left brake group
489 @param cmd brake setting in percent (0.0 - 1.0) */
490 void SetLBrake(double cmd) {LeftBrake = cmd;}
492 /** Sets the right brake group
493 @param cmd brake setting in percent (0.0 - 1.0) */
494 void SetRBrake(double cmd) {RightBrake = cmd;}
496 /** Sets the center brake group
497 @param cmd brake setting in percent (0.0 - 1.0) */
498 void SetCBrake(double cmd) {CenterBrake = cmd;}
500 /** Gets the brake for a specified group.
501 @param bg which brakegroup to retrieve the command for
502 @return the brake setting for the supplied brake group argument */
503 double GetBrake(FGLGear::BrakeGroup bg);
505 /** Gets the left brake.
506 @return the left brake setting. */
507 double GetLBrake(void) const {return LeftBrake;}
509 /** Gets the right brake.
510 @return the right brake setting. */
511 double GetRBrake(void) const {return RightBrake;}
513 /** Gets the center brake.
514 @return the center brake setting. */
515 double GetCBrake(void) const {return CenterBrake;}
518 /** Loads the Flight Control System.
519 Load() is called from FGFDMExec.
520 @param el pointer to the Element instance
521 @return true if succesful */
522 bool Load(Element* el);
524 void AddThrottle(void);
527 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
530 double DaCmd, DeCmd, DrCmd, DsCmd, DfCmd, DsbCmd, DspCmd;
531 double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
532 double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
533 double PTrimCmd, YTrimCmd, RTrimCmd;
534 vector <double> ThrottleCmd;
535 vector <double> ThrottlePos;
536 vector <double> MixtureCmd;
537 vector <double> MixturePos;
538 vector <double> PropAdvanceCmd;
539 vector <double> PropAdvance;
540 vector <bool> PropFeatherCmd;
541 vector <bool> PropFeather;
542 vector <double> SteerPosDeg;
543 double LeftBrake, RightBrake, CenterBrake; // Brake settings
544 double GearCmd,GearPos;
546 vector <FGFCSComponent*> FCSComponents;
547 vector <FGFCSComponent*> APComponents;
548 vector <double*> interface_properties;
549 vector <FGFCSComponent*> sensors;
551 void bindModel(void);
552 void bindThrottle(unsigned int);
553 void unbind(FGPropertyManager *node);
554 void Debug(int from);