Simulating a Behavior with Interaction Input Elements

If prepared for, you can execute and modify interactively the behavior of the components in a diagram.

By modifying the behavior, you can provide your own input into a simulation.

Interaction is limited to 2D only; if your model includes 3D, this is displayed, but you cannot interact with it.

The command is used for models with 2D diagrams containing interactive elements, which can be manipulated during simulation. Several types of interactive element exist (push buttons, sliders, text, etc.) exist. The following elements from the UserInteraction library are supported by this command:

Element Comment on Usage
UserInteraction.Inputs.NumericInputIO Input field to specify a numeric value. Click the field to specify a value, press Enter to validate the change.
UserInteraction.Inputs.Slider Slider to specify a numeric value.
Important: You must click the wanted position. Dragging is not supported.
UserInteraction.Inputs.Knob Knob to specify a numeric value.
Important: You must click the wanted position. Dragging is not supported.
UserInteraction.Inputs.TrigButton Button to specify a Boolean signal to "on". Click to activate.
UserInteraction.Inputs.ToggleButton Button to toggle a Boolean signal. Click to toggle.

The interactive elements are created using specific Modelica annotations. This means that other elements using the same annotations in the same way are also supported.

In this scenario you open, simulate, and modify interactively the model example UserInteraction.Examples.TestInteraction to see the three first elements in the table in work.

Note: To see the Boolean elements in work, you can open UserInteraction.Examples.TestBooleanInteraction instead.


Before you begin: To open the model and specify a suitable stop time of the simulation, do the following:
  1. To simulate with interaction, you must, in the simulation setup, the General tab, activate the option Interactive simulation.

    For more information about reaching the simulation setup, see Setting up a Simulation.

  2. Simulate the model. See Launching a Virtual Execution.
  3. Replay the animation. See Replaying Simulation Results.
  4. Display the content of the model in a dockable panel. See Displaying the Diagram View of a Modelica Class in an Immersive Dockable Panel.
  5. In the Simulation Options dialog box, specify your preferences for the animation. See Managing Simulation Options Using the Simulation Options Dialog Box.

    Important: For this scenario, make sure that the Real time option is activated.

  6. From the Experience Player, click Play Forward .
  7. Interact using the elements described in the three first rows in the table above.

    Note: The input value field in this demo is specified to only handle values in the range 0–10.

    Tip: You can display variable names and values dynamically on the diagram. See Monitoring Variables on the Diagram of Modelica Class Panels.
  8. To end the execution, see last step in Launching a Virtual Execution.