redefine the constructor to be more flexible with constraints, etc.
This commit is contained in:
@@ -31,15 +31,15 @@ class SctEseFormat:
|
|||||||
if len(split) <= longitudeIdx:
|
if len(split) <= longitudeIdx:
|
||||||
sys.stderr.write('Invalid waypoint format: ' + waypoint)
|
sys.stderr.write('Invalid waypoint format: ' + waypoint)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
return Waypoint(split[nameIdx], Waypoint.dms2dd(split[latitudeIdx]), Waypoint.dms2dd(split[longitudeIdx]))
|
return Waypoint(name = split[nameIdx], latitude = split[latitudeIdx], longitude = split[longitudeIdx])
|
||||||
|
|
||||||
def parseRunway(runway : str):
|
def parseRunway(runway : str):
|
||||||
split = list(filter(None, runway.split(' ')))
|
split = list(filter(None, runway.split(' ')))
|
||||||
if 9 != len(split) or '' == split[8]:
|
if 9 != len(split) or '' == split[8]:
|
||||||
return None, None, None
|
return None, None, None
|
||||||
|
|
||||||
waypoint0 = Waypoint(split[0], Waypoint.dms2dd(split[4]), Waypoint.dms2dd(split[5]))
|
waypoint0 = Waypoint(name = split[0], latitude = split[4], longitude = split[5])
|
||||||
waypoint1 = Waypoint(split[1], Waypoint.dms2dd(split[6]), Waypoint.dms2dd(split[7]))
|
waypoint1 = Waypoint(name = split[1], latitude = split[6], longitude = split[7])
|
||||||
|
|
||||||
return split[8], Runway(waypoint0, waypoint1), Runway(waypoint1, waypoint0)
|
return split[8], Runway(waypoint0, waypoint1), Runway(waypoint1, waypoint0)
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Inbound:
|
|||||||
|
|
||||||
# find the nearest runway for an initial guess
|
# find the nearest runway for an initial guess
|
||||||
distance = 100000.0
|
distance = 100000.0
|
||||||
currentPosition = Waypoint('', self.Report.position.latitude, self.Report.position.longitude)
|
currentPosition = Waypoint(latitude = self.Report.position.latitude, longitude = self.Report.position.longitude)
|
||||||
for runway in sequencingConfig.ActiveArrivalRunways:
|
for runway in sequencingConfig.ActiveArrivalRunways:
|
||||||
candidateDistance = runway.Runway.Start.haversine(currentPosition)
|
candidateDistance = runway.Runway.Start.haversine(currentPosition)
|
||||||
if distance > candidateDistance:
|
if distance > candidateDistance:
|
||||||
@@ -70,7 +70,7 @@ class Inbound:
|
|||||||
|
|
||||||
# calculate descend profile
|
# calculate descend profile
|
||||||
flightTimeSeconds = 0
|
flightTimeSeconds = 0
|
||||||
currentHeading = Waypoint('', self.Report.position.latitude, self.Report.position.longitude).bearing(self.PlannedStar.Route[0])
|
currentHeading = Waypoint(latitude = self.Report.position.latitude, longitude = self.Report.position.longitude).bearing(self.PlannedStar.Route[0])
|
||||||
distanceToWaypoint = self.Report.distanceToIAF
|
distanceToWaypoint = self.Report.distanceToIAF
|
||||||
nextWaypointIndex = 0
|
nextWaypointIndex = 0
|
||||||
currentPosition = [ self.Report.dynamics.altitude, self.Report.dynamics.groundSpeed ]
|
currentPosition = [ self.Report.dynamics.altitude, self.Report.dynamics.groundSpeed ]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyproj
|
import pyproj
|
||||||
|
import sys
|
||||||
|
|
||||||
class Waypoint:
|
class Waypoint:
|
||||||
def dms2dd(coordinate : str):
|
def dms2dd(coordinate : str):
|
||||||
@@ -20,9 +21,44 @@ class Waypoint:
|
|||||||
|
|
||||||
return dd
|
return dd
|
||||||
|
|
||||||
def __init__(self, name : str, latitude : float, longitude : float):
|
def coordinateArgument(value):
|
||||||
self.Name = name
|
if True == isinstance(value, str):
|
||||||
self.Coordinate = np.array([ latitude, longitude ])
|
return Waypoint.dms2dd(value)
|
||||||
|
elif True == isinstance(value, (float, int)):
|
||||||
|
return float(value)
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid constructor argument')
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.Name = None
|
||||||
|
self.Coordinate = None
|
||||||
|
self.Altitude = None
|
||||||
|
self.Speed = None
|
||||||
|
self.BaseTurn = False
|
||||||
|
self.FinalTurn = False
|
||||||
|
|
||||||
|
latitude = None
|
||||||
|
longitude = None
|
||||||
|
for key, value in kwargs.items():
|
||||||
|
if 'name' == key.lower():
|
||||||
|
self.Name = str(value)
|
||||||
|
elif 'latitude' == key.lower():
|
||||||
|
latitude = Waypoint.coordinateArgument(value)
|
||||||
|
elif 'longitude' == key.lower():
|
||||||
|
longitude = Waypoint.coordinateArgument(value)
|
||||||
|
elif 'altitude' == key.lower():
|
||||||
|
self.Altitude = int(value)
|
||||||
|
elif 'speed' == key.lower():
|
||||||
|
self.Speed = int(value)
|
||||||
|
elif 'base' == key:
|
||||||
|
self.BaseTurn = bool(value)
|
||||||
|
elif 'final' == key:
|
||||||
|
self.FinalTurn = bool(value)
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid constructor argument: ' + key)
|
||||||
|
|
||||||
|
if None != latitude and None != longitude:
|
||||||
|
self.Coordinate = np.array([ latitude, longitude ])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])
|
return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])
|
||||||
|
|||||||
Reference in New Issue
Block a user