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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 typedef enum { iDe=0, iDaL, iDaR, iDr, iDsb, iDsp, iDf, NNorm } FcIdx;
69 typedef enum { ofRad=0, ofNorm, ofMag , NForms} OutputForm;
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 /** Encapsulates the Flight Control System (FCS) functionality.
80 <ul><li>\URL[Source Code]{FGFCS.cpp.html}</li>
81 <li>\URL[Header File]{FGFCS.h.html}</li></ul>
82 This class owns and contains the list of \URL[components]{FGFCSComponent.html}
83 that define the control system for this aircraft. The config file for the
84 aircraft contains a description of the control path that starts at an input
85 or command and ends at an effector, e.g. an aerosurface. The FCS components
86 which comprise the control laws for an axis are defined sequentially in
87 the configuration file. For instance, for the X-15:
90 < FLIGHT_CONTROL NAME="X-15 SAS">
92 < COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER">
95 INPUT FG_PITCH_TRIM_CMD
99 < COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE">
106 < COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN">
112 < COMPONENT NAME="Pitch Scheduled Gain 1" TYPE="SCHEDULED_GAIN">
116 SCHEDULED_BY FG_ELEVATOR_POS
128 In the above case we can see the first few components of the pitch channel
129 defined. The input to the first component, as can be seen in the "Pitch trim
130 sum" component, is really the sum of two parameters: elevator command (from
131 the stick - a pilot input), and pitch trim. The type of this component is
132 "Summer". Its ID is 0 - the ID is used by other components to reference it.
133 The next component created is an aerosurface scale component - a type of
134 gain (see the LoadFCS() method for insight on how the various types of
135 components map into the actual component classes). You can see the input of
136 the "Pitch Command Scale" component takes "0" as input. When a number is
137 specified as an input, it refers to the ID of another FCS component. In this
138 case, ID 0 refers to the previously defined and discussed "Pitch Trim Sum"
139 component. This continues until the final component for an axis when the
140 OUTPUT keyword specifies where the output is supposed to go. See the
141 individual components for more information on how they are mechanized.
143 @author Jon S. Berndt
153 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGFCS.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
155 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGFCS.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
159 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
163 class FGFCS : public FGModel {
167 @param Executive a pointer to the parent executive object */
172 /** Runs the Flight Controls model; called by the Executive
173 @return false if no error */
176 /// @name Pilot input command retrieval
178 /** Gets the aileron command.
179 @return aileron command in percent */
180 inline double GetDaCmd(void) const { return DaCmd; }
182 /** Gets the elevator command.
183 @return elevator command in percent */
184 inline double GetDeCmd(void) const { return DeCmd; }
186 /** Gets the rudder command.
187 @return rudder command in percent */
188 inline double GetDrCmd(void) const { return DrCmd; }
190 /** Gets the flaps command.
191 @return flaps command in percent */
192 inline double GetDfCmd(void) const { return DfCmd; }
194 /** Gets the speedbrake command.
195 @return speedbrake command in percent */
196 inline double GetDsbCmd(void) const { return DsbCmd; }
198 /** Gets the spoiler command.
199 @return spoiler command in percent */
200 inline double GetDspCmd(void) const { return DspCmd; }
202 /** Gets the throttle command.
203 @param engine engine ID number
204 @return throttle command in percent ( 0 - 100) for the given engine */
205 double GetThrottleCmd(int engine) const;
207 /** Gets the mixture command.
208 @param engine engine ID number
209 @return mixture command in percent ( 0 - 100) for the given engine */
210 inline double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
212 /** Gets the prop pitch command.
213 @param engine engine ID number
214 @return pitch command in percent ( 0.0 - 1.0) for the given engine */
215 inline double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
217 /** Gets the pitch trim command.
218 @return pitch trim command in percent */
219 inline double GetPitchTrimCmd(void) const { return PTrimCmd; }
221 /** Gets the rudder trim command.
222 @return rudder trim command in percent */
223 inline double GetYawTrimCmd(void) const { return YTrimCmd; }
225 /** Gets the aileron trim command.
226 @return aileron trim command in percent */
227 inline double GetRollTrimCmd(void) const { return RTrimCmd; }
229 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
231 @return the current value of the gear extend/retract command*/
232 inline double GetGearCmd(void) const { return GearCmd; }
235 /// @name Aerosurface position retrieval
237 /** Gets the left aileron position.
238 @return aileron position in radians */
239 inline double GetDaLPos( int form = ofRad )
240 const { return DaLPos[form]; }
242 /// @name Aerosurface position retrieval
244 /** Gets the right aileron position.
245 @return aileron position in radians */
246 inline double GetDaRPos( int form = ofRad )
247 const { return DaRPos[form]; }
249 /** Gets the elevator position.
250 @return elevator position in radians */
251 inline double GetDePos( int form = ofRad )
252 const { return DePos[form]; }
254 /** Gets the rudder position.
255 @return rudder position in radians */
256 inline double GetDrPos( int form = ofRad )
257 const { return DrPos[form]; }
259 /** Gets the speedbrake position.
260 @return speedbrake position in radians */
261 inline double GetDsbPos( int form = ofRad )
262 const { return DsbPos[form]; }
264 /** Gets the spoiler position.
265 @return spoiler position in radians */
266 inline double GetDspPos( int form = ofRad )
267 const { return DspPos[form]; }
269 /** Gets the flaps position.
270 @return flaps position in radians */
271 inline double GetDfPos( int form = ofRad )
272 const { return DfPos[form]; }
274 /** Gets the throttle position.
275 @param engine engine ID number
276 @return throttle position for the given engine in percent ( 0 - 100)*/
277 double GetThrottlePos(int engine) const;
279 /** Gets the mixture position.
280 @param engine engine ID number
281 @return mixture position for the given engine in percent ( 0 - 100)*/
282 inline double GetMixturePos(int engine) const { return MixturePos[engine]; }
284 /** Gets the gear position (0 up, 1 down), defaults to down
285 @return gear position (0 up, 1 down) */
286 inline double GetGearPos(void) const { return GearPos; }
288 /** Gets the prop pitch position.
289 @param engine engine ID number
290 @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
291 inline double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
294 /** Retrieves the State object pointer.
295 This is used by the FGFCS-owned components.
296 @return pointer to the State object */
297 inline FGState* GetState(void) { return State; }
299 /** Retrieves a components output value
300 @param idx the index of the component (the component ID)
301 @return output value from the component */
302 double GetComponentOutput(int idx);
304 /** Retrieves the component name
305 @param idx the index of the component (the component ID)
306 @return name of the component */
307 string GetComponentName(int idx);
309 /** Retrieves all component names for inclusion in output stream */
310 string GetComponentStrings(void);
312 /** Retrieves all component outputs for inclusion in output stream */
313 string GetComponentValues(void);
315 /// @name Pilot input command setting
317 /** Sets the aileron command
318 @param cmd aileron command in percent*/
319 inline void SetDaCmd( double cmd ) { DaCmd = cmd; }
321 /** Sets the elevator command
322 @param cmd elevator command in percent*/
323 inline void SetDeCmd(double cmd ) { DeCmd = cmd; }
325 /** Sets the rudder command
326 @param cmd rudder command in percent*/
327 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
329 /** Sets the flaps command
330 @param cmd flaps command in percent*/
331 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
333 /** Sets the speedbrake command
334 @param cmd speedbrake command in percent*/
335 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
337 /** Sets the spoilers command
338 @param cmd spoilers command in percent*/
339 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
341 /** Sets the pitch trim command
342 @param cmd pitch trim command in percent*/
343 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
345 /** Sets the rudder trim command
346 @param cmd rudder trim command in percent*/
347 inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
349 /** Sets the aileron trim command
350 @param cmd aileron trim command in percent*/
351 inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
353 /** Sets the throttle command for the specified engine
354 @param engine engine ID number
355 @param cmd throttle command in percent (0 - 100)*/
356 void SetThrottleCmd(int engine, double cmd);
358 /** Sets the mixture command for the specified engine
359 @param engine engine ID number
360 @param cmd mixture command in percent (0 - 100)*/
361 void SetMixtureCmd(int engine, double cmd);
363 /** Set the gear extend/retract command, defaults to down
364 @param gear command 0 for up, 1 for down */
365 void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
367 /** Sets the propeller pitch command for the specified engine
368 @param engine engine ID number
369 @param cmd mixture command in percent (0.0 - 1.0)*/
370 void SetPropAdvanceCmd(int engine, double cmd);
373 /// @name Aerosurface position setting
375 /** Sets the left aileron position
376 @param cmd left aileron position in radians*/
377 inline void SetDaLPos( int form , double pos )
378 { DaLPos[form] = pos; }
380 /** Sets the right aileron position
381 @param cmd right aileron position in radians*/
382 inline void SetDaRPos( int form , double pos )
383 { DaRPos[form] = pos; }
385 /** Sets the elevator position
386 @param cmd elevator position in radians*/
387 inline void SetDePos( int form , double pos )
388 { DePos[form] = pos; }
390 /** Sets the rudder position
391 @param cmd rudder position in radians*/
392 inline void SetDrPos( int form , double pos )
393 { DrPos[form] = pos; }
395 /** Sets the flaps position
396 @param cmd flaps position in radians*/
397 inline void SetDfPos( int form , double pos )
398 { DfPos[form] = pos; }
400 /** Sets the speedbrake position
401 @param cmd speedbrake position in radians*/
402 inline void SetDsbPos( int form , double pos )
403 { DsbPos[form] = pos; }
405 /** Sets the spoiler position
406 @param cmd spoiler position in radians*/
407 inline void SetDspPos( int form , double pos )
408 { DspPos[form] = pos; }
410 /** Sets the actual throttle setting for the specified engine
411 @param engine engine ID number
412 @param cmd throttle setting in percent (0 - 100)*/
413 void SetThrottlePos(int engine, double cmd);
415 /** Sets the actual mixture setting for the specified engine
416 @param engine engine ID number
417 @param cmd mixture setting in percent (0 - 100)*/
418 void SetMixturePos(int engine, double cmd);
420 /** Set the gear extend/retract position, defaults to down
421 @param gear position 0 up, 1 down */
422 void SetGearPos(double gearpos) { GearPos = gearpos; }
425 /** Sets the actual prop pitch setting for the specified engine
426 @param engine engine ID number
427 @param cmd prop pitch setting in percent (0.0 - 1.0)*/
428 void SetPropAdvance(int engine, double cmd);
431 /// @name Landing Gear brakes
433 /** Sets the left brake group
434 @param cmd brake setting in percent (0.0 - 1.0) */
435 void SetLBrake(double cmd) {LeftBrake = cmd;}
437 /** Sets the right brake group
438 @param cmd brake setting in percent (0.0 - 1.0) */
439 void SetRBrake(double cmd) {RightBrake = cmd;}
441 /** Sets the center brake group
442 @param cmd brake setting in percent (0.0 - 1.0) */
443 void SetCBrake(double cmd) {CenterBrake = cmd;}
445 /** Gets the brake for a specified group.
446 @param bg which brakegroup to retrieve the command for
447 @return the brake setting for the supplied brake group argument */
448 double GetBrake(FGLGear::BrakeGroup bg);
451 /** Loads the Flight Control System.
452 The FGAircraft instance is actually responsible for reading the config file
453 and calling the various Loadxx() methods of the other systems, passing in
454 the config file instance pointer. LoadFCS() is called from FGAircraft.
455 @param AC_cfg pointer to the config file instance
456 @return true if succesful */
457 bool Load(FGConfigFile* AC_cfg);
459 void AddThrottle(void);
461 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
464 void bindModel(void);
468 double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
469 double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
470 double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
471 double PTrimCmd, YTrimCmd, RTrimCmd;
472 vector <double> ThrottleCmd;
473 vector <double> ThrottlePos;
474 vector <double> MixtureCmd;
475 vector <double> MixturePos;
476 vector <double> PropAdvanceCmd;
477 vector <double> PropAdvance;
478 double LeftBrake, RightBrake, CenterBrake; // Brake settings
479 double GearCmd,GearPos;
482 void Normalize(void);
484 vector <FGFCSComponent*> Components;
485 int ToNormalize[NNorm];
486 void Debug(int from);