Branch data Line data Source code
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 : :
44 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 : : DEFINITIONS
46 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 : :
48 : : #define ID_SWITCH "$Id: FGSwitch.h,v 1.13 2009/10/02 10:30:09 jberndt Exp $"
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 one 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 attribute, 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, additional tests can be specified, which allows for
84 : : complex groupings of logical comparisons. Each test contains
85 : : additional conditions, as well as possibly additional tests.
86 : :
87 : : @code
88 : : <switch name="switch1">
89 : : <default value="{property|value}"/>
90 : : <test logic="{AND|OR}" value="{property|value}">
91 : : {property} {conditional} {property|value}
92 : : <test logic="{AND|OR}">
93 : : {property} {conditional} {property|value}
94 : : ...
95 : : </test>
96 : : ...
97 : : </test>
98 : : <test logic="{AND|OR}" value="{property|value}">
99 : : {property} {conditional} {property|value}
100 : : ...
101 : : </test>
102 : : ...
103 : : [<output> {property} </output>]
104 : : </switch>
105 : : @endcode
106 : :
107 : : Here's an example:
108 : :
109 : : @code
110 : : <switch name="roll a/p autoswitch">
111 : : <default value="0.0"/>
112 : : <test value="fcs/roll-ap-error-summer">
113 : : ap/attitude_hold == 1
114 : : </test>
115 : : </switch>
116 : : @endcode
117 : :
118 : : Note: In the "logic" attribute, "AND" is the default logic, if none is supplied.
119 : :
120 : : The above example specifies that the default value of the component (i.e. the
121 : : output property of the component, addressed by the property, ap/roll-ap-autoswitch)
122 : : is 0.0. If or when the attitude hold switch is selected (property
123 : : ap/attitude_hold takes the value 1), the value of the switch component will be
124 : : whatever value fcs/roll-ap-error-summer is.
125 : :
126 : : @author Jon S. Berndt
127 : : @version $Id: FGSwitch.h,v 1.13 2009/10/02 10:30:09 jberndt Exp $
128 : : */
129 : :
130 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 : : CLASS DECLARATION
132 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
133 : :
134 : : class FGSwitch : public FGFCSComponent
135 : : {
136 : : public:
137 : : /** Constructor
138 : : @param fcs a pointer to the parent FGFCS class
139 : : @param element a pointer to the Element (from the config file XML tree)
140 : : that represents this switch component */
141 : : FGSwitch(FGFCS* fcs, Element* element);
142 : :
143 : : /// Destructor
144 : : ~FGSwitch();
145 : :
146 : : /** Executes the switch logic.
147 : : @return true - always*/
148 : : bool Run(void);
149 : :
150 : : enum eLogic {elUndef=0, eAND, eOR, eDefault};
151 : : enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
152 : :
153 : : private:
154 : :
155 : 35 : struct test {
156 : : vector <FGCondition*> conditions;
157 : : eLogic Logic;
158 : : double OutputVal;
159 : : FGPropertyManager *OutputProp;
160 : : float sign;
161 : :
162 : : double GetValue(void) {
163 [ + + ][ + + ]: 1402177 : if (OutputProp == 0L) return OutputVal;
164 : 252454 : else return OutputProp->getDoubleValue()*sign;
165 : : }
166 : :
167 : 35 : test(void) { // constructor for the test structure
168 : 35 : Logic = elUndef;
169 : 35 : OutputVal = 0.0;
170 : 35 : OutputProp = 0L;
171 : 35 : sign = 1.0;
172 : : }
173 : :
174 : : };
175 : :
176 : : vector <test*> tests;
177 : :
178 : : void Debug(int from);
179 : : };
180 : : }
181 : : #endif
|