Workflow Example

Sequence workflow example

The following sequence workflow example defines 4 lights (Light1, .. Light4), that each have 2 light settings (Light<n> on/off). 5 scenes are created from the light settings. One that turns all lights off (Scene0), and an individual scene to turn each light on (Scene1 to 4).

First step of the sequence samples a tag measurement, that comes from a data collector. The data collecter could be connected to a factory control system, or control units, where it acts as an interface to the vision system. In this example, we use the "SetState" activity to sample a tag measurement, that gives out the product ID of the product being processed. This value is saved into the sequence workflow state, and can be used in all subsequent activities.

The next steps in the sequence workflow (step 1 to 9) the different scenes are activiated and an image is acquired for each scene. In this case, the sampled product ID is used to name the image files in the image acquire activities.

After the image acquire the vision algorithm, in the form of a custom model, is executed by the step activity "ExecuteModel", where the custom model is named "VisionModel".

In this example we assume that the custom model produces the following tag values in the output: "Factory1.Line1.PassFail", "Factory1.Line1.PassFailInfo" and "Factory1.Line1.Validity". The output value configuration of the custom model belongs to the asset hierarchy setup, and is not specified in the sequences workflow configuration. The steps 11, 12 and 13 publishes the outputs from the custom model as measurements using the "PublishState" activity. This means that the measurements can be sent back to the factory control system, or control units, using the data collector modules. Again, this is set up in the asset hierarchy.

Step 14 uses the "WrapResult" activity to save both workflow state information and an output file coming from the custom vision model (output.json) and consolidate all the information into a new file called "result.json".

Step 15 ends the sequence workflow with success. If any errors occur during execution, the "stepOnError" property is set to step 16 for all the steps from 0 to 10. This means that execution will continue at step 16 if an error occurs. From step 16 to 18 the outputs "Factory1.Line1.PassFail", "Factory1.Line1.PassFailInfo" and "Factory1.Line1.Validity" are published, but with default values indicating failure (if the states do not exist in the sequence workflow state). Step 19 generates the output "result.json" file, with all sequence workflow states, and step 20 ends the sequence workflow indicating that an error was detected during the exection.

