< Previous | Next >

Lesson 9: Specifying the high-level behavior and simulating the model

In this lesson you, specify the high-level behavior of the control system components using statecharts and simulate the full model.
In the initial design, you used a statechart to specify the behavior of the ControlSystem. Since the structure of the ControlSystem has now been specified in terms of its components, you need to add statecharts for each of the component blocks to reflect their behavior and modify the ControlSystem statechart to reflect its collaborative behavior.

Creating statecharts for component blocks

To add a statechart for the Sensor:

  1. In the browser, select the Sensor block and Add New > Diagrams > Statechart.
  2. Using the State tool State tool, add two states named idle and reading.
  3. Use the Default Transition tool Default Transition tool to add a default transition to the idle state.
  4. Use the Transition tool Transition tool to add a transition from the idle state to the reading state. In the placeholder that appears on the transition, add an event named evRead.
  5. Add a transition from the reading state back to the idle state.
Upon receiving the evRead event, the Sensor part transitions from its idle state to its reading state. Then it transfers the value of temperature from the ControlSystem (which it knows as cs) to its temperature attribute and returns to idle. Your Sensor statechart should resemble this example.
Sensor statechart
Note: The symbol in the upper right corner of the reading state Symbol indicates that the state has text in the Entry Action or Exit Action fields. If you click the symbol, it shows and hides the text in the Reactions compartment on the state symbol. The example shows the text in the Reactions compartment.

At this level of analysis, the Actuator part turns on or off the rated amount of heat when commanded to do so. The heat is delegated to the ControlSystem and flows to the SystemUnderControl.

To add a statechart for the Actuator:
  1. In the browser, select the Actuator block and Add New > Diagrams > Statechart.
  2. Using the State tool, add three states named idle, heating_on, and heating_off.
  3. Add a Default Transition to the idle state.
  4. Use the Condition Connector tool Condition Connector tool to add a condition connector to the diagram.
  5. Add a Transition from idle to the condition and from the condition to heating_on and from the condition to heating_off.
  6. Add a Transition from heating_on to idle and from heating_off to idle.
  7. Double-click the transition from idle to the condition. In the Features window, set Trigger: tm(750). Click OK.
  8. Double-click the transition from the condition to heating_on. In the Features window, set the Guard: heat_data and type cs->setHeat(rating); as the code for Action. Click OK.
  9. Double-click the transition from the condition to heating_off. In the Features window, set the Guard: else and type cs->setHeat(0.0); as the code for Action. Click OK.
The completed statechart for the Actuator should resemble this example.
Actuator statechart - completed
Note: Rhapsody® automatically adds square brackets and forward slash characters that are elements of the transition syntax when you use the Features window to specify the trigger, guard, and action for a transition. Alternatively, you need to enter these characters yourself when you enter text directly into the transition placeholder on the diagram.

Creating the Controller statechart

At this point in the design, the Controller only needs to respond to changes in the mode of operation where, in standby mode it must disable the heater and in normal mode it must enable the heater. Later, as the design evolves, the Controller needs a control algorithm.
  1. Select the Controller block in the browser and Add > New Diagram > Statechart.
  2. Using the State tool, add two states to the diagram named controlling and standingby.
  3. Add a Default Transition to the controlling state.
  4. Add a Transition from controlling to standingby and set the event placeholder to a new event called evStandby.
  5. Add a Transition from standingby to controlling and set a new event called evNormal.
  6. Double-click the controlling state to open the Features window. Add the following line of text to the Action on entry: setHeat_data(ENABLED);
  7. Click OK.
  8. Double-click the standingby state. Add the following line of text to the Action on entry: setHeat_data(DISABLED);
  9. Click OK.
The revised Controller statechart should resemble this example.
Controller statechart - revised

Updating the ControlSystem statechart

