< Previous | Next >

Lesson 7: Simulating the model

This lesson shows how to use model simulation to check the design and guides you to run the same simulation on the tutorial model.
After you watch the video demonstrating model simulation, you can perform the steps on your model.

Watch the "ControlSystem simulation" in the Related information section below to see the model simulation demonstration.

Note: In the simulation, the temperature of the water increases in real time, so the model temperature is initially set to 39.5 degrees C to avoid a long wait in simulation.

Simulation requires the generation and execution of code from the model, so that the model must be correctly specified. If there are errors in making the changes from the preceding lessons, or if any changes are incomplete, the code cannot be generated, and the model does not execute.

To generate and build the configuration for simulation:

  1. In the browser, open the SpaPoolTemp_Control_Architecture folder.
  2. Select Simulation > Full Build. You are asked to create an Animate directory. Select Yes.
  3. Rhapsody® generates code for the elements of interest, compiles and links the code into an executable file and runs it. This should take only a few seconds. If the build is successful, the Simulation toolbar becomes active. You can verify that the simulation was correctly built by checking the Build page in the Output window for the "Build Done" message. If step 2 is not successful, a "Build Failed" message displays. See to the Troubleshooting steps below.

  4. To start the simulation, click the Go Idle button in the Simulation toolbar. The simulation starts, but immediately pauses to allow you to set up statechart animation to observe the simulation.
  5. Close all drawing windows using WindowClose All.
  6. Select Tools > Simulated Statechart and choose the ControlSystem statechart, as shown. Click OK.
    Open Animated Statechart window
  7. To resume the simulation, click the Go button Go button on the Simulation toolbar. You can now use the Power® and Mode panel buttons to operate the system while observing the change in temperature on the TEMP display. Keep in mind that the temperature change, especially when the system is cooling, is very gradual.
Bonus

If a more precise view of the temperature change is required, you can open the Features window for the ControlSystem instance. From the browser under the ControlSystem block, double-click on the Instance Context[0]->cs. Click on the pin button in the upper right hand corner of the dialog box to focus it.

Troubleshooting

If your version of the project does not build successfully, use these troubleshooting techniques to locate and correct the problem:
  • Compare the statecharts in your project with the ones described in lessons 4 and 5.
  • Compare your internal block definition diagram with the one described in lesson 4.

Lesson checkpoint

In this lesson, you learned the following:
  • Generating and building a model configuration
  • Simulating system operations in a statechart with a panel
In the next lesson, you build the architecture for the control system.
< Previous | Next >

Feedback