{
   "lights": [
       {
           "id": "Light1",
           "channel": 0,
           "description": "Ring light"
       },
       {
           "id": "Light2",
           "channel": 1,
           "description": "Bar light 1"
       },
       {
           "id": "Light3",
           "channel": 2,
           "description": "Bar light 2"
       },
       {
           "id": "Light4",
           "channel": 3,
           "description": "Bar light 3"
       }
   ],
   "lightSettings": [
       {
           "id": "Light1 off",
           "lightId": "Light1",
           "lightLevel": 0
       },
       {
           "id": "Light1 on",
           "lightId": "Light1",
           "lightLevel": 255
       },
       {
           "id": "Light2 off",
           "lightId": "Light2",
           "lightLevel": 0
       },
       {
           "id": "Light2 on",
           "lightId": "Light2",
           "lightLevel": 128
       },
       {
           "id": "Light3 off",
           "lightId": "Light3",
           "lightLevel": 0
       },
       {
           "id": "Light3 on",
           "lightId": "Light3",
           "lightLevel": 200
       },
       {
           "id": "Light4 off",
           "lightId": "Light4",
           "lightLevel": 0
       },
       {
           "id": "Light4 on",
           "lightId": "Light4",
           "lightLevel": 191
       }
   ],
   "scenes": [
       {
           "id": "Scene0",
           "name": "Lights off",
           "lightSettingsIds": [
               "Light1 off",
               "Light2 off",
               "Light3 off",
               "Light4 off"
           ]
       },
       {
           "id": "Scene1",
           "name": "Brightfield",
           "lightSettingsIds": [
               "Light1 on",
               "Light2 off",
               "Light3 off",
               "Light4 off"
           ]
       },
       {
           "id": "Scene2",
           "name": "Darkfield 1",
           "lightSettingsIds": [
               "Light1 off",
               "Light2 on",
               "Light3 off",
               "Light4 off"
           ]
       },
       {
           "id": "Scene3",
           "name": "Darkfield 2",
           "lightSettingsIds": [
               "Light1 off",
               "Light2 off",
               "Light3 on",
               "Light4 off"
           ]
       },
       {
           "id": "Scene4",
           "name": "Darkfield 3",
           "lightSettingsIds": [
               "Light1 off",
               "Light2 off",
               "Light3 off",
               "Light4 on"
           ]
       }
   ],
   "sequences": [
       {
           "id": "1",
           "name": "vision sequence",
           "steps": [
               {
                   "name": "GetProductId",
                   "description": "Get product id from tag value",
                   "order": 0,
                   "activityType": "SetState",
                   "parameters": {
                       "tagName": "Factory1.Line1.ProductId"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetBrightfieldScene",
                   "description": "Set top light on",
                   "order": 1,
                   "activityType": "SetScene",
                   "parameters": {
                       "sceneId": "Scene1"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "GetBrightfieldImage",
                   "description": "Brightfield image acquire",
                   "order": 2,
                   "activityType": "CameraAcquireToFile",
                   "parameters": {
                       "filename": "img_bf_{Factory1.Line1.ProductId}.bmp",
                       "exposureUs": "15000"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetDFLight1",
                   "description": "Set darkfield light 1 on",
                   "order": 3,
                   "activityType": "SetScene",
                   "parameters": {
                       "sceneId": "Scene2"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "GetDarkfieldImage1",
                   "description": "Darkfield image 1",
                   "order": 4,
                   "activityType": "CameraAcquireToFile",
                   "parameters": {
                       "filename": "img_df1_{Factory1.Line1.ProductId}.bmp",
                       "exposureUs": "15000"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetDFLight2",
                   "description": "Set darkfield light 2 on",
                   "order": 5,
                   "activityType": "SetScene",
                   "parameters": {
                       "sceneId": "Scene3"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "GetDarkfieldImage2",
                   "description": "img3",
                   "order": 6,
                   "activityType": "CameraAcquireToFile",
                   "parameters": {
                       "filename": "img_df2_{Factory1.Line1.ProductId}.bmp",
                       "exposureUs": "15000"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetDFLight3",
                   "description": "Set darkfield light 3 on",
                   "order": 7,
                   "activityType": "SetScene",
                   "parameters": {
                       "sceneId": "Scene4"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "GetDarkfieldImage3",
                   "description": "img4",
                   "order": 8,
                   "activityType": "CameraAcquireToFile",
                   "parameters": {
                       "filename": "img_df3_{Factory1.Line1.ProductId}.bmp",
                       "exposureUs": "15000"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetLightsOff",
                   "description": "Set lighting off",
                   "order": 9,
                   "activityType": "SetScene",
                   "parameters": {
                       "sceneId": "Scene0"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "ExecuteVision",
                   "description": "Executing vision model",
                   "order": 10,
                   "activityType": "ExecuteModel",
                   "parameters": {
                       "modelName": "VisionModel"
                   },
                   "stepOnError": 16
               },
               {
                   "name": "SetResultPassFail",
                   "description": "Write vision pass fail tag value",
                   "order": 11,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.PassFail"
                   },
                   "stepOnError": null
               },
               {
                   "name": "SetResultPassFailInfo",
                   "description": "Write vision pass fail info tag value",
                   "order": 12,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.PassFailInfo"
                   },
                   "stepOnError": null
               },
               {
                   "name": "SetResultValidity",
                   "description": "Write vision validity tag value",
                   "order": 13,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.Validity"
                   },
                   "stepOnError": null
               },
               {
                   "name": "WriteResultToFile",
                   "description": "Write vision output to file",
                   "order": 14,
                   "activityType": "WrapResult",
                   "parameters": {
                       "fileName": "result.json",
                       "template": "{\"id\": <state;workflowid>,\"payload\": <json;output.json>}"
                   },
                   "stepOnError": null
               },
               {
                   "name": "EndSuccessfully",
                   "description": "End workflow successfully",
                   "order": 15,
                   "activityType": "EndWorkflow",
                   "parameters": {
                       "success": "true"
                   },
                   "stepOnError": null
               },
               {
                   "name": "SetResultPassFail",
                   "description": "Publish vision pass fail tag value",
                   "order": 16,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.PassFail",
                       "datatype": "analog",
                       "value": "0"
                   },
                   "stepOnError": null
               },
               {
                   "name": "SetResultPassFailInfo",
                   "description": "Publish vision pass fail info tag value",
                   "order": 17,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.PassFailInfo",
                       "datatype": "analog",
                       "value": "0"
                   },
                   "stepOnError": null
               },
               {
                   "name": "SetResultValidity",
                   "description": "Publish vision validity tag value",
                   "order": 18,
                   "activityType": "PublishState",
                   "parameters": {
                       "tagName": "Factory1.Line1.Validity",
                       "datatype": "analog",
                       "value": "0"
                   },
                   "stepOnError": null
               },
               {
                   "name": "WriteErrorResultToFile",
                   "description": "Write error vision output to file",
                   "order": 19,
                   "activityType": "WrapResult",
                   "parameters": {
                       "fileName": "result.json",
                       "template": "{\"id\": <state;workflowid>,\"payload\": <json;output.json>}"
                   },
                   "stepOnError": null
               },
               {
                   "name": "EndWithFail",
                   "description": "End workflow with failure",
                   "order": 20,
                   "activityType": "EndWorkflow",
                   "parameters": {
                       "success": "false"
                   },
                   "stepOnError": null
               }
           ],
           "trigger": {
               "type": "OnTagChange",
               "parameters": "Factory1.Line1.Trigger"
           }
       }
   ]
}

Last updated

Was this helpful?