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