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