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
100 // Configuration values
101 double Kp; // proportional gain
103 double alpha; // low pass filter weighing factor (usually 0.1)
104 double beta; // process value weighing factor for
105 // calculating proportional error
107 double gamma; // process value weighing factor for
108 // calculating derivative error
111 double Ti; // Integrator time (sec)
112 double Td; // Derivator time (sec)
114 double u_min; // Minimum output clamp
115 double u_max; // Maximum output clamp
117 // Previous state tracking values
118 double ep_n_1; // ep[n-1] (prop error)
119 double edf_n_1; // edf[n-1] (derivative error)
120 double edf_n_2; // edf[n-2] (derivative error)
121 double u_n_1; // u[n-1] (output)
127 FGPIDController( SGPropertyNode *node );
128 FGPIDController( SGPropertyNode *node, bool old );
129 ~FGPIDController() {}
131 void update_old( double dt );
132 void update( double dt );
137 * A simplistic P [ + I ] PID controller
140 class FGPISimpleController : public FGXMLAutoComponent {
144 // proportional component data
147 SGPropertyNode *offset_prop;
150 // integral component data
155 // post functions for output
162 double y_n; // measured process value
163 double r_n; // reference (set point) value
165 double u_min; // Minimum output clamp
166 double u_max; // Maximum output clamp
171 FGPISimpleController( SGPropertyNode *node );
172 ~FGPISimpleController() {}
174 void update( double dt );
179 * Model an autopilot system.
183 class FGXMLAutopilot : public SGSubsystem
195 void update( double dt );
201 typedef vector<FGXMLAutoComponent *> comp_list;
206 SGPropertyNode *config_props;
207 comp_list components;
211 #endif // _XMLAUTO_HXX