Skip to content

Commit 9b4ddf9

Browse files
committed
feat: add assemblyController state machine
1 parent a40c632 commit 9b4ddf9

1 file changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import
2+
"https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl"
3+
4+
import "./events.pkl" as Events
5+
import "./serviceTypes.pkl" as ServiceTypes
6+
7+
assemblyControllerFSM = new csml.StateMachine {
8+
states {
9+
["detectingStartState"] = new csml.Initial {
10+
on {
11+
[Events.eBeamInterruptedStart] {
12+
to = "capturePhotoState"
13+
}
14+
15+
[Events.eJobDone] {
16+
to = "jobDoneState"
17+
}
18+
}
19+
}
20+
21+
["capturePhotoState"] {
22+
entry {
23+
new csml.Invoke {
24+
type = ServiceTypes.stTakePhoto
25+
}
26+
}
27+
28+
after {
29+
["photoCaptureTimeout"] {
30+
delay = "10000"
31+
triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoCaptureTimedOut}}
32+
}
33+
}
34+
35+
on {
36+
[Events.ePhotoCaptured] {
37+
to = "scanPhotoState"
38+
}
39+
40+
[Events.eJobDone] {
41+
to = "jobDoneState"
42+
}
43+
44+
[Events.ePhotoCaptureTimedOut] {
45+
to = "capturePhotoState"
46+
}
47+
}
48+
}
49+
50+
["scanPhotoState"] {
51+
entry {
52+
new csml.Invoke {
53+
type = ServiceTypes.stScanPhoto
54+
input {
55+
["imgData"] = "$data"
56+
}
57+
}
58+
}
59+
60+
after {
61+
["photoScanTimeout"] {
62+
delay = "10000"
63+
triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoScanTimedOut}}
64+
}
65+
}
66+
67+
exit {
68+
new csml.Emit { event { topic = Events.eScanned }; target = "'monitor'" }
69+
}
70+
71+
on {
72+
[Events.ePhotoScanned] {
73+
yields {
74+
new csml.Match {
75+
cases {
76+
new csml.Case {
77+
of = "$validObject"
78+
yields {
79+
new csml.Emit { event = new csml.Internal { topic = Events.eCheckValidObject } }
80+
}
81+
}
82+
new csml.Case {
83+
of = "!($validObject)"
84+
yields {
85+
new csml.Emit {
86+
event = new csml.Internal { topic = Events.eCheckInvalidObject }
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
95+
[Events.eCheckInvalidObject] {
96+
to = "errorState"
97+
}
98+
99+
[Events.eCheckValidObject] {
100+
to = "detectingEndState"
101+
yields {
102+
new csml.Emit {
103+
event = new csml.Event { topic = Events.eObjectValid }
104+
target = "'conveyorBelt'"
105+
}
106+
}
107+
}
108+
109+
[Events.ePhotoScanTimedOut] {
110+
yields {
111+
new csml.Invoke {
112+
type = ServiceTypes.stScanPhoto
113+
input {
114+
["imgData"] = "$data"
115+
}
116+
}
117+
}
118+
}
119+
120+
[Events.eJobDone] {
121+
to = "jobDoneState"
122+
}
123+
}
124+
}
125+
126+
["errorState"] {
127+
entry {
128+
new csml.Emit {
129+
event {
130+
topic = Events.eProcessMessage
131+
data { ["msg"] = "'Assembly error: Invalid object detected'" }
132+
}
133+
target = "'messageProcessor'"
134+
}
135+
136+
new csml.Invoke {
137+
type = ServiceTypes.stDiscardObject
138+
}
139+
}
140+
141+
on {
142+
[Events.eJobDone] {
143+
to = "jobDoneState"
144+
}
145+
146+
[Events.eObjectDiscarded] {
147+
to = "detectingStartState"
148+
}
149+
}
150+
}
151+
152+
["detectingEndState"] {
153+
on {
154+
[Events.eBeamInterruptedEnd] {
155+
to = "unloadingState"
156+
yields {
157+
new csml.Emit {
158+
event = new csml.Event { topic = Events.eStartUnload }
159+
target = "'conveyorBelt'"
160+
}
161+
}
162+
}
163+
164+
[Events.eJobDone] {
165+
to = "jobDoneState"
166+
}
167+
}
168+
}
169+
170+
["unloadingState"] {
171+
on {
172+
[Events.ePickedUp] {
173+
to = "detectingStartState"
174+
}
175+
176+
[Events.eJobDone] {
177+
to = "jobDoneState"
178+
}
179+
}
180+
}
181+
182+
["jobDoneState"] = new csml.Terminal {}
183+
}
184+
}

0 commit comments

Comments
 (0)