]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/flight_control/FGSwitch.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / flight_control / FGSwitch.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGSwitch.h
4  Author:       Jon S. Berndt
5  Date started: 12/23/2002
6
7  ------------- Copyright (C) 2002 jon@jsbsim.org  -------------
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
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 "input_output/FGXMLElement.h"
42 #include "math/FGCondition.h"
43 #include "math/FGPropertyValue.h"
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 #define ID_SWITCH "$Id: FGSwitch.h,v 1.14 2011/04/05 20:20:21 andgi Exp $"
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 namespace JSBSim {
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 /** Encapsulates a switch for the flight control system.
62
63 The switch component models a switch - either on/off or a multi-choice rotary
64 switch. The switch can represent a physical cockpit switch, or can represent a
65 logical switch, where several conditions might need to be satisfied before a
66 particular state is reached. The value of the switch - the output value for the
67 component - is chosen depending on the state of the switch. Each switch is
68 comprised of one or more tests. Each test has a value associated with it. The
69 first test that evaluates to true will set the output value of the switch
70 according to the value parameter belonging to that test. Each test contains one
71 or more conditions, which each must be logically related (if there are more than
72 one) given the value of the logic attribute, and which takes the form:
73
74   property conditional property|value
75
76 e.g.
77
78   qbar ge 21.0
79
80 or,
81
82   roll_rate == pitch_rate
83
84 Within a test, additional tests can be specified, which allows for
85 complex groupings of logical comparisons. Each test contains
86 additional conditions, as well as possibly additional tests.
87
88 @code
89 <switch name="switch1">
90   <default value="{property|value}"/>
91   <test logic="{AND|OR}" value="{property|value}">
92     {property} {conditional} {property|value}
93     <test logic="{AND|OR}">
94       {property} {conditional} {property|value}
95       ...
96     </test>
97     ...
98   </test>
99   <test logic="{AND|OR}" value="{property|value}">
100     {property} {conditional} {property|value}
101     ...
102   </test>
103   ...
104   [<output> {property} </output>]
105 </switch>
106 @endcode
107
108 Here's an example:
109
110 @code
111 <switch name="roll a/p autoswitch">
112   <default value="0.0"/>
113   <test value="fcs/roll-ap-error-summer">
114     ap/attitude_hold == 1
115   </test>
116 </switch>
117 @endcode
118
119 Note: In the "logic" attribute, "AND" is the default logic, if none is supplied.
120
121 The above example specifies that the default value of the component (i.e. the
122 output property of the component, addressed by the property, ap/roll-ap-autoswitch)
123 is 0.0.  If or when the attitude hold switch is selected (property
124 ap/attitude_hold takes the value 1), the value of the switch component will be
125 whatever value fcs/roll-ap-error-summer is.
126
127 @author Jon S. Berndt
128 @version $Id: FGSwitch.h,v 1.14 2011/04/05 20:20:21 andgi Exp $
129 */
130
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 CLASS DECLARATION
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
134
135 class FGSwitch  : public FGFCSComponent
136 {
137 public:
138   /** Constructor
139       @param fcs a pointer to the parent FGFCS class
140       @param element a pointer to the Element (from the config file XML tree)
141              that represents this switch component */
142   FGSwitch(FGFCS* fcs, Element* element);
143
144   /// Destructor
145   ~FGSwitch();
146
147   /** Executes the switch logic.
148       @return true - always*/
149   bool Run(void);
150
151   enum eLogic {elUndef=0, eAND, eOR, eDefault};
152   enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
153
154 private:
155
156   struct test {
157     vector <FGCondition*> conditions;
158     eLogic Logic;
159     double OutputVal;
160     FGPropertyValue *OutputProp;
161     float sign;
162
163     double GetValue(void) {
164       if (OutputProp == 0L) return OutputVal;
165       else                  return OutputProp->GetValue()*sign;
166     }
167
168     test(void) { // constructor for the test structure
169       Logic      = elUndef;
170       OutputVal  = 0.0;
171       OutputProp = 0L;
172       sign       = 1.0;
173     }
174
175   };
176
177   vector <test*> tests;
178
179   void Debug(int from);
180 };
181 }
182 #endif