fgswitch.h
来自「6 DOF Missle Simulation」· C头文件 代码 · 共 182 行
H
182 行
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Header: FGSwitch.h Author: Jon S. Berndt Date started: 12/23/2002 ------------- Copyright (C) 2002 jsb@hal-pc.org ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Further information about the GNU Lesser General Public License can also be found on the world wide web at http://www.gnu.org.HISTORY--------------------------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%SENTRY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#ifndef FGSWITCH_H#define FGSWITCH_H/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%INCLUDES%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#include "FGFCSComponent.h"#include <input_output/FGXMLElement.h>#include <math/FGCondition.h>/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DEFINITIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#define ID_SWITCH "$Id$"/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FORWARD DECLARATIONS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/namespace JSBSim {/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CLASS DOCUMENTATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*//** Encapsulates a switch for the flight control system.The switch component models a switch - either on/off or a multi-choice rotaryswitch. The switch can represent a physical cockpit switch, or can represent alogical switch, where several conditions might need to be satisfied before aparticular state is reached. The value of the switch - the output value for thecomponent - is chosen depending on the state of the switch. Each switch iscomprised of one or more tests. Each test has a value associated with it. Thefirst test that evaluates to true will set the output value of the switchaccording to the value parameter belonging to that test. Each test contains oneor more conditions, which each must be logically related (if there are more thanone) given the value of the logic attribute, and which takes the form: property conditional property|valuee.g. qbar ge 21.0or, roll_rate == pitch_rateWithin a test, additional tests can be specified, which allows forcomplex groupings of logical comparisons. Each test containsadditional conditions, as well as possibly additional tests.@code<switch name="switch1"> <default value="{property|value}"/> <test logic="{AND|OR}" value="{property|value}"> {property} {conditional} {property|value} <test logic="{AND|OR}"> {property} {conditional} {property|value} ... </test> ... </test> <test logic="{AND|OR}" value="{property|value}"> {property} {conditional} {property|value} ... </test> ... [<output> {property} </output>]</switch>@endcodeHere's an example:@code<switch name="roll a/p autoswitch"> <default value="0.0"/> <test value="fcs/roll-ap-error-summer"> ap/attitude_hold == 1 </test></switch>@endcodeNote: In the "logic" attribute, "AND" is the default logic, if none is supplied.The above example specifies that the default value of the component (i.e. theoutput property of the component, addressed by the property, ap/roll-ap-autoswitch)is 0.0. If or when the attitude hold switch is selected (propertyap/attitude_hold takes the value 1), the value of the switch component will bewhatever value fcs/roll-ap-error-summer is.@author Jon S. Berndt@version $Id$*//*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CLASS DECLARATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/class FGSwitch : public FGFCSComponent{public: /** Constructor @param fcs a pointer to the parent FGFCS class @param element a pointer to the Element (from the config file XML tree) that represents this switch component */ FGSwitch(FGFCS* fcs, Element* element); /// Destructor ~FGSwitch(); /** Executes the switch logic. @return true - always*/ bool Run(void); enum eLogic {elUndef=0, eAND, eOR, eDefault}; enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};private: struct test { vector <FGCondition*> conditions; eLogic Logic; double OutputVal; FGPropertyManager *OutputProp; float sign; double GetValue(void) { if (OutputProp == 0L) return OutputVal; else return OutputProp->getDoubleValue()*sign; } test(void) { // constructor for the test structure Logic = elUndef; OutputVal = 0.0; OutputProp = 0L; sign = 1.0; } }; vector <test*> tests; void Debug(int from);};}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?