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