]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/newauto.hxx
Bugfix. The engine thrust is recalculated based on the current N1 value
[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 #include <Main/fgfs.hxx>
34 #include <Main/fg_props.hxx>
35
36 // Structures
37 class FGAutopilot : public FGSubsystem
38 {
39
40 public:
41
42     enum fgAutoHeadingMode {
43         FG_DG_HEADING_LOCK = 0,   // follow bug on directional gryo
44         FG_TC_HEADING_LOCK = 1,   // keep turn coordinator zero'd
45         FG_TRUE_HEADING_LOCK = 2, // lock to true heading (i.e. a perfect world)
46         FG_HEADING_NAV1 = 3,      // follow nav1 radial
47         FG_HEADING_NAV2 = 4,      // follow nav2 radial
48         FG_HEADING_WAYPOINT = 5   // track next waypoint
49     };
50
51     enum fgAutoAltitudeMode {
52         FG_ALTITUDE_LOCK = 0,     // lock to a specific altitude
53         FG_ALTITUDE_TERRAIN = 1,  // try to maintain a specific AGL
54         FG_ALTITUDE_GS1 = 2,      // follow glide slope 1
55         FG_ALTITUDE_GS2 = 3,      // follow glide slope 2
56         FG_ALTITUDE_ARM = 4       // ascend to selected altitude
57     };
58
59
60 private:
61
62     bool heading_hold;          // the current state of the heading hold
63     bool altitude_hold;         // the current state of the altitude hold
64     bool auto_throttle;         // the current state of the auto throttle
65
66     fgAutoHeadingMode heading_mode;
67     fgAutoAltitudeMode altitude_mode;
68
69     SGWayPoint waypoint;        // the waypoint the AP should steer to.
70
71     // double TargetLatitude;   // the latitude the AP should steer to.
72     // double TargetLongitude;  // the longitude the AP should steer to.
73     double TargetDistance;      // the distance to Target.
74     double DGTargetHeading;     // the apparent DG heading to steer towards.
75     double TargetHeading;       // the true heading the AP should steer to.
76     double TargetAltitude;      // altitude to hold
77     double TargetAGL;           // the terrain separation
78
79     double TargetSpeed;         // speed to shoot for
80     double alt_error_accum;     // altitude error accumulator
81     double climb_error_accum;   // climb error accumulator (for GS)
82     double speed_error_accum;   // speed error accumulator
83
84     double TargetSlope;         // the glide slope hold value
85     
86     double MaxRoll ;            // the max the plane can roll for the turn
87     double RollOut;             // when the plane should roll out
88                                 // measured from Heading
89     double MaxAileron;          // how far to move the aleroin from center
90     double RollOutSmooth;       // deg to use for smoothing Aileron Control
91     double MaxElevator;         // the maximum elevator allowed
92     double SlopeSmooth;         // smoothing angle for elevator
93         
94     // following for testing disengagement of autopilot upon pilot
95     // interaction with controls
96     double old_aileron;
97     double old_elevator;
98     double old_elevator_trim;
99     double old_rudder;
100         
101     // manual controls override beyond this value
102     double disengage_threshold; 
103
104     // For future cross track error adjust
105     double old_lat;
106     double old_lon;
107
108     // keeping these locally to save work inside main loop
109     char TargetLatitudeStr[64];
110     char TargetLongitudeStr[64];
111     char TargetLatLonStr[64];
112     char TargetWP1Str[64];
113     char TargetWP2Str[64];
114     char TargetWP3Str[64];
115     char TargetHeadingStr[64];
116     char TargetAltitudeStr[64];
117
118     // property nodes
119     SGPropertyNode *latitude_node;
120     SGPropertyNode *longitude_node;
121     SGPropertyNode *altitude_node;
122     SGPropertyNode *altitude_agl_node;
123     SGPropertyNode *vertical_speed_node;
124     SGPropertyNode *heading_node;
125     SGPropertyNode *roll_node;
126     SGPropertyNode *pitch_node;
127
128     SGPropertyNode *min_climb;           // minimum climb speed
129     SGPropertyNode *best_climb;          // best climb speed
130     SGPropertyNode *elevator_adj_factor; // factor to optimize altitude hold adjustments
131     SGPropertyNode *integral_contrib;    // amount of contribution of the integral
132                                 // component of the pid
133     SGPropertyNode *zero_pitch_throttle; // amount of throttle at which the aircraft does not pitch up
134     SGPropertyNode *zero_pitch_trim_full_throttle; // amount of trim required to level at full throttle
135     SGPropertyNode *max_aileron_node; // maximum aileron setting range -1 ~ 1
136     SGPropertyNode *max_roll_node; // maximum roll setting in degrees
137     SGPropertyNode *roll_out_node; // start rollout offset from desired heading in degrees
138     SGPropertyNode *roll_out_smooth_node; // rollout smoothing offset in degrees
139
140     SGPropertyNode *TargetClimbRate;    // target climb rate
141     SGPropertyNode *TargetDescentRate;  // target decent rate
142     SGPropertyNode *current_throttle; // current throttle (engine 0)
143
144 public:
145
146     // constructor
147     FGAutopilot();
148
149     // destructor
150     ~FGAutopilot();
151
152 \f
153     ////////////////////////////////////////////////////////////////////
154     // Implementation of FGSubsystem.
155     ////////////////////////////////////////////////////////////////////
156
157     void init ();
158     void bind ();
159     void unbind ();
160     void update (double dt);
161
162     // Reset the autopilot system
163     void reset(void);
164
165     void AltitudeSet( double new_altitude );
166     void AltitudeAdjust( double inc );
167     void HeadingAdjust( double inc );
168     void AutoThrottleAdjust( double inc );
169
170     void HeadingSet( double value );
171
172     inline bool get_HeadingEnabled() const { return heading_hold; }
173     inline void set_HeadingEnabled( bool value ) { heading_hold = value; }
174     inline fgAutoHeadingMode get_HeadingMode() const { return heading_mode; }
175     void set_HeadingMode( fgAutoHeadingMode mode );
176
177     inline bool get_AltitudeEnabled() const { return altitude_hold; }
178     inline void set_AltitudeEnabled( bool value ) { altitude_hold = value; }
179     inline fgAutoAltitudeMode get_AltitudeMode() const { return altitude_mode;}
180     void set_AltitudeMode( fgAutoAltitudeMode mode );
181
182     inline bool get_AutoThrottleEnabled() const { return auto_throttle; }
183     void set_AutoThrottleEnabled( bool value );
184
185     /* inline void set_WayPoint( const double lon, const double lat, 
186                               const double alt, const string s ) {
187         waypoint = SGWayPoint( lon, lat, alt, SGWayPoint::WGS84, "Current WP" );
188     } */
189     inline double get_TargetLatitude() const {
190         return waypoint.get_target_lat();
191     }
192     inline double get_TargetLongitude() const {
193         return waypoint.get_target_lon();
194     }
195     inline void set_old_lat( double val ) { old_lat = val; }
196     inline void set_old_lon( double val ) { old_lon = val; }
197     inline double get_TargetHeading() const { return TargetHeading; }
198     inline void set_TargetHeading( double val ) { TargetHeading = val; }
199     inline double get_DGTargetHeading() const { return DGTargetHeading; }
200     inline void set_DGTargetHeading( double val ) { DGTargetHeading = val; }
201     inline double get_TargetDistance() const { return TargetDistance; }
202     inline void set_TargetDistance( double val ) { TargetDistance = val; }
203     inline double get_TargetAltitude() const { return TargetAltitude; }
204     inline void set_TargetAltitude( double val ) { TargetAltitude = val; }
205     inline double get_TargetAGL() const { return TargetAGL; }
206     inline void set_TargetAGL( double val ) { TargetAGL = val; }
207     inline double get_TargetClimbRate() const {
208         return TargetClimbRate->getFloatValue();
209     }
210     inline void set_TargetClimbRate( double val ) {
211         fgSetFloat( "/autopilot/config/target-climb-rate-fpm",  val);
212     }
213
214     inline char *get_TargetLatitudeStr() { return TargetLatitudeStr; }
215     inline char *get_TargetLongitudeStr() { return TargetLongitudeStr; }
216     inline char *get_TargetWP1Str() { return TargetWP1Str; }
217     inline char *get_TargetWP2Str() { return TargetWP2Str; }
218     inline char *get_TargetWP3Str() { return TargetWP3Str; }
219     inline char *get_TargetHeadingStr() { return TargetHeadingStr; }
220     inline char *get_TargetAltitudeStr() { return TargetAltitudeStr; }
221     inline char *get_TargetLatLonStr() { return TargetLatLonStr; }
222
223     // utility functions
224     void MakeTargetLatLonStr( double lat, double lon );
225     void MakeTargetAltitudeStr( double altitude );
226     void MakeTargetHeadingStr( double bearing );
227     void MakeTargetWPStr( double distance );
228     void update_old_control_values();
229
230     // accessors
231     inline double get_MaxRoll() const { return MaxRoll; }
232     inline void set_MaxRoll( double val ) { MaxRoll = val; }
233     inline double get_RollOut() const { return RollOut; }
234     inline void set_RollOut( double val ) { RollOut = val; }
235
236     inline double get_MaxAileron() const { return MaxAileron; }
237     inline void set_MaxAileron( double val ) { MaxAileron = val; }
238     inline double get_RollOutSmooth() const { return RollOutSmooth; }
239     inline void set_RollOutSmooth( double val ) { RollOutSmooth = val; }
240
241 private:
242
243     bool getAPAltitudeLock () const;
244     void setAPAltitudeLock (bool lock);
245     double getAPAltitude () const;
246     void setAPAltitude (double altitude);
247     bool getAPGSLock () const;
248     void setAPGSLock (bool lock);
249     bool getAPTerrainLock () const;
250     void setAPTerrainLock (bool lock);
251     double getAPClimb () const;
252     void setAPClimb (double rate);
253     bool getAPHeadingLock () const;
254     void setAPHeadingLock (bool lock);
255     double getAPHeadingBug () const;
256     void setAPHeadingBug (double heading);
257     bool getAPWingLeveler () const;
258     void setAPWingLeveler (bool lock);
259     bool getAPNAV1Lock () const;
260     void setAPNAV1Lock (bool lock);
261     bool getAPAutoThrottleLock () const;
262     void setAPAutoThrottleLock (bool lock);
263     double getAPRudderControl () const;
264     void setAPRudderControl (double value);
265     double getAPElevatorControl () const;
266     void setAPElevatorControl (double value);
267     double getAPThrottleControl () const;
268     void setAPThrottleControl (double value);
269
270 };
271
272
273 #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_DG_HEADING_LOCK
274 // #define DEFAULT_AP_HEADING_LOCK FGAutopilot::FG_TRUE_HEADING_LOCK
275 #define DEFAULT_AP_ALTITUDE_LOCK FGAutopilot::FG_ALTITUDE_LOCK
276
277
278 /**
279  * static functions for autopilot properties
280  */
281
282 #endif // _NEWAUTO_HXX
283