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>
43 #include <simgear/props/props.hxx>
44 #include <simgear/structure/subsystem_mgr.hxx>
48 * Base class for other autopilot components
51 class FGXMLAutoComponent {
57 SGPropertyNode *enable_prop;
61 SGPropertyNode *input_prop;
62 SGPropertyNode *r_n_prop;
64 vector <SGPropertyNode *> output_list;
68 FGXMLAutoComponent() :
77 virtual ~FGXMLAutoComponent() {}
79 virtual void update (double dt) {}
81 inline string get_name() { return name; }
86 * Roy Ovesen's PID controller
89 class FGPIDController : public FGXMLAutoComponent {
97 double y_n; // measured process value
98 double r_n; // reference (set point) value
99 double y_scale; // scale process input from property system
100 double r_scale; // scale reference input from property system
102 // Configuration values
103 double Kp; // proportional gain
105 double alpha; // low pass filter weighing factor (usually 0.1)
106 double beta; // process value weighing factor for
107 // calculating proportional error
109 double gamma; // process value weighing factor for
110 // calculating derivative error
113 double Ti; // Integrator time (sec)
114 double Td; // Derivator time (sec)
116 double u_min; // Minimum output clamp
117 double u_max; // Maximum output clamp
119 // Previous state tracking values
120 double ep_n_1; // ep[n-1] (prop error)
121 double edf_n_1; // edf[n-1] (derivative error)
122 double edf_n_2; // edf[n-2] (derivative error)
123 double u_n_1; // u[n-1] (output)
129 FGPIDController( SGPropertyNode *node );
130 FGPIDController( SGPropertyNode *node, bool old );
131 ~FGPIDController() {}
133 void update_old( double dt );
134 void update( double dt );
139 * A simplistic P [ + I ] PID controller
142 class FGPISimpleController : public FGXMLAutoComponent {
146 // proportional component data
149 SGPropertyNode *offset_prop;
152 // integral component data
157 // post functions for output
164 double y_n; // measured process value
165 double r_n; // reference (set point) value
166 double y_scale; // scale process input from property system
167 double r_scale; // scale reference input from property system
169 double u_min; // Minimum output clamp
170 double u_max; // Maximum output clamp
175 FGPISimpleController( SGPropertyNode *node );
176 ~FGPISimpleController() {}
178 void update( double dt );
183 * Predictor - calculates value in x seconds future.
186 class FGPredictor : public FGXMLAutoComponent {
190 // proportional component data
200 double ivalue; // input value
204 FGPredictor( SGPropertyNode *node );
207 void update( double dt );
212 * Model an autopilot system.
216 class FGXMLAutopilot : public SGSubsystem
228 void update( double dt );
234 typedef vector<FGXMLAutoComponent *> comp_list;
239 SGPropertyNode *config_props;
240 comp_list components;
244 #endif // _XMLAUTO_HXX