You are here: Start » Program Examples » HMI Run Run once FSM

HMI Run Run once FSM

Aim

The task is to create a simple application where user activates an inspection mode through the HMI Panel. It can be run continously or once.

Hints

In this project the Registers will be useful. Use a Variant macrofilter to have multiple alternative execution paths, in this case you need to have four variants. The state of the application is modified with the Global Parameters and the HMI Events.

Solution (AVS)

  1. Add the GrabImage_FromFiles filter to the ACQUIRE section.

  2. Create the Global Parameter State of type String. Set its initial value to Running. Add the ReadParameter filter to the PROCESS SECTION and set its output as the State parameter.

  3. Create the Variant macrofilter Inspection and create the inImage input of type Image. In Creating a Variant macrofilter window:

    • Define the forking port of type Macrofilter input.
    • Set its Name to State.
    • Set type of data to the String. It is equivalent of 'switch-case' statement.
    • Connect it to the ReadParameter filter output.
  4. Connect the variant Image input to the GrabImage_FromFiles output.

  5. In Program Editor: create 2 new variants of the Inspection macrofilter and name them: Running, RunningOnce.

  6. Change the name of default variant to Paused.

  7. Add a macrofilter register of type Image, name it LastImage and set its initial value to the macrofilter Image input.

  8. In the Running variant create a Step macrofilter named ProcessImage. Inside this step:

    • Create an input and an output of type Image.
    • Add the ThresholdImage filter and connet its Image input and output with the step's.
  9. Return to the the Running variant:

    • Connet the Image input of the ProcessImage with the macrofilter input.
    • Connet the Image output of the ProcessImage with the nextLastImage register and the macrofilter output.
  10. In the RunningOnce variant:

    • Add the ProcessImage step.
    • Connet the Image input of the ProcessImage with the macrofilter input.
    • Connet the Image output of the ProcessImage with the nextLastImage register and the macrofilter output.
    • After the ProcessImage step add the WriteParameter filter with the State input and set its value to Paused.
  11. In the Paused variant:

    • Connet the prevLastImage register with the nextLastImage register and the macrofilter output.
  12. Open the HMI Designer. It is available in a View tab, or in a Toolbar.

  13. To allow the user to set the lower limit of threshold range, add to the HMI the TrackBar control available in the Controls category of HMI Controls.

    • Connect its outValue with the inMinValue inside the ProcessImage macrofilter.
  14. Add to the HMI 3 ImpulseButton controls and set their Text parameter to Run, Run Once and Pause.

  15. Now you need to create a Event macrofilter using the buttons. To do so, press the firtd one on the HMI and go to Events window to create a new event handler for the Click action. Set its name to ControlButtonClicked:

  16. Navigate to the newly created Event macrofilter by clicking it twice in the Project Explorer. Inside of it:

    • Add the ReadParameter filter with the State output.
    • Create a formula:

      • Drag the ReadParameter output to the formula to create an input and name it PreviousState.
      • Create 3 other inputs of type Bool and name them: inRunButton, PauseButton, RunOnceButton. Connect them to the Value outputs of the HMI buttons.
      • Write the formula:

      outState = if inRunButton then "Running" else if inPauseButton then "Paused" else if inRunOnceButton then "RunningOnce" else inPreviousState

    • Add the WriteParameter filter with the State input. Connect the input with the formula output.

  17. Connect the ControlButtonClicked event handler with the rest of the HMI buttons for the Click action.

  18. Add to the HMI a VideoBox control. Connect its Image input to the Inspection variant output.

  19. Generally the program is finished, however there is good practice to disable the controls which should not be used in each state. To accomplish this, create a new Step macrofilter, name it EnableHmiButtons and add it after the Inspection variant in the Main Task macrofilter.

  20. Insied the created step:

    • Add the ReadParameter filter with the State output.
    • Add a formula.
    • Connect the ReadParameter output with the Formula and name the created input as State.

      outRunEnabled = inState <> "Running"

      outPauseEnabled = inState == "Running"

      outRunOnceEnabled = inState == "Paused"

    • Connect the Formula outputs to the Enabled inputs of the HMI buttons.

  21. Add the Delay filter in the Main Task macrofilter and set the inTime to 50. This filter suspends the program workflow for 50 milliseconds.

Macrofilter Main.

Macrofilter Inspection(Paused)

Macrofilter Inspection(Running)

Macrofilter Inspection(RunningOnce)

Macrofilter ProcessImage.

Macrofilter EnableHmiButtons.

Macrofilter ControlButtonClicked.

Further Readings