Main Content

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

This example shows how to convert a harness model that uses a Signal Editor block as an input to a harness-free model with root input ports. The example uses data from the MAT-file of Signal Editor block of the harness model for the harness-free model. The example removes the Signal Editor block from the harness model and adds root input ports to create a harness-free model. Then, the data in the MAT-files is mapped to the root input ports of the model.

Open the Example Model

For this example, open and modify the model sldemo_autotrans from Modeling an Automatic Transmission Controller.

Remove the Signal Editor Block

Replace the Signal Editor block named ManeuversGUI with two input ports.

  1. Delete the Signal Editor block named ManeuversGUI.

  2. From the Simulink/Commonly Used Blocks library, drag two Inport blocks into the model.

  3. Connect the input ports to the lines previously connected to the Signal Editor block.

  4. Rename the input 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 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 from the MAT-file previously used by the Signal Editor block.

In the Modeling tab, select Model Settings. In the Data Import/Export pane, click the Connect Inputs button.

Map Signals to Root Inport

The Root Inport Mapper tool opens.

The 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 Browse button. In the browser, select the MAT-file from the local working example folder. For this example, the file name is VehicleManeuvers.mat.

Select a Mapping Mode

When you select the MAT-file VehicleManeuvers.mat, 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 input port with the matching block name.

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

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

  • Custom - Maps using a MATLAB function.

The selected MAT-file has input data with variables of the same name as the harness signals Throttle and Brake, and 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 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 Update Model. This verifies the mapping.

  3. Click the Map button.

When compiling the data, Simulink evaluates input ports against the following criteria to determine compatibility issues. The status of this compatibility is reflected by the table colors green, orange, or red. Warnings and errors are flagged with diagnostic messages. If the Options > Update Model option is not selected, Root Inport Mapper determines the compatibility status by evaluating these block parameters and assigned signals:

  • 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 'Passing_Maneuver' in the scenario dataset list. To prepare for simulation, click Mark for Simulation. This action applies the mapping variables to the Configuration Parameter Data Import/Export > External Input text box. If this text box has content, it is overwritten.

Simulating the Model

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

Related Examples

More About