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