Changes and additions to utility functions to support voice ATC rendering and AI taxiing.
This commit is contained in:
parent
2a1c00b8e4
commit
46011ab535
2 changed files with 185 additions and 129 deletions
|
@ -22,12 +22,36 @@
|
|||
#include <simgear/math/point3d.hxx>
|
||||
#include <simgear/constants.h>
|
||||
#include <plib/sg.h>
|
||||
#include <iomanip.h>
|
||||
//#include <iomanip.h>
|
||||
|
||||
#include "ATCutils.hxx"
|
||||
|
||||
// Convert any number to spoken digits
|
||||
string ConvertNumToSpokenDigits(string n) {
|
||||
//cout << "n = " << n << endl;
|
||||
string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
|
||||
string pt = "decimal";
|
||||
string str = "";
|
||||
|
||||
for(unsigned int i=0; i<n.length(); ++i) {
|
||||
//cout << "n.substr(" << i << ",1 = " << n.substr(i,1) << endl;
|
||||
if(n.substr(i,1) == " ") {
|
||||
// do nothing
|
||||
} else if(n.substr(i,1) == ".") {
|
||||
str += pt;
|
||||
} else {
|
||||
str += nums[atoi((n.substr(i,1)).c_str())];
|
||||
}
|
||||
if(i != (n.length()-1)) { // ie. don't add a space at the end.
|
||||
str += " ";
|
||||
}
|
||||
}
|
||||
|
||||
return(str);
|
||||
}
|
||||
|
||||
// Convert a 2 digit rwy number to a spoken-style string
|
||||
string convertNumToSpokenString(int n) {
|
||||
string ConvertRwyNumToSpokenString(int n) {
|
||||
string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
|
||||
// Basic error/sanity checking
|
||||
while(n < 0) {
|
||||
|
@ -44,7 +68,8 @@ string convertNumToSpokenString(int n) {
|
|||
int index = n/10;
|
||||
str += nums[index];
|
||||
n -= (index * 10);
|
||||
str += "-";
|
||||
//str += "-";
|
||||
str += " "; //Changed this for the benefit of the voice token parser - prefer the "-" in the visual output though.
|
||||
str += nums[n];
|
||||
return(str);
|
||||
}
|
||||
|
@ -53,38 +78,38 @@ string convertNumToSpokenString(int n) {
|
|||
string GetPhoneticIdent(int i) {
|
||||
// TODO - Check i is between 1 and 26 and wrap if necessary
|
||||
switch(i) {
|
||||
case 1 : return("Alpha");
|
||||
case 2 : return("Bravo");
|
||||
case 3 : return("Charlie");
|
||||
case 4 : return("Delta");
|
||||
case 5 : return("Echo");
|
||||
case 6 : return("Foxtrot");
|
||||
case 7 : return("Golf");
|
||||
case 8 : return("Hotel");
|
||||
case 9 : return("Indigo");
|
||||
case 10 : return("Juliet");
|
||||
case 11 : return("Kilo");
|
||||
case 12 : return("Lima");
|
||||
case 13 : return("Mike");
|
||||
case 14 : return("November");
|
||||
case 15 : return("Oscar");
|
||||
case 16 : return("Papa");
|
||||
case 17 : return("Quebec");
|
||||
case 18 : return("Romeo");
|
||||
case 19 : return("Sierra");
|
||||
case 20 : return("Tango");
|
||||
case 21 : return("Uniform");
|
||||
case 22 : return("Victor");
|
||||
case 23 : return("Whiskey");
|
||||
case 24 : return("X-ray");
|
||||
case 25 : return("Yankee");
|
||||
case 26 : return("Zulu");
|
||||
case 1 : return("alpha");
|
||||
case 2 : return("bravo");
|
||||
case 3 : return("charlie");
|
||||
case 4 : return("delta");
|
||||
case 5 : return("echo");
|
||||
case 6 : return("foxtrot");
|
||||
case 7 : return("golf");
|
||||
case 8 : return("hotel");
|
||||
case 9 : return("india");
|
||||
case 10 : return("juliet");
|
||||
case 11 : return("kilo");
|
||||
case 12 : return("lima");
|
||||
case 13 : return("mike");
|
||||
case 14 : return("november");
|
||||
case 15 : return("oscar");
|
||||
case 16 : return("papa");
|
||||
case 17 : return("quebec");
|
||||
case 18 : return("romeo");
|
||||
case 19 : return("sierra");
|
||||
case 20 : return("tango");
|
||||
case 21 : return("uniform");
|
||||
case 22 : return("victor");
|
||||
case 23 : return("whiskey");
|
||||
case 24 : return("x-ray");
|
||||
case 25 : return("yankee");
|
||||
case 26 : return("zulu");
|
||||
}
|
||||
// We shouldn't get here
|
||||
return("Error");
|
||||
}
|
||||
|
||||
// Given two positions, get the HORIZONTAL separation (in meters)
|
||||
// Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
|
||||
double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2) {
|
||||
double x; //East-West separation
|
||||
double y; //North-South separation
|
||||
|
@ -104,6 +129,7 @@ double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2) {
|
|||
|
||||
// Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
|
||||
// Expects to be fed orthogonal co-ordinates, NOT lat & lon !
|
||||
// The units of the separation will be those of the input.
|
||||
double dclGetLinePointSeparation(double px, double py, double x1, double y1, double x2, double y2) {
|
||||
double vecx = x2-x1;
|
||||
double vecy = y2-y1;
|
||||
|
@ -120,7 +146,8 @@ double dclGetLinePointSeparation(double px, double py, double x1, double y1, dou
|
|||
return(d);
|
||||
}
|
||||
|
||||
// Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
|
||||
// Given a position (lat/lon/elev), heading and vertical angle (degrees), and distance (meters), calculate the new position.
|
||||
// This function assumes the world is spherical. If geodetic accuracy is required use the functions is sg_geodesy instead!
|
||||
// Assumes that the ground is not hit!!! Expects heading and angle in degrees, distance in meters.
|
||||
Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double distance) {
|
||||
//cout << setprecision(10) << pos.lon() << ' ' << pos.lat() << '\n';
|
||||
|
@ -152,22 +179,42 @@ Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double dist
|
|||
return(Point3D(lon*DCL_RADIANS_TO_DEGREES, lat*DCL_RADIANS_TO_DEGREES, elev));
|
||||
}
|
||||
|
||||
// Get a heading in degrees from one lat/lon to another.
|
||||
// This function assumes the world is spherical. If geodetic accuracy is required use the functions is sg_geodesy instead!
|
||||
// Warning - at the moment we are not checking for identical points - currently it returns 90 in this instance.
|
||||
double GetHeadingFromTo(Point3D A, Point3D B) {
|
||||
double latA = A.lat() * DCL_DEGREES_TO_RADIANS;
|
||||
double lonA = A.lon() * DCL_DEGREES_TO_RADIANS;
|
||||
double latB = B.lat() * DCL_DEGREES_TO_RADIANS;
|
||||
double lonB = B.lon() * DCL_DEGREES_TO_RADIANS;
|
||||
double xdist = sin(lonB - lonA) * (double)SG_EQUATORIAL_RADIUS_M * cos((latA+latB)/2.0);
|
||||
double ydist = sin(latB - latA) * (double)SG_EQUATORIAL_RADIUS_M;
|
||||
|
||||
#if 0
|
||||
/* Determine location in runway coordinates */
|
||||
if(xdist >= 0) {
|
||||
if(ydist > 0) {
|
||||
return(atan(xdist/ydist) * DCL_RADIANS_TO_DEGREES);
|
||||
} else if (ydist == 0) {
|
||||
return(90.0);
|
||||
} else {
|
||||
return(180.0 - atan(xdist/fabs(ydist)) * DCL_RADIANS_TO_DEGREES);
|
||||
}
|
||||
} else {
|
||||
if(ydist > 0) {
|
||||
return(360.0 - atan(fabs(xdist)/ydist) * DCL_RADIANS_TO_DEGREES);
|
||||
} else if (ydist == 0) {
|
||||
return(270.0);
|
||||
} else {
|
||||
return(180.0 + atan(xdist/ydist) * DCL_RADIANS_TO_DEGREES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Radius_to_rwy = Sea_level_radius + Runway_altitude;
|
||||
cos_rwy_hdg = cos(Runway_heading*DEG_TO_RAD);
|
||||
sin_rwy_hdg = sin(Runway_heading*DEG_TO_RAD);
|
||||
|
||||
D_cg_north_of_rwy = Radius_to_rwy*(Latitude - Runway_latitude);
|
||||
D_cg_east_of_rwy = Radius_to_rwy*cos(Runway_latitude)
|
||||
*(Longitude - Runway_longitude);
|
||||
D_cg_above_rwy = Radius_to_vehicle - Radius_to_rwy;
|
||||
|
||||
X_cg_rwy = D_cg_north_of_rwy*cos_rwy_hdg
|
||||
+ D_cg_east_of_rwy*sin_rwy_hdg;
|
||||
Y_cg_rwy =-D_cg_north_of_rwy*sin_rwy_hdg
|
||||
+ D_cg_east_of_rwy*cos_rwy_hdg;
|
||||
H_cg_rwy = D_cg_above_rwy;
|
||||
#endif
|
||||
// Given a heading (in degrees), bound it from 0 -> 360
|
||||
void dclBoundHeading(double &hdg) {
|
||||
while(hdg < 0.0) {
|
||||
hdg += 360.0;
|
||||
}
|
||||
while(hdg > 360.0) {
|
||||
hdg -= 360.0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,11 @@ SG_USING_STD(string);
|
|||
*
|
||||
********************************/
|
||||
|
||||
// Convert any number to spoken digits
|
||||
string ConvertNumToSpokenDigits(string n);
|
||||
|
||||
// Convert a 2 digit rwy number to a spoken-style string
|
||||
string convertNumToSpokenString(int n);
|
||||
string ConvertRwyNumToSpokenString(int n);
|
||||
|
||||
// Return the phonetic letter of a letter represented as an integer 1->26
|
||||
string GetPhoneticIdent(int i);
|
||||
|
@ -47,7 +50,7 @@ string GetPhoneticIdent(int i);
|
|||
*
|
||||
********************************/
|
||||
|
||||
// Given two positions, get the HORIZONTAL separation
|
||||
// Given two positions, get the HORIZONTAL separation (in meters)
|
||||
double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2);
|
||||
|
||||
// Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
|
||||
|
@ -57,3 +60,9 @@ double dclGetLinePointSeparation(double px, double py, double x1, double y1, dou
|
|||
// Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
|
||||
// Assumes that the ground is not hit!!! Expects heading and angle in degrees, distance in meters.
|
||||
Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double distance);
|
||||
|
||||
// Get a heading from one lat/lon to another (in degrees)
|
||||
double GetHeadingFromTo(Point3D A, Point3D B);
|
||||
|
||||
// Given a heading (in degrees), bound it from 0 -> 360
|
||||
void dclBoundHeading(double &hdg);
|
||||
|
|
Loading…
Add table
Reference in a new issue