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 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.
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 if (element->GetName() == string("lag_filter")) {
64 } else if (element->GetName() == string("lead_lag_filter")) {
65 Type = "LEAD_LAG_FILTER";
66 } else if (element->GetName() == string("washout_filter")) {
67 Type = "WASHOUT_FILTER";
68 } else if (element->GetName() == string("second_order_filter")) {
69 Type = "SECOND_ORDER_FILTER";
70 } else if (element->GetName() == string("integrator")) {
72 } else if (element->GetName() == string("summer")) {
74 } else if (element->GetName() == string("pure_gain")) {
76 } else if (element->GetName() == string("scheduled_gain")) {
77 Type = "SCHEDULED_GAIN";
78 } else if (element->GetName() == string("aerosurface_scale")) {
79 Type = "AEROSURFACE_SCALE";
80 } else if (element->GetName() == string("switch")) {
82 } else if (element->GetName() == string("kinematic")) {
84 } else if (element->GetName() == string("deadband")) {
86 } else if (element->GetName() == string("fcs_function")) {
87 Type = "FCS_FUNCTION";
88 } else if (element->GetName() == string("pid")) {
90 } else if (element->GetName() == string("sensor")) {
92 } else if (element->GetName() == string("accelerometer")) {
93 Type = "ACCELEROMETER";
94 } else if (element->GetName() == string("actuator")) {
96 } else { // illegal component in this channel
100 Name = element->GetAttributeValue("name");
102 FGPropertyManager *tmp=0;
104 input_element = element->FindElement("input");
105 while (input_element) {
106 input = input_element->GetDataLine();
107 if (input[0] == '-') {
108 InputSigns.push_back(-1.0);
111 InputSigns.push_back( 1.0);
113 tmp = PropertyManager->GetNode(input);
115 InputNodes.push_back( tmp );
117 cerr << fgred << " In component: " << Name << " unknown property "
118 << input << " referenced. Aborting" << reset << endl;
121 input_element = element->FindNextElement("input");
124 if (element->FindElement("output")) {
126 OutputNode = PropertyManager->GetNode( element->FindElementValue("output"), true );
128 cerr << endl << " Unable to process property: " << element->FindElementValue("output") << endl;
129 throw(string("Invalid output property name in flight control definition"));
133 clip_el = element->FindElement("clipto");
135 clip_string = clip_el->FindElementValue("min");
136 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
137 if (clip_string[0] == '-') {
139 clip_string.erase(0,1);
141 ClipMinPropertyNode = PropertyManager->GetNode( clip_string );
143 clipmin = clip_el->FindElementValueAsNumber("min");
145 clip_string = clip_el->FindElementValue("max");
146 if (clip_string.find_first_not_of("+-.0123456789") != string::npos) { // it's a property
147 if (clip_string[0] == '-') {
149 clip_string.erase(0,1);
151 ClipMaxPropertyNode = PropertyManager->GetNode( clip_string );
153 clipmax = clip_el->FindElementValueAsNumber("max");
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 FGFCSComponent::~FGFCSComponent()
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 void FGFCSComponent::SetOutput(void)
172 OutputNode->setDoubleValue(Output);
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 bool FGFCSComponent::Run(void)
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 void FGFCSComponent::Clip(void)
187 if (ClipMinPropertyNode != 0) clipmin = clipMinSign*ClipMinPropertyNode->getDoubleValue();
188 if (ClipMaxPropertyNode != 0) clipmax = clipMaxSign*ClipMaxPropertyNode->getDoubleValue();
189 if (Output > clipmax) Output = clipmax;
190 else if (Output < clipmin) Output = clipmin;
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 // The old way of naming FCS components allowed upper or lower case, spaces, etc.
197 // but then the names were modified to fit into a property name heirarchy. This
198 // was confusing (it wasn't done intentionally - it was a carryover from the early
199 // design). We now support the direct naming of properties in the FCS component
200 // name attribute. The old way is supported in code at this time, but deprecated.
202 void FGFCSComponent::bind(void)
205 if (Name.find("/") == string::npos) {
206 tmp = "fcs/" + PropertyManager->mkPropertyName(Name, true);
210 PropertyManager->Tie( tmp, this, &FGFCSComponent::GetOutput);
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 // The bitmasked value choices are as follows:
215 // unset: In this case (the default) JSBSim would only print
216 // out the normally expected messages, essentially echoing
217 // the config files as they are read. If the environment
218 // variable is not set, debug_lvl is set to 1 internally
219 // 0: This requests JSBSim not to output any messages
221 // 1: This value explicity requests the normal JSBSim
223 // 2: This value asks for a message to be printed out when
224 // a class is instantiated
225 // 4: When this value is set, a message is displayed when a
226 // FGModel object executes its Run() method
227 // 8: When this value is set, various runtime state variables
228 // are printed out periodically
229 // 16: When set various parameters are sanity checked and
230 // a message is printed out when they go out of bounds
232 void FGFCSComponent::Debug(int from)
236 if (debug_lvl <= 0) return;
238 if (debug_lvl & 1) { // Standard console startup message output
240 cout << endl << " Loading Component \"" << Name
241 << "\" of type: " << Type << endl;
244 if (ClipMinPropertyNode != 0L) {
245 if (clipMinSign < 0.0) propsign="-";
246 cout << " Minimum limit: " << propsign << ClipMinPropertyNode->GetName() << endl;
249 cout << " Minimum limit: " << clipmin << endl;
251 if (ClipMaxPropertyNode != 0L) {
252 if (clipMaxSign < 0.0) propsign="-";
253 cout << " Maximum limit: " << propsign << ClipMaxPropertyNode->GetName() << endl;
256 cout << " Maximum limit: " << clipmax << endl;
261 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
262 if (from == 0) cout << "Instantiated: FGFCSComponent" << endl;
263 if (from == 1) cout << "Destroyed: FGFCSComponent" << endl;
265 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
267 if (debug_lvl & 8 ) { // Runtime state variables
269 if (debug_lvl & 16) { // Sanity checking
271 if (debug_lvl & 64) {
272 if (from == 0) { // Constructor
273 cout << IdSrc << endl;
274 cout << IdHdr << endl;