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.
:
- To add a statechart for the Sensor, in the browser, select
the Sensor block and .
- Using the State tool
, add two states named idle and reading.
- Use the Default Transition tool
to add a default transition
to the idle state.
- Use the 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.
- 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.
Note: The symbol in the upper right corner
of the reading state

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, in the browser, select the
Actuator block and .
- Using the State tool, add three states named idle, heating_on,
and heating_off.
- Add a Default Transition to the idle state.
- Use the Condition Connector tool
to
add a condition connector to the diagram.
- Add a Transition from idle to the condition and from
the condition to heating_on and from the condition to heating_off.
- Add a Transition from heating_on to
idle and from heating_off to idle.
- Double-click the transition from idle to the condition. In the
Features window, set Trigger to tm(750).
Click OK.
- Double-click the transition from the condition to heating_on.
In the Features window, set the Guard to heat_data and
type cs->setHeat(rating); as the code for Action.
Click OK.
- Double-click the transition from the condition to heating_off.
In the Features window, set the Guard toelse and
type cs->setHeat(0.0); as the code for Action.
Click OK.
The completed statechart for the Actuator must resemble this
example:
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.
To create
the
Controller statechart, 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.
- Select the Controller block in the browser and .
- Using the State tool, add two states to the diagram named controlling and standingby.
- Add a Default Transition to the controlling state.
- Add a Transition from controlling to standingby and
set the event placeholder to a new event called evStandby.
- Add a Transition from standingby to
controlling and set a new event called evNormal.
- Double-click the controlling state to open the Features window.
Add the following line of text to the Action on entry: setHeat_data(ENABLED);
- Click OK.
- Double-click the standingby state. Add the following
line of text to the Action on entry: setHeat_data(DISABLED);
- Click OK.
The revised Controller statechart must resemble this example:

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.
- To clear the diagram drawing area, select .
- In the browser, open the statechart for the ControlSystem.
- 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%.
- While holding the Alt key, expand the On
state symbol downwards about 50% taller and to the right about 50%
wider.
- 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.
- 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.
- Move the Standby state to the right to place it near the right
edge of the On state.
- To delete the two evMode transitions, right-click the transitions
and select Delete from Model.
- 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:- Double-click the upper send action to open the Features window.
Set Target: itsController; set Event: evStandby.
Click OK.
- Add a Transition from the Normal state to the upper send action
and another transition from the send action to the Standby state.
- Right-click the transition out of Normal and select .
- Double-click the lower send action to open its Features window.
Set Target: con; set Event: evNormal.
Click OK.
- 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.
- Right-click on the transition out of Standby and select .
- Add a State to the left side of the delegating_temperature compartment;
name it idle.
- Add a Send Action to the right side of the compartment. Set Target:
sen; set Event: evRead. Click OK.
- Connect a Transition from the idle state to the send action. Right-click
on the transition and select .
- Connect a Transition from the send action to the idle state.
Your completed statechart should resemble this example.
Full Model Simulation
To
generate and build the configuration for the full model simulation:
- Select .
- Review the Build page in the Output window for the "Build Done"
message.
- A DOS window displays with a message indicating that the model
is "Executing."
- Click the 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.
- Select and select the ControlSystem
statechart Context[0]->cs instance. Expand the statechart to show
the instrument panel elements.
- Select and select the Controller statechart
Context[0]->cs->con instance.
- Select and select the Actuator statechart
Context[0]->cs->act instance. You might also want to select and select the Sensor statechart Context[0]->cs->sen
instance, but this diagram is not required for the simulation operation.
- 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.
- Click the 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.
- 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: