]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/analogcomponent.hxx
Fix various route-manager issues reported by Hyde.
[flightgear.git] / src / Autopilot / analogcomponent.hxx
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 "inputvalue.hxx"
27 #include "component.hxx"
28
29 namespace FGXMLAutopilot {
30
31 /**
32  * @brief Base class for analog autopilot components
33  *
34  * Each analog component has
35  * <ul>
36  *   <li>one value input</li>
37  *   <li>one reference input</li>
38  *   <li>one minimum clamp input</li>
39  *   <li>one maximum clamp input</li>
40  *   <li>an optional periodical definition</li>
41  * </ul>
42  */
43 class AnalogComponent : public Component {
44
45 private:
46     /**
47      * @brief a flag signalling that the output property value shall be fed back
48      *        to the active input property if this component is disabled. This flag
49      *        reflects the &lt;feedback-if-disabled&gt; boolean property.
50      */
51     bool _feedback_if_disabled;
52
53 protected:
54     /**
55      * @brief the value input
56      */
57     InputValueList _valueInput;
58
59     /**
60      * @brief the reference input
61      */
62     InputValueList _referenceInput;
63
64     /**
65      * @brief the minimum output clamp input
66      */
67     InputValueList _minInput;
68
69     /**
70      * @brief the maximum output clamp input
71      */
72     InputValueList _maxInput;
73
74     /**
75      * @brief the configuration for periodical outputs
76      */
77     PeriodicalValue_ptr _periodical;
78
79     /**
80      * @brief A constructor for an analog component. Call configure() to 
81      * configure this component from a property node
82      */
83     AnalogComponent();
84
85     /**
86      * @brief This method configures this analog component from a property node. Gets
87      *        called multiple times from the base class configure method for every 
88               config node.
89      * @param nodeName the name of the configuration node provided in configNode
90      * @param configNode the configuration node itself
91      * @return true if the node was handled, false otherwise.
92      */
93     virtual bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode );
94
95     /**
96      * @brief clamp the given value if &lt;min&gt; and/or &lt;max&gt; inputs were given
97      * @param the value to clamp
98      * @return the clamped value
99      */
100     double clamp( double value ) const;
101
102    /**
103     * @brief overideable method being called from the update() method if this component
104     *        is disabled. Analog components feed back it's output value to the active 
105              input value if disabled and feedback-if-disabled is true 
106     */
107     virtual void disabled( double dt );
108
109     /**
110      * @brief return the current double value of the output property
111      * @return the current value of the output property
112      * If no output property is configured, a value of zero will be returned.
113      * If more than one output property is configured, the value of the first output property
114      * is returned. The current value of the output property will be clamped to the configured
115      * values of &lt;min&gt; and/or &lt;max&gt;. 
116      */
117     inline double get_output_value() const {
118       return _output_list.size() == 0 ? 0.0 : clamp(_output_list[0]->getDoubleValue());
119     }
120
121     simgear::PropertyList _output_list;
122     SGPropertyNode_ptr _passive_mode;
123
124     inline void set_output_value( double value ) {
125         // passive_ignore == true means that we go through all the
126         // motions, but drive the outputs.  This is analogous to
127         // running the autopilot with the "servos" off.  This is
128         // helpful for things like flight directors which position
129         // their vbars from the autopilot computations.
130         if ( _honor_passive && _passive_mode->getBoolValue() ) return;
131         value = clamp( value );
132         for( simgear::PropertyList::iterator it = _output_list.begin();
133              it != _output_list.end(); ++it)
134           (*it)->setDoubleValue( value );
135     }
136
137 public:
138     const PeriodicalValue * getPeriodicalValue() const { return _periodical; }
139 };
140
141 inline void AnalogComponent::disabled( double dt )
142 {
143   if( _feedback_if_disabled && _output_list.size() > 0 ) {    
144     InputValue * input;
145     if( (input = _valueInput.get_active() ) != NULL )
146       input->set_value( _output_list[0]->getDoubleValue() );
147   }
148 }
149
150 }
151 #endif // ANALOGCOMPONENT_HXX