1
0
Fork 0
flightgear/src/ATC/approach.hxx

186 lines
6.3 KiB
C++
Raw Normal View History

// 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., 675 Mass Ave, Cambridge, MA 02139, 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( __BORLANDC__ ) || (__APPLE__)
# include <iostream>
#else
# include <istream.h>
#include <iomanip.h>
#endif
SG_USING_STD(istream);
SG_USING_STD(string);
#include "ATC.hxx"
//DCL - a complete guess for now.
#define FG_APPROACH_DEFAULT_RANGE 100
// Contains all 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
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
// 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 aiport
// 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 alt at next waypoint
double ahdg; // assigned heading
bool on_crs; // is the plane on course?
double tlm; // time when last message was sent
PlaneApp(void);
};
class FGApproach : public FGATC {
int bucket;
string active_runway;
double active_rw_hdg;
bool display; // Flag to indicate whether we should be outputting to the display.
bool displaying; // Flag to indicate whether we are outputting to the display.
int num_planes; // number of planes on the stack
PlaneApp planes[max_planes]; // Array of planes
string transmission;
bool first;
SGPropertyNode *comm1_node;
SGPropertyNode *comm2_node;
// for failure modeling
string trans_ident; // transmitted ident
bool approach_failed; // approach failed?
public:
FGApproach(void);
~FGApproach(void);
void Init();
void Update();
// 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(string pid);
// Remove plane from stack if out of range
int RemovePlane();
//Indicate that this instance should be outputting to the ATC display
inline void SetDisplay(void) {display = true;}
//Indicate that this instance should not be outputting to the ATC display
inline void SetNoDisplay(void) {display = false;}
inline double get_bucket() const { return bucket; }
inline int get_pnum() const { return num_planes; }
inline string get_trans_ident() { return trans_ident; }
inline atc_type GetType() { return APPROACH; }
private:
void update_plane_dat();
void get_active_runway();
// ========================================================================
// get heading and distance between two points; point2 ---> point1
// input: point1 = heading in degrees, distance
// input: point2 = heading in degrees, distance
// ouput: 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 *lon_node;
SGPropertyNode *lat_node;
SGPropertyNode *elev_node;
//Update the transmission string
void UpdateTransmission(void);
};
#endif // _FG_APPROACH_HXX