1 // xmlauto.hxx - a more flexible, generic way to build autopilots
3 // Written by Curtis Olson, started January 2004.
5 // Copyright (C) 2004 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define _XMLAUTO_HXX 1
28 # error This library requires C++
35 #include <simgear/compiler.h>
45 #include <simgear/props/props.hxx>
46 #include <simgear/structure/subsystem_mgr.hxx>
50 * Base class for other autopilot components
53 class FGXMLAutoComponent {
59 SGPropertyNode *enable_prop;
63 SGPropertyNode *input_prop;
64 SGPropertyNode *r_n_prop;
66 vector <SGPropertyNode *> output_list;
70 FGXMLAutoComponent() :
79 virtual ~FGXMLAutoComponent() {}
81 virtual void update (double dt) {}
83 inline string get_name() { return name; }
88 * Roy Ovesen's PID controller
91 class FGPIDController : public FGXMLAutoComponent {
99 double y_n; // measured process value
100 double r_n; // reference (set point) value
101 double y_scale; // scale process input from property system
102 double r_scale; // scale reference input from property system
104 // Configuration values
105 double Kp; // proportional gain
107 double alpha; // low pass filter weighing factor (usually 0.1)
108 double beta; // process value weighing factor for
109 // calculating proportional error
111 double gamma; // process value weighing factor for
112 // calculating derivative error
115 double Ti; // Integrator time (sec)
116 double Td; // Derivator time (sec)
118 double u_min; // Minimum output clamp
119 double u_max; // Maximum output clamp
121 // Previous state tracking values
122 double ep_n_1; // ep[n-1] (prop error)
123 double edf_n_1; // edf[n-1] (derivative error)
124 double edf_n_2; // edf[n-2] (derivative error)
125 double u_n_1; // u[n-1] (output)
131 FGPIDController( SGPropertyNode *node );
132 FGPIDController( SGPropertyNode *node, bool old );
133 ~FGPIDController() {}
135 void update_old( double dt );
136 void update( double dt );
141 * A simplistic P [ + I ] PID controller
144 class FGPISimpleController : public FGXMLAutoComponent {
148 // proportional component data
151 SGPropertyNode *offset_prop;
154 // integral component data
159 // post functions for output
166 double y_n; // measured process value
167 double r_n; // reference (set point) value
168 double y_scale; // scale process input from property system
169 double r_scale; // scale reference input from property system
171 double u_min; // Minimum output clamp
172 double u_max; // Maximum output clamp
177 FGPISimpleController( SGPropertyNode *node );
178 ~FGPISimpleController() {}
180 void update( double dt );
185 * Predictor - calculates value in x seconds future.
188 class FGPredictor : public FGXMLAutoComponent {
192 // proportional component data
202 double ivalue; // input value
206 FGPredictor( SGPropertyNode *node );
209 void update( double dt );
214 * FGDigitalFilter - a selection of digital filters
217 * Double exponential filter
218 * Moving average filter
221 * All these filters are low-pass filters.
225 class FGDigitalFilter : public FGXMLAutoComponent
228 double Tf; // Filter time [s]
229 unsigned int samples; // Number of input samples to average
230 double rateOfChange; // The maximum allowable rate of change [1/s]
231 deque <double> output;
232 deque <double> input;
238 FGDigitalFilter(SGPropertyNode *node);
239 ~FGDigitalFilter() {}
241 void update(double dt);
245 * Model an autopilot system.
249 class FGXMLAutopilot : public SGSubsystem
261 void update( double dt );
267 typedef vector<FGXMLAutoComponent *> comp_list;
272 SGPropertyNode *config_props;
273 comp_list components;
277 #endif // _XMLAUTO_HXX