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>
39 #include "transmission.hxx"
41 //DCL - a complete guess for now.
42 #define FG_APPROACH_DEFAULT_RANGE 100
44 // Contains all the information about a plane that the approach control needs
45 const int max_planes = 20; // max number of planes on the stack
46 const int max_wp = 10; // max number of waypoints for approach phase
47 const double max_ta = 130; // max turning angle for plane during approach
48 const double tbm = 2.0; // min time (in sec) between two messages
49 const double lfl = 10.0; // length of final leg
53 // variables for plane if it's on the radar
54 std::string ident; // indentification of plane
55 double lon; // longitude in degrees
56 double lat; // latitude in degrees
57 double alt; // Altitute above sea level in feet
58 double hdg; // heading of plane in degrees
59 double dist; // distance to airport in miles
60 double brg; // bearing relative to airport in degrees
61 double spd; // speed above ground
62 int contact; // contact with approach established?
65 // 2 = handed off to tower
66 double turn_rate; // standard turning rate of the plane in seconds per degree
67 double desc_rate; // standard descent rate of the plane in feets per minute
68 double clmb_rate; // standard climb rate of the plane in feets per minute
70 // additional variables if contact has been established
71 int wpn; // number of waypoints
72 double wpts[max_wp][6]; // assigned waypoints for approach phase
73 // first wp in list is airport
74 // last waypoint point at which contact was established
75 // second index: 0 = bearing to airport
76 // second index: 1 = distance to airport
77 // second index: 2 = alt
78 // second index: 3 = ETA
79 // second index: 4 = heading to next waypoint
80 // second index: 5 = distance to next waypoint
82 double dnwp; // distance to next waypoint
83 double dcc; // closest distance to current assigned course
84 double dnc; // closest distance to course from next to next to next wp
85 double aalt; // assigned altitude
86 double ahdg; // assigned heading
87 bool on_crs; // is the plane on course?
88 bool wp_change; // way point has changed
89 double tlm; // time when last message was sent
90 TransCode lmc; // code of last message
94 class FGApproach : public FGATC {
98 std::string active_runway;
100 double active_rw_lon;
101 double active_rw_lat;
102 double active_rw_len;
104 int num_planes; // number of planes on the stack
105 PlaneApp planes[max_planes]; // Array of planes
106 std::string transmission;
109 SGPropertyNode_ptr comm1_node;
110 SGPropertyNode_ptr comm2_node;
112 SGPropertyNode_ptr atcmenu_node;
113 SGPropertyNode_ptr atcopt0_node;
114 SGPropertyNode_ptr atcopt1_node;
115 SGPropertyNode_ptr atcopt2_node;
116 SGPropertyNode_ptr atcopt3_node;
117 SGPropertyNode_ptr atcopt4_node;
118 SGPropertyNode_ptr atcopt5_node;
119 SGPropertyNode_ptr atcopt6_node;
120 SGPropertyNode_ptr atcopt7_node;
121 SGPropertyNode_ptr atcopt8_node;
122 SGPropertyNode_ptr atcopt9_node;
124 // for failure modeling
125 std::string trans_ident; // transmitted ident
126 bool approach_failed; // approach failed?
135 void Update(double dt);
137 // Add new plane to stack if not already registered
138 // Input: pid - id of plane (name)
139 // Output: "true" if added; "false" if already existend
140 void AddPlane(const std::string& pid);
142 // Remove plane from stack if out of range
145 inline double get_bucket() const { return bucket; }
146 inline int get_pnum() const { return num_planes; }
147 inline const std::string& get_trans_ident() { return trans_ident; }
151 void calc_wp( const int &i);
153 void update_plane_dat();
155 void get_active_runway();
157 void update_param(const int &i);
159 double round_alt( bool hl, double alt );
161 double angle_diff_deg( const double &a1, const double &a2);
163 void set_message(const std::string &s);
165 // ========================================================================
166 // get point2 given starting point1 and course and distance
167 // input: point1 = heading in degrees, distance
168 // input: course in degrees, distance
169 // output: point2 = heading in degrees, distance
170 // ========================================================================
171 void calc_cd_head_dist(const double &h1, const double &d1,
172 const double &course, const double &dist,
173 double *h2, double *d2);
176 // ========================================================================
177 // get heading and distance between two points; point2 ---> point1
178 // input: point1 = heading in degrees, distance
179 // input: point2 = heading in degrees, distance
180 // output: course in degrees, distance
181 // ========================================================================
182 void calc_hd_course_dist(const double &h1, const double &d1,
183 const double &h2, const double &d2,
184 double *course, double *dist);
188 // ========================================================================
189 // closest distance between a point and a straigt line in 2 dim.
190 // the input variables are given in (heading, distance)
191 // relative to a common point
192 // input: point = heading in degrees, distance
193 // input: straigt line = anker vector (heading in degrees, distance),
194 // heading of direction vector
196 // ========================================================================
197 double calc_psl_dist(const double &h1, const double &d1,
198 const double &h2, const double &d2,
201 // Pointers to current users position
202 SGPropertyNode_ptr lon_node;
203 SGPropertyNode_ptr lat_node;
204 SGPropertyNode_ptr elev_node;
205 SGPropertyNode_ptr hdg_node;
206 SGPropertyNode_ptr speed_node;
207 SGPropertyNode_ptr etime_node;
209 //Update the transmission string
210 void UpdateTransmission(void);
212 friend std::istream& operator>> ( std::istream&, FGApproach& );
215 #endif // _FG_APPROACH_HXX