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 * A simple proportional controler
89 class FGPIDController : public FGXMLAutoComponent {
93 // proportional component data
96 SGPropertyNode *offset_prop;
99 // integral component data
104 // prep functions for error term
107 // post functions for output
114 double y_n; // measured process value
115 double r_n; // reference (set point) value
117 // Configuration values
118 double Kp; // proportional gain
120 double alpha; // low pass filter weighing factor (usually 0.1)
121 double beta; // process value weighing factor for
122 // calculating proportional error
124 double gamma; // process value weighing factor for
125 // calculating derivative error
128 double Ti; // Integrator time (sec)
129 double Td; // Derivator time (sec)
131 double u_min; // Minimum output clamp
132 double u_max; // Maximum output clamp
134 // Previous state tracking values
135 double ep_n_1; // ep[n-1] (prop error)
136 double edf_n_1; // edf[n-1] (derivative error)
137 double edf_n_2; // edf[n-2] (derivative error)
138 double u_n_1; // u[n-1] (output)
144 FGPIDController( SGPropertyNode *node );
145 FGPIDController( SGPropertyNode *node, bool old );
146 ~FGPIDController() {}
148 void update_old( double dt );
149 void update( double dt );
154 * Model an autopilot system.
158 class FGXMLAutopilot : public SGSubsystem
170 void update( double dt );
176 typedef vector<FGXMLAutoComponent *> comp_list;
181 SGPropertyNode *config_props;
182 comp_list components;
186 #endif // _XMLAUTO_HXX