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
153 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
157 class FGFCS : public FGModel {
161 @param Executive a pointer to the parent executive object */
166 /** Runs the Flight Controls model; called by the Executive
167 @return false if no error */
170 /// @name Pilot input command retrieval
172 /** Gets the aileron command.
173 @return aileron command in radians */
174 inline double GetDaCmd(void) { return DaCmd; }
176 /** Gets the elevator command.
177 @return elevator command in radians */
178 inline double GetDeCmd(void) { return DeCmd; }
180 /** Gets the rudder command.
181 @return rudder command in radians */
182 inline double GetDrCmd(void) { return DrCmd; }
184 /** Gets the flaps command.
185 @return flaps command in radians */
186 inline double GetDfCmd(void) { return DfCmd; }
188 /** Gets the speedbrake command.
189 @return speedbrake command in radians */
190 inline double GetDsbCmd(void) { return DsbCmd; }
192 /** Gets the spoiler command.
193 @return spoiler command in radians */
194 inline double GetDspCmd(void) { return DspCmd; }
196 /** Gets the throttle command.
197 @param engine engine ID number
198 @return throttle command in percent ( 0 - 100) for the given engine */
199 double GetThrottleCmd(int engine);
201 /** Gets the mixture command.
202 @param engine engine ID number
203 @return mixture command in percent ( 0 - 100) for the given engine */
204 inline double GetMixtureCmd(int engine) { return MixtureCmd[engine]; }
206 /** Gets the pitch trim command.
207 @return pitch trim command in radians */
208 inline double GetPitchTrimCmd(void) { return PTrimCmd; }
211 /// @name Aerosurface position retrieval
213 /** Gets the aileron position.
214 @return aileron position in radians */
215 inline double GetDaPos(void) { return DaPos; }
217 /** Gets the elevator position.
218 @return elevator position in radians */
219 inline double GetDePos(void) { return DePos; }
221 /** Gets the rudder position.
222 @return rudder position in radians */
223 inline double GetDrPos(void) { return DrPos; }
225 /** Gets the flaps position.
226 @return flaps position in radians */
227 inline double GetDfPos(void) { return DfPos; }
229 /** Gets the speedbrake position.
230 @return speedbrake position in radians */
231 inline double GetDsbPos(void) { return DsbPos; }
233 /** Gets the spoiler position.
234 @return spoiler position in radians */
235 inline double GetDspPos(void) { return DspPos; }
237 /** Gets the throttle position.
238 @param engine engine ID number
239 @return throttle position for the given engine in percent ( 0 - 100)*/
240 double GetThrottlePos(int engine);
242 /** Gets the mixture position.
243 @param engine engine ID number
244 @return mixture position for the given engine in percent ( 0 - 100)*/
245 inline double GetMixturePos(int engine) { return MixturePos[engine]; }
248 /** Retrieves the State object pointer.
249 This is used by the FGFCS-owned components.
250 @return pointer to the State object */
251 inline FGState* GetState(void) { return State; }
253 /** Retrieves a components output value
254 @param idx the index of the component (the component ID)
255 @return output value from the component */
256 double GetComponentOutput(eParam idx);
258 /** Retrieves the component name
259 @param idx the index of the component (the component ID)
260 @return name of the component */
261 string GetComponentName(int idx);
263 /** Retrieves all component names for inclusion in output stream */
264 string GetComponentStrings(void);
266 /** Retrieves all component outputs for inclusion in output stream */
267 string GetComponentValues(void);
269 /// @name Pilot input command setting
271 /** Sets the aileron command
272 @param cmd aileron command in radians*/
273 inline void SetDaCmd(double cmd) { DaCmd = cmd; }
275 /** Sets the elevator command
276 @param cmd elevator command in radians*/
277 inline void SetDeCmd(double cmd) { DeCmd = cmd; }
279 /** Sets the rudder command
280 @param cmd rudder command in radians*/
281 inline void SetDrCmd(double cmd) { DrCmd = cmd; }
283 /** Sets the flaps command
284 @param cmd flaps command in radians*/
285 inline void SetDfCmd(double cmd) { DfCmd = cmd; }
287 /** Sets the speedbrake command
288 @param cmd speedbrake command in radians*/
289 inline void SetDsbCmd(double cmd) { DsbCmd = cmd; }
291 /** Sets the spoilers command
292 @param cmd spoilers command in radians*/
293 inline void SetDspCmd(double cmd) { DspCmd = cmd; }
295 /** Sets the pitch trim command
296 @param cmd pitch trim command in radians*/
297 inline void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
299 /** Sets the throttle command for the specified engine
300 @param engine engine ID number
301 @param cmd throttle command in percent (0 - 100)*/
302 void SetThrottleCmd(int engine, double cmd);
304 /** Sets the mixture command for the specified engine
305 @param engine engine ID number
306 @param cmd mixture command in percent (0 - 100)*/
307 void SetMixtureCmd(int engine, double cmd);
310 /// @name Aerosurface position setting
312 /** Sets the aileron position
313 @param cmd aileron position in radians*/
314 inline void SetDaPos(double cmd) { DaPos = cmd; }
316 /** Sets the elevator position
317 @param cmd elevator position in radians*/
318 inline void SetDePos(double cmd) { DePos = cmd; }
320 /** Sets the rudder position
321 @param cmd rudder position in radians*/
322 inline void SetDrPos(double cmd) { DrPos = cmd; }
324 /** Sets the flaps position
325 @param cmd flaps position in radians*/
326 inline void SetDfPos(double cmd) { DfPos = cmd; }
328 /** Sets the speedbrake position
329 @param cmd speedbrake position in radians*/
330 inline void SetDsbPos(double cmd) { DsbPos = cmd; }
332 /** Sets the spoiler position
333 @param cmd spoiler position in radians*/
334 inline void SetDspPos(double cmd) { DspPos = cmd; }
336 /** Sets the actual throttle setting for the specified engine
337 @param engine engine ID number
338 @param cmd throttle setting in percent (0 - 100)*/
339 void SetThrottlePos(int engine, double cmd);
341 /** Sets the actual mixture setting for the specified engine
342 @param engine engine ID number
343 @param cmd mixture setting in percent (0 - 100)*/
344 void SetMixturePos(int engine, double cmd);
347 /// @name Landing Gear brakes
349 /** Sets the left brake group
350 @param cmd brake setting in percent (0.0 - 1.0) */
351 void SetLBrake(double cmd) {LeftBrake = cmd;}
353 /** Sets the right brake group
354 @param cmd brake setting in percent (0.0 - 1.0) */
355 void SetRBrake(double cmd) {RightBrake = cmd;}
357 /** Sets the center brake group
358 @param cmd brake setting in percent (0.0 - 1.0) */
359 void SetCBrake(double cmd) {CenterBrake = cmd;}
361 /** Gets the brake for a specified group.
362 @param bg which brakegroup to retrieve the command for
363 @return the brake setting for the supplied brake group argument */
364 double GetBrake(FGLGear::BrakeGroup bg);
367 /** Loads the Flight Control System.
368 The FGAircraft instance is actually responsible for reading the config file
369 and calling the various Loadxx() methods of the other systems, passing in
370 the config file instance pointer. LoadFCS() is called from FGAircraft.
371 @param AC_cfg pointer to the config file instance
372 @return true if succesful */
373 bool Load(FGConfigFile* AC_cfg);
375 void AddThrottle(void);
378 double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
379 double DaPos, DePos, DrPos, DfPos, DsbPos, DspPos;
381 vector <double> ThrottleCmd;
382 vector <double> ThrottlePos;
383 vector <double> MixtureCmd;
384 vector <double> MixturePos;
385 double LeftBrake, RightBrake, CenterBrake; // Brake settings
387 vector <FGFCSComponent*> Components;