Skip to content

Commit

Permalink
Refactor plot_circular_path.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Evang264 committed Nov 3, 2024
1 parent 999c21c commit 8f7804d
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions modules/plot_circular_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
Module to plot n circular waypoints, given a center and radius.
"""

import math
import csv
import math

from .waypoint import Waypoint
from modules.common.mavlink.modules.drone_odometry import DronePosition
from modules.common.mavlink.modules.drone_odometry_local import DronePositionLocal
from modules.common.mavlink.modules.local_global_conversion import drone_position_global_from_local

from .waypoint import Waypoint


def move_coordinates_by_offset(
start_point: Waypoint, offset_x: float, offset_y: float, name: str
Expand All @@ -29,24 +30,19 @@ def move_coordinates_by_offset(
Waypoint: the resulting waypoint after being moved by offset from the
original waypoint.
"""
offset_local = DronePositionLocal.create(offset_y, offset_x, 0)
_, offset_local = DronePositionLocal.create(offset_y, offset_x, 0)

# Because drone_position_global_from_local requires DronePosition class,
# we need to convert Waypoint to DronePosition first
start_lat = start_point.location_ground.latitude
start_lon = start_point.location_ground.longitude
start_alt = start_point.altitude
start_point_converted = DronePosition.create(start_lat, start_lon, start_alt)

success, end_point = drone_position_global_from_local(
start_point_converted, start_point, offset_local
_, start_point_converted = DronePosition.create(
start_point.location_ground.latitude,
start_point.location_ground.longitude,
start_point.altitude,
)

end_lat = end_point.latitude
end_lon = end_point.longitude
end_alt = end_point.altitude
end_point_converted = Waypoint(name, end_lat, end_lon, end_alt)
return end_point_converted
_, end_point = drone_position_global_from_local(start_point_converted, offset_local)

return Waypoint(name, end_point.latitude, end_point.longitude, end_point.altitude)


def generate_circular_path(center: Waypoint, radius: float, num_points: int) -> "list[Waypoint]":
Expand Down

0 comments on commit 8f7804d

Please sign in to comment.