Main Content

sltest.observer.observeElement

Observe model element

Since R2024b

    Description

    [obsport,obsmodel] = sltest.observer.observeElement("Signal",path,port) observes the signal connected to the port index, port, of the block specified by its path by creating an Observer model, adding an Observer Port block to the model, and setting the block to observe the signal.

    example

    [obsport,obsmodel] = sltest.observer.observeElement("SFData",path,dataobj) observes the Stateflow® data object, dataobj, in the Stateflow chart specify by its path by creating an Observer model, adding an Observer Port block to the model, and setting the block to observe the object.

    example

    [obsport,obsmodel] = sltest.observer.observeElement("SFStateActivity",path,stateobj,activity) observes the specified activity of the Stateflow state, stateobj, in the Stateflow chart specify by its path by creating an Observer model, adding an Observer Port block to the model, and setting the block to observe the object. state activity. The state must be at the top level of the Stateflow chart.

    example

    [obsport,obsmodel] = sltest.observer.observeElement("FMUInternalVariable",path,fmuvar) observes the Functional Mockup Unit (FMU) internal variable, fmuvar, in the FMU specified by its path by creating an Observer model, adding an Observer Port block to the model, and setting the block to observe the variable.

    example

    [obsport,obsmodel] = sltest.observer.observeElement(___,obsref) creates and configures an Observer Port block in the existing Observer model that is linked to the specified Observer Reference block, obsref.

    example

    Examples

    collapse all

    Observe the output_torque signal from the second output port of the transmission block in the sf_car model.

    import sltest.observer.*
    openExample("sf_car") 
    
    [obsport,obsmodel] = observeElement("Signal",...
       Simulink.BlockPath("sf_car/transmission"),2);

    Observe the up_th data in the Stateflow chart in the sf_car model.

    import sltest.observer.*
    openExample("sf_car") 
    
    sfdataobj = find(sfroot,"-isa","Stateflow.Data",...
       "-depth",4,Name = "up_th");
    [obsport,obsmodel] = observeElement("SFData",...
       Simulink.BlockPath("sf_car/shift_logic"),sfdataobj);

    Observe the OFF state in the Stateflow chart of the observe_sfstate_activity model.

    import sltest.observer.*
    open_system("observe_sfstate_activity") 
    
    blockPath = Simulink.BlockPath...
       ({'observe_sfstate_activity/Chart'});
    chartObj = find(sfroot,"-isa","Stateflow.Chart");
    stateObj = find(chartObj,"-isa",...
       "Stateflow.State",Name="OFF");
    activityType = 'Self';
    
    obsRef = Simulink.findBlocksOfType...
       ('observe_sfstate_activity','ObserverReference');
    [obsport,obsmodel] = observeElement("SFStateActivity",...
       blockPath,stateObj,activityType,obsRef);

    Observe the controlSignal internal variable in a Functional Mockup Unit (FMU) in the fmuPIDwithInternalVar model.

    import sltest.observer.*
    openExample("fmuPIDwithInternalVar")
    
    fmuvar = 'controlSignal';
    blockPath = Simulink.BlockPath('fmuPIDwithInternalVar/FMU');
    
    [obsport,obsmodel] = observeElement("FMUInternalVariable",...
       blockPath,fmuvar);

    Input Arguments

    collapse all

    Path to the element to observe in the system model, specified as a Simulink.BlockPath object. The paths specific to each element type are:

    • 'Signal' — The block from which the signal originates

    • 'SFData' — The top level of the Stateflow chart that contains the data

    • 'SFStateActivity' — The top level of the Stateflow chart that contains the state activity

    • 'FMUInternalVariable' — The Functional Model Unit

    Port index that identifies the port of the signal, specified as an integer.

    Stateflow data object to observe, specified as a Stateflow.Data (Stateflow) object.

    Stateflow state object to observe, specified as a Stateflow.State (Stateflow) object.

    Stateflow activity type, specified as 'Self'. For information about Stateflow activity types, see Monitor State Activity Through Active State Data (Stateflow).

    FMU internal variable to observe, specified as a string or character vector.

    Observer Reference block, specified as a string, character vector, or double. Use a string or character vector to specify the path of the Observer Reference block, or use a double to specify the handle of the Observer Reference block.

    Output Arguments

    collapse all

    Observer Port block, returned as a double data type block handle.

    Observer model, returned as a double data type model handle.

    Version History

    Introduced in R2024b