b537677277
Robot into its own Class instead of lose Global Variables that cause circular imports StateClass usage instead of the old RobotState.py New Input Class for Controller and randome intputs
35 lines
939 B
Python
35 lines
939 B
Python
"""
|
|
states/State.py - Abstract base class for state machine
|
|
"""
|
|
from abc import ABC, abstractmethod
|
|
from typing import TYPE_CHECKING, Optional, Dict
|
|
|
|
if TYPE_CHECKING:
|
|
from Robot import Robot
|
|
|
|
|
|
class State(ABC):
|
|
"""Abstract base class for all robot states."""
|
|
|
|
@abstractmethod
|
|
def enter(self, robot: "Robot") -> None:
|
|
"""Called once when entering the state."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def execute(self, robot: "Robot") -> Optional[str]:
|
|
"""
|
|
Called every control loop tick.
|
|
Returns Optional[str] containing the name of the next state if transitioning,
|
|
or None to stay in the current state.
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def exit(self, robot: "Robot") -> None:
|
|
"""Called once when exiting the state."""
|
|
pass
|
|
|
|
|
|
# Registry mapping state key names to state instances
|
|
STATE_REGISTRY: Dict[str, State] = {} |