]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/newauto.hxx
Fixes for default chase view values.
[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/misc/props.hxx>
31 #include <simgear/route/waypoint.hxx>
32
33 #include <Main/fg_props.hxx>
34
35 // Structures
36 class FGAutopilot {
37
38 public:
39
40     enum fgAutoHeadingMode {
41         FG_DG_HEADING_LOCK = 0,   // follow bug on directional gryo
42         FG_TC_HEADING_LOCK = 1,   // keep turn coordinator zero'd
43         FG_TRUE_HEADING_LOCK = 2, // lock to true heading (i.e. a perfect world)
44         FG_HEADING_NAV1 = 3,      // follow nav1 radial
45         FG_HEADING_NAV2 = 4,      // follow nav2 radial
46         FG_HEADING_WAYPOINT = 5   // track next waypoint
47     };
48
49     enum fgAutoAltitudeMode {
50         FG_ALTITUDE_LOCK = 0,     // lock to a specific altitude
51         FG_ALTITUDE_TERRAIN = 1,  // try to maintain a specific AGL
52         FG_ALTITUDE_GS1 = 2,      // follow glide slope 1
53         FG_ALTITUDE_GS2 = 3       // follow glide slope 2
54     };
55
56 private:
57
58     bool heading_hold;          // the current state of the heading hold
59     bool altitude_hold;         // the current state of the altitude hold
60     bool auto_throttle;         // the current state of the auto throttle
61
62     fgAutoHeadingMode heading_mode;
63     fgAutoAltitudeMode altitude_mode;
64
65     SGWayPoint waypoint;        // the waypoint the AP should steer to.
66
67     // double TargetLatitude;   // the latitude the AP should steer to.
68     // double TargetLongitude;  // the longitude the AP should steer to.
69     double TargetDistance;      // the distance to Target.
70     double DGTargetHeading;     // the apparent DG heading to steer towards.
71     double TargetHeading;       // the true heading the AP should steer to.
72     double TargetAltitude;      // altitude to hold
73     double TargetAGL;           // the terrain separation
74     SGPropertyNode *min_climb;           // minimum climb speed
75     SGPropertyNode *best_climb;          // best climb speed
76     SGPropertyNode *elevator_adj_factor; // factor to optimize altitude hold adjustments
77     SGPropertyNode *integral_contrib;    // amount of contribution of the integral
78                                 // component of the pid
79     SGPropertyNode *zero_pitch_throttle; // amount of throttle at which the aircraft does not pitch up
80     SGPropertyNode *zero_pitch_trim_full_throttle; // amount of trim required to level at full throttle
81     SGPropertyNode *TargetClimbRate;    // target climb rate
82     SGPropertyNode *TargetDescentRate;  // target decent rate
83     SGPropertyNode *current_throttle; // current throttle (engine 0)
84     double TargetSpeed;         // speed to shoot for
85     double alt_error_accum;     // altitude error accumulator
86     double climb_error_accum;   // climb error accumulator (for GS)
87     double speed_error_accum;   // speed error accumulator
88
89     double TargetSlope;         // the glide slope hold value
90     
91     double MaxRoll ;            // the max the plane can roll for the turn
92     double RollOut;             // when the plane should roll out
93                                 // measured from Heading
94     double MaxAileron;          // how far to move the aleroin from center
95     double RollOutSmooth;       // deg to use for smoothing Aileron Control
96     double MaxElevator;         // the maximum elevator allowed
97     double SlopeSmooth;         // smoothing angle for elevator
98         
99     // following for testing disengagement of autopilot upon pilot
100     // interaction with controls
101     double old_aileron;
102     double old_elevator;
103     double old_elevator_trim;
104     double old_rudder;
105         
106     // manual controls override beyond this value
107     double disengage_threshold; 
108
109     // For future cross track error adjust
110     double old_lat;
111     double old_lon;
112
113     // keeping these locally to save work inside main loop
114     char TargetLatitudeStr[64];
115     char TargetLongitudeStr[64];
116     char TargetLatLonStr[64];
117     char TargetWP1Str[64];
118     char TargetWP2Str[64];
119     char TargetWP3Str[64];
120     char TargetHeadingStr[64];
121     char TargetAltitudeStr[64];
122
123     SGPropertyNode *latitude_node;
124     SGPropertyNode *longitude_node;
125     SGPropertyNode *altitude_node;
126     SGPropertyNode *altitude_agl_node;
127     SGPropertyNode *vertical_speed_node;
128     SGPropertyNode *heading_node;
129     SGPropertyNode *roll_node;
130
131 public:
132
133     // constructor
134     FGAutopilot();
135
136     // destructor
137     ~FGAutopilot();
138
139     // Initialize autopilot system
140     void init();
141
142     // Reset the autopilot system
143     void reset(void);
144
145     // run an interation of the autopilot (updates control positions)
146     int run();
147
148     void AltitudeSet( double new_altitude );
149     void AltitudeAdjust( double inc );
150     void HeadingAdjust( double inc );
151     void AutoThrottleAdjust( double inc );
152
153     void HeadingSet( double value );
154
155     inline bool get_HeadingEnabled() const { return heading_hold; }
156     inline void set_HeadingEnabled( bool value ) { heading_hold = value; }
157     inline fgAutoHeadingMode get_HeadingMode() const { return heading_mode; }
158     void set_HeadingMode( fgAutoHeadingMode mode );
159
160     inline bool get_AltitudeEnabled() const { return altitude_hold; }
161     inline void set_AltitudeEnabled( bool value ) { altitude_hold = value; }
162     inline fgAutoAltitudeMode get_AltitudeMode() const { return altitude_mode;}
163     void set_AltitudeMode( fgAutoAltitudeMode mode );
164
165     inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
166     void set_AutoThrottleEnabled( bool value );
167
168     /* inline void set_WayPoint( const double lon, const double lat, 
169                               const double alt, const string s ) {
170         waypoint = SGWayPoint( lon, lat, alt, SGWayPoint::WGS84, "Current WP" );
171     } */
172     inline double get_TargetLatitude() const {
173         return waypoint.get_target_lat();
174     }
175     inline double get_TargetLongitude() const {
176         return waypoint.get_target_lon();
177     }
178     inline void set_old_lat( double val ) { old_lat = val; }
179     inline void set_old_lon( double val ) { old_lon = val; }
180     inline double get_TargetHeading() const { return TargetHeading; }
181     inline void set_TargetHeading( double val ) { TargetHeading = val; }
182     inline double get_DGTargetHeading() const { return DGTargetHeading; }
183     inline void set_DGTargetHeading( double val ) { DGTargetHeading = val; }
184     inline double get_TargetDistance() const { return TargetDistance; }
185     inline void set_TargetDistance( double val ) { TargetDistance = val; }
186     inline double get_TargetAltitude() const { return TargetAltitude; }
187     inline void set_TargetAltitude( double val ) { TargetAltitude = val; }
188     inline double get_TargetAGL() const { return TargetAGL; }
189     inline void set_TargetAGL( double val ) { TargetAGL = val; }
190     inline double get_TargetClimbRate() const {
191         return TargetClimbRate->getFloatValue();
192     }
193     inline void set_TargetClimbRate( double val ) {
194         fgSetFloat( "/autopilot/config/target-climb-rate-fpm",  val);
195     }
196
197     inline char *get_TargetLatitudeStr() { return TargetLatitudeStr; }
198     inline char *get_TargetLongitudeStr() { return TargetLongitudeStr; }
199     inline char *get_TargetWP1Str() { return TargetWP1Str; }
200     inline char *get_TargetWP2Str() { return TargetWP2Str; }
201     inline char *get_TargetWP3Str() { return TargetWP3Str; }
202     inline char *get_TargetHeadingStr() { return TargetHeadingStr; }
203     inline char *get_TargetAltitudeStr() { return TargetAltitudeStr; }
204     inline char *get_TargetLatLonStr() { return TargetLatLonStr; }
205
206     // utility functions
207     void MakeTargetLatLonStr( double lat, double lon );
208     void MakeTargetAltitudeStr( double altitude );
209     void MakeTargetHeadingStr( double bearing );
210     void MakeTargetWPStr( double distance );
211     void update_old_control_values();
212
213     // accessors
214     inline double get_MaxRoll() const { return MaxRoll; }
215     inline void set_MaxRoll( double val ) { MaxRoll = val; }
216     inline double get_RollOut() const { return RollOut; }
217     inline void set_RollOut( double val ) { RollOut = val; }
218
219     inline double get_MaxAileron() const { return MaxAileron; }
220     inline void set_MaxAileron( double val ) { MaxAileron = val; }
221     inline double get_RollOutSmooth() const { return RollOutSmooth; }
222     inline void set_RollOutSmooth( double val ) { RollOutSmooth = val; }
223
224 };
225
226
227 extern FGAutopilot *current_autopilot;
228
229 #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_DG_HEADING_LOCK
230 // #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_TRUE_HEADING_LOCK
231
232 #endif // _NEWAUTO_HXX