1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 12/23/2002
7 ------------- Copyright (C) -------------
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
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
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.
23 Further information about the GNU 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 "../FGConfigFile.h"
42 #include "FGCondition.h"
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 #define ID_SWITCH "$Id$"
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 /** Encapsulates a switch for the flight control system.
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:
73 property conditional property|value
81 roll_rate < pitch_rate
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.
88 \<COMPONENT NAME="switch1" TYPE="SWITCH"\>
89 \<TEST LOGIC="{AND|OR|DEFAULT}" OUTPUT="{property|value}"\>
90 {property} {conditional} {property|value}
91 \<CONDITION_GROUP LOGIC="{AND|OR}"\>
92 {property} {conditional} {property|value}
97 \<TEST LOGIC="{AND|OR}" OUTPUT="{property|value}"\>
98 {property} {conditional} {property|value}
107 \<COMPONENT NAME="Roll A/P Autoswitch" TYPE="SWITCH">
108 \<TEST LOGIC="DEFAULT" VALUE="0.0">
110 \<TEST LOGIC="AND" VALUE="fcs/roll-ap-error-summer">
111 ap/attitude_hold == 1
115 The above example specifies that the default value of the component (i.e. the
116 output property of the component, addressed by the property, ap/roll-ap-autoswitch)
117 is 0.0. If or when the attitude hold switch is selected (property
118 ap/attitude_hold takes the value 1), the value of the switch component will be
119 whatever value fcs/roll-ap-error-summer is.
120 @author Jon S. Berndt
124 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
128 class FGSwitch : public FGFCSComponent
131 FGSwitch(FGFCS* fcs, FGConfigFile* AC_cfg);
138 FGConfigFile* AC_cfg;
140 enum eLogic {elUndef=0, eAND, eOR, eDefault};
141 enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
144 vector <FGCondition> conditions;
147 FGPropertyManager *OutputProp;
150 double GetValue(void) {
151 if (OutputProp == 0L) return OutputVal;
152 else return OutputProp->getDoubleValue()*sign;
155 test(void) { // constructor for the test structure
166 void Debug(int from);