1 // analogcomponent.cxx - Base class for analog autopilot components
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
6 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
7 // Copyright (C) 2010 Torsten Dreyer - Torsten (at) t3r (dot) de
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.
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.
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.
23 #include "analogcomponent.hxx"
24 #include <Main/fg_props.hxx>
26 using namespace FGXMLAutopilot;
28 AnalogComponent::AnalogComponent() :
30 _feedback_if_disabled(false),
31 _passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) )
35 double AnalogComponent::clamp( double value ) const
37 //If this is a periodical value, normalize it into our domain
40 value = _periodical->normalize( value );
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;
52 bool AnalogComponent::configure( const std::string & nodeName, SGPropertyNode_ptr configNode )
54 SG_LOG( SG_AUTOPILOT, SG_BULK, "AnalogComponent::configure(" << nodeName << ")" );
55 if( Component::configure( nodeName, configNode ) )
58 if ( nodeName == "feedback-if-disabled" ) {
59 _feedback_if_disabled = configNode->getBoolValue();
63 if ( nodeName == "output" ) {
64 // grab all <prop> and <property> childs
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 );
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 );
79 // no <prop> elements, text node of <output> is property name
81 _output_list.push_back( fgGetNode(configNode->getStringValue(), true ) );
86 if( nodeName == "input" ) {
87 _valueInput.push_back( new InputValue( configNode ) );
91 if( nodeName == "reference" ) {
92 _referenceInput.push_back( new InputValue( configNode ) );
96 if( nodeName == "min" || nodeName == "u_min" ) {
97 _minInput.push_back( new InputValue( configNode ) );
101 if( nodeName == "max" || nodeName == "u_max" ) {
102 _maxInput.push_back( new InputValue( configNode ) );
106 if( nodeName == "period" ) {
107 _periodical = new PeriodicalValue( configNode );
111 SG_LOG( SG_AUTOPILOT, SG_BULK, "AnalogComponent::configure(" << nodeName << ") [unhandled]" );