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 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76 /** Encapsulates the Flight Control System (FCS) functionality.
77 <ul><li>\URL[Source Code]{FGFCS.cpp.html}</li>
78 <li>\URL[Header File]{FGFCS.h.html}</li></ul>
79 This class owns and contains the list of \URL[components]{FGFCSComponent.html}
80 that define the control system for this aircraft. The config file for the
81 aircraft contains a description of the control path that starts at an input
82 or command and ends at an effector, e.g. an aerosurface. The FCS components
83 which comprise the control laws for an axis are defined sequentially in
84 the configuration file. For instance, for the X-15:
87 < FLIGHT_CONTROL NAME="X-15 SAS">
89 < COMPONENT NAME="Pitch Trim Sum" TYPE="SUMMER">
92 INPUT FG_PITCH_TRIM_CMD
96 < COMPONENT NAME="Pitch Command Scale" TYPE="AEROSURFACE_SCALE">
103 < COMPONENT NAME="Pitch Gain 1" TYPE="PURE_GAIN">
109 < COMPONENT NAME="Pitch Scheduled Gain 1" TYPE="SCHEDULED_GAIN">
113 SCHEDULED_BY FG_ELEVATOR_POS
125 In the above case we can see the first few components of the pitch channel
126 defined. The input to the first component, as can be seen in the "Pitch trim
127 sum" component, is really the sum of two parameters: elevator command (from
128 the stick - a pilot input), and pitch trim. The type of this component is
129 "Summer". Its ID is 0 - the ID is used by other components to reference it.
130 The next component created is an aerosurface scale component - a type of
131 gain (see the LoadFCS() method for insight on how the various types of
132 components map into the actual component classes). You can see the input of
133 the "Pitch Command Scale" component takes "0" as input. When a number is
134 specified as an input, it refers to the ID of another FCS component. In this
135 case, ID 0 refers to the previously defined and discussed "Pitch Trim Sum"
136 component. This continues until the final component for an axis when the
137 OUTPUT keyword specifies where the output is supposed to go. See the
138 individual components for more information on how they are mechanized.
140 @author Jon S. Berndt
152 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
156 class FGFCS : public FGModel {
160 @param Executive a pointer to the parent executive object */
165 /** Runs the Flight Controls model; called by the Executive
166 @return false if no error */
169 /// @name Pilot input command retrieval
171 /** Gets the aileron command.
172 @return aileron command in percent */
173 inline double GetDaCmd(void) { return DaCmd; }
175 /** Gets the elevator command.
176 @return elevator command in percent */
177 inline double GetDeCmd(void) { return DeCmd; }
179 /** Gets the rudder command.
180 @return rudder command in percent */
181 inline double GetDrCmd(void) { return DrCmd; }
183 /** Gets the flaps command.
184 @return flaps command in percent */
185 inline double GetDfCmd(void) { return DfCmd; }
187 /** Gets the speedbrake command.
188 @return speedbrake command in percent */
189 inline double GetDsbCmd(void) { return DsbCmd; }
191 /** Gets the spoiler command.
192 @return spoiler command in percent */
193 inline double GetDspCmd(void) { 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);
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) { 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) { return PropAdvanceCmd[engine]; }
210 /** Gets the pitch trim command.
211 @return pitch trim command in percent */
212 inline double GetPitchTrimCmd(void) { return PTrimCmd; }
214 /** Gets the rudder trim command.
215 @return rudder trim command in percent */
216 inline double GetYawTrimCmd(void) { return YTrimCmd; }
218 /** Gets the aileron trim command.
219 @return aileron trim command in percent */
220 inline double GetRollTrimCmd(void) { 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) { return GearCmd; }
228 /// @name Aerosurface position retrieval
230 /** Gets the aileron position.
231 @return aileron position in radians */
232 inline double GetDaPos(void) { return DaPos; }
234 /** Gets the elevator position.
235 @return elevator position in radians */
236 inline double GetDePos(void) { return DePos; }
238 /** Gets the rudder position.
239 @return rudder position in radians */
240 inline double GetDrPos(void) { return DrPos; }
242 /** Gets the flaps position.
243 @return flaps position in radians */
244 inline double GetDfPos(void) { return DfPos; }
246 /** Gets the speedbrake position.
247 @return speedbrake position in radians */
248 inline double GetDsbPos(void) { return DsbPos; }
250 /** Gets the spoiler position.
251 @return spoiler position in radians */
252 inline double GetDspPos(void) { return DspPos; }
254 /** Gets the throttle position.
255 @param engine engine ID number
256 @return throttle position for the given engine in percent ( 0 - 100)*/
257 double GetThrottlePos(int engine);
259 /** Gets the mixture position.
260 @param engine engine ID number
261 @return mixture position for the given engine in percent ( 0 - 100)*/
262 inline double GetMixturePos(int engine) { return MixturePos[engine]; }
264 /** Gets the gear position (0 up, 1 down), defaults to down
265 @return gear position (0 up, 1 down) */
266 inline double GetGearPos(void) { return GearPos; }
268 /** Gets the prop pitch position.
269 @param engine engine ID number
270 @return prop pitch position for the given engine in percent ( 0.0-1.0)*/
271 inline double GetPropAdvance(int engine) { return PropAdvance[engine]; }
274 /** Retrieves the State object pointer.
275 This is used by the FGFCS-owned components.
276 @return pointer to the State object */
277 inline FGState* GetState(void) { return State; }
279 /** Retrieves a components output value
280 @param idx the index of the component (the component ID)
281 @return output value from the component */
282 double GetComponentOutput(eParam idx);
284 /** Retrieves the component name
285 @param idx the index of the component (the component ID)
286 @return name of the component */
287 string GetComponentName(int idx);
289 /** Retrieves all component names for inclusion in output stream */
290 string GetComponentStrings(void);
292 /** Retrieves all component outputs for inclusion in output stream */
293 string GetComponentValues(void);
295 /// @name Pilot input command setting
297 /** Sets the aileron command
298 @param cmd aileron command in percent*/
299 inline void SetDaCmd(double cmd) { DaCmd = cmd; }
301 /** Sets the elevator command
302 @param cmd elevator command in percent*/
303 inline void SetDeCmd(double cmd) { DeCmd = cmd; }
305 /** Sets the rudder command
306 @param cmd rudder command in percent*/
307 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
309 /** Sets the flaps command
310 @param cmd flaps command in percent*/
311 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
313 /** Sets the speedbrake command
314 @param cmd speedbrake command in percent*/
315 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
317 /** Sets the spoilers command
318 @param cmd spoilers command in percent*/
319 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
321 /** Sets the pitch trim command
322 @param cmd pitch trim command in percent*/
323 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
325 /** Sets the rudder trim command
326 @param cmd rudder trim command in percent*/
327 inline void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
329 /** Sets the aileron trim command
330 @param cmd aileron trim command in percent*/
331 inline void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
333 /** Sets the throttle command for the specified engine
334 @param engine engine ID number
335 @param cmd throttle command in percent (0 - 100)*/
336 void SetThrottleCmd(int engine, double cmd);
338 /** Sets the mixture command for the specified engine
339 @param engine engine ID number
340 @param cmd mixture command in percent (0 - 100)*/
341 void SetMixtureCmd(int engine, double cmd);
343 /** Set the gear extend/retract command, defaults to down
344 @param gear command 0 for up, 1 for down */
345 void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
347 /** Sets the propeller pitch command for the specified engine
348 @param engine engine ID number
349 @param cmd mixture command in percent (0.0 - 1.0)*/
350 void SetPropAdvanceCmd(int engine, double cmd);
353 /// @name Aerosurface position setting
355 /** Sets the aileron position
356 @param cmd aileron position in radians*/
357 inline void SetDaPos(double cmd) { DaPos = cmd; }
359 /** Sets the elevator position
360 @param cmd elevator position in radians*/
361 inline void SetDePos(double cmd) { DePos = cmd; }
363 /** Sets the rudder position
364 @param cmd rudder position in radians*/
365 inline void SetDrPos(double cmd) { DrPos = cmd; }
367 /** Sets the flaps position
368 @param cmd flaps position in radians*/
369 inline void SetDfPos(double cmd) { DfPos = cmd; }
371 /** Sets the speedbrake position
372 @param cmd speedbrake position in radians*/
373 inline void SetDsbPos(double cmd) { DsbPos = cmd; }
375 /** Sets the spoiler position
376 @param cmd spoiler position in radians*/
377 inline void SetDspPos(double cmd) { DspPos = cmd; }
379 /** Sets the actual throttle setting for the specified engine
380 @param engine engine ID number
381 @param cmd throttle setting in percent (0 - 100)*/
382 void SetThrottlePos(int engine, double cmd);
384 /** Sets the actual mixture setting for the specified engine
385 @param engine engine ID number
386 @param cmd mixture setting in percent (0 - 100)*/
387 void SetMixturePos(int engine, double cmd);
389 /** Set the gear extend/retract position, defaults to down
390 @param gear position 0 up, 1 down */
391 void SetGearPos(double gearpos) { GearPos = gearpos; }
394 /** Sets the actual prop pitch setting for the specified engine
395 @param engine engine ID number
396 @param cmd prop pitch setting in percent (0.0 - 1.0)*/
397 void SetPropAdvance(int engine, double cmd);
400 /// @name Landing Gear brakes
402 /** Sets the left brake group
403 @param cmd brake setting in percent (0.0 - 1.0) */
404 void SetLBrake(double cmd) {LeftBrake = cmd;}
406 /** Sets the right brake group
407 @param cmd brake setting in percent (0.0 - 1.0) */
408 void SetRBrake(double cmd) {RightBrake = cmd;}
410 /** Sets the center brake group
411 @param cmd brake setting in percent (0.0 - 1.0) */
412 void SetCBrake(double cmd) {CenterBrake = cmd;}
414 /** Gets the brake for a specified group.
415 @param bg which brakegroup to retrieve the command for
416 @return the brake setting for the supplied brake group argument */
417 double GetBrake(FGLGear::BrakeGroup bg);
420 /** Loads the Flight Control System.
421 The FGAircraft instance is actually responsible for reading the config file
422 and calling the various Loadxx() methods of the other systems, passing in
423 the config file instance pointer. LoadFCS() is called from FGAircraft.
424 @param AC_cfg pointer to the config file instance
425 @return true if succesful */
426 bool Load(FGConfigFile* AC_cfg);
428 void AddThrottle(void);
431 double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
432 double DaPos, DePos, DrPos, DfPos, DsbPos, DspPos;
433 double PTrimCmd, YTrimCmd, RTrimCmd;
434 vector <double> ThrottleCmd;
435 vector <double> ThrottlePos;
436 vector <double> MixtureCmd;
437 vector <double> MixturePos;
438 vector <double> PropAdvanceCmd;
439 vector <double> PropAdvance;
440 double LeftBrake, RightBrake, CenterBrake; // Brake settings
441 double GearCmd,GearPos;
443 vector <FGFCSComponent*> Components;
444 void Debug(int from);