redefine the constructor to be more flexible with constraints, etc.

This commit is contained in:
Sven Czarnian
2021-10-13 16:16:03 +02:00
parent 014379740b
commit 909cfc9e27
3 changed files with 44 additions and 8 deletions

View File

@@ -31,15 +31,15 @@ class SctEseFormat:
if len(split) <= longitudeIdx:
sys.stderr.write('Invalid waypoint format: ' + waypoint)
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):
split = list(filter(None, runway.split(' ')))
if 9 != len(split) or '' == split[8]:
return None, None, None
waypoint0 = Waypoint(split[0], Waypoint.dms2dd(split[4]), Waypoint.dms2dd(split[5]))
waypoint1 = Waypoint(split[1], Waypoint.dms2dd(split[6]), Waypoint.dms2dd(split[7]))
waypoint0 = Waypoint(name = split[0], latitude = split[4], longitude = split[5])
waypoint1 = Waypoint(name = split[1], latitude = split[6], longitude = split[7])
return split[8], Runway(waypoint0, waypoint1), Runway(waypoint1, waypoint0)

View File

@@ -37,7 +37,7 @@ class Inbound:
# find the nearest runway for an initial guess
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:
candidateDistance = runway.Runway.Start.haversine(currentPosition)
if distance > candidateDistance:
@@ -70,7 +70,7 @@ class Inbound:
# calculate descend profile
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
nextWaypointIndex = 0
currentPosition = [ self.Report.dynamics.altitude, self.Report.dynamics.groundSpeed ]

View File

@@ -2,6 +2,7 @@
import numpy as np
import pyproj
import sys
class Waypoint:
def dms2dd(coordinate : str):
@@ -20,9 +21,44 @@ class Waypoint:
return dd
def __init__(self, name : str, latitude : float, longitude : float):
self.Name = name
self.Coordinate = np.array([ latitude, longitude ])
def coordinateArgument(value):
if True == isinstance(value, str):
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):
return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])