]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGSwitch.h
Make yasim accept the launchbar and hook properties. They are not tied to anything...
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGSwitch.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGSwitch.h
4  Author:       Jon S. Berndt
5  Date started: 12/23/2002
6
7  ------------- Copyright (C)  -------------
8
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
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 General Public License for more
17  details.
18
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33 #ifndef FGSWITCH_H
34 #define FGSWITCH_H
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCSComponent.h"
41 #include "../FGConfigFile.h"
42 #include "FGCondition.h"
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #define ID_SWITCH "$Id$"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FORWARD DECLARATIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 namespace JSBSim {
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS DOCUMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 /** Encapsulates a switch for the flight control system.
61
62 The SWITCH component models a switch - either on/off or a multi-choice rotary
63 switch. The switch can represent a physical cockpit switch, or can represent a
64 logical switch, where several conditions might need to be satisfied before a
65 particular state is reached. The VALUE of the switch - the output value for the
66 component - is chosen depending on the state of the switch. Each switch is
67 comprised of two or more TESTs. Each TEST has a VALUE associated with it. The
68 first TEST that evaluates to TRUE will set the output value of the switch
69 according to the VALUE parameter belonging to that TEST. Each TEST contains one
70 or more CONDITIONS, which each must be logically related (if there are more than
71 one) given the value of the LOGIC parameter, and which takes the form:
72
73   property conditional property|value
74
75 e.g.
76
77   qbar GE 21.0
78
79 or,
80
81   roll_rate < pitch_rate
82
83 Within a TEST, a CONDITION_GROUP can be specified. A CONDITION_GROUP allows for
84 complex groupings of logical comparisons. Each CONDITION_GROUP contains
85 additional conditions, as well as possibly additional CONDITION_GROUPs.
86
87 <pre>
88 \<COMPONENT NAME="switch1" TYPE="SWITCH"\>
89   \<TEST LOGIC="{AND|OR|DEFAULT}" VALUE="{property|value}"\>
90     {property} {conditional} {property|value}
91     \<CONDITION_GROUP LOGIC="{AND|OR}"\>
92       {property} {conditional} {property|value}
93       ...
94     \</CONDITION_GROUP\>
95     ...
96   \</TEST>
97   \<TEST LOGIC="{AND|OR}" VALUE="{property|value}"\>
98     {property} {conditional} {property|value}
99     ...
100   \</TEST\>
101   ...
102   [OUTPUT \<property>]
103 \</COMPONENT\>
104 </pre>
105
106 Here's an example:
107 <pre>
108 \<COMPONENT NAME="Roll A/P Autoswitch" TYPE="SWITCH">
109   \<TEST LOGIC="DEFAULT" VALUE="0.0">
110   \</TEST>
111   \<TEST LOGIC="AND" VALUE="fcs/roll-ap-error-summer">
112     ap/attitude_hold == 1
113   \</TEST>
114 \</COMPONENT>
115 </pre>
116 The above example specifies that the default value of the component (i.e. the
117 output property of the component, addressed by the property, ap/roll-ap-autoswitch)
118 is 0.0.  If or when the attitude hold switch is selected (property
119 ap/attitude_hold takes the value 1), the value of the switch component will be
120 whatever value fcs/roll-ap-error-summer is.
121 @author Jon S. Berndt
122 @version $Id$
123 */
124
125 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 CLASS DECLARATION
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
128
129 class FGSwitch  : public FGFCSComponent
130 {
131 public:
132   FGSwitch(FGFCS* fcs, FGConfigFile* AC_cfg);
133   ~FGSwitch();
134
135   bool Run(void);
136
137   enum eLogic {elUndef=0, eAND, eOR, eDefault};
138   enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
139
140 private:
141   FGFCS* fcs;
142   FGConfigFile* AC_cfg;
143
144   struct test {
145     vector <FGCondition> conditions;
146     eLogic Logic;
147     double OutputVal;
148     FGPropertyManager *OutputProp;
149     float sign;
150
151     double GetValue(void) {
152       if (OutputProp == 0L) return OutputVal;
153       else                  return OutputProp->getDoubleValue()*sign;
154     }
155
156     test(void) { // constructor for the test structure
157       Logic      = elUndef;
158       OutputVal  = 0.0;
159       OutputProp = 0L;
160       sign       = 1.0;
161     }
162
163   };
164
165   vector <test> tests;
166
167   void Debug(int from);
168 };
169 }
170 #endif