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