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( SGPropertyNode& cfg_node,
53 const std::string& cfg_name,
54 SGPropertyNode& prop_root )
56 if( cfg_name == "feedback-if-disabled" )
58 _feedback_if_disabled = cfg_node.getBoolValue();
62 if( cfg_name == "output" )
64 // grab all <prop> and <property> childs.
66 for( int i = 0; i < cfg_node.nChildren(); ++i )
68 SGPropertyNode& child = *cfg_node.getChild(i);
69 const std::string& name = child.getNameString();
71 // Allow "prop" for backwards compatiblity
72 if( name != "property" && name != "prop" )
75 _output_list.push_back( prop_root.getNode(child.getStringValue(), true) );
79 // no <prop> elements, text node of <output> is property name
81 _output_list.push_back
83 prop_root.getNode(cfg_node.getStringValue(), true)
89 if( cfg_name == "input" )
91 _valueInput.push_back( new InputValue(prop_root, cfg_node) );
95 if( cfg_name == "reference" )
97 _referenceInput.push_back( new InputValue(prop_root, cfg_node) );
101 if( cfg_name == "min" || cfg_name == "u_min" )
103 _minInput.push_back( new InputValue(prop_root, cfg_node) );
107 if( cfg_name == "max" || cfg_name == "u_max" )
109 _maxInput.push_back( new InputValue(prop_root, cfg_node) );
113 if( cfg_name == "period" )
115 _periodical = new PeriodicalValue(prop_root, cfg_node);
119 return Component::configure(cfg_node, cfg_name, prop_root);