Skip to content

Commit

Permalink
Add Mapping state and impl #29
Browse files Browse the repository at this point in the history
  • Loading branch information
RexBerry committed Nov 8, 2024
1 parent aefccb5 commit 3c70a0e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
10 changes: 9 additions & 1 deletion state_machine/states/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
"""Defines the state classes."""

from state_machine.states.impl import Airdrop, Land, ODLC, Start, Takeoff, Waypoint
from state_machine.states.impl import (
Airdrop,
Land,
Mapping,
ODLC,
Start,
Takeoff,
Waypoint,
)
from state_machine.states.state import State
1 change: 1 addition & 0 deletions state_machine/states/impl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from state_machine.states.impl.airdrop_impl import Airdrop
from state_machine.states.impl.land_impl import Land
from state_machine.states.impl.mapping_impl import Mapping
from state_machine.states.impl.odlc_impl import ODLC
from state_machine.states.impl.start_impl import Start
from state_machine.states.impl.takeoff_impl import Takeoff
Expand Down
44 changes: 44 additions & 0 deletions state_machine/states/impl/mapping_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Implements the behavior of the Mapping state."""

import asyncio
import logging

import dronekit

from state_machine.state_tracker import (
update_state,
update_drone,
update_flight_settings,
)
from state_machine.states.mapping import Mapping


async def run(self: Mapping) -> None:
"""
Implements the run method for the Mapping state.
This method captures photos of the mapping area and then transitions to the ODLC state.
Returns
-------
ODLC : State
The next state after the drone has successfully landed.
"""
try:
update_state("Mapping")
update_drone(self.drone)
update_flight_settings(self.flight_settings)

logging.info("Mapping")

# TODO: Implement the mapping state
raise NotImplementedError("Mapping state not implemented yet")

logging.info("Mapping state complete.")
except asyncio.CancelledError as ex:
logging.error("Mapping state canceled")
raise ex


# Setting the run_callable attribute of the Mapping class to the run function
Mapping.run_callable = run
30 changes: 30 additions & 0 deletions state_machine/states/mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Declares the Mapping state class."""

from typing import Awaitable, Callable, ClassVar

from state_machine.states.state import State


class Mapping(State):
"""
The Mapping state of the state machine.
This state represents the phase in which the drone is capturing photos of the mapping area.
Attributes
----------
run_callable : ClassVar[Callable[["Mapping"], Awaitable[State]]]
The callable object to call when this state is run. This object is
shared between all instances of this class.
Methods
-------
run(self) -> Awaitable[State]:
Execute the logic associated with this state and return the next state
to transition to.
"""

run_callable: ClassVar[Callable[["Mapping"], Awaitable[State]]]

def run(self) -> Awaitable[State]:
return self.run_callable()

0 comments on commit 3c70a0e

Please sign in to comment.