Skip to content

Commit

Permalink
created commands data structure (#16)
Browse files Browse the repository at this point in the history
* created decision data struture

* added enum for command types

* formatting

* better command names

* updated function names
  • Loading branch information
ashum68 authored Jun 23, 2024
1 parent 1351f61 commit 5dd54e2
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions modules/decision_command.py
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}"

0 comments on commit 5dd54e2

Please sign in to comment.