FlightGear next
analogcomponent.hxx
Go to the documentation of this file.
1// analogcomponent.hxx - 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#ifndef __ANALOGCOMPONENT_HXX
24#define __ANALOGCOMPONENT_HXX 1
25
26#include <simgear/misc/inputvalue.hxx>
27#include "component.hxx"
28
29namespace FGXMLAutopilot {
30
44{
45private:
51 bool _feedback_if_disabled;
52
53protected:
57 simgear::ValueList _valueInput;
58
62 simgear::ValueList _referenceInput;
63
67 simgear::ValueList _minInput;
68
72 simgear::ValueList _maxInput;
73
77 simgear::PeriodicalValue_ptr _periodical;
78
84
94 bool configure( SGPropertyNode& cfg_node,
95 const std::string& cfg_name,
96 SGPropertyNode& prop_root ) override;
97
103 double clamp( double value ) const;
104
110 void disabled( double dt ) override;
111
120 inline double get_output_value() const {
121 return _output_list.empty() ? 0.0 : clamp(_output_list[0]->getDoubleValue());
122 }
123
124 simgear::PropertyList _output_list;
125 SGPropertyNode_ptr _passive_mode;
126
127 inline void set_output_value( double value ) {
128 // passive_ignore == true means that we go through all the
129 // motions, but drive the outputs. This is analogous to
130 // running the autopilot with the "servos" off. This is
131 // helpful for things like flight directors which position
132 // their vbars from the autopilot computations.
133 if ( _honor_passive && _passive_mode->getBoolValue() ) return;
134 value = clamp( value );
135 for( simgear::PropertyList::iterator it = _output_list.begin();
136 it != _output_list.end(); ++it)
137 (*it)->setDoubleValue( value );
138 }
139
140public:
141 const simgear::PeriodicalValue_ptr getPeriodicalValue() const { return _periodical; }
142
147 void collectDependentProperties(std::set<const SGPropertyNode*>& props) const;
148};
149
150inline void AnalogComponent::disabled( double dt )
151{
152 if( _feedback_if_disabled && ! _output_list.empty() ) {
153 auto activeInput = _valueInput.get_active();
154 if (activeInput) {
155 activeInput->set_value(_output_list[0]->getDoubleValue());
156 }
157 }
158}
159
160}
161#endif // ANALOGCOMPONENT_HXX
const simgear::PeriodicalValue_ptr getPeriodicalValue() const
simgear::ValueList _valueInput
the value input
void disabled(double dt) override
overideable method being called from the update() method if this component is disabled.
bool configure(SGPropertyNode &cfg_node, const std::string &cfg_name, SGPropertyNode &prop_root) override
This method configures this analog component from a property node.
AnalogComponent()
A constructor for an analog component.
simgear::ValueList _referenceInput
the reference input
void collectDependentProperties(std::set< const SGPropertyNode * > &props) const
Add to <props> all properties that are used by this component.
double clamp(double value) const
clamp the given value if <min> and/or <max> inputs were given
simgear::ValueList _minInput
the minimum output clamp input
simgear::PeriodicalValue_ptr _periodical
the configuration for periodical outputs
double get_output_value() const
return the current double value of the output property
simgear::ValueList _maxInput
the maximum output clamp input
bool _honor_passive
a (historic) flag signalling the derived class that it should compute it's internal state but shall n...
Definition component.hxx:73
Component()
A constructor for an empty Component.
Definition component.cxx:30