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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include <models/flight_control/FGFCSComponent.h>
45 #include <models/FGModel.h>
46 #include <models/FGLGear.h>
47 #include <input_output/FGXMLFileRead.h>
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 typedef enum { ofRad=0, ofDeg, ofNorm, ofMag , NForms} OutputForm;
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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:
77 <flight_control name="X-15 SAS">
79 <summer name="Pitch Trim Sum">
80 <input> fcs/elevator-cmd-norm </input>
81 <input> fcs/pitch-trim-cmd-norm </input>
88 <aerosurface_scale name="Pitch Command Scale">
89 <input> fcs/pitch-trim-sum </input>
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.
110 Another option for the flight controls portion of the config file is that in
111 addition to using the "NAME" attribute in,
114 <flight_control name="X-15 SAS">
117 one can also supply a filename:
120 <flight_control name="X-15 SAS" file="X15.xml">
124 In this case, the FCS would be read in from another file.
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
169 @author Jon S. Berndt
185 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
189 class FGFCS : public FGModel, public FGXMLFileRead
194 @param Executive a pointer to the parent executive object */
199 bool InitModel(void);
201 /** Runs the Flight Controls model; called by the Executive
202 @return false if no error */
205 /// @name Pilot input command retrieval
207 /** Gets the aileron command.
208 @return aileron command in range from -1.0 - 1.0 */
209 double GetDaCmd(void) const { return DaCmd; }
211 /** Gets the elevator command.
212 @return elevator command in range from -1.0 - 1.0 */
213 double GetDeCmd(void) const { return DeCmd; }
215 /** Gets the rudder command.
216 @return rudder command in range from -1.0 - 1.0 */
217 double GetDrCmd(void) const { return DrCmd; }
219 /** Gets the steering command.
220 @return steering command in range from -1.0 - 1.0 */
221 double GetDsCmd(void) const { return DsCmd; }
223 /** Gets the flaps command.
224 @return flaps command in range from 0 to 1.0 */
225 double GetDfCmd(void) const { return DfCmd; }
227 /** Gets the speedbrake command.
228 @return speedbrake command in range from 0 to 1.0 */
229 double GetDsbCmd(void) const { return DsbCmd; }
231 /** Gets the spoiler command.
232 @return spoiler command in range from 0 to 1.0 */
233 double GetDspCmd(void) const { return DspCmd; }
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;
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]; }
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]; }
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]; }
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; }
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; }
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; }
267 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
269 @return the current value of the gear extend/retract command*/
270 double GetGearCmd(void) const { return GearCmd; }
273 /// @name Aerosurface position retrieval
275 /** Gets the left aileron position.
276 @return aileron position in radians */
277 double GetDaLPos( int form = ofRad )
278 const { return DaLPos[form]; }
280 /// @name Aerosurface position retrieval
282 /** Gets the right aileron position.
283 @return aileron position in radians */
284 double GetDaRPos( int form = ofRad )
285 const { return DaRPos[form]; }
287 /** Gets the elevator position.
288 @return elevator position in radians */
289 double GetDePos( int form = ofRad )
290 const { return DePos[form]; }
292 /** Gets the rudder position.
293 @return rudder position in radians */
294 double GetDrPos( int form = ofRad )
295 const { return DrPos[form]; }
297 /** Gets the speedbrake position.
298 @return speedbrake position in radians */
299 double GetDsbPos( int form = ofRad )
300 const { return DsbPos[form]; }
302 /** Gets the spoiler position.
303 @return spoiler position in radians */
304 double GetDspPos( int form = ofRad )
305 const { return DspPos[form]; }
307 /** Gets the flaps position.
308 @return flaps position in radians */
309 double GetDfPos( int form = ofRad )
310 const { return DfPos[form]; }
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;
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]; }
322 /** Gets the steering position.
323 @return steering position in degrees */
324 double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
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; }
330 /** Gets the tailhook position (0 up, 1 down)
331 @return tailhook position (0 up, 1 down) */
332 double GetTailhookPos(void) const { return TailhookPos; }
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; }
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]; }
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]; }
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; }
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);
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
363 string GetComponentValues(string delimeter);
365 /// @name Pilot input command setting
367 /** Sets the aileron command
368 @param cmd aileron command */
369 void SetDaCmd( double cmd ) { DaCmd = cmd; }
371 /** Sets the elevator command
372 @param cmd elevator command in percent*/
373 void SetDeCmd(double cmd ) { DeCmd = cmd; }
375 /** Sets the rudder command
376 @param cmd rudder command in percent*/
377 void SetDrCmd(double cmd) { DrCmd = cmd; }
379 /** Sets the steering command
380 @param cmd steering command in percent*/
381 void SetDsCmd(double cmd) { DsCmd = cmd; }
383 /** Sets the flaps command
384 @param cmd flaps command in percent*/
385 void SetDfCmd(double cmd) { DfCmd = cmd; }
387 /** Sets the speedbrake command
388 @param cmd speedbrake command in percent*/
389 void SetDsbCmd(double cmd) { DsbCmd = cmd; }
391 /** Sets the spoilers command
392 @param cmd spoilers command in percent*/
393 void SetDspCmd(double cmd) { DspCmd = cmd; }
395 /** Sets the pitch trim command
396 @param cmd pitch trim command in percent*/
397 void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
399 /** Sets the rudder trim command
400 @param cmd rudder trim command in percent*/
401 void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
403 /** Sets the aileron trim command
404 @param cmd aileron trim command in percent*/
405 void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
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);
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);
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; }
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);
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);
432 /// @name Aerosurface position setting
434 /** Sets the left aileron position
435 @param cmd left aileron position in radians*/
436 void SetDaLPos( int form , double pos );
438 /** Sets the right aileron position
439 @param cmd right aileron position in radians*/
440 void SetDaRPos( int form , double pos );
442 /** Sets the elevator position
443 @param cmd elevator position in radians*/
444 void SetDePos( int form , double pos );
446 /** Sets the rudder position
447 @param cmd rudder position in radians*/
448 void SetDrPos( int form , double pos );
450 /** Sets the flaps position
451 @param cmd flaps position in radians*/
452 void SetDfPos( int form , double pos );
454 /** Sets the speedbrake position
455 @param cmd speedbrake position in radians*/
456 void SetDsbPos( int form , double pos );
458 /** Sets the spoiler position
459 @param cmd spoiler position in radians*/
460 void SetDspPos( int form , double pos );
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);
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);
472 /** Sets the steering position
473 @param cmd steering position in degrees*/
474 void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
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; }
480 /** Set the tailhook position
481 @param tailhook position 0 up, 1 down */
482 void SetTailhookPos(double hookpos) { TailhookPos = hookpos; }
484 /** Set the wing fold position
485 @param wing fold position 0 unfolded, 1 folded */
486 void SetWingFoldPos(double foldpos) { WingFoldPos = foldpos; }
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);
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);
499 /// @name Landing Gear brakes
501 /** Sets the left brake group
502 @param cmd brake setting in percent (0.0 - 1.0) */
503 void SetLBrake(double cmd) {LeftBrake = cmd;}
505 /** Sets the right brake group
506 @param cmd brake setting in percent (0.0 - 1.0) */
507 void SetRBrake(double cmd) {RightBrake = cmd;}
509 /** Sets the center brake group
510 @param cmd brake setting in percent (0.0 - 1.0) */
511 void SetCBrake(double cmd) {CenterBrake = cmd;}
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);
518 /** Gets the left brake.
519 @return the left brake setting. */
520 double GetLBrake(void) const {return LeftBrake;}
522 /** Gets the right brake.
523 @return the right brake setting. */
524 double GetRBrake(void) const {return RightBrake;}
526 /** Gets the center brake.
527 @return the center brake setting. */
528 double GetCBrake(void) const {return CenterBrake;}
531 enum SystemType { stFCS, stSystem, stAutoPilot };
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);
540 ifstream* FindSystemFile(string system_filename);
541 string FindSystemFullPathname(string system_filename);
543 void AddThrottle(void);
547 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
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;
567 typedef vector <FGFCSComponent*> FCSCompVec;
569 FCSCompVec FCSComponents;
570 FCSCompVec APComponents;
572 vector <double*> interface_properties;
574 void bindModel(void);
575 void bindThrottle(unsigned int);
576 void Debug(int from);