Debian Codegraph @

src/FDM/JSBSim/models/FGFCS.h

raw symbols SCIP
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Header: FGGFCS.h
4 Author: Jon S. Berndt
5 Date started: 12/12/98
6
7 ------------- Copyright (C) 1999 Jon S. Berndt ([email protected]) -------------
8
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13
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 Lesser General Public License for more
17 details.
18
19 You should have received a copy of the GNU Lesser 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.
22
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 12/12/98 JSB Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGFCS_H
35 #define FGFCS_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <iosfwd>
42 #include <vector>
43 #include <string>
44
45 #include "models/FGModel.h"
46 #include "models/FGLGear.h"
47 #include "models/FGGroundReactions.h"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 class FGFCSChannel;
56 typedef enum { ofRad=0, ofDeg, ofNorm, ofMag , NForms} OutputForm;
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 CLASS DOCUMENTATION
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 /** Encapsulates the Flight Control System (FCS) functionality.
63 This class also encapsulates the identical "system" and "autopilot" capability.
64 FGFCS owns and contains the list of FGFCSComponents
65 that define a system or systems for the modeled aircraft. The config file
66 for the aircraft contains a description of the control path that starts at
67 an input or command and ends at an effector, e.g. an aerosurface. The FCS
68 components which comprise the control laws for an axis are defined
69 sequentially in the configuration file. For instance, for the X-15:
70
71 @code
72 <flight_control name="X-15 SAS">
73 <channel>
74 <summer name="Pitch Trim Sum">
75 <input> fcs/elevator-cmd-norm </input>
76 <input> fcs/pitch-trim-cmd-norm </input>
77 <clipto>
78 <min>-1</min>
79 <max>1</max>
80 </clipto>
81 </summer>
82
83 <aerosurface_scale name="Pitch Command Scale">
84 <input> fcs/pitch-trim-sum </input>
85 <range>
86 <min> -50 </min>
87 <max> 50 </max>
88 </range>
89 </aerosurface_scale>
90
91 ... etc.
92 @endcode
93
94 In the above case we can see the first few components of the pitch channel
95 defined. The input to the first component (a summer), as can be seen in the "Pitch trim
96 sum" component, is really the sum of two parameters: elevator command (from
97 the stick - a pilot input), and pitch trim.
98 The next component created is an aerosurface scale component - a type of
99 gain (see the LoadFCS() method for insight on how the various types of
100 components map into the actual component classes). This continues until the
101 final component for an axis when the
102 \<output> element is usually used to specify where the output is supposed to go. See the
103 individual components for more information on how they are mechanized.
104
105 Another option for the flight controls portion of the config file is that in
106 addition to using the "NAME" attribute in,
107
108 @code
109 <flight_control name="X-15 SAS">
110 @endcode
111
112 one can also supply a filename:
113
114 @code
115 <flight_control name="X-15 SAS" file="X15.xml">
116 </flight_control>
117 @endcode
118
119 In this case, the FCS would be read in from another file.
120
121 <h2>Properties</h2>
122 @property fcs/aileron-cmd-norm normalized aileron command
123 @property fcs/elevator-cmd-norm normalized elevator command
124 @property fcs/rudder-cmd-norm
125 @property fcs/steer-cmd-norm
126 @property fcs/flap-cmd-norm
127 @property fcs/speedbrake-cmd-norm
128 @property fcs/spoiler-cmd-norm
129 @property fcs/pitch-trim-cmd-norm
130 @property fcs/roll-trim-cmd-norm
131 @property fcs/yaw-trim-cmd-norm
132 @property gear/gear-cmd-norm
133 @property fcs/left-aileron-pos-rad
134 @property fcs/left-aileron-pos-deg
135 @property fcs/left-aileron-pos-norm
136 @property fcs/mag-left-aileron-pos-rad
137 @property fcs/right-aileron-pos-rad
138 @property fcs/right-aileron-pos-deg
139 @property fcs/right-aileron-pos-norm
140 @property fcs/mag-right-aileron-pos-rad
141 @property fcs/elevator-pos-rad
142 @property fcs/elevator-pos-deg
143 @property fcs/elevator-pos-norm
144 @property fcs/mag-elevator-pos-rad
145 @property fcs/rudder-pos-rad
146 @property fcs/rudder-pos-deg
147 @property fcs/rudder-pos-norm
148 @property fcs/mag-rudder-pos-rad
149 @property fcs/flap-pos-rad
150 @property fcs/flap-pos-deg
151 @property fcs/flap-pos-norm
152 @property fcs/speedbrake-pos-rad
153 @property fcs/speedbrake-pos-deg
154 @property fcs/speedbrake-pos-norm
155 @property fcs/mag-speedbrake-pos-rad
156 @property fcs/spoiler-pos-rad
157 @property fcs/spoiler-pos-deg
158 @property fcs/spoiler-pos-norm
159 @property fcs/mag-spoiler-pos-rad
160 @property fcs/wing-fold-pos-norm
161 @property gear/gear-pos-norm
162 @property gear/tailhook-pos-norm
163
164 @author Jon S. Berndt
165 @version $Revision: 1.55 $
166 @see FGActuator
167 @see FGDeadBand
168 @see FGFCSFunction
169 @see FGFilter
170 @see FGGain
171 @see FGKinemat
172 @see FGPID
173 @see FGSensor
174 @see FGSummer
175 @see FGSwitch
176 @see FGWaypoint
177 @see FGAngles
178 @see FGFCSComponent
179 @see Element
180 @see FGDistributor
181 */
182
183 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 CLASS DECLARATION
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
186
187 class JSBSIM_API FGFCS : public FGModel
188 {
189
190 public:
191 /** Constructor
192 @param Executive a pointer to the parent executive object */
193 FGFCS(FGFDMExec*);
194 /// Destructor
195 ~FGFCS() override;
196
197 bool InitModel(void) override;
198
199 /** Runs the Flight Controls model; called by the Executive
200 Can pass in a value indicating if the executive is directing the simulation to Hold.
201 @param Holding if true, the executive has been directed to hold the sim from
202 advancing time. Some models may ignore this flag, such as the Input
203 model, which may need to be active to listen on a socket for the
204 "Resume" command to be given.
205 @return false if no error */
206 bool Run(bool Holding) override;
207
208 /// @name Pilot input command retrieval
209 //@{
210 /** Gets the aileron command.
211 @return aileron command in range from -1.0 - 1.0 */
212 double GetDaCmd(void) const { return DaCmd; }
213
214 /** Gets the elevator command.
215 @return elevator command in range from -1.0 - 1.0 */
216 double GetDeCmd(void) const { return DeCmd; }
217
218 /** Gets the rudder command.
219 @return rudder command in range from -1.0 - 1.0 */
220 double GetDrCmd(void) const { return DrCmd; }
221
222 /** Gets the steering command.
223 @return steering command in range from -1.0 - 1.0 */
224 double GetDsCmd(void) const { return fdmex->GetGroundReactions()->GetDsCmd(); }
225
226 /** Gets the flaps command.
227 @return flaps command in range from 0 to 1.0 */
228 double GetDfCmd(void) const { return DfCmd; }
229
230 /** Gets the speedbrake command.
231 @return speedbrake command in range from 0 to 1.0 */
232 double GetDsbCmd(void) const { return DsbCmd; }
233
234 /** Gets the spoiler command.
235 @return spoiler command in range from 0 to 1.0 */
236 double GetDspCmd(void) const { return DspCmd; }
237
238 /** Gets the throttle command.
239 @param engine engine ID number
240 @return throttle command in range from 0 - 1.0 for the given engine */
241 double GetThrottleCmd(int engine) const;
242
243 const std::vector<double>& GetThrottleCmd() const {return ThrottleCmd;}
244
245 /** Gets the mixture command.
246 @param engine engine ID number
247 @return mixture command in range from 0 - 1.0 for the given engine */
248 double GetMixtureCmd(int engine) const { return MixtureCmd[engine]; }
249
250 const std::vector<double>& GetMixtureCmd() const {return MixtureCmd;}
251
252 /** Gets the prop pitch command.
253 @param engine engine ID number
254 @return pitch command in range from 0.0 - 1.0 for the given engine */
255 double GetPropAdvanceCmd(int engine) const { return PropAdvanceCmd[engine]; }
256
257 /** Gets the prop feather command.
258 @param engine engine ID number
259 @return feather command for the given engine (on / off)*/
260 bool GetFeatherCmd(int engine) const { return PropFeatherCmd[engine]; }
261
262 /** Gets the pitch trim command.
263 @return pitch trim command in range from -1.0 to 1.0 */
264 double GetPitchTrimCmd(void) const { return PTrimCmd; }
265
266 /** Gets the rudder trim command.
267 @return rudder trim command in range from -1.0 - 1.0 */
268 double GetYawTrimCmd(void) const { return YTrimCmd; }
269
270 /** Gets the aileron trim command.
271 @return aileron trim command in range from -1.0 - 1.0 */
272 double GetRollTrimCmd(void) const { return RTrimCmd; }
273
274 /** Get the gear extend/retract command. 0 commands gear up, 1 down.
275 defaults to down.
276 @return the current value of the gear extend/retract command*/
277 double GetGearCmd(void) const { return GearCmd; }
278 //@}
279
280 /// @name Aerosurface position retrieval
281 //@{
282 /** Gets the left aileron position.
283 @return aileron position in radians */
284 double GetDaLPos( int form = ofRad )
285 const { return DaLPos[form]; }
286
287 /** Gets the right aileron position.
288 @return aileron position in radians */
289 double GetDaRPos( int form = ofRad )
290 const { return DaRPos[form]; }
291
292 /** Gets the elevator position.
293 @return elevator position in radians */
294 double GetDePos( int form = ofRad )
295 const { return DePos[form]; }
296
297 /** Gets the rudder position.
298 @return rudder position in radians */
299 double GetDrPos( int form = ofRad )
300 const { return DrPos[form]; }
301
302 /** Gets the speedbrake position.
303 @return speedbrake position in radians */
304 double GetDsbPos( int form = ofRad )
305 const { return DsbPos[form]; }
306
307 /** Gets the spoiler position.
308 @return spoiler position in radians */
309 double GetDspPos( int form = ofRad )
310 const { return DspPos[form]; }
311
312 /** Gets the flaps position.
313 @return flaps position in radians */
314 double GetDfPos( int form = ofRad )
315 const { return DfPos[form]; }
316
317 /** Gets the throttle position.
318 @param engine engine ID number
319 @return throttle position for the given engine in range from 0 - 1.0 */
320 double GetThrottlePos(int engine) const;
321
322 const std::vector<double>& GetThrottlePos() const {return ThrottlePos;}
323
324 /** Gets the mixture position.
325 @param engine engine ID number
326 @return mixture position for the given engine in range from 0 - 1.0 */
327 double GetMixturePos(int engine) const { return MixturePos[engine]; }
328
329 const std::vector<double>& GetMixturePos() const {return MixturePos;}
330
331 /** Gets the gear position (0 up, 1 down), defaults to down
332 @return gear position (0 up, 1 down) */
333 double GetGearPos(void) const { return GearPos; }
334
335 /** Gets the tailhook position (0 up, 1 down)
336 @return tailhook position (0 up, 1 down) */
337 double GetTailhookPos(void) const { return TailhookPos; }
338
339 /** Gets the wing fold position (0 unfolded, 1 folded)
340 @return wing fold position (0 unfolded, 1 folded) */
341 double GetWingFoldPos(void) const { return WingFoldPos; }
342
343 /** Gets the prop pitch position.
344 @param engine engine ID number
345 @return prop pitch position for the given engine in range from 0 - 1.0 */
346 double GetPropAdvance(int engine) const { return PropAdvance[engine]; }
347
348 const std::vector<double>& GetPropAdvance() const { return PropAdvance; }
349
350 /** Gets the prop feather position.
351 @param engine engine ID number
352 @return prop fether for the given engine (on / off)*/
353 bool GetPropFeather(int engine) const { return PropFeather[engine]; }
354
355 const std::vector<bool>& GetPropFeather() const { return PropFeather; }
356 //@}
357
358 /** Retrieves all component names for inclusion in output stream
359 @param delimiter either a tab or comma string depending on output type
360 @return a string containing the descriptive names for all components */
361 std::string GetComponentStrings(const std::string& delimiter) const;
362
363 /** Retrieves all component outputs for inclusion in output stream
364 @param delimiter either a tab or comma string depending on output type
365 @return a string containing the numeric values for the current set of
366 component outputs */
367 std::string GetComponentValues(const std::string& delimiter) const;
368
369 /// @name Pilot input command setting
370 //@{
371 /** Sets the aileron command
372 @param cmd aileron command */
373 void SetDaCmd( double cmd ) { DaCmd = cmd; }
374
375 /** Sets the elevator command
376 @param cmd elevator command in percent*/
377 void SetDeCmd(double cmd ) { DeCmd = cmd; }
378
379 /** Sets the rudder command
380 @param cmd rudder command in percent*/
381 void SetDrCmd(double cmd) { DrCmd = cmd; }
382
383 /** Sets the steering command
384 @param cmd steering command in percent*/
385 void SetDsCmd(double cmd) { fdmex->GetGroundReactions()->SetDsCmd( cmd ); }
386
387 /** Sets the flaps command
388 @param cmd flaps command in percent*/
389 void SetDfCmd(double cmd) { DfCmd = cmd; }
390
391 /** Sets the speedbrake command
392 @param cmd speedbrake command in percent*/
393 void SetDsbCmd(double cmd) { DsbCmd = cmd; }
394
395 /** Sets the spoilers command
396 @param cmd spoilers command in percent*/
397 void SetDspCmd(double cmd) { DspCmd = cmd; }
398
399 /** Sets the pitch trim command
400 @param cmd pitch trim command in percent*/
401 void SetPitchTrimCmd(double cmd) { PTrimCmd = cmd; }
402
403 /** Sets the rudder trim command
404 @param cmd rudder trim command in percent*/
405 void SetYawTrimCmd(double cmd) { YTrimCmd = cmd; }
406
407 /** Sets the aileron trim command
408 @param cmd aileron trim command in percent*/
409 void SetRollTrimCmd(double cmd) { RTrimCmd = cmd; }
410
411 /** Sets the throttle command for the specified engine
412 @param engine engine ID number
413 @param cmd normalized throttle command (0.0 - 1.0)*/
414 void SetThrottleCmd(int engine, double cmd);
415
416 /** Sets the mixture command for the specified engine
417 @param engine engine ID number
418 @param cmd normalized mixture command (0.0 - 1.0)*/
419 void SetMixtureCmd(int engine, double cmd);
420
421 /** Set the gear extend/retract command, defaults to down
422 @param gear command 0 for up, 1 for down */
423 void SetGearCmd(double gearcmd) { GearCmd = gearcmd; }
424
425 /** Sets the propeller pitch command for the specified engine
426 @param engine engine ID number
427 @param cmd pitch command in percent (0.0 - 1.0)*/
428 void SetPropAdvanceCmd(int engine, double cmd);
429
430 /** Sets the propeller feather command for the specified engine
431 @param engine engine ID number
432 @param cmd feather (bool)*/
433 void SetFeatherCmd(int engine, bool cmd);
434 //@}
435
436 /// @name Aerosurface position setting
437 //@{
438 /** Sets the left aileron position
439 @param cmd left aileron position in radians*/
440 void SetDaLPos( int form , double pos );
441
442 /** Sets the right aileron position
443 @param cmd right aileron position in radians*/
444 void SetDaRPos( int form , double pos );
445
446 /** Sets the elevator position
447 @param cmd elevator position in radians*/
448 void SetDePos( int form , double pos );
449
450 /** Sets the rudder position
451 @param cmd rudder position in radians*/
452 void SetDrPos( int form , double pos );
453
454 /** Sets the flaps position
455 @param cmd flaps position in radians*/
456 void SetDfPos( int form , double pos );
457
458 /** Sets the speedbrake position
459 @param cmd speedbrake position in radians*/
460 void SetDsbPos( int form , double pos );
461
462 /** Sets the spoiler position
463 @param cmd spoiler position in radians*/
464 void SetDspPos( int form , double pos );
465
466 /** Sets the actual throttle setting for the specified engine
467 @param engine engine ID number
468 @param cmd normalized throttle setting (0.0 - 1.0)*/
469 void SetThrottlePos(int engine, double cmd);
470
471 /** Sets the actual mixture setting for the specified engine
472 @param engine engine ID number
473 @param cmd normalized mixture setting (0.0 - 1.0)*/
474 void SetMixturePos(int engine, double cmd);
475
476 /** Set the gear extend/retract position, defaults to down
477 @param gear position 0 up, 1 down */
478 void SetGearPos(double gearpos) { GearPos = gearpos; }
479
480 /** Set the tailhook position
481 @param tailhook position 0 up, 1 down */
482 void SetTailhookPos(double hookpos) { TailhookPos = hookpos; }
483
484 /** Set the wing fold position
485 @param wing fold position 0 unfolded, 1 folded */
486 void SetWingFoldPos(double foldpos) { WingFoldPos = foldpos; }
487
488 /** Sets the actual prop pitch setting for the specified engine
489 @param engine engine ID number
490 @param cmd prop pitch setting in percent (0.0 - 1.0)*/
491 void SetPropAdvance(int engine, double cmd);
492
493 /** Sets the actual prop feather setting for the specified engine
494 @param engine engine ID number
495 @param cmd prop fether setting (bool)*/
496 void SetPropFeather(int engine, bool cmd);
497 //@}
498
499 /// @name Landing Gear brakes
500 //@{
501 /** Sets the left brake group
502 @param cmd brake setting in percent (0.0 - 1.0) */
503 void SetLBrake(double cmd) {BrakePos[FGLGear::bgLeft] = cmd;}
504
505 /** Sets the right brake group
506 @param cmd brake setting in percent (0.0 - 1.0) */
507 void SetRBrake(double cmd) {BrakePos[FGLGear::bgRight] = cmd;}
508
509 /** Sets the center brake group
510 @param cmd brake setting in percent (0.0 - 1.0) */
511 void SetCBrake(double cmd) {BrakePos[FGLGear::bgCenter] = cmd;}
512
513 /** Gets the brake for a specified group.
514 @param bg which brakegroup to retrieve the command for
515 @return the brake setting for the supplied brake group argument */
516 double GetBrake(FGLGear::BrakeGroup bg);
517
518 const std::vector<double>& GetBrakePos() const {return BrakePos;}
519
520 /** Gets the left brake.
521 @return the left brake setting. */
522 double GetLBrake(void) const {return BrakePos[FGLGear::bgLeft];}
523
524 /** Gets the right brake.
525 @return the right brake setting. */
526 double GetRBrake(void) const {return BrakePos[FGLGear::bgRight];}
527
528 /** Gets the center brake.
529 @return the center brake setting. */
530 double GetCBrake(void) const {return BrakePos[FGLGear::bgCenter];}
531 //@}
532
533 enum SystemType { stFCS, stSystem, stAutoPilot };
534
535 /** Loads the Flight Control System.
536 Load() is called from FGFDMExec.
537 @param el pointer to the Element instance
538 @return true if succesful */
539 bool Load(Element* el) override;
540
541 SGPath FindFullPathName(const SGPath& path) const override;
542
543 void AddThrottle(void);
544 double GetDt(void) const;
545
546 FGPropertyManager* GetPropertyManager(void) { return PropertyManager; }
547
548 bool GetTrimStatus(void) const { return FDMExec->GetTrimStatus(); }
549 double GetChannelDeltaT(void) const { return GetDt() * ChannelRate; }
550
551 private:
552 double DaCmd, DeCmd, DrCmd, DfCmd, DsbCmd, DspCmd;
553 double DePos[NForms], DaLPos[NForms], DaRPos[NForms], DrPos[NForms];
554 double DfPos[NForms], DsbPos[NForms], DspPos[NForms];
555 double PTrimCmd, YTrimCmd, RTrimCmd;
556 std::vector <double> ThrottleCmd;
557 std::vector <double> ThrottlePos;
558 std::vector <double> MixtureCmd;
559 std::vector <double> MixturePos;
560 std::vector <double> PropAdvanceCmd;
561 std::vector <double> PropAdvance;
562 std::vector <bool> PropFeatherCmd;
563 std::vector <bool> PropFeather;
564 //double LeftBrake, RightBrake, CenterBrake; // Brake settings
565 std::vector <double> BrakePos; // left, center, right - defined by FGLGear:: enum
566 double GearCmd,GearPos;
567 double TailhookPos, WingFoldPos;
568 SystemType systype;
569 int ChannelRate;
570 FGFDMExec* fdmex;
571
572 typedef std::vector <FGFCSChannel*> Channels;
573 Channels SystemChannels;
574 void bind(void);
575 void bindThrottle(unsigned int);
576 void Debug(int from) override;
577 };
578 }
579
580 #endif