]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/analogcomponent.cxx
Merge commit 'refs/merge-requests/13' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / Autopilot / analogcomponent.cxx
1 // analogcomponent.cxx - Base class for analog autopilot components
2 //
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
5 //
6 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
7 // Copyright (C) 2010  Torsten Dreyer - Torsten (at) t3r (dot) de
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 //
23 #include "analogcomponent.hxx"
24 #include <Main/fg_props.hxx>
25
26 using namespace FGXMLAutopilot;
27
28 AnalogComponent::AnalogComponent() :
29   Component(),
30   _feedback_if_disabled(false),
31   _passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) )
32 {
33 }
34
35 double AnalogComponent::clamp( double value ) const
36 {
37     //If this is a periodical value, normalize it into our domain 
38     // before clamping
39     if( _periodical )
40       value = _periodical->normalize( value );
41
42     // clamp, if either min or max is defined
43     if( _minInput.size() + _maxInput.size() > 0 ) {
44         double d = _maxInput.get_value();
45         if( value > d ) value = d;
46         d = _minInput.get_value();
47         if( value < d ) value = d;
48     }
49     return value;
50 }
51
52 bool AnalogComponent::configure( const std::string & nodeName, SGPropertyNode_ptr configNode )
53 {
54   SG_LOG( SG_AUTOPILOT, SG_BULK, "AnalogComponent::configure(" << nodeName << ")" << endl );
55   if( Component::configure( nodeName, configNode ) )
56     return true;
57
58   if ( nodeName == "feedback-if-disabled" ) {
59     _feedback_if_disabled = configNode->getBoolValue();
60     return true;
61   } 
62
63   if ( nodeName == "output" ) {
64     // grab all <prop> and <property> childs
65     int found = 0;
66     // backwards compatibility: allow <prop> elements
67     SGPropertyNode_ptr prop;
68     for( int i = 0; (prop = configNode->getChild("prop", i)) != NULL; i++ ) { 
69       SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
70       _output_list.push_back( tmp );
71       found++;
72     }
73     for( int i = 0; (prop = configNode->getChild("property", i)) != NULL; i++ ) { 
74       SGPropertyNode *tmp = fgGetNode( prop->getStringValue(), true );
75       _output_list.push_back( tmp );
76       found++;
77     }
78
79     // no <prop> elements, text node of <output> is property name
80     if( found == 0 )
81       _output_list.push_back( fgGetNode(configNode->getStringValue(), true ) );
82
83     return true;
84   }
85
86   if( nodeName == "input" ) {
87     _valueInput.push_back( new InputValue( configNode ) );
88     return true;
89   }
90
91   if( nodeName == "reference" ) {
92     _referenceInput.push_back( new InputValue( configNode ) );
93     return true;
94   }
95
96   if( nodeName == "min" || nodeName == "u_min" ) {
97     _minInput.push_back( new InputValue( configNode ) );
98     return true;
99   }
100
101   if( nodeName == "max" || nodeName == "u_max" ) {
102     _maxInput.push_back( new InputValue( configNode ) );
103     return true;
104   }
105
106   if( nodeName == "period" ) {
107     _periodical = new PeriodicalValue( configNode );
108     return true;
109   }
110
111   SG_LOG( SG_AUTOPILOT, SG_BULK, "AnalogComponent::configure(" << nodeName << ") [unhandled]" << endl );
112   return false;
113 }