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