-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
96 lines (67 loc) · 2.81 KB
/
example.py
File metadata and controls
96 lines (67 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = "Ricardo Ribeiro"
__credits__ = ["Ricardo Ribeiro"]
__license__ = "MIT"
__version__ = "1.0"
__maintainer__ = "Ricardo Ribeiro"
__email__ = "ricardojvr@gmail.com"
__status__ = "Production"
from pyStateMachine.States.State import State, goto
from pyStateMachine.StateMachineControllers.StatesController import StatesController
from pyStateMachine.StateMachineControllers.StatesControllerDebug import StatesControllerDebug
#########################################################################
#########################################################################
#########################################################################
class InitialState(State):
def run(self, inVar):
print "### InitialState"
return self.shared
@goto('AState', 'BState')
def LedActive(self, inVar): return False
@goto('CState')
def LeverActivated(self, inVar): return False
#########################################################################
#########################################################################
#########################################################################
class AState(State):
def run(self, inVar):
print '+++ AState'
inVar._passedA=True
return inVar
@goto('InitialState')
def MotorOn(self, inVar): return True
@goto()
def MotorOff(self, inVar): return True
#########################################################################
#########################################################################
#########################################################################
class BState(State):
def run(self, inVar):
print '--- BState'
inVar._passedB=True
return inVar
@goto(false='InitialState', true='CState')
def Reset(self, inVar): return True
#########################################################################
#########################################################################
#########################################################################
class CState(State):
def run(self, inVar):
print '--- CState'
inVar._passedB=True
return inVar
@goto(true='InitialState', false='AState')
def Reset(self, inVar):
"""
Check if is True
"""
return False
#########################################################################
#########################################################################
#########################################################################
class StatesVariables(object):
def __init__(self): self._passedA = False; self._passedB = False
#controller = StatesController([InitialState(), AState(), BState(), CState()], sharedVar=StatesVariables() )
controller = StatesControllerDebug([InitialState(), AState(), BState(), CState()], sharedVar=StatesVariables(), size=(800,600) )
while not controller.ended: controller.iterateStates()