Main Content

Publish Actor Behavior as Proto File, Package, Action Asset or Event Asset

This topic explains how to publish your Simulink® or MATLAB® System object™ actor behaviors as proto files, packages, action assets or event assets using the publishActorBehavior, publishActor, publishCustomAction or publishCustomEvent functions.

Proto files are specific to RoadRunner and have a .slprotodata extension. This data interface allows you to combine your behavior model and its parameters and share them with RoadRunner. You can then tune these parameters in the RoadRunner environment.

Generate Behavior Proto File for Simulink or MATLAB System Object Behavior

Use the publishActorBehavior function to generate a behavior proto file from your Simulink behavior.

  1. For demonstration purposes, suppose you create the Simulink model, foo01.slx. This code below initiates the model and then assigns a new workspace variable gain with value 2.0.

    % ---------------------- Setup a SL Model -----------------------
    model = 'foo01';
    new_system(model);
    modelWorkspace = get_param(model,'ModelWorkspace');
     
    var_name = 'gain01';
    var_value = 2.0;
     
    % Assign to model workspace
    assignin(modelWorkspace,var_name,var_value);
     
    % Set model argument
    set_param(model,'ParameterArgumentNames',var_name);
    params = Simulink.internal.getModelParameterInfo(model);
     
    save_system(model);
    close_system(model,0);
  2. To create a proto file for foo01.slx, use this command.

    Simulink.publish.publishActorBehavior('foo01.slx');

    This command creates the foo01.slprotodata file in your current directory.

  3. You can now drag foo01.slprotodata into any folder under MyProject/Assets. For this example, the file is placed in the Vehicles folder.

    The proto file appears as a behavior under the Vehicles folder

  4. Double-click the foo01 behavior and observe that the gain parameter and its value appears. You can now tune this parameter for simulation purposes.

    The gain parameter is displayed in the Attributes pane. The parameter value is 2.

  5. Attach the proto file to your vehicle in your scenario.

    The proto file is attached to a vehicle

You can also use this workflow to generate a behavior proto file from a MATLAB System object behavior.

For example, suppose that you create the behavior MySystemObjectBehavior.m. To publish your behavior as a proto file, use this command.

Simulink.publish.publishActorBehavior('MySystemObjectBehavior.m');

Generate Package from Simulink Model or MATLAB System Object

You can also publish your behavior as a package in a .zip file. Publishing in a .zip file allows you to create a package that includes the supporting files for your model, for example, a .mat file. To publish your Simulink model, Simulink project, or MATLAB System object behavior as a package, use the publishActor function.

For example, to publish your MySystemObjectBehavior.m behavior as a package, use this command.

Simulink.publish.publishActor('MySystemObjectBehavior.m',OutputFile="packageoutput.zip");

The package includes:

  • Metadata folder — Stores the actor files. packageInfo.json contains the package type, MATLAB version, and publish date to identify the package.

  • Model files — An .slx or .m file.

  • Data files — Dependent data files for use in setup and cleanup scripts, such as model callbacks, .mat files, and .sldd files.

Generate Packages for Reuse and Improving Simulation Performance

You can generate ready-to-run packages for your Simulink models that include RoadRunner scenario blocks and MATLAB System blocks containing RoadRunner simulation APIs.

Using ready-to-run packages as your actor behaviors allows you to associate the same behavior with multiple actors in your scenario, modify behavior parameters locally for each actor, and improve simulation performance. For more information, see Publish Ready-to-Run Actor Behaviors for Reuse and Simulation Performance.

To create a ready-to-run package, use the publishActor function. For example, you can publish myActorBehaviorModel as a ready-to-run package. After you create your package as a ZIP file, you can attach it to multiple actors in your scenario.

Simulink.publish.publishActor('myActorBehaviorModel', PackageType='ReadyToRun');

Generate Action Asset File from Simulink Model

You can publish your Simulink actor behavior model containing a user-defined action as an action asset file in the .seaction format. To publish a user-defined action as an action asset file, use the publishCustomAction function.

To use this function successfully:

  • A Simulink model must read the user-defined action from a Simulink bus object, saved as a MAT-file.

  • The Simulink model must contain a RoadRunner Scenario block that links the MAT-file to the name of an action in RoadRunner Scenario.

You can use the published .seaction file in the action phases of a scenario simulation.

Generate Event Asset File from Simulink Model

You can publish your Simulink actor behavior model containing a user-defined event as an event asset file in the .seevent format. To publish a user-defined event as an event asset file, use the publishCustomEvent function.

To use this function successfully:

  • A Simulink model must read the user-defined event from a Simulink bus object, saved as a MAT file.

  • A Simulink model must contain a RoadRunner Scenario block that links the MAT file to the name of an event in RoadRunner Scenario.

You can use the published .seevent file in the action phases of a scenario simulation.

See Also

| | |

Related Topics