1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGFCSComponent.cpp
7 ------------- Copyright (C) 2000 -------------
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.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
30 --------------------------------------------------------------------------------
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGFCSComponent.h"
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_FCSCOMPONENT;
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs)
53 Element *input_element, *clip_el;
54 Input = Output = clipmin = clipmax = 0.0;
55 OutputNode = treenode = 0;
56 ClipMinPropertyNode = ClipMaxPropertyNode = 0;
57 clipMinSign = clipMaxSign = 1.0;
58 IsOutput = clip = false;
59 string input, clip_string;
61 PropertyManager = fcs->GetPropertyManager();
62 Type = element->GetAttributeValue("type"); // Old, deprecated format
64 if (element->GetName() == string("lag_filter")) {
66 } else if (element->GetName() == string("lead_lag_filter")) {
67 Type = "LEAD_LAG_FILTER";
68 } else if (element->GetName() == string("washout_filter")) {
69 Type = "WASHOUT_FILTER";
70 } else if (element->GetName() == string("second_order_filter")) {
71 Type = "SECOND_ORDER_FILTER";
72 } else if (element->GetName() == string("integrator")) {
74 } else if (element->GetName() == string("summer")) {
76 } else if (element->GetName() == string("pure_gain")) {
78 } else if (element->GetName() == string("scheduled_gain")) {
79 Type = "SCHEDULED_GAIN";
80 } else if (element->GetName() == string("aerosurface_scale")) {
81 Type = "AEROSURFACE_SCALE";
82 } else if (element->GetName() == string("switch")) {
84 } else if (element->GetName() == string("kinematic")) {
86 } else if (element->GetName() == string("deadband")) {
88 } else if (element->GetName() == string("fcs_function")) {
89 Type = "FCS_FUNCTION";
90 } else if (element->GetName() == string("sensor")) {
92 } else { // illegal component in this channel
97 Name = element->GetAttributeValue("name");
99 input_element = element->FindElement("input");
100 while (input_element) {
101 input = input_element->GetDataLine();
102 if (input[0] == '-') {
103 InputSigns.push_back(-1.0);
106 InputSigns.push_back( 1.0);
108 InputNodes.push_back( resolveSymbol(input) );
109 input_element = element->FindNextElement("input");
112 if (element->FindElement("output")) {
114 OutputNode = PropertyManager->GetNode( element->FindElementValue("output") );
116 cerr << endl << " Unable to process property: " << element->FindElementValue("output") << endl;
117 throw(string("Invalid output property name in flight control definition"));
121 clip_el = element->FindElement("clipto");
123 clip_string = clip_el->FindElementValue("min");
124 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
125 if (clip_string[0] == '-') clipMinSign = -1.0;
126 ClipMinPropertyNode = PropertyManager->GetNode( clip_string );
128 clipmin = clip_el->FindElementValueAsNumber("min");
130 clip_string = clip_el->FindElementValue("max");
131 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
132 if (clip_string[0] == '-') clipMaxSign = -1.0;
133 ClipMaxPropertyNode = PropertyManager->GetNode( clip_string );
135 clipmax = clip_el->FindElementValueAsNumber("max");
143 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 FGFCSComponent::~FGFCSComponent()
147 // string tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
148 // PropertyManager->Untie( tmp);
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 void FGFCSComponent::SetOutput(void)
157 OutputNode->setDoubleValue(Output);
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 bool FGFCSComponent::Run(void)
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 void FGFCSComponent::Clip(void)
172 if (ClipMinPropertyNode != 0) clipmin = clipMinSign*ClipMinPropertyNode->getDoubleValue();
173 if (ClipMaxPropertyNode != 0) clipmax = clipMaxSign*ClipMaxPropertyNode->getDoubleValue();
174 if (Output > clipmax) Output = clipmax;
175 else if (Output < clipmin) Output = clipmin;
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 FGPropertyManager* FGFCSComponent::resolveSymbol(string token)
184 FGPropertyManager* tmp = PropertyManager->GetNode(token,false);
186 if (token.find("/") == token.npos) prop = "model/" + token;
187 cerr << "Creating new property " << prop << endl;
188 tmp = PropertyManager->GetNode(token,true);
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 void FGFCSComponent::bind(void)
198 string tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
199 PropertyManager->Tie( tmp, this, &FGFCSComponent::GetOutput);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 // The bitmasked value choices are as follows:
204 // unset: In this case (the default) JSBSim would only print
205 // out the normally expected messages, essentially echoing
206 // the config files as they are read. If the environment
207 // variable is not set, debug_lvl is set to 1 internally
208 // 0: This requests JSBSim not to output any messages
210 // 1: This value explicity requests the normal JSBSim
212 // 2: This value asks for a message to be printed out when
213 // a class is instantiated
214 // 4: When this value is set, a message is displayed when a
215 // FGModel object executes its Run() method
216 // 8: When this value is set, various runtime state variables
217 // are printed out periodically
218 // 16: When set various parameters are sanity checked and
219 // a message is printed out when they go out of bounds
221 void FGFCSComponent::Debug(int from)
223 if (debug_lvl <= 0) return;
225 if (debug_lvl & 1) { // Standard console startup message output
227 cout << endl << " Loading Component \"" << Name
228 << "\" of type: " << Type << endl;
231 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
232 if (from == 0) cout << "Instantiated: FGFCSComponent" << endl;
233 if (from == 1) cout << "Destroyed: FGFCSComponent" << endl;
235 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
237 if (debug_lvl & 8 ) { // Runtime state variables
239 if (debug_lvl & 16) { // Sanity checking
241 if (debug_lvl & 64) {
242 if (from == 0) { // Constructor
243 cout << IdSrc << endl;
244 cout << IdHdr << endl;