"""ParkingStateMachine keeps track of parking.
See :mod:`simulation.src.simulation_evaluation.src.state_machine.states.parking` for
implementation details of the states used in this StateMachine.
"""
from typing import Callable
from simulation.src.simulation_evaluation.src.state_machine.states.parking import (
FailureInLeftLane,
FailureInRightLane,
InParkingZone,
Off,
Parking,
ParkingAttempt,
ParkingOut,
SuccessfullyParked,
)
from .state_machine import StateMachine
[docs]class ParkingStateMachine(StateMachine):
"""Keep track of parking."""
off: "State" = Off() # noqa: F821
"""Default state"""
in_parking_zone: "State" = InParkingZone() # noqa: F821
"""The car is inside a parking zone"""
parking_attempt: "State" = ParkingAttempt() # noqa: F821
"""The car starts an attempt to park in"""
parking: "State" = Parking() # noqa: F821
"""The car drives into a parking space"""
successfully_parked: "State" = SuccessfullyParked() # noqa: F821
"""The car successfully parkes inside a parking space"""
parking_out: "State" = ParkingOut() # noqa: F821
"""The car drives out of the parkin space"""
failure_in_right: "State" = FailureInRightLane() # noqa: F821
"""End state when the car drives in the right lane when it's not allowed to"""
failure_in_left: "State" = FailureInLeftLane() # noqa: F821
"""End state when the car drives in the left lane when it's not allowed to"""
def __init__(self, callback: Callable[[], None]):
"""Initialize ParkingStateMachine.
Arguments:
callback: Function which gets executed when the state changes
"""
super().__init__(
state_machine=self.__class__,
initial_state=ParkingStateMachine.off,
callback=callback,
)