]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/approach.hxx
Modified Files:
[flightgear.git] / src / ATC / approach.hxx
index cdd06a68c20c1dff3e336818023e5cd9179e0319..9aec71d0174e96bc9535d99387d31ffe8ca27609 100644 (file)
-// approach.hxx -- Approach class\r
-//\r
-// Written by Alexander Kappes, started March 2002.\r
-//\r
-// Copyright (C) 2002  Alexander Kappes\r
-//\r
-// This program is free software; you can redistribute it and/or\r
-// modify it under the terms of the GNU General Public License as\r
-// published by the Free Software Foundation; either version 2 of the\r
-// License, or (at your option) any later version.\r
-//\r
-// This program is distributed in the hope that it will be useful, but\r
-// WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
-// General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, write to the Free Software\r
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
-\r
-\r
-#ifndef _FG_APPROACH_HXX\r
-#define _FG_APPROACH_HXX\r
-\r
-#include <stdio.h>\r
-\r
-#include <simgear/compiler.h>\r
-#include <simgear/math/sg_geodesy.hxx>\r
-#include <simgear/misc/sgstream.hxx>\r
-#include <simgear/magvar/magvar.hxx>\r
-#include <simgear/timing/sg_time.hxx>\r
-#include <simgear/bucket/newbucket.hxx>\r
-\r
-#include <Main/fg_props.hxx>\r
-\r
-#ifdef SG_HAVE_STD_INCLUDES\r
-#  include <istream>\r
-#include <iomanip>\r
-#elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
-#  include <iostream.h>\r
-#elif defined( __BORLANDC__ )\r
-#  include <iostream>\r
-#else\r
-#  include <istream.h>\r
-#include <iomanip.h>\r
-#endif\r
-\r
-#if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
-SG_USING_STD(istream);\r
-#endif\r
-\r
-SG_USING_STD(string);\r
-\r
-#include "ATC.hxx"\r
-#include "transmission.hxx"\r
-\r
-//DCL - a complete guess for now.\r
-#define FG_APPROACH_DEFAULT_RANGE 100\r
-\r
-// Contains all the information about a plane that the approach control needs\r
-const int    max_planes = 20;  // max number of planes on the stack\r
-const int    max_wp = 10;      // max number of waypoints for approach phase\r
-const double max_ta = 130;     // max turning angle for plane during approach\r
-const double tbm    = 20000.0; // min time (in ms) between two messages\r
-const double lfl    = 10.0;    // length of final leg\r
-\r
-struct PlaneApp {\r
-\r
-  // variables for plane if it's on the radar\r
-  string ident;          // indentification of plane\r
-  double lon;            // longitude in degrees\r
-  double lat;            // latitude in degrees\r
-  double alt;            // Altitute above sea level in feet\r
-  double hdg;            // heading of plane in degrees\r
-  double dist;           // distance to airport in miles\r
-  double brg;            // bearing relative to airport in degrees\r
-  double spd;            // speed above ground\r
-  int    contact;        // contact with approach established?\r
-                         // 0 = no contact yet\r
-                         // 1 = in contact\r
-                         // 2 = handed off to tower\r
-  double turn_rate;      // standard turning rate of the plane in seconds per degree\r
-  double desc_rate;      // standard descent rate of the plane in feets per minute\r
-  double clmb_rate;      // standard climb rate of the plane in feets per minute\r
-\r
-  // additional variables if contact has been established\r
-  int    wpn;                 // number of waypoints\r
-  double wpts[max_wp][6];     // assigned waypoints for approach phase \r
-                              // first wp in list is airport\r
-                              // last waypoint point at which contact was established\r
-                              // second index: 0 = bearing to airport\r
-                              // second index: 1 = distance to airport\r
-                              // second index: 2 = alt \r
-                              // second index: 3 = ETA\r
-                              // second index: 4 = heading to next waypoint\r
-                              // second index: 5 = distance to next waypoint\r
-\r
-  double dnwp;           // distance to next waypoint\r
-  double dcc;            // closest distance to current assigned course\r
-  double dnc;            // closest distance to course from next to next to next wp\r
-  double aalt;           // assigned altitude\r
-  double ahdg;           // assigned heading\r
-  bool   on_crs;         // is the plane on course?\r
-  bool   wp_change;      // way point has changed\r
-  double tlm;            // time when last message was sent\r
-  TransCode lmc;         // code of last message\r
-};\r
-\r
-\r
-class FGApproach : public FGATC {\r
-\r
-  int      bucket;\r
-\r
-  string active_runway;         \r
-  double active_rw_hdg;\r
-  double active_rw_lon;\r
-  double active_rw_lat;\r
-  double active_rw_len;\r
-\r
-  bool     display;            // Flag to indicate whether we should be outputting to the display.\r
-  bool     displaying;         // Flag to indicate whether we are outputting to the display.\r
-  int      num_planes;          // number of planes on the stack\r
-  PlaneApp planes[max_planes];  // Array of planes\r
-  string   transmission;\r
-  bool     first;\r
-\r
-  SGPropertyNode *comm1_node;\r
-  SGPropertyNode *comm2_node;\r
-\r
-  SGPropertyNode *atcmenu_node;\r
-  SGPropertyNode *atcopt0_node;\r
-  SGPropertyNode *atcopt1_node;\r
-  SGPropertyNode *atcopt2_node;\r
-  SGPropertyNode *atcopt3_node;\r
-  SGPropertyNode *atcopt4_node;\r
-  SGPropertyNode *atcopt5_node;\r
-  SGPropertyNode *atcopt6_node;\r
-  SGPropertyNode *atcopt7_node;\r
-  SGPropertyNode *atcopt8_node;\r
-  SGPropertyNode *atcopt9_node;\r
-\r
-  // for failure modeling\r
-  string trans_ident;  // transmitted ident\r
-  bool approach_failed;        // approach failed?\r
-\r
-public:\r
-\r
-  FGApproach(void);\r
-  ~FGApproach(void);\r
-\r
-  void Init();\r
-\r
-  void Update();\r
-\r
-  // Add new plane to stack if not already registered \r
-  // Input:  pid - id of plane (name) \r
-  // Output: "true" if added; "false" if already existend\r
-  void AddPlane(string pid);\r
-\r
-  // Remove plane from stack if out of range\r
-  int RemovePlane();\r
-  \r
-  //Indicate that this instance should be outputting to the ATC display\r
-  inline void SetDisplay(void) {display = true;}\r
-  \r
-  //Indicate that this instance should not be outputting to the ATC display\r
-  inline void SetNoDisplay(void) {display = false;}\r
-  \r
-  inline double get_bucket() const { return bucket; }\r
-  inline int get_pnum() const { return num_planes; }\r
-  inline string get_trans_ident() { return trans_ident; }\r
-  inline atc_type GetType() { return APPROACH; }\r
-  \r
-private:\r
-\r
-  void calc_wp( const int &i);\r
-\r
-  void update_plane_dat();\r
-\r
-  void get_active_runway();\r
-\r
-  void update_param(const int &i);\r
-\r
-  double round_alt( bool hl, double alt );\r
-\r
-  double angle_diff_deg( const double &a1, const double &a2);\r
-\r
-// ========================================================================\r
-// get point2 given starting point1 and course and distance\r
-// input:  point1 = heading in degrees, distance\r
-// input:  course in degrees, distance\r
-// output: point2 = heading in degrees, distance\r
-// ========================================================================\r
-  void calc_cd_head_dist(const double &h1, const double &d1,\r
-                        const double &course, const double &dist,\r
-                        double *h2, double *d2);\r
-\r
-\r
-// ========================================================================\r
-// get heading and distance between two points; point2 ---> point1\r
-// input:  point1 = heading in degrees, distance\r
-// input:  point2 = heading in degrees, distance\r
-// output: course in degrees, distance\r
-// ========================================================================\r
-  void calc_hd_course_dist(const double &h1, const double &d1,\r
-                          const double &h2, const double &d2,\r
-                          double *course, double *dist);\r
-\r
-\r
-\r
-// ========================================================================\r
-// closest distance between a point and a straigt line in 2 dim.\r
-// the input variables are given in (heading, distance) \r
-// relative to a common point\r
-// input:  point        = heading in degrees, distance\r
-// input:  straigt line = anker vector (heading in degrees, distance), \r
-//                        heading of direction vector\r
-// output: distance\r
-// ========================================================================\r
-  double calc_psl_dist(const double &h1, const double &d1,\r
-                      const double &h2, const double &d2,\r
-                      const double &h3);\r
-\r
-  // Pointers to current users position\r
-  SGPropertyNode *lon_node;\r
-  SGPropertyNode *lat_node;\r
-  SGPropertyNode *elev_node;\r
-  SGPropertyNode *hdg_node;\r
-  SGPropertyNode *speed_node;\r
-  SGPropertyNode *etime_node;\r
-  \r
-  //Update the transmission string\r
-  void UpdateTransmission(void);\r
-  \r
-  friend istream& operator>> ( istream&, FGApproach& );\r
-};\r
-\r
-#endif // _FG_APPROACH_HXX\r
+// approach.hxx -- Approach class
+//
+// Written by Alexander Kappes, started March 2002.
+//
+// Copyright (C) 2002  Alexander Kappes
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+
+#ifndef _FG_APPROACH_HXX
+#define _FG_APPROACH_HXX
+
+#include <stdio.h>
+
+#include <simgear/compiler.h>
+#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/misc/sgstream.hxx>
+#include <simgear/magvar/magvar.hxx>
+#include <simgear/timing/sg_time.hxx>
+#include <simgear/bucket/newbucket.hxx>
+
+#include <Main/fg_props.hxx>
+
+#ifdef SG_HAVE_STD_INCLUDES
+#  include <istream>
+#include <iomanip>
+#elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
+#  include <iostream.h>
+#elif defined( __BORLANDC__ )
+#  include <iostream>
+#else
+#  include <istream.h>
+#include <iomanip.h>
+#endif
+
+#if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
+SG_USING_STD(istream);
+#endif
+
+SG_USING_STD(string);
+
+#include "ATC.hxx"
+#include "transmission.hxx"
+
+//DCL - a complete guess for now.
+#define FG_APPROACH_DEFAULT_RANGE 100
+
+// Contains all the information about a plane that the approach control needs
+const int    max_planes = 20;  // max number of planes on the stack
+const int    max_wp = 10;      // max number of waypoints for approach phase
+const double max_ta = 130;     // max turning angle for plane during approach
+const double tbm    = 2.0;     // min time (in sec) between two messages
+const double lfl    = 10.0;    // length of final leg
+
+struct PlaneApp {
+
+  // variables for plane if it's on the radar
+  string ident;          // indentification of plane
+  double lon;            // longitude in degrees
+  double lat;            // latitude in degrees
+  double alt;            // Altitute above sea level in feet
+  double hdg;            // heading of plane in degrees
+  double dist;           // distance to airport in miles
+  double brg;            // bearing relative to airport in degrees
+  double spd;            // speed above ground
+  int    contact;        // contact with approach established?
+                         // 0 = no contact yet
+                         // 1 = in contact
+                         // 2 = handed off to tower
+  double turn_rate;      // standard turning rate of the plane in seconds per degree
+  double desc_rate;      // standard descent rate of the plane in feets per minute
+  double clmb_rate;      // standard climb rate of the plane in feets per minute
+
+  // additional variables if contact has been established
+  int    wpn;                 // number of waypoints
+  double wpts[max_wp][6];     // assigned waypoints for approach phase 
+                              // first wp in list is airport
+                              // last waypoint point at which contact was established
+                              // second index: 0 = bearing to airport
+                              // second index: 1 = distance to airport
+                              // second index: 2 = alt 
+                              // second index: 3 = ETA
+                              // second index: 4 = heading to next waypoint
+                              // second index: 5 = distance to next waypoint
+
+  double dnwp;           // distance to next waypoint
+  double dcc;            // closest distance to current assigned course
+  double dnc;            // closest distance to course from next to next to next wp
+  double aalt;           // assigned altitude
+  double ahdg;           // assigned heading
+  bool   on_crs;         // is the plane on course?
+  bool   wp_change;      // way point has changed
+  double tlm;            // time when last message was sent
+  TransCode lmc;         // code of last message
+};
+
+
+class FGApproach : public FGATC {
+
+  int      bucket;
+
+  string active_runway;         
+  double active_rw_hdg;
+  double active_rw_lon;
+  double active_rw_lat;
+  double active_rw_len;
+
+  int      num_planes;          // number of planes on the stack
+  PlaneApp planes[max_planes];  // Array of planes
+  string   transmission;
+  bool     first;
+
+  SGPropertyNode_ptr comm1_node;
+  SGPropertyNode_ptr comm2_node;
+
+  SGPropertyNode_ptr atcmenu_node;
+  SGPropertyNode_ptr atcopt0_node;
+  SGPropertyNode_ptr atcopt1_node;
+  SGPropertyNode_ptr atcopt2_node;
+  SGPropertyNode_ptr atcopt3_node;
+  SGPropertyNode_ptr atcopt4_node;
+  SGPropertyNode_ptr atcopt5_node;
+  SGPropertyNode_ptr atcopt6_node;
+  SGPropertyNode_ptr atcopt7_node;
+  SGPropertyNode_ptr atcopt8_node;
+  SGPropertyNode_ptr atcopt9_node;
+
+  // for failure modeling
+  string trans_ident;  // transmitted ident
+  bool approach_failed;        // approach failed?
+
+public:
+
+  FGApproach(void);
+  ~FGApproach(void);
+
+  void Init();
+
+  void Update(double dt);
+
+  // Add new plane to stack if not already registered 
+  // Input:  pid - id of plane (name) 
+  // Output: "true" if added; "false" if already existend
+  void AddPlane(const string& pid);
+
+  // Remove plane from stack if out of range
+  int RemovePlane();
+  
+  inline double get_bucket() const { return bucket; }
+  inline int get_pnum() const { return num_planes; }
+  inline const string& get_trans_ident() { return trans_ident; }
+  
+private:
+
+  void calc_wp( const int &i);
+
+  void update_plane_dat();
+
+  void get_active_runway();
+
+  void update_param(const int &i);
+
+  double round_alt( bool hl, double alt );
+
+  double angle_diff_deg( const double &a1, const double &a2);
+
+  void set_message(const string &s);
+
+// ========================================================================
+// get point2 given starting point1 and course and distance
+// input:  point1 = heading in degrees, distance
+// input:  course in degrees, distance
+// output: point2 = heading in degrees, distance
+// ========================================================================
+  void calc_cd_head_dist(const double &h1, const double &d1,
+                        const double &course, const double &dist,
+                        double *h2, double *d2);
+
+
+// ========================================================================
+// get heading and distance between two points; point2 ---> point1
+// input:  point1 = heading in degrees, distance
+// input:  point2 = heading in degrees, distance
+// output: course in degrees, distance
+// ========================================================================
+  void calc_hd_course_dist(const double &h1, const double &d1,
+                          const double &h2, const double &d2,
+                          double *course, double *dist);
+
+
+
+// ========================================================================
+// closest distance between a point and a straigt line in 2 dim.
+// the input variables are given in (heading, distance) 
+// relative to a common point
+// input:  point        = heading in degrees, distance
+// input:  straigt line = anker vector (heading in degrees, distance), 
+//                        heading of direction vector
+// output: distance
+// ========================================================================
+  double calc_psl_dist(const double &h1, const double &d1,
+                      const double &h2, const double &d2,
+                      const double &h3);
+
+  // Pointers to current users position
+  SGPropertyNode_ptr lon_node;
+  SGPropertyNode_ptr lat_node;
+  SGPropertyNode_ptr elev_node;
+  SGPropertyNode_ptr hdg_node;
+  SGPropertyNode_ptr speed_node;
+  SGPropertyNode_ptr etime_node;
+  
+  //Update the transmission string
+  void UpdateTransmission(void);
+  
+  friend istream& operator>> ( istream&, FGApproach& );
+};
+
+#endif // _FG_APPROACH_HXX