Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Converting Harness-Driven Models to Use Harness-Free External Inputs

This example shows how to convert a harness model that uses a Signal Builder block as an input to a harness-free model with root inports. The example collects data from the harness model and stores it in MAT-files, for use by the harness-free model. After storing the data, the example removes the Signal Builder block from the harness model and adds root inports to create a harness-free model. Then, the data in the MAT-files is mapped to the root inports of the model.

Save Harness Data to MAT-Files

Before converting the model to be harness-free, capture the test cases in the harness.

For this example, you will modify the model sldemo_autotrans from the Modeling an Automatic Transmission Controller example.

Open the example model. In the MATLAB Command Window type sldemo_autotrans.

Use MATLAB function slexAutotransRootInportsSaveActiveGroup to save the Signal Builder block data of the active group into a MAT-file. At the command line type slexAutotransRootInportsSaveActiveGroup('slexAutotransRootInport','ManeuversGUI'). This function creates a MAT-file in the current directory with the same name as the active group. The function slexAutotransRootInportsSaveActiveGroup has been provided with this example.

Remove the Signal Builder Block

Remove the Signal Builder block named ManeuversGUI and replace it with two inports.

  1. Delete the Signal Builder block named ManeuversGUI.

  2. Open the Simulink Library Browser and select Commonly Used Blocks.

  3. Drag and drop two input ports from the Library Browser to the model.

  4. Connect the input ports to the lines previously connected to the Signal Builder block.

  5. Rename the inport ports. Name the input port connected to the Throttle line Throttle. Name the input port connected to the BrakeTorque line Brake.

Save the model as slexAutotransRootInportsExample1.slx or use the example slexAutotransRootInportsExample.slx.

The remaining steps of this example use the model slexAutotransRootInportsExample.slx. If you saved the model with a different name use your model name in the steps going forward.

Set Up Harness-Free Inputs

Now that the model is harness-free, set up the inputs that you already saved (See "Save Harness Data to MAT-Files").

From the Simulation->Model Configuration Parameters->Data Import/Export pane, click the Connect Input button.

Map Signals to Root Inport

The Root Inport Mapper tool opens.

This example uses this tool to set up the model inputs from the MAT-file and map those inputs to an input port, based on a mapping algorithm. To select the MAT-file that contains the input data, click the From MAT-File button on the Root Inport Mapper toolbar. When the link dialog appears, click the Open Folder button. In the browser, select the MAT-file that you saved earlier.

Select a Mapping Mode

Once you select the MAT-file slexAutotransRootInportPassingManeuver.mat that contains the input data, determine the root input port to which to send input data. Simulink matches input data with input ports based on one of five criteria:

  • Port Order - Maps in the order it appears in the file to the corresponding port number.

  • Block Name - Maps by variable name to the corresponding root inport with the matching block name.

  • Signal Name - Maps by variable name to the corresponding root inport with the matching signal name.

  • Block Path - Maps by the BlockPath parameter to the corresponding root inport with the matching block path.

  • Custom - Maps using a MATLAB function.

Earlier in this example, you used the slexAutotransRootInportsSaveActiveGroup to save input data to variables of the same name as the harness signals Throttle and Brake, and you added input ports with names matching the variables. Given the set of conditions for the input data and the model input ports, the best choice for a mapping criteria is Block Name. Using this criteria, Simulink tries try to match input data variable names to the names of the input ports. To select this option:

  1. Click the Block Name radio button.

  2. Click the Options button and select Compile from the dropdown. This will provide some verification on the mapping.

  3. Click the Map button.

When compiling the data, Simulink evaluates inports against the following criteria to determine whether or not there is a compatibility issue. The status of this compatibility is reflected by the table colors green, orange, or red. Clicking a cell in the table which has orange or red color will open the Comparison Tool for further inspection.

  • Data Type - Double, single, enum, ....

  • Complexity - Real or complex

  • Dimensions - Signal dimensions vs port dimensions

Finalize the Inputs to the Model

Review the results of the mapping compatibility. Click the Scenario Dataset 'ds' in the scenario dataset list. To apply the results of the Map action and load the data that was mapped to the input ports from the MAT-file to the base workspace click the Mark for Simulation button. This action also sets the Model Configuration Parameters->Data Import/Export->External Input edit box with the proper comma-separated list of inputs.

Simulating the Model

With the changes applied you can now simulate the model and view the results. Click the Play button on the model. To view the results of the simulation, double-click the Scope Block PlotResults.

Was this topic helpful?