Comments (9)
I may be completely wrong, but It will serve to hold back expectations until the specialist @fgmacedo Is here to clear architecture design out. From my perspective, this library inspires itself in the concept of a static state-machine, which means it is driven by intended interface transition trigger actions. My understanding about your interpretation regards a dynamic interaction between output entries and inner states, which classifies as a finite automata (nomination is sensitive at this point, I got myself confusing it while discussing with this library's author). You might reach this complexity type with this library, but it will require some creativity at transitions activation.
from python-statemachine.
It might be a misconception. The definition you are biased to is probably from eletronics. The most recurrent state machine on eletronics are those created by Mealy and Moore. These requires input, memory and output. The ideas given here are rather permissive than reactive. The developer mindset was not focused on developing an automatic connected net, although it might be implemented with such.
from python-statemachine.
So can you easily add some condition to change state? For example states: start, fill, wash, drain
when temperature>50Celsius go from start to fill, when level sensor=True, set time=0 & go from FILL to WASH , when time>10 minutes go from WASH to DRAIN. If during WASH, level sensor=False go back to FILL....can you use this package with some modification to create such a FSM? Perhaps by adding a condition class?
from python-statemachine.
I seem to be equally biased, could you please elaborate a bit on
The ideas given here are rather permissive than reactive.
The syntactic sugar supplied by the package is tempting, but even looking at the tests in the package I can't see how to use it in a real-world application. Is anyone using this in a relatively simple context.
Any pointers would be greatly appreciated.
from python-statemachine.
I too am struggling with figuring out how to use the python-statemachine package to implement a load conscious, event driven FSM architecture.
I have figured out to put transition tests in "on_entry_stateA()" and transition actions in "on_transitionA2B()" and a "cycle transition" which is a null event (transition to itself) for every state. This design allows yielding the processor when no event is present, and testing for events when given the processor, BUT the processing is not limited when events are actually present - the states "run away" - continuing to transition until a state cannot transition.
Fragments from my current design: drive.py which simulates an FSM to drive a robot until an obstacle appears.
# transitions perform actions:
def on_w2d(self): # waiting to drive transition
logging.info("transition accepted drive_request: {}".format(drive_request))
motor_speed = drive_request
def on_d2o(self): # drive to obstacle transition
logging.info("transition stopping")
motor_speed = 0
# loop will use "cycle = every state to itself"
cycle = startup.to.itself() | waiting.to.itself() | driving.to.itself() | obstacle.to.itself() | exit.to.itself()
# event detectors in on_entering_<state>
def on_enter_waiting(self):
logging.info("checking events - ef:{} dist:{} req:{}".format(exit_flag, distance_reading, drive_request))
if exit_flag:
self.quit()
elif distance_reading <= OBSTACLE: # should not drive?
self.w2o()
elif drive_request > 0: # drive wanted?
self.w2d()
...
main():
while True:
drive_behavior.cycle()
sleep(1/states_per_second)
If there are no events to be processed, the loop executes only the null transition and the event check of the current state.
BUT, if there are events the cycle will proceed from state to state until a state with no events is hit.
# only one state executed when no events trigger a transition
2022-05-29 14:10:09,886 main: cycle: 4
2022-05-29 14:10:09,887 on_cycle: null transition
2022-05-29 14:10:09,888 on_enter_waiting: checking events - ef:False dist:3000 req:0
# if events do trigger a transition then multiple states are executed, possibly unlimited
2022-05-29 14:10:10,889 main: cycle: 5
2022-05-29 14:10:10,890 on_cycle: null transition
2022-05-29 14:10:10,891 on_enter_waiting: checking events - ef:False dist:3000 req:10
2022-05-29 14:10:10,891 on_w2d: transition accepted drive_request: 10
2022-05-29 14:10:10,892 on_enter_driving: checking events - ef:False dist:3000 req:10
(In one try, I had two states transition to each other until the stack overflowed.)
from python-statemachine.
@slowrunner It has been a while since you gave a thumbs-up on this issue. Have you accomplished any progress on your demands, with or without these library features?
from python-statemachine.
@slowrunner It has been a while since you gave a thumbs-up on this issue. Have you accomplished any progress on your demands, with or without these library features?
I was able to determine the strengths of the package and what adaptations would be needed to form the basis for autonomous mobile robot control, but my focus moved to ROS2 and intend to learn behavior trees as a control structure. Many folks are suggesting behavior trees are more expressive for the complex resource constrained decisions needed in mobile robots.
from python-statemachine.
I am glad you solved your curiosity issues. ROS is popular. I am not familiar with ROS2. Decision-making is environment dependent on robotics. However, it is off-topic here.
from python-statemachine.
Took a while, but for now, some of your questions are better documented:
- https://python-statemachine.readthedocs.io/en/develop/actions.html
- https://python-statemachine.readthedocs.io/en/develop/transitions.html
Please let me know if you have any other issues.
from python-statemachine.
Related Issues (20)
- Incompatible with spy wrapper from pytest-mock HOT 3
- Add automation (GH action) to publish a new version on pypi HOT 1
- Simple question HOT 10
- Generate the code from PlantUML diagrams HOT 2
- Type annotations missing for `initial_state` and `final_states`; leading to linting errors with Pylint/Pyright HOT 3
- Expensive instantiation of StateMachine HOT 3
- AttributeError: object has no attribute 'model' HOT 3
- Enable Multithreading HOT 2
- [Feature request] State machine based workflow for database storage on entity state tracking HOT 1
- Action callback gets called twice when mixing definition methods HOT 1
- Check that all state transitions can reach a final state. HOT 6
- Execute a state machine from another state machine HOT 1
- Guards and conditions passed as strings really necessary? HOT 6
- ROS2, state transition not possible HOT 2
- Send a state machine over MQTT / serializing-deserializing a SM HOT 6
- Question: How can I use cond functions to gatekeep, but not fail? HOT 5
- Failed to generate a graphic image HOT 2
- Models instantiated in Djangos setUpTestData seem to skip conditions HOT 5
- @<transition>.cond decorator bug, general question about running code on every transition even if TransitionNotAllowed is raised HOT 3
- Persistence, timeouts, and branching conditionals? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-statemachine.