BDD & STM: Control

Gallery
Tutorial
This diagram shows the Block Control with a supporting StateMachine ControlSM:
Click on the image to view it full size

The ControlSM stays in Off until it receives a 1 from the switch of the UsageScenarioSM, after which it enters Warmup. It won't move to On until the water temperature is at least 99 °C, then it waits until either a usage scenario switch 0 is received, or the water volume (as sent from the WaterTank) is too low, then enters CoolDown, where it stays until the water temperature is below the safeTemperature. If a usage scenario switch 0 is received during Warmup or On it just goes immediately to CoolDown.

In the spec (and in the MagicDraw/Cameo sample) it has a Transition test from On to CoolDown that employs a comparison of the water temperature with 0 using the == operator. Using their naming:


when (waterVolumeIn.rSig==0)
On export to Modelica (using the naming in the spec) this would give:

      Modelica.StateGraph.Transition ControlStateMachine_region1_transition6(condition=waterVolumeIn==0);
Noting that:

It turns out such a comparison waterVolumeIn==0 is not permitted for Reals in Modelica, and the Wolfram SystemModeler tool - for example - enforces this Modelica language rule (and won't validate or run):

For the sake of getting it to run without introducing an additional Modelica function, a HACK has been used here in the trail version. Instead of testing for 0, it just tests for a very low value:


when (iWaterVolume.rSig <= 0.1)

The same issue would also afflict some of the other Transition tests for the iSwitch Port and the iMode Port if they had used RealSignalInElement, but they have been sneakily set here to use IntegerSignalInElement instead, since they only ever use 0 or 1 anyway.

There's a similar slight HACK with the iFanPowerRatio Port being also set to use IntegerSignalInElement. In a real system one might imagine using a range of values between 0 and 1, but in the system as shown it only ever takes a 0 (off) or 1 (on), so using an Integer is fine here too. The fan is either on or off.

Up next
Notes
Snippets (quotes/extracts)
Visit also
Visit also (backlinks)
Related slides (includes other tutorials)
Related slides (backlinks, includes other tutorials)