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