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 <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 \<component name="Pitch Trim Sum" type="SUMMER">
88 <input> fcs/elevator-cmd-norm </input>
89 <input> fcs/pitch-trim-cmd-norm </input>
96 \<component name="Pitch Command Scale" TYPE="AEROSURFACE_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, 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
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.
119 Another option for the flight controls portion of the config file is that in
120 addition to using the "NAME" attribute in,
123 \<flight_control name="X-15 SAS">
126 one can also supply a filename:
129 \<flight_control name="X-15 SAS" file="X15.xml">
133 In this case, the FCS would be read in from another file.
135 @author Jon S. Berndt
147 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
151 class FGFCS : public FGModel {
155 @param Executive a pointer to the parent executive object */
160 /** Runs the Flight Controls model; called by the Executive
161 @return false if no error */
164 /// @name Pilot input command retrieval
166 /** Gets the aileron command.
167 @return aileron command in range from -1.0 - 1.0 */
168 inline double GetDaCmd(void) const { return DaCmd; }
170 /** Gets the elevator command.
171 @return elevator command in range from -1.0 - 1.0 */
172 inline double GetDeCmd(void) const { return DeCmd; }
174 /** Gets the rudder command.
175 @return rudder command in range from -1.0 - 1.0 */
176 inline double GetDrCmd(void) const { return DrCmd; }
178 /** Gets the steering command.
179 @return steering command in range from -1.0 - 1.0 */
180 inline double GetDsCmd(void) const { return DsCmd; }
182 /** Gets the flaps command.
183 @return flaps command in range from 0 to 1.0 */
184 inline double GetDfCmd(void) const { return DfCmd; }
186 /** Gets the speedbrake command.
187 @return speedbrake command in range from 0 to 1.0 */
188 inline double GetDsbCmd(void) const { return DsbCmd; }
190 /** Gets the spoiler command.
191 @return spoiler command in range from 0 to 1.0 */
192 inline double GetDspCmd(void) const { return DspCmd; }
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;
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]; }
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]; }
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]; }
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; }
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; }
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; }
226 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
228 @return the current value of the gear extend/retract command*/
229 inline double GetGearCmd(void) const { return GearCmd; }
232 /// @name Aerosurface position retrieval
234 /** Gets the left aileron position.
235 @return aileron position in radians */
236 inline double GetDaLPos( int form = ofRad )
237 const { return DaLPos[form]; }
239 /// @name Aerosurface position retrieval
241 /** Gets the right aileron position.
242 @return aileron position in radians */
243 inline double GetDaRPos( int form = ofRad )
244 const { return DaRPos[form]; }
246 /** Gets the elevator position.
247 @return elevator position in radians */
248 inline double GetDePos( int form = ofRad )
249 const { return DePos[form]; }
251 /** Gets the rudder position.
252 @return rudder position in radians */
253 inline double GetDrPos( int form = ofRad )
254 const { return DrPos[form]; }
256 /** Gets the speedbrake position.
257 @return speedbrake position in radians */
258 inline double GetDsbPos( int form = ofRad )
259 const { return DsbPos[form]; }
261 /** Gets the spoiler position.
262 @return spoiler position in radians */
263 inline double GetDspPos( int form = ofRad )
264 const { return DspPos[form]; }
266 /** Gets the flaps position.
267 @return flaps position in radians */
268 inline double GetDfPos( int form = ofRad )
269 const { return DfPos[form]; }
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;
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]; }
281 /** Gets the steering position.
282 @return steering position in degrees */
283 double GetSteerPosDeg(int gear) const { return SteerPosDeg[gear]; }
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; }
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]; }
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]; }
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; }
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);
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
314 string GetComponentValues(string delimeter);
316 /// @name Pilot input command setting
318 /** Sets the aileron command
319 @param cmd aileron command */
320 inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
322 /** Sets the elevator command
323 @param cmd elevator command in percent*/
324 inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
326 /** Sets the rudder command
327 @param cmd rudder command in percent*/
328 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
330 /** Sets the steering command
331 @param cmd steering command in percent*/
332 inline void SetDsCmd(double cmd) { DsCmd = cmd; }
334 /** Sets the flaps command
335 @param cmd flaps command in percent*/
336 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
338 /** Sets the speedbrake command
339 @param cmd speedbrake command in percent*/
340 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
342 /** Sets the spoilers command
343 @param cmd spoilers command in percent*/
344 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
346 /** Sets the pitch trim command
347 @param cmd pitch trim command in percent*/
348 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
350 /** Sets the rudder trim command
351 @param cmd rudder trim command in percent*/
352 inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
354 /** Sets the aileron trim command
355 @param cmd aileron trim command in percent*/
356 inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
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);
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);
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; }
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);
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);
383 /// @name Aerosurface position setting
385 /** Sets the left aileron position
386 @param cmd left aileron position in radians*/
387 inline void SetDaLPos( int form , double pos );
389 /** Sets the right aileron position
390 @param cmd right aileron position in radians*/
391 inline void SetDaRPos( int form , double pos );
393 /** Sets the elevator position
394 @param cmd elevator position in radians*/
395 inline void SetDePos( int form , double pos );
397 /** Sets the rudder position
398 @param cmd rudder position in radians*/
399 inline void SetDrPos( int form , double pos );
401 /** Sets the flaps position
402 @param cmd flaps position in radians*/
403 inline void SetDfPos( int form , double pos );
405 /** Sets the speedbrake position
406 @param cmd speedbrake position in radians*/
407 inline void SetDsbPos( int form , double pos );
409 /** Sets the spoiler position
410 @param cmd spoiler position in radians*/
411 inline void SetDspPos( int form , double pos );
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);
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);
423 /** Sets the steering position
424 @param cmd steering position in degrees*/
425 void SetSteerPosDeg(int gear, double pos) { SteerPosDeg[gear] = pos; }
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; }
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);
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);
443 /// @name Landing Gear brakes
445 /** Sets the left brake group
446 @param cmd brake setting in percent (0.0 - 1.0) */
447 void SetLBrake(double cmd) {LeftBrake = cmd;}
449 /** Sets the right brake group
450 @param cmd brake setting in percent (0.0 - 1.0) */
451 void SetRBrake(double cmd) {RightBrake = cmd;}
453 /** Sets the center brake group
454 @param cmd brake setting in percent (0.0 - 1.0) */
455 void SetCBrake(double cmd) {CenterBrake = cmd;}
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);
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);
471 void AddThrottle(void);
474 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
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;
493 vector <FGFCSComponent*> FCSComponents;
494 vector <FGFCSComponent*> APComponents;
495 vector <double*> interface_properties;
496 vector <FGFCSComponent*> sensors;
498 void bindModel(void);
499 void bindThrottle(unsigned int);
500 void unbind(FGPropertyManager *node);
501 void Debug(int from);