No project description provided
Project description
procaaso-state-machine
The ProCaaSo based state machine is an ENS centric implementaion of a finite state machine. It's goal is to provide users a state machine that works well within the ProCaaSo App loop, its handlers, classes, methods and other such details will be outlined below.
StateMachine Class
The StateMachine class is a deterministic finite acceptor state machine designed for use within the ProCaaSo framework. It works in conjunction with the State object from the procaaso_state module. State objects should be defined and complete before addition to the StateMachine. It is recommended to handle StateMachine logic with try-except statements to catch any errors.
Initialization
from procaaso_state_machine.procaaso_state import State
state_machine_instance = StateMachine()
Attributes
instruments(dict): A dictionary containing each instrument object added to the machine.__states(dict): A dictionary ofStateobjects that the state machine keeps track of.__currentStateId(int): Tracks identification for the current state.__currentTransitions(list): A list of current transitions based on the current state.__isConfigured(bool): Tracks whether the machine is able to enter its initial state.
Methods
add_state(state: State)
Add a State object to the StateMachine.
state_machine_instance.add_state(my_state_object)
Raises:
KeyError: If the state ID is already present in theStateMachine.Exception: If an unexpected exception occurs during the process.
get_states() -> dict
Get the dictionary containing the State objects in the StateMachine.
states_dict = state_machine_instance.get_states()
Raises:
Exception: If an unexpected exception occurs during the process.
get_current_state_id() -> int
Get the ID of the current state.
current_state_id = state_machine_instance.get_current_state_id()
Raises:
Exception: If an unexpected exception occurs during the process.
get_current_transitions() -> list
Get the list of current transitions.
current_transitions_list = state_machine_instance.get_current_transitions()
Raises:
Exception: If an unexpected exception occurs during the process.
transition_state(newStateId: int)
Transition to a new state.
state_machine_instance.transition_state(2)
Raises:
Exception: If an unexpected exception occurs during the process.
start_state_machine(initialStateId: int)
Start the StateMachine.
state_machine_instance.start_state_machine(1)
Raises:
Exception: If theStateMachineis already configured and/or running.
add_instrument(instruments: dict)
Add instruments to the StateMachine.
state_machine_instance.add_instrument({"instrument1": data1, "instrument2": data2})
Raises:
TypeError: If the provided instruments are not of type 'dict'.Exception: If an unexpected exception occurs during the process.
get_instruments() -> dict
Get the instruments dictionary from the StateMachine.
instruments_dict = state_machine_instance.get_instruments()
Raises:
Exception: If an unexpected exception occurs during the process.
get_state_start_time() -> float
Get the start time of the state.
start_time = state_machine_instance.get_state_start_time()
Raises:
Exception: If retrieving the start time fails.
get_time_elapsed_in_state() -> float
Get the elapsed time since the state started.
elapsed_time = state_machine_instance.get_time_elapsed_in_state()
Raises:
Exception: If retrieving the elapsed time fails.
State Class
The State class represents a state object within the ProCaaSo framework. Each state must have a unique ID, and routines and transitions are added manually through the class methods.
Initialization
from typing import Callable
from procaaso_state import State
state_instance = State(0)
Attributes
__apartOfStateMachine(bool): A boolean to track if the state is part of a state machine.__routines(dict): A dictionary containing the routines registered to run.__transitions(list): A list of all valid states to transition to.id(int): The state number, each state should only have one ID.
Methods
set_routine(routineName: str, routine: Callable)
Set a routine with a given name in the object's routines dictionary.
state_instance.set_routine("my_routine", my_callable_routine)
Raises:
TypeError: If routineName is not of type 'str' or routine is not of type 'Callable'.Exception: If an unexpected exception occurs during the process.Exception: If the state is already part of a state machine.
get_routines() -> dict
Get the dictionary containing the routines registered in the state.
routines_dict = state_instance.get_routines()
set_transition(transitionId: int)
Set a transition ID in the object's transitions list.
state_instance.set_transition(123)
Raises:
TypeError: If transitionId is not of type 'int'.Exception: If an unexpected exception occurs during the process.Exception: If the state is already part of a state machine.
get_transitions() -> List[int]
Get the list of valid state transitions from the current state.
transitions_list = state_instance.get_transitions()
set_state_machine()
Set the __apart_of_state_machine variable. Do not recommend users accessing this directly. A State may only be added to a State Machine object once.
Raises:
Exception: If the state is already part of a state machine.
get_state_machine() -> bool
Get the __apart_of_state_machine of the state object.
isApartOfStateMachine = state_instance.get_state_machine()
get_id() -> int
Get the ID of the state.
state_id = state_instance.get_id()
Note: Methods prefixed with double underscores (e.g., __set_routine, __set_current_state_id) are intended for internal use and should not be accessed directly by users.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file procaaso_state_machine-0.0.1.tar.gz.
File metadata
- Download URL: procaaso_state_machine-0.0.1.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebbdedd36193d4afb85a1b009b2dce990d54db5cee92acb776e5d921bfb980a7
|
|
| MD5 |
eb581db3bc44ded24fddd532bb62a1ba
|
|
| BLAKE2b-256 |
0ef14744df5589ce099b2ea8d8a98943a072ccaf4c2f1001ee59e87759971c2b
|
File details
Details for the file procaaso_state_machine-0.0.1-py3-none-any.whl.
File metadata
- Download URL: procaaso_state_machine-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa19f25a0faaf8e6fd4ffe41fd395177eefcaabf9829b9255ed888c0cf82367
|
|
| MD5 |
5c7bbe82627bed81409578d3f543bf98
|
|
| BLAKE2b-256 |
367cd0d12fec821fa1740af51b82b8b3c55fb0ed8f3b39da243427e6367cfd94
|