1 // approach.hxx -- Approach class
3 // Written by Alexander Kappes, started March 2002.
5 // Copyright (C) 2002 Alexander Kappes
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef _FG_APPROACH_HXX
23 #define _FG_APPROACH_HXX
27 #include <simgear/compiler.h>
28 #include <simgear/math/sg_geodesy.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/magvar/magvar.hxx>
31 #include <simgear/timing/sg_time.hxx>
32 #include <simgear/bucket/newbucket.hxx>
34 #include <Main/fg_props.hxx>
36 #ifdef SG_HAVE_STD_INCLUDES
38 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
39 # include <iostream.h>
40 #elif defined( __BORLANDC__ )
47 #include "transmission.hxx"
49 //DCL - a complete guess for now.
50 #define FG_APPROACH_DEFAULT_RANGE 100
52 // Contains all the information about a plane that the approach control needs
53 const int max_planes = 20; // max number of planes on the stack
54 const int max_wp = 10; // max number of waypoints for approach phase
55 const double max_ta = 130; // max turning angle for plane during approach
56 const double tbm = 2.0; // min time (in sec) between two messages
57 const double lfl = 10.0; // length of final leg
61 // variables for plane if it's on the radar
62 std::string ident; // indentification of plane
63 double lon; // longitude in degrees
64 double lat; // latitude in degrees
65 double alt; // Altitute above sea level in feet
66 double hdg; // heading of plane in degrees
67 double dist; // distance to airport in miles
68 double brg; // bearing relative to airport in degrees
69 double spd; // speed above ground
70 int contact; // contact with approach established?
73 // 2 = handed off to tower
74 double turn_rate; // standard turning rate of the plane in seconds per degree
75 double desc_rate; // standard descent rate of the plane in feets per minute
76 double clmb_rate; // standard climb rate of the plane in feets per minute
78 // additional variables if contact has been established
79 int wpn; // number of waypoints
80 double wpts[max_wp][6]; // assigned waypoints for approach phase
81 // first wp in list is airport
82 // last waypoint point at which contact was established
83 // second index: 0 = bearing to airport
84 // second index: 1 = distance to airport
85 // second index: 2 = alt
86 // second index: 3 = ETA
87 // second index: 4 = heading to next waypoint
88 // second index: 5 = distance to next waypoint
90 double dnwp; // distance to next waypoint
91 double dcc; // closest distance to current assigned course
92 double dnc; // closest distance to course from next to next to next wp
93 double aalt; // assigned altitude
94 double ahdg; // assigned heading
95 bool on_crs; // is the plane on course?
96 bool wp_change; // way point has changed
97 double tlm; // time when last message was sent
98 TransCode lmc; // code of last message
102 class FGApproach : public FGATC {
106 std::string active_runway;
107 double active_rw_hdg;
108 double active_rw_lon;
109 double active_rw_lat;
110 double active_rw_len;
112 int num_planes; // number of planes on the stack
113 PlaneApp planes[max_planes]; // Array of planes
114 std::string transmission;
117 SGPropertyNode_ptr comm1_node;
118 SGPropertyNode_ptr comm2_node;
120 SGPropertyNode_ptr atcmenu_node;
121 SGPropertyNode_ptr atcopt0_node;
122 SGPropertyNode_ptr atcopt1_node;
123 SGPropertyNode_ptr atcopt2_node;
124 SGPropertyNode_ptr atcopt3_node;
125 SGPropertyNode_ptr atcopt4_node;
126 SGPropertyNode_ptr atcopt5_node;
127 SGPropertyNode_ptr atcopt6_node;
128 SGPropertyNode_ptr atcopt7_node;
129 SGPropertyNode_ptr atcopt8_node;
130 SGPropertyNode_ptr atcopt9_node;
132 // for failure modeling
133 std::string trans_ident; // transmitted ident
134 bool approach_failed; // approach failed?
143 void Update(double dt);
145 // Add new plane to stack if not already registered
146 // Input: pid - id of plane (name)
147 // Output: "true" if added; "false" if already existend
148 void AddPlane(const std::string& pid);
150 // Remove plane from stack if out of range
153 inline double get_bucket() const { return bucket; }
154 inline int get_pnum() const { return num_planes; }
155 inline const std::string& get_trans_ident() { return trans_ident; }
159 void calc_wp( const int &i);
161 void update_plane_dat();
163 void get_active_runway();
165 void update_param(const int &i);
167 double round_alt( bool hl, double alt );
169 double angle_diff_deg( const double &a1, const double &a2);
171 void set_message(const std::string &s);
173 // ========================================================================
174 // get point2 given starting point1 and course and distance
175 // input: point1 = heading in degrees, distance
176 // input: course in degrees, distance
177 // output: point2 = heading in degrees, distance
178 // ========================================================================
179 void calc_cd_head_dist(const double &h1, const double &d1,
180 const double &course, const double &dist,
181 double *h2, double *d2);
184 // ========================================================================
185 // get heading and distance between two points; point2 ---> point1
186 // input: point1 = heading in degrees, distance
187 // input: point2 = heading in degrees, distance
188 // output: course in degrees, distance
189 // ========================================================================
190 void calc_hd_course_dist(const double &h1, const double &d1,
191 const double &h2, const double &d2,
192 double *course, double *dist);
196 // ========================================================================
197 // closest distance between a point and a straigt line in 2 dim.
198 // the input variables are given in (heading, distance)
199 // relative to a common point
200 // input: point = heading in degrees, distance
201 // input: straigt line = anker vector (heading in degrees, distance),
202 // heading of direction vector
204 // ========================================================================
205 double calc_psl_dist(const double &h1, const double &d1,
206 const double &h2, const double &d2,
209 // Pointers to current users position
210 SGPropertyNode_ptr lon_node;
211 SGPropertyNode_ptr lat_node;
212 SGPropertyNode_ptr elev_node;
213 SGPropertyNode_ptr hdg_node;
214 SGPropertyNode_ptr speed_node;
215 SGPropertyNode_ptr etime_node;
217 //Update the transmission string
218 void UpdateTransmission(void);
220 friend std::istream& operator>> ( std::istream&, FGApproach& );
223 #endif // _FG_APPROACH_HXX