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 IsOutput = clip = false;
58 string input, clip_string;
60 PropertyManager = fcs->GetPropertyManager();
61 Type = element->GetAttributeValue("type"); // Old, deprecated format
63 if (element->GetName() == string("lag_filter")) {
65 } else if (element->GetName() == string("lead_lag_filter")) {
66 Type = "LEAD_LAG_FILTER";
67 } else if (element->GetName() == string("washout_filter")) {
68 Type = "WASHOUT_FILTER";
69 } else if (element->GetName() == string("second_order_filter")) {
70 Type = "SECOND_ORDER_FILTER";
71 } else if (element->GetName() == string("integrator")) {
73 } else if (element->GetName() == string("summer")) {
75 } else if (element->GetName() == string("pure_gain")) {
77 } else if (element->GetName() == string("scheduled_gain")) {
78 Type = "SCHEDULED_GAIN";
79 } else if (element->GetName() == string("aerosurface_scale")) {
80 Type = "AEROSURFACE_SCALE";
81 } else if (element->GetName() == string("switch")) {
83 } else if (element->GetName() == string("kinematic")) {
85 } else if (element->GetName() == string("deadband")) {
87 } else if (element->GetName() == string("fcs_function")) {
88 Type = "FCS_FUNCTION";
89 } else if (element->GetName() == string("sensor")) {
91 } else { // illegal component in this channel
96 Name = element->GetAttributeValue("name");
98 input_element = element->FindElement("input");
99 while (input_element) {
100 input = input_element->GetDataLine();
101 if (input[0] == '-') {
102 InputSigns.push_back(-1.0);
105 InputSigns.push_back( 1.0);
107 InputNodes.push_back( resolveSymbol(input) );
108 input_element = element->FindNextElement("input");
111 if (element->FindElement("output")) {
113 OutputNode = PropertyManager->GetNode( element->FindElementValue("output") );
115 cerr << endl << " Unable to process property: " << element->FindElementValue("output") << endl;
116 throw(string("Invalid output property name in flight control definition"));
120 clip_el = element->FindElement("clipto");
122 clip_string = clip_el->FindElementValue("min");
123 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
124 ClipMinPropertyNode = PropertyManager->GetNode( clip_string );
126 clipmin = clip_el->FindElementValueAsNumber("min");
128 clip_string = clip_el->FindElementValue("max");
129 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
130 ClipMaxPropertyNode = PropertyManager->GetNode( clip_string );
132 clipmax = clip_el->FindElementValueAsNumber("max");
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 FGFCSComponent::~FGFCSComponent()
144 // string tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
145 // PropertyManager->Untie( tmp);
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 void FGFCSComponent::SetOutput(void)
154 OutputNode->setDoubleValue(Output);
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 bool FGFCSComponent::Run(void)
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 void FGFCSComponent::Clip(void)
169 if (ClipMinPropertyNode != 0) clipmin = ClipMinPropertyNode->getDoubleValue();
170 if (ClipMaxPropertyNode != 0) clipmax = ClipMaxPropertyNode->getDoubleValue();
171 if (Output > clipmax) Output = clipmax;
172 else if (Output < clipmin) Output = clipmin;
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 FGPropertyManager* FGFCSComponent::resolveSymbol(string token)
181 FGPropertyManager* tmp = PropertyManager->GetNode(token,false);
183 if (token.find("/") == token.npos) prop = "model/" + token;
184 cerr << "Creating new property " << prop << endl;
185 tmp = PropertyManager->GetNode(token,true);
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 void FGFCSComponent::bind(void)
195 string tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
196 PropertyManager->Tie( tmp, this, &FGFCSComponent::GetOutput);
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 // The bitmasked value choices are as follows:
201 // unset: In this case (the default) JSBSim would only print
202 // out the normally expected messages, essentially echoing
203 // the config files as they are read. If the environment
204 // variable is not set, debug_lvl is set to 1 internally
205 // 0: This requests JSBSim not to output any messages
207 // 1: This value explicity requests the normal JSBSim
209 // 2: This value asks for a message to be printed out when
210 // a class is instantiated
211 // 4: When this value is set, a message is displayed when a
212 // FGModel object executes its Run() method
213 // 8: When this value is set, various runtime state variables
214 // are printed out periodically
215 // 16: When set various parameters are sanity checked and
216 // a message is printed out when they go out of bounds
218 void FGFCSComponent::Debug(int from)
220 if (debug_lvl <= 0) return;
222 if (debug_lvl & 1) { // Standard console startup message output
224 cout << endl << " Loading Component \"" << Name
225 << "\" of type: " << Type << endl;
228 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
229 if (from == 0) cout << "Instantiated: FGFCSComponent" << endl;
230 if (from == 1) cout << "Destroyed: FGFCSComponent" << endl;
232 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
234 if (debug_lvl & 8 ) { // Runtime state variables
236 if (debug_lvl & 16) { // Sanity checking
238 if (debug_lvl & 64) {
239 if (from == 0) { // Constructor
240 cout << IdSrc << endl;
241 cout << IdHdr << endl;