You are here: Start » Program Examples » HMI Start Stop

HMI Start Stop

Aim

The task is to create a simple application where user activates an inspection mode through the HMI Panel.

If inspection mode is not activated, input image is displayed.

In the inspection mode threshold operation is performed.

Hints

Use a Variant macrofilter to have multiple alternative execution paths, in this case you need to have two variants. If you defined a forking port type as Macrofilter input, the inspection variant would execute once. This is because in the next iteration of the program an output of the Start ImpulseButton will be false. Therefore the better way is to define forking port type as Macrofilter register, then you will be able to remember previous state.

Solution (AVS)

  1. Create Step macrofilter GrabImage and create output outImage of type Image.

  2. Add to this macrofilter EnumerateImages filter to get load consecutive images of some disk directory.

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

    • Define the forking port of type Macrofilter register.
    • Set its Name to regState.
    • Set type of data to String. It is equivalent of 'switch-case' statement.
  4. Set the Initial value of the regState register to Stopped. This can be accomplished in editor which can be opened by right-clicking on a prevState.

  5. In Program Editor: create new variant of inspection macrofilter and name it Inspecting.

  6. Change the name of default variant to Stopped.

  7. In the Inspecting variant: add ThresholdImage filter and connect its input with the macrofilter's input.

  8. In the Inspecting variant: add Formula and create the following inputs: inStopPressed of type Bool and inPrevState of type String. This formula is responsible for specifying the next state, depending on whether Stop button has been clicked.

    • Add the output outNextState and type the formula: outNextState = inStopPressed ? "Stopped" : inPrevState.
    • Connect the input inPrevState with the register prevState.
  9. Open the HMI Designer. It is available in a View tab, or in a Toolbar.

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

  11. Add to the HMI ImpulseButton control and set its Text parameter to Stop.

    • Connect outValue with the input inStopPressed. From now, program executes Inspecting variant, until the Stop button is clicked.
  12. Connect the outNextState with register nextState.

  13. Create the macrofilter's output outState and also connect it with the outNextState.

  14. In the Stopped variant: add Formula and create the following inputs: inStartPressed of type Bool and inPrevState of type String. Connect its ports, except inStartPressed, as in the Inspecting variant.

  15. Add to the HMI ImpulseButton control and set its Text parameter to Start.

    • Connect outValue with the input inStartPressed. From now, program executes Stopped variant until Start button is clicked.
  16. Connect input inImage of the macrofilter with its output outImage, since no operations on image is performed in this variant.

  17. 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, add another Formula in the Main Task macrofilter.

  18. Create input inState and connect it with the output of Inspection macrofilter.

  19. Create output outStartEnabled of type Bool. Type the formula: inState <> "Inspecting". The outStartEnabled is True if the variant is Stopped.

    • Connect this output with the Start button's input inEnabled. From now this button will be disabled in Inspecting state.
  20. Create output outStopEnabled of type Bool. Type the formula: inState <> "Stopped". The outStopEnabled is True if the state is Inspecting.

    • Connect this output with the Stop button's input inEnabled. From now this button will be disabled in Stopped state.
  21. Create output outControlsEnabled of type Bool. Type the formula: inState == "Inspecting". The outControlsEnabled is True if the state is Inspecting.

    • Connect this output with the TrackBar's input inEnabled. From now this TrackBar will be enabled in Inspecting state.
  22. Add Delay filter and set inTime to 500. This filter suspends the program workflow for 500 milliseconds.

Macrofilter Main

Macrofilter Inspection(Inspecting)

Macrofilter Inspection(Stopped)

Used Filters

Icon Name Description
Delay Suspends the program workflow for inTime milliseconds.
ThresholdImage Image binarization when the illumination is constant and uniform.
GrabImage_FromFiles Can be used as EnumerateImages, but its state is global in a program - does not reset when some task is finished.

Further Readings