-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created commands data structure (#16)
* created decision data struture * added enum for command types * formatting * better command names * updated function names
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Command data structure used by decision module. | ||
""" | ||
|
||
import enum | ||
|
||
|
||
class DecisionCommand: | ||
""" | ||
Contains command to send to drone. | ||
The following are valid command constructors: | ||
* DecisionCommand.create_stop_command | ||
* DecisionCommand.create_resume_command | ||
""" | ||
|
||
__create_key = object() | ||
|
||
class CommandType(enum.Enum): | ||
""" | ||
Valid commands. | ||
""" | ||
|
||
STOP_MISSION_AND_HALT = 0 | ||
RESUME_MISSION = 1 | ||
|
||
@classmethod | ||
def create_stop_mission_and_halt_command(cls) -> "tuple[bool, DecisionCommand | None]": | ||
""" | ||
Command to stop and loiter the drone. | ||
""" | ||
return True, DecisionCommand( | ||
cls.__create_key, DecisionCommand.CommandType.STOP_MISSION_AND_HALT | ||
) | ||
|
||
@classmethod | ||
def create_resume_mission_command(cls) -> "tuple[bool, DecisionCommand | None]": | ||
""" | ||
Command to resume auto mission. | ||
""" | ||
return True, DecisionCommand(cls.__create_key, DecisionCommand.CommandType.RESUME_MISSION) | ||
|
||
def __init__(self, create_key: object, command: CommandType) -> None: | ||
""" | ||
Private constructor, use create() method. | ||
""" | ||
assert create_key is DecisionCommand.__create_key, "Use create() method" | ||
|
||
self.command = command | ||
|
||
def __str__(self) -> str: | ||
""" | ||
String representation | ||
""" | ||
return f"{self.__class__.__name__}: {self.command}" |