Main Content

Test a Unique Chart Configuration

An operating point is a snapshot of the state of a Simulink® model at a specific time during simulation. For a Stateflow® chart, an operating point includes:

  • Activity of chart states

  • Values of chart local data

  • Values of chart output data

  • Values of persistent data in MATLAB® functions and Truth Table blocks

For more information, see Using Operating Points in Stateflow.

Goal of the Tutorial

Suppose that you want to test the response of the old_sf_car model to a sudden change in value for gear.

This model simulates for 30 seconds, but you want to see what happens when the value of gear changes at t = 10. You can simulate the model, save the operating point at t = 10, load and modify the operating point, and then simulate again between t = 10 and 20.

StepTaskReference
1Define the operating point for your chart.Define the Operating Point
2Load the operating point and modify values.Load the Operating Point and Modify Values
3Test the modified operating point by running the model.Test the Modified Operating Point

Define the Operating Point

  1. Open the model old_sf_car.

  2. Enable saving of an operating point.

    1. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.

    2. Select the Final states check box.

    3. Enter a name, such as old_sf_car_ctx01.

    4. Select the Save final operating point check box.

    5. Click Apply.

     Programmatic equivalent

  3. Define the start and stop times for this simulation segment.

    1. In the Model Configuration Parameters dialog box, go to the Solver pane.

    2. For Start time, enter 0.

    3. For Stop time, enter 10.

    4. Click OK.

     Programmatic equivalent

  4. Start simulation.

    When you simulate the model, you save the complete operating point at t = 10 in the variable old_sf_car_ctx01 in the MATLAB base workspace.

    At t = 10, the engine is operating at a steady-state value of 2500 RPM.

  5. Disable saving of an operating point.

    This step prevents you from overwriting the operating point you saved in the previous step.

    1. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.

    2. Clear the Save final operating point check box.

    3. Clear the Final states check box.

    4. Click OK.

     Programmatic equivalent

Load the Operating Point and Modify Values

  1. Enable loading of an operating point.

    1. Open the Model Configuration Parameters dialog box and go to the Data Import/Export pane.

    2. Select the Initial state check box.

    3. Enter the variable that contains the operating point of your chart: old_sf_car_ctx01.

    4. Click OK.

     Programmatic equivalent

  2. Define an object handle for the operating point values of the shift_logic chart.

    At the command prompt, type:

    blockpath = 'old_sf_car/shift_logic';
    c = old_sf_car_ctx01.get(modelOperatingPoint, 'blockpath');

    Tip

    If the chart appears highlighted in the model window, you can specify the block path using gcb (Simulink):

    c = old_sf_car_ctx01.get(gcb);

     Copy and reference operating points with the get method

  3. Look at the contents of the operating point.

    c = 
    
      Block:    "shift_logic"    (handle)    (active)
      Path:     old_sf_car/shift_logic
    
      Contains:
    
        + gear_state         "State (AND)"          (active)
        + selection_state    "State (AND)"          (active)
          gear               "Block output data"    double [1, 1]
          

    The operating point of your chart contains a list of states and data in hierarchical order.

  4. Highlight the states that are active in your chart at t = 10.

    At the command prompt, type:

    c.highlightActiveStates;

    In the chart, all active states appear highlighted.

    Tip

    To check if a single state is active, you can use the isActive method. For example, type:

    c.gear_state.fourth.isActive

    This command returns true (1) when a state is active and false (0) otherwise. For information on other methods, see Methods for Interacting with the Operating Point of a Chart.

  5. Change the active substate of selection_state to downshifting.

    Use this command:

    c.selection_state.downshifting.setActive;

    The newly active substate appears highlighted in the chart.

  6. Change the value of output data gear.

    When you type c.gear at the command prompt, you see a list of data properties similar to this:

    >> c.gear
    
    ans = 
    
          Description: 'Block output data'
             DataType: 'double'
                 Size: '[1, 1]'
                Range: [1x1 struct]
         InitialValue: [1x0 double]
                Value: 4
     

    You can change the value of gear from 4 to 1 by typing

    c.gear.Value = 1;
    However, you cannot change the data type or size of gear. Also, you cannot specify a new value that falls outside the range set by the Minimum and Maximum parameters. For details, see Rules for Modifying Data Values .

  7. Save the modified operating point.

    Use this command:

    old_sf_car_ctx01 = old_sf_car_ctx01.set(blockpath, c);

Test the Modified Operating Point

  1. Define the new stop time for the simulation segment to test.

    1. In the Model Configuration Parameters dialog box, go to the Solver pane.

    2. For Stop time, enter 20.

    3. Click OK.

    You do not need to enter a new start time because the simulation continues from where it left off.

     Programmatic equivalent

  2. Start simulation.

    The engine reacts as follows:

Related Topics