Skip to content

Commit

Permalink
Consistently include age of flight message in calculations, or not
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond LeClair committed Feb 9, 2023
1 parent 901121b commit 1dad621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
12 changes: 8 additions & 4 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
from datetime import datetime, timedelta
from distutils.util import strtobool
import errno
import json
from json.decoder import JSONDecodeError
Expand Down Expand Up @@ -84,7 +85,7 @@
camera_longitude = None
camera_altitude = None
camera_lead = None

include_age = strtobool(os.getenv("INCLUDE_AGE", "True"))

def calculate_bearing_correction(b):
return (b + cameraBearingCorrection) % 360
Expand Down Expand Up @@ -413,7 +414,10 @@ def calculateCameraPositionB(
# Compute lead time accounting for age of message, and specified
# lead time
a_datetime = utils.convert_time(a_time)
a_lead = (datetime.utcnow() - a_datetime).total_seconds() + camera_lead # [s]
if include_age:
a_lead = (datetime.utcnow() - a_datetime).total_seconds() + camera_lead # [s]
else:
a_lead = camera_lead # [s]

# Assign position of the tripod
t_varphi = camera_latitude # [deg]
Expand Down Expand Up @@ -494,7 +498,7 @@ def calculateCameraPositionA():
global angularVelocityVertical
global elevation

(lat, lon, alt) = utils.calc_travel_3d(currentPlane, camera_lead)
(lat, lon, alt) = utils.calc_travel_3d(currentPlane, camera_lead, include_age=include_age)
distance3d = utils.coordinate_distance_3d(
camera_latitude, camera_longitude, camera_altitude, lat, lon, alt
)
Expand All @@ -509,7 +513,7 @@ def calculateCameraPositionA():
distance2d, cameraAltitude=camera_altitude, airplaneAltitude=alt
)
(angularVelocityHorizontal, angularVelocityVertical) = utils.angular_velocity(
currentPlane, camera_latitude, camera_longitude, camera_altitude
currentPlane, camera_latitude, camera_longitude, camera_altitude, include_age=include_age
)
# logging.info("Angular Velocity - Horizontal: {} Vertical: {}".format(angularVelocityHorizontal, angularVelocityVertical))
cameraTilt = elevation
Expand Down
21 changes: 13 additions & 8 deletions axis-ptz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def convert_time(inp_date_time):
return out_date_time


def calc_travel_3d(current_plane, lead_s: float):
def calc_travel_3d(current_plane, lead_s: float, include_age=True):
"""Extrapolate the 3D position of the aircraft
Arguments:
Expand All @@ -264,11 +264,16 @@ def calc_travel_3d(current_plane, lead_s: float):
heading = current_plane["track"]
climb_rate = current_plane["verticalRate"]

lat_lon_age = datetime.utcnow() - lat_lon_time
lat_lon_age_s = lat_lon_age.total_seconds() + lead_s
if include_age:
lat_lon_age = datetime.utcnow() - lat_lon_time
lat_lon_age_s = lat_lon_age.total_seconds() + lead_s

alt_age = datetime.utcnow() - altitude_time
alt_age_s = alt_age.total_seconds() + lead_s
alt_age = datetime.utcnow() - altitude_time
alt_age_s = alt_age.total_seconds() + lead_s

else:
lat_lon_age_s = lead_s
alt_age_s = lead_s

R = float(6371) # Radius of the Earth in km
brng = math.radians(heading) # Bearing is 90 degrees converted to radians.
Expand All @@ -294,8 +299,8 @@ def calc_travel_3d(current_plane, lead_s: float):
return (lat2, lon2, alt2)


def angular_velocity(currentPlane, camera_latitude, camera_longitude, camera_altitude):
(lat, lon, alt) = calc_travel_3d(currentPlane, 0)
def angular_velocity(currentPlane, camera_latitude, camera_longitude, camera_altitude, include_age=True):
(lat, lon, alt) = calc_travel_3d(currentPlane, 0, include_age=include_age)
distance2d = coordinate_distance(camera_latitude, camera_longitude, lat, lon)
bearing1 = bearingFromCoordinate(
cameraPosition=[camera_latitude, camera_longitude],
Expand All @@ -306,7 +311,7 @@ def angular_velocity(currentPlane, camera_latitude, camera_longitude, camera_alt
distance2d, cameraAltitude=camera_altitude, airplaneAltitude=alt
)

(lat, lon, alt) = calc_travel_3d(currentPlane, 1)
(lat, lon, alt) = calc_travel_3d(currentPlane, 1, include_age=include_age)
distance2d = coordinate_distance(camera_latitude, camera_longitude, lat, lon)
bearing2 = bearingFromCoordinate(
cameraPosition=[camera_latitude, camera_longitude],
Expand Down

0 comments on commit 1dad621

Please sign in to comment.