Table of Contents
State Diagram Editor Introduction Part III
In this third part of the tutorial you will learn how to simulate a created model to see for yourself if the machine does what it is supposed to do. Or to run through a model with colleagues or customers and confirm that the behavior is as expected.
A model can only be simulated if it is error free. The absence of errors can be checked with the check button in the button bar. If there are no errors, the simulation is possible in the Tree View (see Figure 1).
Simulation without timer
The simulation can be started with the button “Start”. Once the simulation has been started, the events processed by the currently active state (in red) and its parents (also in red) are displayed. A click on an event triggers the state change. Afterwards, the possible events that originate from the new state are displayed. Events of a timer have to be triggered by a click just like all other events. A click on the “Stop” button ends the simulation.
The code “executed” in the actions is recorded in the output window. This makes it possible to track which actions are executed when the state changes.
Note: Actions refer to the code that you have entered as Entry/Exit/Do code or for transitions.
Simulation with timer
In statemachines, one or more timers are very often used to trigger time-controlled actions. Timers send a user defined event to the machine at timeout. To simulate this semi-automatically, it is possible to specify timer commands in the comment of actions in a predefined notation. The timer commands are introduced by a special sequence, by default these are three “
@@@”. Then the timer command follows in XML syntax. This makes it possible to create, start or stop timers and thus make the simulation more realistic.
To activate the timer simulation, check the “Activate Timers” option before starting the simulation. If timers fire faster than approx. 200ms (depending on the computer a little more or less), a reduction should be set at “Timer Ratio”, otherwise the real-time image build-up is no longer possible. Or other events can no longer be clicked. By default the “Timer Ratio” is 1:1.
The following functions are available. Times are always specified in ms. A unique timer ID is required in each case. When creating a timer, the event must be specified (in the example
evTimeout), which is injected into the simulator when the time expires. Timers can fire cyclically or once.
<TimerCreate timeout_ms="400" id="T1" event="evTimeout/> <TimerIncrement value_ms="100" id="T1"/> <TimerDecrement value_ms="100" id="T1"/> <TimerSetTimeout timeout_ms="400" id="T1" /> <TimerStartAcyclic id="T1" />" <TimerStartOnce id="T1"/> <TimerStop id="T1" />
In the following video you can see how to work with the simulation. After switching on the microwave oven the timer T1 was created. The user can now increase or decrease the time via
evDec/evInc. If he closes the door, the timer T1 starts running. After the time has elapsed, the sent evTimeout event automatically switches to the Completet state. In between, the time can still be changed via
Note: It is important to pay attention to the fact that the entered program code with the timer later e.g. in C or C++ are realized, agrees with the simulation code in the comment! Since this takes place however in the same input field this is not difficult (it in the picture above at the example of a transition).