Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced all Waypoint class instances with LocationGround; removed Waypoint class #36

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/common
Submodule common updated 39 files
+0 −33 .gitignore
+0 −51 comms/TelemMessages/GroundStation.lcm
+0 −24 comms/TelemMessages/common.lcm
+0 −25 comms/TelemMessages/jetson.lcm
+0 −60 comms/TelemMessages/messages.json
+0 −31 comms/Tools/build_messages.sh
+0 −10 comms/Tools/install_lcm.sh
+0 −12 comms/Tools/list_usb.sh
+0 −15 comms/Tools/message_include.sh
+0 −187 comms/Tools/py_gen_helpers.py
+0 −0 comms/__init__.py
+0 −31 comms/loopback.py
+0 −86 comms/modules/TelemMessages/GroundStationData.py
+0 −74 comms/modules/TelemMessages/GroundStationDisarm.py
+0 −80 comms/modules/TelemMessages/GroundStationPIDSetResponse.py
+0 −81 comms/modules/TelemMessages/GroundStationPIDValues.py
+0 −83 comms/modules/TelemMessages/GroundStationWaypoints.py
+0 −70 comms/modules/TelemMessages/Header.py
+0 −74 comms/modules/TelemMessages/JetsonLandingInitiationCommand.py
+0 −74 comms/modules/TelemMessages/JetsonMovementRequest.py
+0 −77 comms/modules/TelemMessages/JetsonOdometryData.py
+0 −78 comms/modules/TelemMessages/JetsonRelativeMovementCommand.py
+0 −71 comms/modules/TelemMessages/PIDController.py
+0 −66 comms/modules/TelemMessages/PIDValues.py
+0 −77 comms/modules/TelemMessages/SensorData.py
+0 −67 comms/modules/TelemMessages/Waypoint.py
+0 −19 comms/modules/TelemMessages/__init__.py
+0 −0 comms/modules/__init__.py
+0 −89 comms/modules/generic_comms_device.py
+0 −61 comms/modules/helper.py
+0 −23 comms/receive.py
+0 −21 comms/transmit.py
+3 −3 kml/expected_document.kml
+14 −12 kml/modules/ground_locations_to_kml.py
+54 −0 kml/modules/location_ground.py
+12 −7 kml/test_ground_locations_to_kml.py
+96 −0 mavlink/modules/flight_controller.py
+9 −0 mavlink/test_flight_controller.py
+140 −0 mavlink/test_mission_ended.py
6 changes: 3 additions & 3 deletions modules/load_waypoint_name_to_coordinates_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"""
import pathlib

from . import waypoint
from .common.kml.modules import location_ground


def load_waypoint_name_to_coordinates_map(waypoint_file_path: pathlib.Path) \
-> "tuple[bool, dict[str, waypoint.Waypoint]]":
-> "tuple[bool, dict[str, location_ground.LocationGround]]":
"""
Creates a name to coordinate dictionary from the CSV file.
"""
Expand All @@ -23,7 +23,7 @@ def load_waypoint_name_to_coordinates_map(waypoint_file_path: pathlib.Path) \
continue

name, latitude, longitude = parts
name_to_coordinates_map[name] = waypoint.Waypoint(name, float(latitude), float(longitude))
name_to_coordinates_map[name] = location_ground.LocationGround(name, float(latitude), float(longitude))

if len(name_to_coordinates_map) > 0:
return True, name_to_coordinates_map
Expand Down
52 changes: 0 additions & 52 deletions modules/waypoint.py

This file was deleted.

14 changes: 7 additions & 7 deletions modules/waypoint_names_to_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
This file contains a function for converting waypoint names to coordinates.
"""

from . import waypoint
from .common.kml.modules import location_ground


