From a40c6327251f7fdfeee04bf7bbc00589437ce7a8 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:55:33 +0200 Subject: [PATCH 01/22] feat: add jobController state machine --- .idea/.gitignore | 10 +++++ .idea/Cirrina-CSML-SmartFactory.iml | 9 +++++ .idea/ktfmt.xml | 6 +++ .idea/misc.xml | 7 ++++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ smartFactory/jobController.pkl | 58 +++++++++++++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Cirrina-CSML-SmartFactory.iml create mode 100644 .idea/ktfmt.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 smartFactory/jobController.pkl diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Cirrina-CSML-SmartFactory.iml b/.idea/Cirrina-CSML-SmartFactory.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Cirrina-CSML-SmartFactory.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/ktfmt.xml b/.idea/ktfmt.xml new file mode 100644 index 0000000..228bfae --- /dev/null +++ b/.idea/ktfmt.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dd4ead3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0c846f2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/smartFactory/jobController.pkl b/smartFactory/jobController.pkl new file mode 100644 index 0000000..f422101 --- /dev/null +++ b/smartFactory/jobController.pkl @@ -0,0 +1,58 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "events.pkl" as Events +import "variables.pkl" as Vars + +jobControllerFSM = new csml.StateMachine { + transient { + ["totalProducts"] = "5" + } + + states { + ["startingState"] = new csml.Initial { + entry { + new csml.Emit { + event { + topic = Events.eProcessMessage + data { ["msg"] = "'Job started...'" } + } + target = "'messageProcessor'" + } + } + + always { + new csml.Transition { + to = "runningState" + } + } + } + + ["runningState"] { + on { + [Events.eProductComplete] { + yields { + new csml.Eval { expression = "\(Vars.vProductsCompleted) += 1" } + new csml.Emit { event = new csml.Internal { topic = Events.eCheckJobDone } } + } + } + + [Events.eCheckJobDone] { + to = "jobDoneState" + provided = "\(Vars.vProductsCompleted) >= totalProducts" + } + } + } + + ["jobDoneState"] = new csml.Terminal { + entry { + new csml.Eval { expression = "\(Vars.vIsJobDone) = true" } + new csml.Emit { + event { topic = Events.eProcessMessage; data { ["msg"] = "'Job done...'" } } + target = "'messageProcessor'" + } + new csml.Emit { event { topic = Events.eJobDone } } + } + } + } +} From 9b4ddf9fc5edf86a3a73c4422e2ffe21d42bf2f4 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:56:12 +0200 Subject: [PATCH 02/22] feat: add assemblyController state machine --- smartFactory/assemblyController.pkl | 184 ++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 smartFactory/assemblyController.pkl diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl new file mode 100644 index 0000000..fda38fa --- /dev/null +++ b/smartFactory/assemblyController.pkl @@ -0,0 +1,184 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "./events.pkl" as Events +import "./serviceTypes.pkl" as ServiceTypes + +assemblyControllerFSM = new csml.StateMachine { + states { + ["detectingStartState"] = new csml.Initial { + on { + [Events.eBeamInterruptedStart] { + to = "capturePhotoState" + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["capturePhotoState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stTakePhoto + } + } + + after { + ["photoCaptureTimeout"] { + delay = "10000" + triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoCaptureTimedOut}} + } + } + + on { + [Events.ePhotoCaptured] { + to = "scanPhotoState" + } + + [Events.eJobDone] { + to = "jobDoneState" + } + + [Events.ePhotoCaptureTimedOut] { + to = "capturePhotoState" + } + } + } + + ["scanPhotoState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stScanPhoto + input { + ["imgData"] = "$data" + } + } + } + + after { + ["photoScanTimeout"] { + delay = "10000" + triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoScanTimedOut}} + } + } + + exit { + new csml.Emit { event { topic = Events.eScanned }; target = "'monitor'" } + } + + on { + [Events.ePhotoScanned] { + yields { + new csml.Match { + cases { + new csml.Case { + of = "$validObject" + yields { + new csml.Emit { event = new csml.Internal { topic = Events.eCheckValidObject } } + } + } + new csml.Case { + of = "!($validObject)" + yields { + new csml.Emit { + event = new csml.Internal { topic = Events.eCheckInvalidObject } + } + } + } + } + } + } + } + + [Events.eCheckInvalidObject] { + to = "errorState" + } + + [Events.eCheckValidObject] { + to = "detectingEndState" + yields { + new csml.Emit { + event = new csml.Event { topic = Events.eObjectValid } + target = "'conveyorBelt'" + } + } + } + + [Events.ePhotoScanTimedOut] { + yields { + new csml.Invoke { + type = ServiceTypes.stScanPhoto + input { + ["imgData"] = "$data" + } + } + } + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["errorState"] { + entry { + new csml.Emit { + event { + topic = Events.eProcessMessage + data { ["msg"] = "'Assembly error: Invalid object detected'" } + } + target = "'messageProcessor'" + } + + new csml.Invoke { + type = ServiceTypes.stDiscardObject + } + } + + on { + [Events.eJobDone] { + to = "jobDoneState" + } + + [Events.eObjectDiscarded] { + to = "detectingStartState" + } + } + } + + ["detectingEndState"] { + on { + [Events.eBeamInterruptedEnd] { + to = "unloadingState" + yields { + new csml.Emit { + event = new csml.Event { topic = Events.eStartUnload } + target = "'conveyorBelt'" + } + } + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["unloadingState"] { + on { + [Events.ePickedUp] { + to = "detectingStartState" + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["jobDoneState"] = new csml.Terminal {} + } +} From 9ee45eab908d9363e6107a7acd27b9824e3af845 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:56:54 +0200 Subject: [PATCH 03/22] feat: add belt state machine --- smartFactory/belt.pkl | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 smartFactory/belt.pkl diff --git a/smartFactory/belt.pkl b/smartFactory/belt.pkl new file mode 100644 index 0000000..2a4596c --- /dev/null +++ b/smartFactory/belt.pkl @@ -0,0 +1,67 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "events.pkl" as Events +import "serviceTypes.pkl" as ServiceTypes + +beltFsm = new csml.StateMachine { + states { + ["loadingState"] = new csml.Initial { + on { + [Events.eObjectValid] { + to = "transportingState" + } + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + ["transportingState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stMoveBelt + } + } + + exit { + new csml.Invoke { + type = ServiceTypes.stStopBelt + } + } + + on { + [Events.eStartUnload] { + to = "unloadingState" + } + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["jobDoneState"] = new csml.Terminal {} + + ["unloadingState"] { + entry { + new csml.Emit { event { topic = Events.eArmPickup }; target = "'arm'" } + } + + after { + ["armPickupTimeout"] { + delay = "1000" + triggers = new csml.Emit { event { topic = Events.eArmPickup }; target = "'arm'" } + } + } + + on { + [Events.eJobDone] { + to = "jobDoneState" + } + + [Events.ePickedUp] { + to = "loadingState" + } + } + } + } +} From 8331b65df41d66425508ae843eaafa070b29b5ce Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:57:22 +0200 Subject: [PATCH 04/22] feat: add arm state machine --- smartFactory/arm.pkl | 236 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 smartFactory/arm.pkl diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl new file mode 100644 index 0000000..f3b9757 --- /dev/null +++ b/smartFactory/arm.pkl @@ -0,0 +1,236 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "events.pkl" as Events +import "serviceTypes.pkl" as ServiceTypes +import "variables.pkl" as Vars + +armFSM = new csml.StateMachine { + transient { + ["pickupSuccess"] = "true" + ["errorMsg"] = "''" + ["partsAssembled"] = "0" + ["partsPerProduct"] = "3" + } + + states { + ["idleState"] = new csml.Initial { + entry { + new csml.Match { + cases { + new csml.Case { + of = "!pickupSuccess" + yields { + new csml.Emit { event = new csml.Internal { topic = Events.ePickupNotSuccess } } + } + } + } + } + } + + on { + [Events.eJobDone] { + to = "jobDoneState" + } + [Events.eArmPickup] { + to = "pickupState" + provided = "!\(Vars.vIsJobDone)" + } + [Events.ePickupNotSuccess] { + to = "pickupState" + } + } + } + + ["pickupState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stPickup + } + } + + after { + ["pickupTimeout"] { + delay = "10000" + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.eArmPickupUpdateStatusTimedout } + } + } + } + + on { + [Events.eUpdatePickupStatus] { + yields { + new csml.Eval { expression = "pickupSuccess = $success" } + new csml.Match { + cases { + new csml.Case { + of = "$success" + yields { + new csml.Emit { + event { topic = Events.ePickedUp } + } + } + } + } + default = new csml.Eval { expression = "errorMsg = 'Pickup failed...'" } + } + new csml.Emit { event = new csml.Internal { topic = Events.eCheckPickUpSuccess } } + } + } + + [Events.eCheckPickUpSuccess] { + to = "assembleState" + provided = "pickupSuccess" + or = "errorState" + } + + [Events.eArmPickupUpdateStatusTimedout] { + to = "errorState" + yields { + new csml.Eval { expression = "pickupSuccess = false" } + new csml.Eval { expression = "errorMsg = 'Pickup timeout...'" } + } + } + } + } + + ["errorState"] { + entry { + new csml.Emit { + event { + topic = Events.eProcessMessage + data { ["msg"] = "'Fatal robotic arm failure: ' + errorMsg" } + } + target = "'messageProcessor'" + } + } + + after { + ["pickupRetryTimeout"] { + delay = "2000" + triggers = new csml.Emit { event = new csml.Internal { topic = Events.eRetry } } + } + } + + on { + [Events.eRetry] { + to = "assembleState" + provided = "pickupSuccess" + or = "returnState" + } + + [Events.eUpdatePickupStatus] { + yields { + new csml.Eval { expression = "pickupSuccess = $success" } + } + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["assembleState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stAssemble + } + } + + after { + ["assemblyTimeout"] { + delay = "10000" + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.eArmAssemblyUpdateStatusTimedout } + } + } + } + + on { + [Events.eCheckAssembleSuccess] { + yields { + new csml.Match { + cases { + new csml.Case { + of = "$success" + yields { + new csml.Emit { + event = new csml.Internal { topic = Events.eAssemblySuccessful } + } + } + } + new csml.Case { + of = "!($success)" + yields { + new csml.Emit { + event = new csml.Internal { topic = Events.eAssemblyUnsuccessful } + } + } + } + } + } + } + } + + [Events.eAssemblySuccessful] { + to = "returnState" + yields { + new csml.Eval { expression = "partsAssembled = partsAssembled + 1" } + new csml.Emit { + event { topic = Events.eAssemblyComplete } + target = "'monitor'" + } + } + } + + [Events.eAssemblyUnsuccessful] { + to = "errorState" + yields { + new csml.Eval { expression = "errorMsg = 'Assemble failed...'" } + } + } + + [Events.eArmAssemblyUpdateStatusTimedout] { + to = "errorState" + yields { + new csml.Eval { expression = "errorMsg = 'Assembly timeout...'" } + } + } + } + } + + ["returnState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stReturnToStart + } + } + + on { + [Events.eResetArm] { + to = "idleState" + yields { + new csml.Match { + cases { + new csml.Case { + of = "partsAssembled >= partsPerProduct" + yields { + new csml.Eval { expression = "partsAssembled = 0" } + new csml.Emit { + event { topic = Events.eProductComplete } + target = "'jobController'" + } + } + } + } + } + } + } + } + } + + ["jobDoneState"] = new csml.Terminal {} + } +} From b80c86d6e886b4969c7917761c1bae5a26190ac8 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:58:54 +0200 Subject: [PATCH 05/22] feat: add messageProcessor state machine --- smartFactory/messageProcessor.pkl | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 smartFactory/messageProcessor.pkl diff --git a/smartFactory/messageProcessor.pkl b/smartFactory/messageProcessor.pkl new file mode 100644 index 0000000..0b8dabb --- /dev/null +++ b/smartFactory/messageProcessor.pkl @@ -0,0 +1,84 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "events.pkl" as Events +import "serviceTypes.pkl" as ServiceTypes +import "variables.pkl" as Vars + +messageProcessorFSM = new csml.StateMachine { + states { + ["idleState"] = new csml.Initial { + on { + [Events.eProcessMessage] { + to = "processState" + } + + [Events.eJobDone] { + to = "jobDoneState" + } + } + } + + ["jobDoneState"] = new csml.Terminal {} + } +} + +emailProcessorFSM = (messageProcessorFSM) { + states { + ["processState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stProcessEmail + input { + ["msg"] = "$msg" + } + } + } + + always { + new csml.Transition { + to = "idleState" + } + } + } + } +} + +smsProcessorFSM = (messageProcessorFSM) { + states { + ["processState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stProcessSms + input { + ["msg"] = "$msg" + } + } + } + + always { + new csml.Transition { + to = "idleState" + } + } + } + } +} + +logProcessorFSM = (messageProcessorFSM) { + states { + ["processState"] { + entry { + new csml.Eval { + expression = "\(Vars.vLogs).add($msg)" + } + } + + always { + new csml.Transition { + to = "idleState" + } + } + } + } +} From af89e88079c20a04e11d7a1451dcf0a85a54d05f Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:59:16 +0200 Subject: [PATCH 06/22] feat: add monitor state machine --- smartFactory/monitor.pkl | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 smartFactory/monitor.pkl diff --git a/smartFactory/monitor.pkl b/smartFactory/monitor.pkl new file mode 100644 index 0000000..cd07f92 --- /dev/null +++ b/smartFactory/monitor.pkl @@ -0,0 +1,72 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "events.pkl" as Events +import "serviceTypes.pkl" as ServiceTypes +import "variables.pkl" as Vars + +monitorFSM = new csml.StateMachine { + transient { + ["nScans"] = "0" + ["nAssemblies"] = "0" + } + states { + ["monitoringState"] = new csml.Initial { + on { + [Events.eScanned] { + yields { + new csml.Eval { expression = "nScans += 1" } + new csml.Emit { event = new csml.Internal { topic = Events.eSendStatistics } } + } + } + [Events.eAssemblyComplete] { + yields { + new csml.Eval { expression = "nAssemblies += 1" } + new csml.Emit { event = new csml.Internal { topic = Events.eSendStatistics } } + } + } + [Events.eSendStatistics] { + yields { + new csml.Invoke { + type = ServiceTypes.stSendStatistics + input { + ["nScans"] = "nScans" + ["nAssemblies"] = "nAssemblies" + ["productsCompleted"] = "\(Vars.vProductsCompleted)" + ["jobDone"] = "\(Vars.vIsJobDone)" + } + } + } + } + [Events.eJobDone] { + to = "jobDoneLogState" + } + } + } + + ["jobDoneLogState"] { + entry { + new csml.Invoke { + type = ServiceTypes.stSendStatistics + input { + ["nScans"] = "nScans" + ["nAssemblies"] = "nAssemblies" + ["productsCompleted"] = "\(Vars.vProductsCompleted)" + ["jobDone"] = "\(Vars.vIsJobDone)" + } + emits { + new csml.ConditionalEvent { + event = new csml.Internal { topic = Events.eMonitorJobCompletionStatisticsLogged } + } + } + } + } + + on { + [Events.eMonitorJobCompletionStatisticsLogged] { to = "jobDoneState" } + } + } + + ["jobDoneState"] = new csml.Terminal {} + } +} From e55a0e5c8952d55b189b019a5ee61ee8dde929da Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 12:59:45 +0200 Subject: [PATCH 07/22] feat: add event declarations --- smartFactory/events.pkl | 115 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 smartFactory/events.pkl diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl new file mode 100644 index 0000000..8bb6577 --- /dev/null +++ b/smartFactory/events.pkl @@ -0,0 +1,115 @@ +// This module contains all event topic definitions for the CSM SmartFactory + +//Event for indicating job is done +eJobDone = "eJobDone" + +//Event for indicating a scan is complete +eScanned = "eScanned" + +//Event for processing message +eProcessMessage = "eProcessMessage" + +//Event for initiating pickup (by robotic arm) +eArmPickup = "eArmPickup" + +//Event for indicating an object is valid +eObjectValid = "eObjectValid" + +//Event for indicating an object is inValid +eObjectInvalid = "eObjectInvalid" + +//Event for indicating a photo has been scanned (by conveyor camera) +ePhotoScanned = "ePhotoScanned" + +//Event for indicating a scanned object is valid +eCheckValidObject = "eCheckValidObject" + +//Event for indicating a scanned object is invalid +eCheckInvalidObject = "eCheckInvalidObject" + +//Event for indicating that start sensor's beam has been interrupted +eBeamInterruptedStart = "eBeamInterruptedStart" + +//Event for indicating that end sensor's beam has been interrupted +eBeamInterruptedEnd = "eBeamInterruptedEnd" + +//Event for indicating that beam detection by sensor is complete +eBeamDetectionPerformed = "beamDetectionPerformed" + +//Event for initating checking of beam detection results +eCheckBeamDetection = "eCheckBeamDetection" + +//Event for initating scanning (by conveyor camera) +eStartScan = "eStartScan" + +//Event for initating unloading (by conveyor belt) +eStartUnload = "eStartUnload" + +//Event for initating check to see if the job is complete +eCheckJobDone = "eCheckJobDone" + +//Event for indicating that pickup failed (by robotic arm) +ePickupNotSuccess = "pickupNotSuccess" + +//Event for initiating update of pickup success status +eUpdatePickupSuccessStatus = "eUpdatePickupSuccessStatus" + +//Event for initating check for pickup success +eCheckPickUpSuccess = "eCheckPickUpSuccess" + +//Event for indicating that the object has been picked up +ePickedUp = "ePickedUp" + +//Event for initiating check for success of pickup retry +eRetry = "eRetry" + +//Event for indicating updated pickup status +eUpdatePickupStatus = "eUpdatePickupStatus" + +//Event for initiating check for success of assembly +eCheckAssembleSuccess = "eCheckAssembleSuccess" + +//Event indicating successful assembly +eAssemblySuccessful = "eAssemblySuccessful" + +//Event indicating unsuccessful assembly +eAssemblyUnsuccessful = "eAssemblyUnsuccessful" + +//Event indicating that a new part was assembled +eAssemblyComplete = "eAssemblyComplete" + +//Event indicating that the assembly of a new product was completed +eProductComplete = "eProductComplete" + +//Event initiating transfer of statistics to external service +eSendStatistics = "eSendStatistics" + +//Event indicating that a message has been processed +eMessageProcessed = "eMessageProcessed" + +//Event indicating that a photo has been captured +ePhotoCaptured = "ePhotoCaptured" + +//Event indicating that the statistics after job completion have been logged by the monitor +eMonitorJobCompletionStatisticsLogged = "eMonitorJobCompletionStatisticsLogged" + +//Event indicating that the conveyor belt has been moved to the start position +eBeltReturnedToStart = "eBeltReturnedToStart" + +//Event indicating that the arm needs to be reset +eResetArm = "eResetArm" + +//Event indicating that an invalid object has been discarded +eObjectDiscarded = "eObjectDiscarded" + +//Event indicating that the arm timed-out while waiting for pickup status +eArmPickupUpdateStatusTimedout = "eArmPickupUpdateStatusTimedout" + +//Event indicating that the arm timed-out while waiting for assembly status +eArmAssemblyUpdateStatusTimedout = "eArmAssemblyUpdateStatusTimedout" + +//Event indicating that the assembly controller timed-out while waiting for captured photo +ePhotoCaptureTimedOut = "ePhotoCaptureTimedOut" + +//Event indicating that the assembly controller timed-out while waiting for photo scan +ePhotoScanTimedOut = "ePhotoScanTimedOut" \ No newline at end of file From 0a6594fdcd021dd91a60e80cd3d72eb5656930eb Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 13:00:12 +0200 Subject: [PATCH 08/22] feat: add service declarations --- smartFactory/serviceTypes.pkl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 smartFactory/serviceTypes.pkl diff --git a/smartFactory/serviceTypes.pkl b/smartFactory/serviceTypes.pkl new file mode 100644 index 0000000..e34eb0a --- /dev/null +++ b/smartFactory/serviceTypes.pkl @@ -0,0 +1,34 @@ +// This module contains all service types for the CSM SmartFactory + +//Service to move conveyor belt +stMoveBelt = "moveBelt" + +//Service to stop conveyor belt +stStopBelt = "stopBelt" + +//Service to take photo (by conveyor camera) +stTakePhoto = "takePhoto" + +//Service to scan photo (by conveyor camera) +stScanPhoto = "scanPhoto" + +//Service to pickup part (by robotic arm) +stPickup = "pickUp" + +//Service to assemble part +stAssemble = "assemble" + +//Service to return arm to start +stReturnToStart = "returnToStart" + +//Service to process email message +stProcessEmail = "processEmail" + +//Service to process sms message +stProcessSms = "processSms" + +//Service to process statistics +stSendStatistics = "sendStatistics" + +//Service to discard invalid object +stDiscardObject = "discardObject" From f2ab438b8e61515d489c0188625b73de301932b1 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 13:00:48 +0200 Subject: [PATCH 09/22] feat: add persistent variable declarations --- smartFactory/variables.pkl | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 smartFactory/variables.pkl diff --git a/smartFactory/variables.pkl b/smartFactory/variables.pkl new file mode 100644 index 0000000..a1f1317 --- /dev/null +++ b/smartFactory/variables.pkl @@ -0,0 +1,10 @@ +// This module contains all persistent variable definitions for the CSM SmartFactory + +//Variable indicating if the job is done +vIsJobDone = "isJobDone" + +//Variable storing the log messages +vLogs = "logProcessorLogs" + +//Variable storing the number of completed products +vProductsCompleted = "productsCompleted" From 59241d993cca2a94432e35c4856f607280613258 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 13:01:10 +0200 Subject: [PATCH 10/22] feat: add main.pkl --- smartFactory/main.pkl | 138 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 smartFactory/main.pkl diff --git a/smartFactory/main.pkl b/smartFactory/main.pkl new file mode 100644 index 0000000..670b520 --- /dev/null +++ b/smartFactory/main.pkl @@ -0,0 +1,138 @@ +amends + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" +import "arm.pkl" +import "assemblyController.pkl" +import "belt.pkl" +import "jobController.pkl" +import "messageProcessor.pkl" +import "monitor.pkl" +import "serviceTypes.pkl" as ServiceTypes +import "variables.pkl" as Vars + +collaborativeStateMachine { + stateMachines { + ["jobControllerFSM"] = jobController.jobControllerFSM + ["beltFSM"] = belt.beltFsm + ["armFSM"] = arm.armFSM + ["messageProcessorFSM"] = messageProcessor.emailProcessorFSM + ["monitorFSM"] = monitor.monitorFSM + ["assemblyControllerFSM"] = assemblyController.assemblyControllerFSM + } + + persistent { + [Vars.vIsJobDone] = "false" + [Vars.vLogs] = "[...]" + [Vars.vProductsCompleted] = "0" + } +} + +instances { + ["messageProcessor"] { stateMachineName = "messageProcessorFSM" } + ["jobController"] { stateMachineName = "jobControllerFSM" } + ["conveyorBelt"] { stateMachineName = "beltFSM" } + ["arm"] { stateMachineName = "armFSM" } + ["monitor"] { stateMachineName = "monitorFSM" } + ["assemblyController"] { stateMachineName = "assemblyControllerFSM" } +} + +bindings { + new HttpServiceImplementationBinding { + name = ServiceTypes.stMoveBelt + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/movebelt" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stStopBelt + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/stopbelt" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stTakePhoto + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/takephoto" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stScanPhoto + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/scanphoto" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stPickup + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/pickup" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stAssemble + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/assemble" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stReturnToStart + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/returntostart" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stProcessEmail + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/process/email" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stProcessSms + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/process/sms" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stSendStatistics + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/statistics" + method = "POST" + } + new HttpServiceImplementationBinding { + name = ServiceTypes.stDiscardObject + `local` = false + scheme = "http" + host = "localhost" + port = 6000 + endPoint = "/discardobject" + method = "POST" + } +} From 3e14f3eafac725efbd3dffb4423b6cf00b0e1060 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Wed, 1 Jul 2026 13:05:30 +0200 Subject: [PATCH 11/22] refactor: match pkl standards --- smartFactory/assemblyController.pkl | 8 ++++++-- smartFactory/events.pkl | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index fda38fa..b0524ea 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -28,7 +28,9 @@ assemblyControllerFSM = new csml.StateMachine { after { ["photoCaptureTimeout"] { delay = "10000" - triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoCaptureTimedOut}} + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.ePhotoCaptureTimedOut } + } } } @@ -60,7 +62,9 @@ assemblyControllerFSM = new csml.StateMachine { after { ["photoScanTimeout"] { delay = "10000" - triggers = new csml.Emit {event = new csml.Internal {topic = Events.ePhotoScanTimedOut}} + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.ePhotoScanTimedOut } + } } } diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 8bb6577..39a03ce 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -112,4 +112,4 @@ eArmAssemblyUpdateStatusTimedout = "eArmAssemblyUpdateStatusTimedout" ePhotoCaptureTimedOut = "ePhotoCaptureTimedOut" //Event indicating that the assembly controller timed-out while waiting for photo scan -ePhotoScanTimedOut = "ePhotoScanTimedOut" \ No newline at end of file +ePhotoScanTimedOut = "ePhotoScanTimedOut" From 19bf805c0098a8d25a9b5bbb1813222ebd26e171 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Thu, 9 Jul 2026 10:08:44 +0200 Subject: [PATCH 12/22] refactor: update manual pickup event name --- smartFactory/arm.pkl | 6 +++--- smartFactory/events.pkl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl index f3b9757..61c442e 100644 --- a/smartFactory/arm.pkl +++ b/smartFactory/arm.pkl @@ -59,7 +59,7 @@ armFSM = new csml.StateMachine { } on { - [Events.eUpdatePickupStatus] { + [Events.eMarkPickedUp] { yields { new csml.Eval { expression = "pickupSuccess = $success" } new csml.Match { @@ -120,9 +120,9 @@ armFSM = new csml.StateMachine { or = "returnState" } - [Events.eUpdatePickupStatus] { + [Events.eMarkPickedUp] { yields { - new csml.Eval { expression = "pickupSuccess = $success" } + new csml.Eval { expression = "pickupSuccess = true" } } } diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 39a03ce..27018b6 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -63,8 +63,8 @@ ePickedUp = "ePickedUp" //Event for initiating check for success of pickup retry eRetry = "eRetry" -//Event for indicating updated pickup status -eUpdatePickupStatus = "eUpdatePickupStatus" +//Event for indicating part has been picked up +eMarkPickedUp = "eMarkPickedUp" //Event for initiating check for success of assembly eCheckAssembleSuccess = "eCheckAssembleSuccess" From 643af0a354ccc85f628e1ff74de64f2aa6153647 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Thu, 9 Jul 2026 10:12:26 +0200 Subject: [PATCH 13/22] revert: pickup event name --- smartFactory/arm.pkl | 6 +++--- smartFactory/events.pkl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl index 61c442e..f3b9757 100644 --- a/smartFactory/arm.pkl +++ b/smartFactory/arm.pkl @@ -59,7 +59,7 @@ armFSM = new csml.StateMachine { } on { - [Events.eMarkPickedUp] { + [Events.eUpdatePickupStatus] { yields { new csml.Eval { expression = "pickupSuccess = $success" } new csml.Match { @@ -120,9 +120,9 @@ armFSM = new csml.StateMachine { or = "returnState" } - [Events.eMarkPickedUp] { + [Events.eUpdatePickupStatus] { yields { - new csml.Eval { expression = "pickupSuccess = true" } + new csml.Eval { expression = "pickupSuccess = $success" } } } diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 27018b6..39a03ce 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -63,8 +63,8 @@ ePickedUp = "ePickedUp" //Event for initiating check for success of pickup retry eRetry = "eRetry" -//Event for indicating part has been picked up -eMarkPickedUp = "eMarkPickedUp" +//Event for indicating updated pickup status +eUpdatePickupStatus = "eUpdatePickupStatus" //Event for initiating check for success of assembly eCheckAssembleSuccess = "eCheckAssembleSuccess" From 86ae4c48a6226651a259904dd10854cddd79ab4c Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Thu, 9 Jul 2026 10:29:09 +0200 Subject: [PATCH 14/22] refactor: fix comment --- smartFactory/events.pkl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 39a03ce..2a03976 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -96,7 +96,7 @@ eMonitorJobCompletionStatisticsLogged = "eMonitorJobCompletionStatisticsLogged" //Event indicating that the conveyor belt has been moved to the start position eBeltReturnedToStart = "eBeltReturnedToStart" -//Event indicating that the arm needs to be reset +//Event indicating that the arm has been reset eResetArm = "eResetArm" //Event indicating that an invalid object has been discarded From 86e5826ec0f983d7122d6a5d567f56f93fbd479a Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Mon, 10 Aug 2026 09:37:55 +0200 Subject: [PATCH 15/22] fix: add timer based retrying of service invocations to fix deadlock due to missing peripheral events --- smartFactory/arm.pkl | 15 ++++++++++++++- smartFactory/assemblyController.pkl | 18 ++++++++++++++++++ smartFactory/belt.pkl | 16 ++++++++++++++++ smartFactory/events.pkl | 9 +++++++++ smartFactory/jobController.pkl | 2 +- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl index f3b9757..6ce57be 100644 --- a/smartFactory/arm.pkl +++ b/smartFactory/arm.pkl @@ -10,7 +10,7 @@ armFSM = new csml.StateMachine { ["pickupSuccess"] = "true" ["errorMsg"] = "''" ["partsAssembled"] = "0" - ["partsPerProduct"] = "3" + ["partsPerProduct"] = "10" } states { @@ -208,6 +208,15 @@ armFSM = new csml.StateMachine { } } + after { + ["armResetTimeout"] { + delay = "10000" + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.eArmResetTimedOut } + } + } + } + on { [Events.eResetArm] { to = "idleState" @@ -228,6 +237,10 @@ armFSM = new csml.StateMachine { } } } + + [Events.eArmResetTimedOut] { + to = "returnState" + } } } diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index b0524ea..c6213cd 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -5,6 +5,7 @@ import "./events.pkl" as Events import "./serviceTypes.pkl" as ServiceTypes assemblyControllerFSM = new csml.StateMachine { + states { ["detectingStartState"] = new csml.Initial { on { @@ -142,6 +143,15 @@ assemblyControllerFSM = new csml.StateMachine { } } + after { + ["objectDisposalTimeout"] { + delay = "10000" + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.eObjectDisposalTimedOut } + } + } + } + on { [Events.eJobDone] { to = "jobDoneState" @@ -150,6 +160,14 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eObjectDiscarded] { to = "detectingStartState" } + + [Events.eObjectDisposalTimedOut] { + yields { + new csml.Invoke { + type = ServiceTypes.stDiscardObject + } + } + } } } diff --git a/smartFactory/belt.pkl b/smartFactory/belt.pkl index 2a4596c..ebf6dec 100644 --- a/smartFactory/belt.pkl +++ b/smartFactory/belt.pkl @@ -23,6 +23,15 @@ beltFsm = new csml.StateMachine { } } + after { + ["transportingTimeout"] { + delay = "10000" + triggers = new csml.Emit { + event = new csml.Internal { topic = Events.eTransportingTimedOut } + } + } + } + exit { new csml.Invoke { type = ServiceTypes.stStopBelt @@ -36,6 +45,13 @@ beltFsm = new csml.StateMachine { [Events.eJobDone] { to = "jobDoneState" } + [Events.eTransportingTimedOut] { + yields { + new csml.Invoke { + type = ServiceTypes.stMoveBelt + } + } + } } } diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 2a03976..0dc556c 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -113,3 +113,12 @@ ePhotoCaptureTimedOut = "ePhotoCaptureTimedOut" //Event indicating that the assembly controller timed-out while waiting for photo scan ePhotoScanTimedOut = "ePhotoScanTimedOut" + +//Event indicating that the belt timed-out while waiting for part to be moved to the end +eTransportingTimedOut = "eTransportingTimedOut" + +//Event indicating that the arm timed-out while waiting to be reset +eArmResetTimedOut = "eArmResetTimedOut" + +//Event indicating that the assembly controller timed-out while waiting for invalid object to be disposed +eObjectDisposalTimedOut = "eObjectDisposalTimedOut" \ No newline at end of file diff --git a/smartFactory/jobController.pkl b/smartFactory/jobController.pkl index f422101..c8627f6 100644 --- a/smartFactory/jobController.pkl +++ b/smartFactory/jobController.pkl @@ -6,7 +6,7 @@ import "variables.pkl" as Vars jobControllerFSM = new csml.StateMachine { transient { - ["totalProducts"] = "5" + ["totalProducts"] = "1" } states { From cd030547699d748ee0833d0b72c160aae8a5d74b Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Thu, 13 Aug 2026 09:49:24 +0200 Subject: [PATCH 16/22] feat: simulate queuing of arrived parts --- smartFactory/arm.pkl | 2 +- smartFactory/assemblyController.pkl | 68 +++++++++++++++++++++++++++++ smartFactory/events.pkl | 8 +++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl index 6ce57be..ddf0927 100644 --- a/smartFactory/arm.pkl +++ b/smartFactory/arm.pkl @@ -10,7 +10,7 @@ armFSM = new csml.StateMachine { ["pickupSuccess"] = "true" ["errorMsg"] = "''" ["partsAssembled"] = "0" - ["partsPerProduct"] = "10" + ["partsPerProduct"] = "100" } states { diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index c6213cd..d2c921e 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -6,10 +6,48 @@ import "./serviceTypes.pkl" as ServiceTypes assemblyControllerFSM = new csml.StateMachine { + transient { + ["firstDetection"] = "true" + ["waitingParts"] = "0" + } + states { ["detectingStartState"] = new csml.Initial { + entry { + new csml.Match { + cases { + new csml.Case { + of = "waitingParts > 0" + yields { + new csml.Eval {expression = "waitingParts -= 1"} + new csml.Emit {event = new csml.Internal{topic = Events.ePartDetectedAtStart}} + } + } + } + } + } + on { [Events.eBeamInterruptedStart] { + to = "detectingStartState" + yields { + new csml.Eval {expression = "waitingParts += 1"} + new csml.Match{ + cases { + new csml.Case { + of = "firstDetection" + yields { + new csml.Emit {event {topic = Events.eProductionStarted}} + new csml.Eval {expression = "firstDetection = false"} + } + } + + } + } + } + } + + [Events.ePartDetectedAtStart] { to = "capturePhotoState" } @@ -47,6 +85,12 @@ assemblyControllerFSM = new csml.StateMachine { [Events.ePhotoCaptureTimedOut] { to = "capturePhotoState" } + + [Events.eBeamInterruptedStart] { + yields { + new csml.Eval {expression = "waitingParts += 1"} + } + } } } @@ -125,6 +169,12 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eJobDone] { to = "jobDoneState" } + + [Events.eBeamInterruptedStart] { + yields { + new csml.Eval {expression = "waitingParts += 1"} + } + } } } @@ -168,6 +218,12 @@ assemblyControllerFSM = new csml.StateMachine { } } } + + [Events.eBeamInterruptedStart] { + yields { + new csml.Eval {expression = "waitingParts += 1"} + } + } } } @@ -186,6 +242,12 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eJobDone] { to = "jobDoneState" } + + [Events.eBeamInterruptedStart] { + yields { + new csml.Eval {expression = "waitingParts += 1"} + } + } } } @@ -198,6 +260,12 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eJobDone] { to = "jobDoneState" } + + [Events.eBeamInterruptedStart] { + yields { + new csml.Eval {expression = "waitingParts += 1"} + } + } } } diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 0dc556c..0bd9403 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -121,4 +121,10 @@ eTransportingTimedOut = "eTransportingTimedOut" eArmResetTimedOut = "eArmResetTimedOut" //Event indicating that the assembly controller timed-out while waiting for invalid object to be disposed -eObjectDisposalTimedOut = "eObjectDisposalTimedOut" \ No newline at end of file +eObjectDisposalTimedOut = "eObjectDisposalTimedOut" + +//Event indicating that the production loop has started (for measurements) +eProductionStarted = "eProductionStarted" + +//Event indicating that an part has been detected at the start of the belt +ePartDetectedAtStart = "ePartDetectedAtStart" \ No newline at end of file From 316bfc616631aa39f11f7bd56f441cab955742e3 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Thu, 13 Aug 2026 14:06:30 +0200 Subject: [PATCH 17/22] fix: message logging --- smartFactory/messageProcessor.pkl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartFactory/messageProcessor.pkl b/smartFactory/messageProcessor.pkl index 0b8dabb..842eb9f 100644 --- a/smartFactory/messageProcessor.pkl +++ b/smartFactory/messageProcessor.pkl @@ -70,7 +70,7 @@ logProcessorFSM = (messageProcessorFSM) { ["processState"] { entry { new csml.Eval { - expression = "\(Vars.vLogs).add($msg)" + expression = "var newLog=\(Vars.vLogs); newLog.add($msg); \(Vars.vLogs)=newLog" } } From 4b3c47fce7b81b4146d4f7529a9d5b9698ffc2b7 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Mon, 17 Aug 2026 13:59:45 +0200 Subject: [PATCH 18/22] fix: switch waitingParts data type to long --- smartFactory/assemblyController.pkl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index d2c921e..dbe4207 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -8,7 +8,7 @@ assemblyControllerFSM = new csml.StateMachine { transient { ["firstDetection"] = "true" - ["waitingParts"] = "0" + ["waitingParts"] = "0L" } states { From cf607954c6b82b07c79b78901787b9f7859bcfe2 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Mon, 17 Aug 2026 14:04:23 +0200 Subject: [PATCH 19/22] fix: add bound check for waitingPartsUpdate --- smartFactory/assemblyController.pkl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index dbe4207..8653beb 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -31,7 +31,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { to = "detectingStartState" yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} new csml.Match{ cases { new csml.Case { From 5529b5749fe0c35af0a1333e80d53a763a8e42a9 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Tue, 25 Aug 2026 12:39:43 +0200 Subject: [PATCH 20/22] chore: remove retry timers --- smartFactory/arm.pkl | 46 -------------------------- smartFactory/assemblyController.pkl | 50 ----------------------------- smartFactory/belt.pkl | 16 --------- 3 files changed, 112 deletions(-) diff --git a/smartFactory/arm.pkl b/smartFactory/arm.pkl index ddf0927..daec1b5 100644 --- a/smartFactory/arm.pkl +++ b/smartFactory/arm.pkl @@ -49,15 +49,6 @@ armFSM = new csml.StateMachine { } } - after { - ["pickupTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.eArmPickupUpdateStatusTimedout } - } - } - } - on { [Events.eUpdatePickupStatus] { yields { @@ -84,14 +75,6 @@ armFSM = new csml.StateMachine { provided = "pickupSuccess" or = "errorState" } - - [Events.eArmPickupUpdateStatusTimedout] { - to = "errorState" - yields { - new csml.Eval { expression = "pickupSuccess = false" } - new csml.Eval { expression = "errorMsg = 'Pickup timeout...'" } - } - } } } @@ -139,15 +122,6 @@ armFSM = new csml.StateMachine { } } - after { - ["assemblyTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.eArmAssemblyUpdateStatusTimedout } - } - } - } - on { [Events.eCheckAssembleSuccess] { yields { @@ -191,13 +165,6 @@ armFSM = new csml.StateMachine { new csml.Eval { expression = "errorMsg = 'Assemble failed...'" } } } - - [Events.eArmAssemblyUpdateStatusTimedout] { - to = "errorState" - yields { - new csml.Eval { expression = "errorMsg = 'Assembly timeout...'" } - } - } } } @@ -208,15 +175,6 @@ armFSM = new csml.StateMachine { } } - after { - ["armResetTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.eArmResetTimedOut } - } - } - } - on { [Events.eResetArm] { to = "idleState" @@ -237,10 +195,6 @@ armFSM = new csml.StateMachine { } } } - - [Events.eArmResetTimedOut] { - to = "returnState" - } } } diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index 8653beb..3ac9c58 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -64,15 +64,6 @@ assemblyControllerFSM = new csml.StateMachine { } } - after { - ["photoCaptureTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.ePhotoCaptureTimedOut } - } - } - } - on { [Events.ePhotoCaptured] { to = "scanPhotoState" @@ -82,10 +73,6 @@ assemblyControllerFSM = new csml.StateMachine { to = "jobDoneState" } - [Events.ePhotoCaptureTimedOut] { - to = "capturePhotoState" - } - [Events.eBeamInterruptedStart] { yields { new csml.Eval {expression = "waitingParts += 1"} @@ -104,15 +91,6 @@ assemblyControllerFSM = new csml.StateMachine { } } - after { - ["photoScanTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.ePhotoScanTimedOut } - } - } - } - exit { new csml.Emit { event { topic = Events.eScanned }; target = "'monitor'" } } @@ -155,17 +133,6 @@ assemblyControllerFSM = new csml.StateMachine { } } - [Events.ePhotoScanTimedOut] { - yields { - new csml.Invoke { - type = ServiceTypes.stScanPhoto - input { - ["imgData"] = "$data" - } - } - } - } - [Events.eJobDone] { to = "jobDoneState" } @@ -193,15 +160,6 @@ assemblyControllerFSM = new csml.StateMachine { } } - after { - ["objectDisposalTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.eObjectDisposalTimedOut } - } - } - } - on { [Events.eJobDone] { to = "jobDoneState" @@ -211,14 +169,6 @@ assemblyControllerFSM = new csml.StateMachine { to = "detectingStartState" } - [Events.eObjectDisposalTimedOut] { - yields { - new csml.Invoke { - type = ServiceTypes.stDiscardObject - } - } - } - [Events.eBeamInterruptedStart] { yields { new csml.Eval {expression = "waitingParts += 1"} diff --git a/smartFactory/belt.pkl b/smartFactory/belt.pkl index ebf6dec..2a4596c 100644 --- a/smartFactory/belt.pkl +++ b/smartFactory/belt.pkl @@ -23,15 +23,6 @@ beltFsm = new csml.StateMachine { } } - after { - ["transportingTimeout"] { - delay = "10000" - triggers = new csml.Emit { - event = new csml.Internal { topic = Events.eTransportingTimedOut } - } - } - } - exit { new csml.Invoke { type = ServiceTypes.stStopBelt @@ -45,13 +36,6 @@ beltFsm = new csml.StateMachine { [Events.eJobDone] { to = "jobDoneState" } - [Events.eTransportingTimedOut] { - yields { - new csml.Invoke { - type = ServiceTypes.stMoveBelt - } - } - } } } From 9b7d6b63c11b5b78f734f9676d41ddd9f5311ba6 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Tue, 25 Aug 2026 12:41:09 +0200 Subject: [PATCH 21/22] chore: remove unused event declarations --- smartFactory/events.pkl | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/smartFactory/events.pkl b/smartFactory/events.pkl index 0bd9403..8b266c1 100644 --- a/smartFactory/events.pkl +++ b/smartFactory/events.pkl @@ -102,27 +102,6 @@ eResetArm = "eResetArm" //Event indicating that an invalid object has been discarded eObjectDiscarded = "eObjectDiscarded" -//Event indicating that the arm timed-out while waiting for pickup status -eArmPickupUpdateStatusTimedout = "eArmPickupUpdateStatusTimedout" - -//Event indicating that the arm timed-out while waiting for assembly status -eArmAssemblyUpdateStatusTimedout = "eArmAssemblyUpdateStatusTimedout" - -//Event indicating that the assembly controller timed-out while waiting for captured photo -ePhotoCaptureTimedOut = "ePhotoCaptureTimedOut" - -//Event indicating that the assembly controller timed-out while waiting for photo scan -ePhotoScanTimedOut = "ePhotoScanTimedOut" - -//Event indicating that the belt timed-out while waiting for part to be moved to the end -eTransportingTimedOut = "eTransportingTimedOut" - -//Event indicating that the arm timed-out while waiting to be reset -eArmResetTimedOut = "eArmResetTimedOut" - -//Event indicating that the assembly controller timed-out while waiting for invalid object to be disposed -eObjectDisposalTimedOut = "eObjectDisposalTimedOut" - //Event indicating that the production loop has started (for measurements) eProductionStarted = "eProductionStarted" From f15da27ea5d4dc6dacc13dab793d415aa081cbd1 Mon Sep 17 00:00:00 2001 From: AryanP281 Date: Tue, 25 Aug 2026 12:47:34 +0200 Subject: [PATCH 22/22] fix: add condition to prevent overflow of waiting parts counter --- smartFactory/assemblyController.pkl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/smartFactory/assemblyController.pkl b/smartFactory/assemblyController.pkl index 3ac9c58..a43796d 100644 --- a/smartFactory/assemblyController.pkl +++ b/smartFactory/assemblyController.pkl @@ -75,7 +75,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} } } } @@ -139,7 +139,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} } } } @@ -171,7 +171,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} } } } @@ -195,7 +195,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} } } } @@ -213,7 +213,7 @@ assemblyControllerFSM = new csml.StateMachine { [Events.eBeamInterruptedStart] { yields { - new csml.Eval {expression = "waitingParts += 1"} + new csml.Eval {expression = "if(waitingParts != 9223372036854775807L) {waitingParts += 1;}"} } } }