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 float GetDaCmd(void) { return DaCmd; }
176 /** Gets the elevator command.
177 @return elevator command in radians */
178 inline float GetDeCmd(void) { return DeCmd; }
180 /** Gets the rudder command.
181 @return rudder command in radians */
182 inline float GetDrCmd(void) { return DrCmd; }
184 /** Gets the flaps command.
185 @return flaps command in radians */
186 inline float GetDfCmd(void) { return DfCmd; }
188 /** Gets the speedbrake command.
189 @return speedbrake command in radians */
190 inline float GetDsbCmd(void) { return DsbCmd; }
192 /** Gets the spoiler command.
193 @return spoiler command in radians */
194 inline float 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 inline float GetThrottleCmd(int engine) { return ThrottleCmd[engine]; }
201 /** Gets the pitch trim command.
202 @return pitch trim command in radians */
203 inline float GetPitchTrimCmd(void) { return PTrimCmd; }
206 /// @name Aerosurface position retrieval
208 /** Gets the aileron position.
209 @return aileron position in radians */
210 inline float GetDaPos(void) { return DaPos; }
212 /** Gets the elevator position.
213 @return elevator position in radians */
214 inline float GetDePos(void) { return DePos; }
216 /** Gets the rudder position.
217 @return rudder position in radians */
218 inline float GetDrPos(void) { return DrPos; }
220 /** Gets the flaps position.
221 @return flaps position in radians */
222 inline float GetDfPos(void) { return DfPos; }
224 /** Gets the speedbrake position.
225 @return speedbrake position in radians */
226 inline float GetDsbPos(void) { return DsbPos; }
228 /** Gets the spoiler position.
229 @return spoiler position in radians */
230 inline float GetDspPos(void) { return DspPos; }
232 /** Gets the throttle position.
233 @param engine engine ID number
234 @return throttle position for the given engine in percent ( 0 - 100)*/
235 inline float GetThrottlePos(int engine) { return ThrottlePos[engine]; }
238 /** Retrieves the State object pointer.
239 This is used by the FGFCS-owned components.
240 @return pointer to the State object */
241 inline FGState* GetState(void) { return State; }
243 /** Retrieves a components output value
244 @param idx the index of the component (the component ID)
245 @return output value from the component */
246 float GetComponentOutput(eParam idx);
248 /** Retrieves the component name
249 @param idx the index of the component (the component ID)
250 @return name of the component */
251 string GetComponentName(int idx);
253 /** Retrieves all component names for inclusion in output stream */
254 string GetComponentStrings(void);
256 /** Retrieves all component outputs for inclusion in output stream */
257 string GetComponentValues(void);
259 /// @name Pilot input command setting
261 /** Sets the aileron command
262 @param cmd aileron command in radians*/
263 inline void SetDaCmd(float cmd) { DaCmd = cmd; }
265 /** Sets the elevator command
266 @param cmd elevator command in radians*/
267 inline void SetDeCmd(float cmd) { DeCmd = cmd; }
269 /** Sets the rudder command
270 @param cmd rudder command in radians*/
271 inline void SetDrCmd(float cmd) { DrCmd = cmd; }
273 /** Sets the flaps command
274 @param cmd flaps command in radians*/
275 inline void SetDfCmd(float cmd) { DfCmd = cmd; }
277 /** Sets the speedbrake command
278 @param cmd speedbrake command in radians*/
279 inline void SetDsbCmd(float cmd) { DsbCmd = cmd; }
281 /** Sets the spoilers command
282 @param cmd spoilers command in radians*/
283 inline void SetDspCmd(float cmd) { DspCmd = cmd; }
285 /** Sets the pitch trim command
286 @param cmd pitch trim command in radians*/
287 inline void SetPitchTrimCmd(float cmd) { PTrimCmd = cmd; }
289 /** Sets the throttle command for the specified engine
290 @param engine engine ID number
291 @param cmd throttle command in percent (0 - 100)*/
292 void SetThrottleCmd(int engine, float cmd);
295 /// @name Aerosurface position setting
297 /** Sets the aileron position
298 @param cmd aileron position in radians*/
299 inline void SetDaPos(float cmd) { DaPos = cmd; }
301 /** Sets the elevator position
302 @param cmd elevator position in radians*/
303 inline void SetDePos(float cmd) { DePos = cmd; }
305 /** Sets the rudder position
306 @param cmd rudder position in radians*/
307 inline void SetDrPos(float cmd) { DrPos = cmd; }
309 /** Sets the flaps position
310 @param cmd flaps position in radians*/
311 inline void SetDfPos(float cmd) { DfPos = cmd; }
313 /** Sets the speedbrake position
314 @param cmd speedbrake position in radians*/
315 inline void SetDsbPos(float cmd) { DsbPos = cmd; }
317 /** Sets the spoiler position
318 @param cmd spoiler position in radians*/
319 inline void SetDspPos(float cmd) { DspPos = cmd; }
321 /** Sets the actual throttle setting for the specified engine
322 @param engine engine ID number
323 @param cmd throttle setting in percent (0 - 100)*/
324 void SetThrottlePos(int engine, float cmd);
327 /// @name Landing Gear brakes
329 /** Sets the left brake group
330 @param cmd brake setting in percent (0.0 - 1.0) */
331 void SetLBrake(float cmd) {LeftBrake = cmd;}
333 /** Sets the right brake group
334 @param cmd brake setting in percent (0.0 - 1.0) */
335 void SetRBrake(float cmd) {RightBrake = cmd;}
337 /** Sets the center brake group
338 @param cmd brake setting in percent (0.0 - 1.0) */
339 void SetCBrake(float cmd) {CenterBrake = cmd;}
341 /** Gets the brake for a specified group.
342 @param bg which brakegroup to retrieve the command for
343 @return the brake setting for the supplied brake group argument */
344 float GetBrake(FGLGear::BrakeGroup bg);
347 /** Loads the Flight Control System.
348 The FGAircraft instance is actually responsible for reading the config file
349 and calling the various Loadxx() methods of the other systems, passing in
350 the config file instance pointer. LoadFCS() is called from FGAircraft.
351 @param AC_cfg pointer to the config file instance
352 @return true if succesful */
353 bool LoadFCS(FGConfigFile* AC_cfg);
355 /** The name of the flight control laws for this aircraft.
356 This is given in the config file, and is not used for anything currently.*/
359 void AddThrottle(void);
362 float DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
363 float DaPos, DePos, DrPos, DfPos, DsbPos, DspPos;
365 vector <float> ThrottleCmd;
366 vector <float> ThrottlePos;
367 float LeftBrake, RightBrake, CenterBrake; // Brake settings
369 vector <FGFCSComponent*> Components;