def waypoint_names_to_coordinates(waypoint_names: "list[str]",
waypoint_mapping: "dict[str, waypoint.Waypoint]") \
-> "tuple[bool, list[waypoint.Waypoint]]":
waypoint_mapping: "dict[str, location_ground.LocationGround]") \
-> "tuple[bool, list[location_ground.LocationGround]]":
"""
Converts a list of waypoint names to their corresponding coordinates based on a waypoint mapping.

Args:
waypoint_names (list[str]): A list of waypoint names.
waypoint_mapping (dict[str, Waypoint]): A dictionary mapping waypoint names to their
corresponding Waypoint objects with coordinates.
waypoint_mapping (dict[str, LocationGround]): A dictionary mapping waypoint names to their
corresponding LocationGround objects with coordinates.

Returns:
tuple[bool, list[Waypoint]]: A tuple containing a boolean indicating the success of the conversion
and a list of Waypoint objects with coordinates corresponding to the given waypoint names.
tuple[bool, list[LocationGround]]: A tuple containing a boolean indicating the success of the conversion
and a list of LocationGround objects with coordinates corresponding to the given waypoint names.
"""
# Handle the case when waypoint_names is empty
if len(waypoint_names) == 0:
Expand Down
10 changes: 5 additions & 5 deletions modules/waypoints_dict_to_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Module to convert waypoints dict to waypoints list.
"""

from . import waypoint
from .common.kml.modules import location_ground


def waypoints_dict_to_list(waypoint_name_to_coordinates: "dict[str, waypoint.Waypoint]") \
-> "tuple[bool, list[waypoint.Waypoint]]":
def waypoints_dict_to_list(waypoint_name_to_coordinates: "dict[str, location_ground.LocationGround]") \
-> "tuple[bool, list[location_ground.LocationGround]]":
"""
Converts dictionary of waypoints into a list.

Parameters
----------
waypoint_name_to_coordinates: dict[str, Waypoint]
waypoint_name_to_coordinates: dict[str, LocationGround]
Waypoint mapping of name to (latitude, longitude).

