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