Skip to content

Commit

Permalink
Integrate Mapping state into the state machine #29
Browse files Browse the repository at this point in the history
  • Loading branch information
RexBerry committed Nov 13, 2024
1 parent d480af6 commit 60bf306
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
33 changes: 33 additions & 0 deletions state_machine/flight_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FlightSettings:
A small description for the current flight
__skip_waypoint: bool
Whether to skip the waypoint state.
__skip_odlc_and_airdrop: bool
Whether to skip the ODLC and airdrop states.
__standard_object_count: int
The number of standard objects to attempt to find.
__sim_flag: bool
Expand All @@ -36,6 +38,8 @@ class FlightSettings:
Sets the parameter for a simple or diagonal takeoff
skip_waypoint() -> bool
Returns whether to skip the waypoint state.
skip_odlc_and_airdrop() -> bool
Returns whether to skip the ODLC and airdrop states.
skip_waypoint(flag: bool) -> None
Setter for configuring whether to skip the waypoint state.
standard_object_count() -> int
Expand All @@ -60,12 +64,14 @@ class FlightSettings:
Set the path to the JSON file containing the boundary and waypoint data.
"""

# pylint: disable=too-many-arguments
def __init__(
self,
simple_takeoff: bool = False,
title: str = DEFAULT_RUN_TITLE,
description: str = DEFAULT_RUN_DESCRIPTION,
skip_waypoint: bool = False,
skip_odlc_and_airdrop: bool = False,
standard_object_count: int = DEFAULT_STANDARD_OBJECT_COUNT,
sim_flag: bool = False,
path_data_path: str = "flight/data/waypoint_data.json",
Expand All @@ -83,6 +89,8 @@ def __init__(
Sets a descriptive explanation for the current flight execution
skip_waypoint : bool
Whether to skip the waypoint state.
skip_odlc_and_airdrop : bool
Whether to skip the ODLC and airdrop states.
standard_object_count : int
The number of standard objects to attempt to find.
sim_flag : bool, default False
Expand All @@ -94,6 +102,7 @@ def __init__(
self.__run_title: str = title
self.__run_description: str = description
self.__skip_waypoint: bool = skip_waypoint
self.__skip_odlc_and_airdrop: bool = skip_odlc_and_airdrop
self.__standard_object_count: int = standard_object_count
self.__sim_flag: bool = sim_flag
self.__path_data_path: str = path_data_path
Expand Down Expand Up @@ -149,6 +158,30 @@ def skip_waypoint(self, flag: bool) -> None:
self.__skip_waypoint = flag

# ----- ODLC Settings ----- #
@property
def skip_odlc_and_airdrop(self) -> bool:
"""
Gets whether to skip the ODLC and airdrop states as a private member variable.
Returns
-------
skip_odlc_and_airdrop : bool
Whether to skip the ODLC and airdrop states.
"""
return self.__skip_waypoint

@skip_odlc_and_airdrop.setter
def skip_odlc_and_airdrop(self, flag: bool) -> None:
"""
Sets whether to skip the ODLC and airdrop states.
Parameters
----------
flag : bool
Whether to skip the ODLC and airdrop states.
"""
self.__skip_odlc_and_airdrop = flag

@property
def standard_object_count(self) -> int:
"""
Expand Down
8 changes: 6 additions & 2 deletions state_machine/states/impl/airdrop_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

from state_machine.states.airdrop import Airdrop
from state_machine.states.land import Land
from state_machine.states.waypoint import Waypoint
from state_machine.states.mapping import Mapping
from state_machine.states.state import State
from state_machine.states.waypoint import Waypoint

# uncomment if automatic
# from flight.maestro.air_drop import AirdropControl
Expand All @@ -30,6 +31,9 @@ async def run(self: Airdrop) -> State:
This method is responsible for initiating the Airdrop process of the drone and transitioning
it back to the Waypoint state.
"""
if self.flight_settings.skip_odlc_and_airdrop:
return Mapping(self.drone, self.flight_settings)

try:
update_state("Airdrop")
logging.info("Airdrop")
Expand Down Expand Up @@ -106,7 +110,7 @@ async def run(self: Airdrop) -> State:

if continue_run:
return Waypoint(self.drone, self.flight_settings)
return Land(self.drone, self.flight_settings)
return Mapping(self.drone, self.flight_settings)

except asyncio.CancelledError as ex:
logging.error("Airdrop state canceled")
Expand Down
8 changes: 5 additions & 3 deletions state_machine/states/impl/mapping_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import asyncio
import logging

import dronekit

from state_machine.state_tracker import (
update_state,
update_drone,
update_flight_settings,
)
from state_machine.states.land import Land
from state_machine.states.mapping import Mapping
from state_machine.states.state import State


async def run(self: Mapping) -> None:
async def run(self: Mapping) -> State:
"""
Implements the run method for the Mapping state.
Expand All @@ -39,6 +39,8 @@ async def run(self: Mapping) -> None:
logging.error("Mapping state canceled")
raise ex

return Land(self.drone, self.flight_settings)


# Setting the run_callable attribute of the Mapping class to the run function
Mapping.run_callable = run
6 changes: 5 additions & 1 deletion state_machine/states/impl/odlc_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from state_machine.flight_settings import FlightSettings
from state_machine.state_tracker import update_state
from state_machine.states.airdrop import Airdrop
from state_machine.states.mapping import Mapping
from state_machine.states.odlc import ODLC
from state_machine.states.state import State
from vision.flyover_vision_pipeline import flyover_pipeline
Expand Down Expand Up @@ -49,6 +50,10 @@ async def run(self: ODLC) -> State:
The type hinting for the capture_status variable is broken, see
https://github.com/python/typeshed/issues/8799
"""

if self.flight_settings.skip_odlc_and_airdrop:
return Mapping(self.drone, self.flight_settings)

try:
update_state("ODLC")
# Syncronized type hint is broken, see https://github.com/python/typeshed/issues/8799
Expand Down Expand Up @@ -132,7 +137,6 @@ async def find_odlcs(self: ODLC, capture_status: "SynchronizedBase[c_bool]") ->

if camera:
await camera.odlc_move_to(
# TODO: Convert to Dronekit
self.drone,
gps_data["odlc_waypoints"][point].latitude,
gps_data["odlc_waypoints"][point].longitude,
Expand Down

0 comments on commit 60bf306

Please sign in to comment.