The behavior specified in the initial statechart for the ControlSystem must now be changed to reflect the behavior provided by its components. Specifically, temperature sensing is to be performed by the Sensor component so the ControlSystem must delegate the temperature flow to its Sensor. Likewise, the Controller now commands its Actuator to produce the heat flow that is delegated back to the ControlSystem. The ControlSystem must also delegate mode change events to the Controller.

  1. To clear the diagram drawing area, select Window > Close All.
  2. In the browser, open the statechart for the ControlSystem.
  3. Draw a selection marquee around the panel elements and move them as a group down to the bottom of the diagram frame to allow the On state to be lengthened by about 50%.
  4. While holding the Alt key, expand the On state symbol downwards about 50% taller and to the right about 50% wider.
  5. Using the And Line tool, click the left edge of the On state to anchor the "and" line, draw horizontally across the On state to create a second vertical compartment. Click the right side of the On state to complete the line. Move the And Line so that it is just below the Standby state.
  6. Double-click in the white space in the upper compartment to open the Features window for the compartment (State). Set Name: delegating_mode. Click OK. Do the same for the lower compartment to set its name to delegating_temperature. Set the Display Options for each compartment to Name.
  7. Move the Standby state to the right to place it near the right edge of the On state.
  8. To delete the two evMode transitions, right-click the transitions and select Delete from Model.
  9. Using the Send Action tool , add two send actions spaced vertically between the Normal and Standby states. Follow these steps to define the send actions:
    1. Double-click the upper send action to open the Features window. Set Target: itsController; set Event: evStandby. Click OK.
    2. Add a Transition from the Normal state to the upper send action and another transition from the send action to the Standby state.
    3. Right-click the transition out of Normal and select Trigger > evMode.
    4. Double-click the lower send action to open its Features window. Set Target: con; set Event: evNormal. Click OK.
    5. Draw a transition from the Standby state to the lower send action and another transition from the send action to the Normal state. Do not be concerned about the direction of the send action symbol. Only the direction of the transition matters.
    6. Right-click on the transition out of Standby and select Trigger > evMode.
  10. Add a State to the left side of the delegating_temperature compartment; name it idle.
  11. Add a Send Action to the right side of the compartment. Set Target: sen; set Event: evRead. Click OK.
  12. Connect a Transition from the idle state to the send action. Right-click on the transition and select Trigger > chTemperature.
  13. Connect a Transition from the send action to the idle state.

Your completed statechart should resemble this example.

ControlSystem statechart - completed

Full Model Simulation

To generate and build the configuration for the full model simulation:

  1. Select Simulation > Full Build.
  2. Review the Build page in the Output window for the "Build Done" message.
  3. A DOS window displays with a message indicating that the model is "Executing."
  4. Click the Go Idle button Go Idle button to start the simulation. The simulation automatically stops to allow you to set up the animated statecharts and other artifacts to observe the execution.
  5. Select Tools > Simulated Statechart and select the ControlSystem statechart Context[0]->cs instance. Expand the statechart to show the instrument panel elements.
  6. Select Tools > Simulated Statechart and select the Controller statechart Context[0]->cs->con instance.
  7. Select Tools > Simulated Statechart and select the Actuator statechart Context[0]->cs->act instance. You might also want to select Tools > Simulated Statechart and select the Sensor statechart Context[0]->cs->sen instance, but this diagram is not required for the simulation operation.
  8. Arrange the statecharts by tiling the windows. Note you can reduce the Zoom factor to 75% and still read most of the information on the charts.
  9. Click the Go button Go button on the Simulation control panel to resume the animation and use the panel buttons (Power & Mode) on the Controller statechart to drive the behavior of the system at the component level. You might need to click the Power button twice to turn on the ControlSystem.
  10. You can observe the values of the temperature and heat attributes by opening the Features window for the instances of the components from the browser. For example, in the browser locate the instance Context[0]->s of the SystemUnderControl block. Double-click the instance and pin the Features window, as shown in this example:
    Features window for instance of Context[0]->s

Lesson checkpoint

In this lesson, you learned the following:
  • Defining high-level behavior in two statecharts
  • Adding transitions
  • Showing and hiding text in class compartment
  • Modifying a previously created statechart
  • Running a full model simulation
The final lesson in the tutorial lists techniques you can use to hand off specifications to software engineers that you defined in the model.
< Previous | Next >

Feedback