1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 12/23/2002
7 ------------- Copyright (C) 2002 jon@jsbsim.org -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGFCSComponent.h"
41 #include "input_output/FGXMLElement.h"
42 #include "math/FGCondition.h"
43 #include "math/FGPropertyValue.h"
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #define ID_SWITCH "$Id: FGSwitch.h,v 1.14 2011/04/05 20:20:21 andgi Exp $"
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /** Encapsulates a switch for the flight control system.
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:
74 property conditional property|value
82 roll_rate == pitch_rate
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.
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}
99 <test logic="{AND|OR}" value="{property|value}">
100 {property} {conditional} {property|value}
104 [<output> {property} </output>]
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
119 Note: In the "logic" attribute, "AND" is the default logic, if none is supplied.
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.
127 @author Jon S. Berndt
128 @version $Id: FGSwitch.h,v 1.14 2011/04/05 20:20:21 andgi Exp $
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
135 class FGSwitch : public FGFCSComponent
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);
147 /** Executes the switch logic.
148 @return true - always*/
151 enum eLogic {elUndef=0, eAND, eOR, eDefault};
152 enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
157 vector <FGCondition*> conditions;
160 FGPropertyValue *OutputProp;
163 double GetValue(void) {
164 if (OutputProp == 0L) return OutputVal;
165 else return OutputProp->GetValue()*sign;
168 test(void) { // constructor for the test structure
177 vector <test*> tests;
179 void Debug(int from);