]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/newauto.hxx
Currently, when the sim pauses, all IO is also halted. To me it generally
[flightgear.git] / src / Autopilot / newauto.hxx
1 // newauto.hxx -- autopilot defines and prototypes (very alpha)
2 // 
3 // Started April 1998  Copyright (C) 1998
4 //
5 // Contributions by Jeff Goeke-Smith <jgoeke@voyager.net>
6 //                  Norman Vine <nhv@cape.com>
7 //                  Curtis Olson <curt@flightgear.org>
8 //
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.
13 //
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.
18 //
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.
22 //
23 // $Id$
24                        
25                        
26 #ifndef _NEWAUTO_HXX
27 #define _NEWAUTO_HXX
28
29
30 #include <simgear/props/props.hxx>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/route/waypoint.hxx>
33
34 #include <Main/fg_props.hxx>
35
36 // Structures
37 class FGAutopilot : public SGSubsystem
38 {
39
40 public:
41
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
49     };
50
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
60     };
61
62 private:
63
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
67
68     fgAutoHeadingMode heading_mode;
69     fgAutoAltitudeMode altitude_mode;
70
71     SGWayPoint waypoint;        // the waypoint the AP should steer to.
72
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
80
81     double TargetVertSpeed;         // vertical speed to shoot for
82
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
87
88     double current_ap_throttle;  // current ap stored throttle setting used to set all engines
89     double previous_speed;  // used to detect acceleration rate
90
91     double TargetSlope;         // the glide slope hold value
92
93     double MaxRoll ;            // the max the plane can roll for the turn
94     double RollOut;             // when the plane should roll out
95                                 // measured from Heading
96     double MaxAileron;          // how far to move the aleroin from center
97     double RollOutSmooth;       // deg to use for smoothing Aileron Control
98     double MaxElevator;         // the maximum elevator allowed
99     double SlopeSmooth;         // smoothing angle for elevator
100
101     // following for testing disengagement of autopilot upon pilot
102     // interaction with controls
103     double old_aileron;
104     double old_elevator;
105     double old_elevator_trim;
106     double old_rudder;
107
108     // manual controls override beyond this value
109     double disengage_threshold; 
110
111     // For future cross track error adjust
112     double old_lat;
113     double old_lon;
114
115     // keeping these locally to save work inside main loop
116     char TargetLatitudeStr[64];
117     char TargetLongitudeStr[64];
118     char TargetLatLonStr[64];
119     char TargetWP1Str[64];
120     char TargetWP2Str[64];
121     char TargetWP3Str[64];
122     char TargetHeadingStr[64];
123     char TargetAltitudeStr[64];
124
125     // property nodes
126     SGPropertyNode *latitude_node;
127     SGPropertyNode *longitude_node;
128     SGPropertyNode *altitude_node;
129     SGPropertyNode *altitude_agl_node;
130     SGPropertyNode *vertical_speed_node;
131     SGPropertyNode *heading_node;
132     SGPropertyNode *indicated_heading_node;
133     SGPropertyNode *roll_node;
134     SGPropertyNode *pitch_node;
135     SGPropertyNode *airspeed_node;
136
137     SGPropertyNode *min_climb;           // minimum climb speed
138     SGPropertyNode *best_climb;          // best climb speed
139     SGPropertyNode *elevator_adj_factor; // factor to optimize altitude hold adjustments
140     SGPropertyNode *integral_contrib;    // amount of contribution of the integral
141                                 // component of the pid
142     SGPropertyNode *zero_pitch_throttle; // amount of throttle at which the aircraft does not pitch up
143     SGPropertyNode *zero_pitch_trim_full_throttle; // amount of trim required to level at full throttle
144     SGPropertyNode *max_aileron_node; // maximum aileron setting range -1 ~ 1
145     SGPropertyNode *max_roll_node; // maximum roll setting in degrees
146     SGPropertyNode *roll_out_node; // start rollout offset from desired heading in degrees
147     SGPropertyNode *roll_out_smooth_node; // rollout smoothing offset in degrees
148     SGPropertyNode *throttle_adj_factor; // factor to optimize autothrottle adjustments
149     SGPropertyNode *throttle_integral;    // amount of contribution of the integral
150                                 // component of the pid
151     SGPropertyNode *speed_change_node;    // anticipated speed change
152
153     SGPropertyNode *TargetClimbRate;    // target climb rate
154     SGPropertyNode *TargetDescentRate;  // target decent rate
155     SGPropertyNode *current_throttle; // current throttle (engine 0)
156     SGPropertyNode *terrain_follow_factor; // modifies the climb rate to
157                         // permit more control when using terrain following mode
158
159 public:
160
161     // constructor
162     FGAutopilot();
163
164     // destructor
165     ~FGAutopilot();
166
167 \f
168     ////////////////////////////////////////////////////////////////////
169     // Implementation of SGSubsystem.
170     ////////////////////////////////////////////////////////////////////
171
172     void init ();
173     void bind ();
174     void unbind ();
175     void update (double dt);
176
177     // Reset the autopilot system
178     void reset(void);
179
180     void AltitudeSet( double new_altitude );
181     void AltitudeAdjust( double inc );
182     void HeadingAdjust( double inc );
183     void AutoThrottleAdjust( double inc );
184
185     void HeadingSet( double value );
186
187     inline bool get_HeadingEnabled() const { return heading_hold; }
188     inline void set_HeadingEnabled( bool value ) { heading_hold = value; }
189     inline fgAutoHeadingMode get_HeadingMode() const { return heading_mode; }
190     void set_HeadingMode( fgAutoHeadingMode mode );
191
192     inline bool get_AltitudeEnabled() const { return altitude_hold; }
193     inline void set_AltitudeEnabled( bool value ) { altitude_hold = value; }
194     inline fgAutoAltitudeMode get_AltitudeMode() const { return altitude_mode;}
195     void set_AltitudeMode( fgAutoAltitudeMode mode );
196
197     inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
198     void set_AutoThrottleEnabled( bool value );
199
200     /* inline void set_WayPoint( const double lon, const double lat, 
201                               const double alt, const string s ) {
202         waypoint = SGWayPoint( lon, lat, alt, SGWayPoint::WGS84, "Current WP" );
203     } */
204     inline double get_TargetLatitude() const {
205         return waypoint.get_target_lat();
206     }
207     inline double get_TargetLongitude() const {
208         return waypoint.get_target_lon();
209     }
210     inline void set_old_lat( double val ) { old_lat = val; }
211     inline void set_old_lon( double val ) { old_lon = val; }
212     inline double get_TargetHeading() const { return TargetHeading; }
213     inline void set_TargetHeading( double val ) { TargetHeading = val; }
214     inline double get_DGTargetHeading() const { return DGTargetHeading; }
215     inline void set_DGTargetHeading( double val ) { DGTargetHeading = val; }
216     inline double get_TargetDistance() const { return TargetDistance; }
217     inline void set_TargetDistance( double val ) { TargetDistance = val; }
218     inline double get_TargetAltitude() const { return TargetAltitude; }
219     inline void set_TargetAltitude( double val ) { TargetAltitude = val; }
220     inline double get_TargetSpeed() const { return TargetSpeed; }
221     inline void set_TargetSpeed( double val ) { TargetSpeed = val; }
222     inline double get_TargetAGL() const { return TargetAGL; }
223     inline void set_TargetAGL( double val ) { TargetAGL = val; }
224     inline double get_TargetClimbRate() const {
225         return TargetClimbRate->getFloatValue();
226     }
227     inline void set_TargetClimbRate( double val ) {
228         fgSetFloat( "/autopilot/config/target-climb-rate-fpm",  val);
229     }
230
231     inline char *get_TargetLatitudeStr() { return TargetLatitudeStr; }
232     inline char *get_TargetLongitudeStr() { return TargetLongitudeStr; }
233     inline char *get_TargetWP1Str() { return TargetWP1Str; }
234     inline char *get_TargetWP2Str() { return TargetWP2Str; }
235     inline char *get_TargetWP3Str() { return TargetWP3Str; }
236     inline char *get_TargetHeadingStr() { return TargetHeadingStr; }
237     inline char *get_TargetAltitudeStr() { return TargetAltitudeStr; }
238     inline char *get_TargetLatLonStr() { return TargetLatLonStr; }
239
240     // utility functions
241     void MakeTargetLatLonStr( double lat, double lon );
242     void MakeTargetAltitudeStr( double altitude );
243     void MakeTargetHeadingStr( double bearing );
244     void MakeTargetWPStr( double distance );
245     void update_old_control_values();
246
247     // accessors
248     inline double get_MaxRoll() {
249         return fgGetFloat( "/autopilot/config/max-roll-deg" );
250     }
251     inline double get_RollOut() {
252         return fgGetFloat( "/autopilot/config/roll-out-deg" );
253     }
254     inline double get_MaxAileron() {
255         return fgGetFloat( "/autopilot/config/max-aileron" );
256     }
257     inline double get_RollOutSmooth() {
258         return fgGetFloat( "/autopilot/config/roll-out-smooth-deg" );
259     }
260     inline void set_MaxRoll( double val ) {
261         fgSetFloat( "/autopilot/config/max-roll-deg", val );
262     }
263     inline void set_RollOut( double val ) {
264         fgSetFloat( "/autopilot/config/roll-out-deg", val );
265     }
266     inline void set_MaxAileron( double val ) {
267         fgSetFloat( "/autopilot/config/max-aileron", val );
268     }
269     inline void set_RollOutSmooth( double val ) {
270         fgSetFloat( "/autopilot/config/roll-out-smooth-deg", val );
271     }
272
273 private:
274
275     bool getAPAltitudeLock () const;
276     void setAPAltitudeLock (bool lock);
277     double getAPAltitude () const;
278     void setAPAltitude (double altitude);
279     bool getAPGSLock () const;
280     void setAPGSLock (bool lock);
281     bool getAPVertSpeedLock () const;
282     void setAPVertSpeedLock (bool lock);
283     bool getAPTerrainLock () const;
284     void setAPTerrainLock (bool lock);
285     double getAPClimb () const;
286     void setAPClimb (double rate);
287     bool getAPHeadingLock () const;
288     void setAPHeadingLock (bool lock);
289     double getAPHeadingBug () const;
290     void setAPHeadingBug (double heading);
291     const char * getAPwaypoint () const;
292     void setAPwaypoint (const char * apt);
293     bool getAPWingLeveler () const;
294     void setAPWingLeveler (bool lock);
295     bool getAPNAV1Lock () const;
296     void setAPNAV1Lock (bool lock);
297     bool getAPAutoThrottleLock () const;
298     void setAPAutoThrottleLock (bool lock);
299     double getAPAutoThrottle () const;
300     void setAPAutoThrottle (double altitude);
301     double getAPRudderControl () const;
302     void setAPRudderControl (double value);
303     double getAPElevatorControl () const;
304     void setAPElevatorControl (double value);
305     double getAPThrottleControl () const;
306     void setAPThrottleControl (double value);
307     double getAPVertSpeed () const;
308     void setAPVertSpeed (double speed);
309
310 };
311
312
313 #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_DG_HEADING_LOCK
314 #define DEFAULT_AP_ALTITUDE_LOCK FGAutopilot::FG_ALTITUDE_LOCK
315 //#define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_TRUE_HEADING_LOCK
316 //#define DEFAULT_AP_ALTITUDE_LOCK FGAutopilot::FG_TRUE_ALTITUDE_LOCK
317
318 /**
319  * static functions for autopilot properties
320  */
321
322 #endif // _NEWAUTO_HXX
323