1 // newauto.hxx -- autopilot defines and prototypes (very alpha)
3 // Started April 1998 Copyright (C) 1998
5 // Contributions by Jeff Goeke-Smith <jgoeke@voyager.net>
6 // Norman Vine <nhv@cape.com>
7 // Curtis Olson <curt@flightgear.org>
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <simgear/props/props.hxx>
31 #include <simgear/route/waypoint.hxx>
33 #include <Main/fgfs.hxx>
34 #include <Main/fg_props.hxx>
37 class FGAutopilot : public FGSubsystem
42 enum fgAutoHeadingMode {
43 FG_DG_HEADING_LOCK = 0, // follow bug on directional gryo (vacuum)
44 FG_TC_HEADING_LOCK = 1, // keep turn coordinator zero'd
45 FG_TRUE_HEADING_LOCK = 2, // lock to true heading (i.e. a perfect world)
46 FG_HEADING_NAV1 = 3, // follow nav1 radial
47 FG_HEADING_NAV2 = 4, // follow nav2 radial
48 FG_HEADING_WAYPOINT = 5 // track next waypoint
51 enum fgAutoAltitudeMode {
52 FG_ALTITUDE_LOCK = 0, // lock to a specific altitude (indicated)
53 FG_ALTITUDE_TERRAIN = 1, // try to maintain a specific AGL
54 FG_ALTITUDE_GS1 = 2, // follow glide slope 1
55 FG_ALTITUDE_GS2 = 3, // follow glide slope 2
56 FG_ALTITUDE_ARM = 4, // ascend to selected altitude
57 FG_TRUE_ALTITUDE_LOCK = 5, // lock to a specific true altitude
58 // (i.e. a perfect world)
59 FG_VERT_SPEED = 6 // ascend or descend at selected fpm
64 bool heading_hold; // the current state of the heading hold
65 bool altitude_hold; // the current state of the altitude hold
66 bool auto_throttle; // the current state of the auto throttle
68 fgAutoHeadingMode heading_mode;
69 fgAutoAltitudeMode altitude_mode;
71 SGWayPoint waypoint; // the waypoint the AP should steer to.
73 // double TargetLatitude; // the latitude the AP should steer to.
74 // double TargetLongitude; // the longitude the AP should steer to.
75 double TargetDistance; // the distance to Target.
76 double DGTargetHeading; // the apparent DG heading to steer towards.
77 double TargetHeading; // the true heading the AP should steer to.
78 double TargetAltitude; // altitude to hold
79 double TargetAGL; // the terrain separation
81 double TargetVertSpeed; // vertical speed to shoot for
83 double TargetSpeed; // speed to shoot for
84 double alt_error_accum; // altitude error accumulator
85 double climb_error_accum; // climb error accumulator (for GS)
86 double speed_error_accum; // speed error accumulator
88 double previous_speed; // used to detect acceleration rate
90 double TargetSlope; // the glide slope hold value
92 double MaxRoll ; // the max the plane can roll for the turn
93 double RollOut; // when the plane should roll out
94 // measured from Heading
95 double MaxAileron; // how far to move the aleroin from center
96 double RollOutSmooth; // deg to use for smoothing Aileron Control
97 double MaxElevator; // the maximum elevator allowed
98 double SlopeSmooth; // smoothing angle for elevator
100 // following for testing disengagement of autopilot upon pilot
101 // interaction with controls
104 double old_elevator_trim;
107 // manual controls override beyond this value
108 double disengage_threshold;
110 // For future cross track error adjust
114 // keeping these locally to save work inside main loop
115 char TargetLatitudeStr[64];
116 char TargetLongitudeStr[64];
117 char TargetLatLonStr[64];
118 char TargetWP1Str[64];
119 char TargetWP2Str[64];
120 char TargetWP3Str[64];
121 char TargetHeadingStr[64];
122 char TargetAltitudeStr[64];
125 SGPropertyNode *latitude_node;
126 SGPropertyNode *longitude_node;
127 SGPropertyNode *altitude_node;
128 SGPropertyNode *altitude_agl_node;
129 SGPropertyNode *vertical_speed_node;
130 SGPropertyNode *heading_node;
131 SGPropertyNode *indicated_heading_node;
132 SGPropertyNode *roll_node;
133 SGPropertyNode *pitch_node;
134 SGPropertyNode *airspeed_node;
136 SGPropertyNode *min_climb; // minimum climb speed
137 SGPropertyNode *best_climb; // best climb speed
138 SGPropertyNode *elevator_adj_factor; // factor to optimize altitude hold adjustments
139 SGPropertyNode *integral_contrib; // amount of contribution of the integral
140 // component of the pid
141 SGPropertyNode *zero_pitch_throttle; // amount of throttle at which the aircraft does not pitch up
142 SGPropertyNode *zero_pitch_trim_full_throttle; // amount of trim required to level at full throttle
143 SGPropertyNode *max_aileron_node; // maximum aileron setting range -1 ~ 1
144 SGPropertyNode *max_roll_node; // maximum roll setting in degrees
145 SGPropertyNode *roll_out_node; // start rollout offset from desired heading in degrees
146 SGPropertyNode *roll_out_smooth_node; // rollout smoothing offset in degrees
147 SGPropertyNode *throttle_adj_factor; // factor to optimize autothrottle adjustments
148 SGPropertyNode *throttle_integral; // amount of contribution of the integral
149 // component of the pid
150 SGPropertyNode *speed_change_node; // anticipated speed change
152 SGPropertyNode *TargetClimbRate; // target climb rate
153 SGPropertyNode *TargetDescentRate; // target decent rate
154 SGPropertyNode *current_throttle; // current throttle (engine 0)
155 SGPropertyNode *terrain_follow_factor; // modifies the climb rate to
156 // permit more control when using terrain following mode
167 ////////////////////////////////////////////////////////////////////
168 // Implementation of FGSubsystem.
169 ////////////////////////////////////////////////////////////////////
174 void update (double dt);
176 // Reset the autopilot system
179 void AltitudeSet( double new_altitude );
180 void AltitudeAdjust( double inc );
181 void HeadingAdjust( double inc );
182 void AutoThrottleAdjust( double inc );
184 void HeadingSet( double value );
186 inline bool get_HeadingEnabled() const { return heading_hold; }
187 inline void set_HeadingEnabled( bool value ) { heading_hold = value; }
188 inline fgAutoHeadingMode get_HeadingMode() const { return heading_mode; }
189 void set_HeadingMode( fgAutoHeadingMode mode );
191 inline bool get_AltitudeEnabled() const { return altitude_hold; }
192 inline void set_AltitudeEnabled( bool value ) { altitude_hold = value; }
193 inline fgAutoAltitudeMode get_AltitudeMode() const { return altitude_mode;}
194 void set_AltitudeMode( fgAutoAltitudeMode mode );
196 inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
197 void set_AutoThrottleEnabled( bool value );
199 /* inline void set_WayPoint( const double lon, const double lat,
200 const double alt, const string s ) {
201 waypoint = SGWayPoint( lon, lat, alt, SGWayPoint::WGS84, "Current WP" );
203 inline double get_TargetLatitude() const {
204 return waypoint.get_target_lat();
206 inline double get_TargetLongitude() const {
207 return waypoint.get_target_lon();
209 inline void set_old_lat( double val ) { old_lat = val; }
210 inline void set_old_lon( double val ) { old_lon = val; }
211 inline double get_TargetHeading() const { return TargetHeading; }
212 inline void set_TargetHeading( double val ) { TargetHeading = val; }
213 inline double get_DGTargetHeading() const { return DGTargetHeading; }
214 inline void set_DGTargetHeading( double val ) { DGTargetHeading = val; }
215 inline double get_TargetDistance() const { return TargetDistance; }
216 inline void set_TargetDistance( double val ) { TargetDistance = val; }
217 inline double get_TargetAltitude() const { return TargetAltitude; }
218 inline void set_TargetAltitude( double val ) { TargetAltitude = val; }
219 inline double get_TargetSpeed() const { return TargetSpeed; }
220 inline void set_TargetSpeed( double val ) { TargetSpeed = val; }
221 inline double get_TargetAGL() const { return TargetAGL; }
222 inline void set_TargetAGL( double val ) { TargetAGL = val; }
223 inline double get_TargetClimbRate() const {
224 return TargetClimbRate->getFloatValue();
226 inline void set_TargetClimbRate( double val ) {
227 fgSetFloat( "/autopilot/config/target-climb-rate-fpm", val);
230 inline char *get_TargetLatitudeStr() { return TargetLatitudeStr; }
231 inline char *get_TargetLongitudeStr() { return TargetLongitudeStr; }
232 inline char *get_TargetWP1Str() { return TargetWP1Str; }
233 inline char *get_TargetWP2Str() { return TargetWP2Str; }
234 inline char *get_TargetWP3Str() { return TargetWP3Str; }
235 inline char *get_TargetHeadingStr() { return TargetHeadingStr; }
236 inline char *get_TargetAltitudeStr() { return TargetAltitudeStr; }
237 inline char *get_TargetLatLonStr() { return TargetLatLonStr; }
240 void MakeTargetLatLonStr( double lat, double lon );
241 void MakeTargetAltitudeStr( double altitude );
242 void MakeTargetHeadingStr( double bearing );
243 void MakeTargetWPStr( double distance );
244 void update_old_control_values();
247 inline double get_MaxRoll() {
248 return fgGetFloat( "/autopilot/config/max-roll-deg" );
250 inline double get_RollOut() {
251 return fgGetFloat( "/autopilot/config/roll-out-deg" );
253 inline double get_MaxAileron() {
254 return fgGetFloat( "/autopilot/config/max-aileron" );
256 inline double get_RollOutSmooth() {
257 return fgGetFloat( "/autopilot/config/roll-out-smooth-deg" );
259 inline void set_MaxRoll( double val ) {
260 fgSetFloat( "/autopilot/config/max-roll-deg", val );
262 inline void set_RollOut( double val ) {
263 fgSetFloat( "/autopilot/config/roll-out-deg", val );
265 inline void set_MaxAileron( double val ) {
266 fgSetFloat( "/autopilot/config/max-aileron", val );
268 inline void set_RollOutSmooth( double val ) {
269 fgSetFloat( "/autopilot/config/roll-out-smooth-deg", val );
274 bool getAPAltitudeLock () const;
275 void setAPAltitudeLock (bool lock);
276 double getAPAltitude () const;
277 void setAPAltitude (double altitude);
278 bool getAPGSLock () const;
279 void setAPGSLock (bool lock);
280 bool getAPVertSpeedLock () const;
281 void setAPVertSpeedLock (bool lock);
282 bool getAPTerrainLock () const;
283 void setAPTerrainLock (bool lock);
284 double getAPClimb () const;
285 void setAPClimb (double rate);
286 bool getAPHeadingLock () const;
287 void setAPHeadingLock (bool lock);
288 double getAPHeadingBug () const;
289 void setAPHeadingBug (double heading);
290 const char * getAPwaypoint () const;
291 void setAPwaypoint (const char * apt);
292 bool getAPWingLeveler () const;
293 void setAPWingLeveler (bool lock);
294 bool getAPNAV1Lock () const;
295 void setAPNAV1Lock (bool lock);
296 bool getAPAutoThrottleLock () const;
297 void setAPAutoThrottleLock (bool lock);
298 double getAPAutoThrottle () const;
299 void setAPAutoThrottle (double altitude);
300 double getAPRudderControl () const;
301 void setAPRudderControl (double value);
302 double getAPElevatorControl () const;
303 void setAPElevatorControl (double value);
304 double getAPThrottleControl () const;
305 void setAPThrottleControl (double value);
306 double getAPVertSpeed () const;
307 void setAPVertSpeed (double speed);
312 #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_DG_HEADING_LOCK
313 #define DEFAULT_AP_ALTITUDE_LOCK FGAutopilot::FG_ALTITUDE_LOCK
314 //#define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_TRUE_HEADING_LOCK
315 //#define DEFAULT_AP_ALTITUDE_LOCK FGAutopilot::FG_TRUE_ALTITUDE_LOCK
318 * static functions for autopilot properties
321 #endif // _NEWAUTO_HXX