Debian Codegraph @

src/Autopilot/analogcomponent.cxx

raw symbols SCIP
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 #include <simgear/misc/strutils.hxx>
27
28 using namespace FGXMLAutopilot;
29
30 AnalogComponent::AnalogComponent() :
31 Component(),
32 _feedback_if_disabled(false),
33 _passive_mode( fgGetNode("/autopilot/locks/passive-mode", true) )
34 {
35 }
36
37 double AnalogComponent::clamp( double value ) const
38 {
39 //If this is a periodical value, normalize it into our domain
40 // before clamping
41 if( _periodical )
42 value = _periodical->normalize( value );
43
44 // clamp, if either min or max is defined
45 if( _minInput.size() + _maxInput.size() > 0 ) {
46 double d = _maxInput.get_value();
47 if( value > d ) value = d;
48 d = _minInput.get_value();
49 if( value < d ) value = d;
50 }
51 return value;
52 }
53
54 bool AnalogComponent::configure( SGPropertyNode& cfg_node,
55 const std::string& cfg_name,
56 SGPropertyNode& prop_root )
57 {
58 if( cfg_name == "feedback-if-disabled" )
59 {
60 _feedback_if_disabled = cfg_node.getBoolValue();
61 return true;
62 }
63
64 if( cfg_name == "output" )
65 {
66 // grab all <prop> and <property> childs.
67 bool found = false;
68 for( int i = 0; i < cfg_node.nChildren(); ++i )
69 {
70 SGPropertyNode* child = cfg_node.getChild(i);
71 const std::string& name = child->getNameString();
72
73 // Allow "prop" for backwards compatiblity
74 if( name != "property" && name != "prop" )
75 continue;
76
77 const auto trimmed = simgear::strutils::strip(child->getStringValue());
78 _output_list.push_back( prop_root.getNode(trimmed, true) );
79 found = true;
80 }
81
82 // no <prop> elements, text node of <output> is property name
83 if( !found ) {
84 const auto trimmed = simgear::strutils::strip(cfg_node.getStringValue());
85 _output_list.push_back(prop_root.getNode(trimmed, true));
86 }
87
88 return true;
89 }
90
91 if( cfg_name == "input" )
92 {
93 _valueInput.push_back(new simgear::Value(prop_root, cfg_node));
94 return true;
95 }
96
97 if( cfg_name == "reference" )
98 {
99 _referenceInput.push_back(new simgear::Value(prop_root, cfg_node));
100 return true;
101 }
102
103 if( cfg_name == "min" || cfg_name == "u_min" )
104 {
105 _minInput.push_back(new simgear::Value(prop_root, cfg_node));
106 return true;
107 }
108
109 if( cfg_name == "max" || cfg_name == "u_max" )
110 {
111 _maxInput.push_back(new simgear::Value(prop_root, cfg_node));
112 return true;
113 }
114
115 if( cfg_name == "period" )
116 {
117 _periodical = new simgear::PeriodicalValue(prop_root, cfg_node);
118 return true;
119 }
120
121 return Component::configure(cfg_node, cfg_name, prop_root);
122 }
123
124 void AnalogComponent::collectDependentProperties(std::set<const SGPropertyNode*>& props) const
125 {
126 _valueInput.collectDependentProperties(props);
127 _referenceInput.collectDependentProperties(props);
128 _minInput.collectDependentProperties(props);
129 _maxInput.collectDependentProperties(props);
130 }