メインコンテンツ

Create Simulink Behavior Models

Implement the functionality of component functions defined in the architecture model from the previous step using Simulink® behavior models.

To open the completed model, run this command.

open("EVPwrCntrllrEMSysFinal.slx");

Create Behavior Model for Service Components

Create the Simulink behavior models for the service components VehicleDynamics_ServiceCmp and BatteryManagementSystem_ServiceCmp, which use client-server communication. Use Simulink export-function models to define and implement the component behavior.

  1. To create a Simulink behavior, right-click a service component and select Create Simulink Behavior.

    Right-click menu for the AccelPdlTrqRequest_ServiceCmp software component with the Create Simulink Behavior option selected.

  2. In the Create Simulink behavior dialog box, set Type to Model Reference: Export-Function. Specify a filename and location to save the template model. Click OK.

    Create Simulink behavior dialog box.

  3. The template model subsystem includes the service interface created in System Composer™.

    Empty Simulink behavior model.

  4. Define the service in the model by implementing the service component algorithm inside the Simulink Function block.

    Original function content copied into the Simulink behavior model shell.

Create the Simulink behavior model for the BrakePdlTrqRequest_ServiceCmp service component, which uses sender-receiver communication.

  1. In the Modeling tab in the toolstrip, open the Functions Editor.

  2. Click the BrakePdlTrqRequest_ServiceCmp component box.

  3. In the Functions Editor, click the add Button to add a function to a software component. button to add a function to the software component.

    Functions editor with the function BrakePdlTrqRequest_ServiceCmp_Function created.

  4. Right-click the component and select Create Simulink Behavior.

    Right-click menu for the BrakePdlTrqRequest_ServiceCmp software component with the Create Simulink Behavior option selected.

  5. In the Create Simulink behavior dialog box, set Type to Model Reference: Export-Function. Specify a filename and location to save the template model. Click OK.

    Create Simulink behavior dialog box.

  6. Open the template model subsystem.

    Empty Simulink behavior model.

  7. Add the algorithm for the service component functionality inside the Function-Call Subsystem block.

    Original function content copied into the Simulink behavior model shell.

You can find the completed service component behavior models for this example in the CreateSimulinkBehaviorModel/ServiceComponent folder.

Create Behavior Model for the Client Component

Create the behavior model for the Energy Management client component.

  1. Right-click on the component and select Create Simulink Behavior.

    Right-click menu for the EnergyMgmtAppCmp software component with the Create Simulink Behavior option selected.

  2. In the Create Simulink behavior dialog box, set Type to Model Reference: Export-Function. Specify a filename and location to save the template model. Click OK.

    Create Simulink behavior dialog box.

  3. Open the model template.

    Empty Simulink behavior model.

    In the component behavior model, subsystems are created for each service that implements client-server communication. Each subsystem contains a Function Caller block.

    Function caller subsystem containing a Function Caller block.

    The Function prototype parameter is set according to the function prototype definitions added to the Interface Editor in the previous step.

    Function Caller block parameters dialog box

  4. Add the algorithm for the component functionality to the Simulink behavior model.

    In this example, the algorithm needed to generate brake and torque commands is added to the Simulink behavior model.

  5. Connect the service component function call inputs and outputs to the client component.

    In this example, the service component function calls are grouped in pre-algorithm and post-algorithm subsystems and connected to the client component to match the original software intent.

    Note

    This example creates the behavior model for the client component using an export-function model. When implementing a call to a synchronous service, you can also use a rate-based model. For more information, see Implement Behavior of Functions Using Simulink (System Composer).

    In this high-level overview of the connected subsystems, the pre-algorithm and post-algorithm subsystems are highlighted in blue, and the Energy Management subsystem is highlighted in green.

    Overview of the main application coponent behavior model connections.

  6. Specify the Sample time (-1 for inherited) parameter for each function-call subsystem input port to 0.01.

  7. Change the execution order of the functions in the Functions Editor so that BrakePdlTrqRequest_ServiceCmp is the first function to execute.

    Functions editor

You can find the completed application component behavior model for this example in the CreateSimulinkBehaviorModel/ApplicationComponent folder.

See Also

Topics