< Previous | Next >

Lesson 5: Adding a statechart to the behavioral design

In this lesson, you add a statechart to the SystemUnderControl in order to model the essential behavior.

The SystemUnderControl is a pool of 720 L of water at some initial temperature that needs to warm up to a reference temperature using heat supplied by the ControlSystem. To characterize the SystemUnderControl, attributes describe the state of the system, and a parametric constraint specifies a mathematical relationship among the input, Q to the SystemUnderControl and its output, deltaT.

Equation

This relationship can be modified to work in the discrete time domain. If Q is expressed as a rate, that is, the ControlSystem (the heat source in this model) provides heat at a maximum rate of 19.049 kJ per second, deltaT becomes a rate, that is, temperature change in degC per second. By using an implicit time period of 1 second the constraint between heat and temperature change can be modeled using a statechart, a discrete time domain artifact.

To add a statechart describing the behavior of SystemUnderControl:

  1. In the browser, expand DesignSynthesisPkg > blocks > Context > Internal Block Diagrams and double-click External Flows to open the internal block diagram.
  2. Right-click on the SystemUnderControl part in the diagram and select Add New > Statechart.
  3. Select the Stamp Mode tool Stamp Mode tool and then click the State. (With stamp mode you can draw more than one version of the same diagram element.)
  4. Click three times in the empty statechart to draw three states. Click Stamp Mode again to stop using it.
  5. Type the label names in each of the three states: idle, warming, and cooling.
  6. Select the Default Transition tool Default Transition tool and click above the idle state and then again on the top of that state.
  7. Double-click the transition line to open the Features window.
  8. In the Action field of the General page, type setTemperature(initialT);
  9. Click OK. Note that the "/" is added automatically as part of the transition syntax.
  10. Select the Condition Connector tool Condition Connector tool and click in the middle of the statechart.
  11. Select the Transition tool Transition tool and draw the arrow from the idle state to the condition connector. Label this transition tm(1000).
  12. Select the Junction Connector tool and click between the warming and cooling states.
  13. Draw transitions from warming and cooling to the junction connector.
  14. Draw a transition from the junction connector to the idle state. Open the Features window for the transition and add the line of text below including the semicolon to the Action field and then click OK. setTemperature(heatFunction());
  15. Draw a transition from the condition connector to the warming state. Label this transition [heat>0].
  16. Draw a transition from the condition connector to the cooling state. Label this transition [else].
  17. In the browser, locate the heatFunction operation under the SystemUnderControl block.
    Browser showing heatFunction under SystemUnderControl block
  18. Double-click the operation to open the Features window and select the Implementation tab.
    Features window showing Implementation tab for heatFunction
  19. Remove the two forward slash characters (C++ comment characters) at the beginning of the implementation content. The text changes from green to another syntax-specific color to indicate that it has been parsed by Rhapsody®. Click OK.
Your statechart should resemble this example.
Statechart

In this statechart, a new temperature is calculated each second taking into account the heat applied (if any) and the cooling. The one second timing of the state transition provides an implicit specification of continuous time that simplifies the constraint equation. For example, coolingRate, normally expressed in degC_per_s becomes degC.

To see the statechart in the internal block diagram:

  1. Select Window > Internal Block Diagram: External Flows in DesignSysntesisPkg::Context.
  2. The yellow statechart symbol Yellow statechart symbol is in the upper right corner of the s:SystemUnderControl part. Click the statechart symbol to open that statechart.

Lesson checkpoint

In this lesson, you learned the following:
  • Defining part behavior within an internal block diagram
  • Adding a statechart to define system behavior
  • Using stamp mode to draw multiple versions of the same type of item in a diagram
  • Opening a statechart from an internal block diagram

In the next lesson, you define a constraint and add a parametric diagram.

< Previous | Next >

Feedback