Returns
Expand All @@ -24,7 +24,7 @@ def waypoints_dict_to_list(waypoint_name_to_coordinates: "dict[str, waypoint.Way
if len(waypoint_name_to_coordinates) == 0:
return False, None

# Create list of all the values in the input dictionary, ie. the Waypoint
# Create list of all the values in the input dictionary, ie. the LocationGround
waypoints_list = list(waypoint_name_to_coordinates.values())

return True, waypoints_list
8 changes: 4 additions & 4 deletions modules/waypoints_to_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

import dronekit

from . import waypoint
from .common.kml.modules import location_ground


MAVLINK_FRAME = dronekit.mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
MAVLINK_COMMAND = dronekit.mavutil.mavlink.MAV_CMD_NAV_WAYPOINT
ACCEPT_RADIUS = 10


def waypoints_to_commands(waypoints: "list[waypoint.Waypoint]",
def waypoints_to_commands(waypoints: "list[location_ground.LocationGround]",
altitude: int) -> "tuple[bool, list[dronekit.Command] | None]":
"""
Convert list of waypoints to dronekit commands.

Parameters
----------
waypoints: list[Waypoint]
list of Waypoint objects containing names and coordinates in decimal degrees.
waypoints: list[LocationGround]
list of locationGround objects containing names and coordinates in decimal degrees.
altitude: int
altitude in meters to command the drone to.

Expand Down
8 changes: 3 additions & 5 deletions path_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from modules import waypoint_tracking
from modules import waypoints_dict_to_list
from modules import waypoints_to_commands
from modules.common.kml.modules import waypoints_to_kml
from modules.common.kml.modules import ground_locations_to_kml


WAYPOINT_FILE_PATH = pathlib.Path("waypoints", "wrestrc_waypoints.csv")
Expand Down Expand Up @@ -51,10 +51,8 @@ def run() -> int:
print("ERROR: convert waypoints from dict to list")
return -1

# TODO: Remove tuple conversion when common repository's waypoint_to_kml() supports Waypoint class
waypoints_list_tuple = [(waypoint.latitude, waypoint.longitude) for waypoint in waypoints_list]
result, _ = waypoints_to_kml.waypoints_to_kml(
waypoints_list_tuple,
result, _ = ground_locations_to_kml.ground_locations_to_kml(
waypoints_list,
KML_FILE_PREFIX, KML_FILE_PARENT_DIRECTORY,
)
if not result:
Expand Down
8 changes: 3 additions & 5 deletions path_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from modules import waypoints_to_commands
from modules import waypoint_tracking
from modules import waypoints_dict_to_list
from modules.common.kml.modules import waypoints_to_kml
from modules.common.kml.modules import ground_locations_to_kml


WAYPOINT_FILE_PATH = pathlib.Path("2024", "waypoints", "wrestrc.csv")
Expand Down Expand Up @@ -49,10 +49,8 @@ def run() -> int:
print("ERROR: Unable to convert waypoints from dict to list")
return -1

# TODO: Remove tuple conversion when common repository's waypoint_to_kml() supports Waypoint class
waypoints_list_tuple = [(waypoint.latitude, waypoint.longitude) for waypoint in waypoints_list]
result, _ = waypoints_to_kml.waypoints_to_kml(
waypoints_list_tuple,
result, _ = ground_locations_to_kml.ground_locations_to_kml(
waypoints_list,
KML_FILE_PREFIX, KML_FILE_PARENT_DIRECTORY,
)
if not result:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_load_waypoint_name_to_coordinates_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib

from modules import load_waypoint_name_to_coordinates_map
from modules import waypoint
from modules.common.kml.modules import location_ground


def test_normal_file():
Expand All @@ -14,8 +14,8 @@ def test_normal_file():
# Setup
normal_csv_file_path = pathlib.Path("tests", "test_csv", "test_normal_csv.csv")
expected = {
"WARG": waypoint.Waypoint("WARG", 43.47323264522664, -80.54011639872981),
"University of Waterloo Station for 301 ION": waypoint.Waypoint(
"WARG": location_ground.LocationGround("WARG", 43.47323264522664, -80.54011639872981),
"University of Waterloo Station for 301 ION": location_ground.LocationGround(
"University of Waterloo Station for 301 ION",
43.4735247614021,
-80.54144667502672,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_waypoints_dict_to_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Testing various formats of waypoints dictionary during conversion to list process.
"""

from modules import waypoint
from modules import waypoints_dict_to_list
from modules.common.kml.modules import location_ground


def test_valid_waypoint_dict():
"""
Test conversion to list for a valid dict.
"""
alpha = waypoint.Waypoint("Alpha", 43.4340501,-80.5789803)
bravo = waypoint.Waypoint("Bravo", 43.4335758,-80.5775237)
charlie = waypoint.Waypoint("Charlie", 43.4336672,-80.57839)
alpha = location_ground.LocationGround("Alpha", 43.4340501,-80.5789803)
bravo = location_ground.LocationGround("Bravo", 43.4335758,-80.5775237)
charlie = location_ground.LocationGround("Charlie", 43.4336672,-80.57839)

waypoint_mapping = {"Alpha": alpha, "Bravo": bravo, "Charlie": charlie}
expected = [alpha, bravo, charlie]
Expand Down
22 changes: 11 additions & 11 deletions tests/test_waypoints_names_to_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Test waypoint names to coordinates function.
"""

from modules import waypoint
from modules import waypoint_names_to_coordinates
from modules.common.kml.modules import location_ground


WAYPOINT_DICTIONARY = {
"Aerial": waypoint.Waypoint("Aerial", 9, 7),
"Group 15": waypoint.Waypoint("Group 15", 3, 4),
"Robotics": waypoint.Waypoint("Robotics", -1, 0),
"Aerial": location_ground.LocationGround("Aerial", 9, 7),
"Group 15": location_ground.LocationGround("Group 15", 3, 4),
"Robotics": location_ground.LocationGround("Robotics", -1, 0),
"University of Waterloo Station for 301 ION": \
waypoint.Waypoint("University of Waterloo Station for 301 ION", 6, 6),
"WARG": waypoint.Waypoint("WARG", 8, 2),
"Waterloo": waypoint.Waypoint("Waterloo", 2, -5),
location_ground.LocationGround("University of Waterloo Station for 301 ION", 6, 6),
"WARG": location_ground.LocationGround("WARG", 8, 2),
"Waterloo": location_ground.LocationGround("Waterloo", 2, -5),
}


Expand All @@ -24,10 +24,10 @@ def test_valid_names():
# Setup
names_valid = ["Waterloo", "Aerial", "Robotics", "Group 15"]
expected = [
waypoint.Waypoint("Waterloo", 2, -5),
waypoint.Waypoint("Aerial", 9, 7),
waypoint.Waypoint("Robotics", -1, 0),
waypoint.Waypoint("Group 15", 3, 4),
location_ground.LocationGround("Waterloo", 2, -5),
location_ground.LocationGround("Aerial", 9, 7),
location_ground.LocationGround("Robotics", -1, 0),
location_ground.LocationGround("Group 15", 3, 4),
]

# Run
Expand Down
8 changes: 4 additions & 4 deletions tests/test_waypoints_to_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import dronekit

from modules import waypoint
from modules import waypoints_to_commands
from modules.common.kml.modules import location_ground


def test_waypoints_to_commands_empty_input():
Expand All @@ -26,9 +26,9 @@ def test_waypoints_to_commands():
Tests functionality correctness of waypoints_to_commands.
"""
waypoints = [
waypoint.Waypoint("Waypoint 1", 42.123, -73.456),
waypoint.Waypoint("Waypoint 2", 42.789, -73.987),
waypoint.Waypoint("Waypoint 3", 42.555, -73.321),
location_ground.LocationGround("Waypoint 1", 42.123, -73.456),
location_ground.LocationGround("Waypoint 2", 42.789, -73.987),
location_ground.LocationGround("Waypoint 3", 42.555, -73.321),
]
altitude = 100

Expand Down
Loading