Skip to content

Commit

Permalink
Change type of attribute time of Point from Optional[float] to float #16
Browse files Browse the repository at this point in the history
  • Loading branch information
RexBerry committed Oct 20, 2022
1 parent bd88931 commit 89eede2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 2 additions & 7 deletions flight/avoidance/obstacle_avoidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,12 @@ async def calculate_avoidance_path(
# Units don't change, only the type of the object
drone_velocity: Velocity = Velocity.from_mavsdk_velocityned(raw_drone_velocity)

obstacle_positions.sort(key=lambda p: p.time or 0.0)
obstacle_positions.sort(key=lambda p: p.time)

# Degree of polynomial used in polynomial regression
polynomial_degree: int = 3
# Create list of times
obstacle_times: list[float] = [
point.time for point in obstacle_positions if point.time is not None
]

# Should hopefully never fail, otherwise I will have a mental breakdown
assert len(obstacle_times) == len(obstacle_positions)
obstacle_times: list[float] = [point.time for point in obstacle_positions]

# Get weights for polynomial regression
# The most recent point should have the highest weight
Expand Down
10 changes: 7 additions & 3 deletions flight/avoidance/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Defines and implements the Point class used in obstacle_avoidance.py
"""

import time
from dataclasses import dataclass

import mavsdk.telemetry
Expand Down Expand Up @@ -39,7 +40,7 @@ class Point:
utm_zone_number: int
utm_zone_letter: str
altitude: float
time: float | None
time: float

@classmethod
def from_dict(cls, position_data: InputPoint) -> "Point":
Expand Down Expand Up @@ -85,9 +86,12 @@ def from_mavsdk_position(cls, position: mavsdk.telemetry.Position) -> "Point":
northing: float
zone_number: int
zone_letter: str
# Can't unpack tuple because mypy complains
easting, northing, zone_number, zone_letter = utm.from_latlon(
position.latitude_deg, position.longitude_deg
)

# Can't directly unpack function return value because mypy complains
return cls(easting, northing, zone_number, zone_letter, position.absolute_altitude_m, None)
# Use time.time() as the time for the point
return cls(
easting, northing, zone_number, zone_letter, position.absolute_altitude_m, time.time()
)

0 comments on commit 89eede2

Please sign in to comment.