Main Content

Author a Test Sequence and Test Assessment

This example shows how to use a Test Sequence block and Test Assessment block to create a test harness for a transmission shift logic controller. The Test Sequence block varies the speed input to the controller and the Test Assessment block verifies that the speed is appropriate for the gear position. For more information, see Test Sequence Basics.

Create a Test Sequence

1. Open the model.

open_system('TransmissionDownshiftTestSequence')

Model_og.png

2. Right-click the shift_controller subsystem and select Test Harness > Create for ‘shift_controller’.

3. In the Create Test Harness dialog box, under Sources and Sinks:

  • Set the source drop-down menu to Test Sequence.

  • Select Add separate assessment block.

  • Select Open harness after creation.

For more information, see Create a Test Harness.

harness_dialog.png

4. Click OK. The test harness for the shift_controller subsystem opens.

testharness_flow.png

5. Double-click the Test Sequence block. The Test Sequence Editor opens.

testSequenceEditor.png

6. Change the name of the first step from Run to Accelerate, and add the step actions that specify the initial throttle setting and how the speed increases:

speed = 10*ramp(et);

throttle = 100;

The ramp function returns the value of a ramp signal of slope 1 at time et, which is the elapsed time of the step. For this example, the speed at a particular time after the beginning of the step is 10 times the value of the ramp at that time. See Test Sequence Editor for more information.

7. Right-click the Accelerate step and select Add step after. Change the name of this step from step_1 to Stop, and add the step actions that stop the test when the throttle and speed are equal to 0:

throttle = 0;

speed = 0;

8. In the Symbols pane, point to Constant and click the add data button addVariableData_16.png. Enter Limit for the constant name and click Add data.

9. Point to Limit and click the edit button editicon.png. In the Constant value field, enter 2. Click OK.

defineLimit.png

10. Right-click the Transition column in the first step, select Add transition. Enter the transition condition for the Accelerate step. In this example, Accelerate transitions to Stop when the system is in fourth gear for at least two seconds. In the Transition column, enter:

duration(gear == 4) >= Limit

11. In the Next Step column, select Stop.

testSequenceEditorFilled.png

12. Save the changes and close the Test Sequence Editor.

Create a Test Assessment

Next, add verifications to the Test Assessment block.

1. Double-click the Test Assessment block to open the editor. The editor displays a default When decomposition sequence in the Step column. For more information, see Assess a Model by Using When Decomposition.

TestAssessmentEditor.png

2. Change the name of the first step from Run to Assessments.

3. Right-click the Assessments step and select Add sub-step. Repeat this step to add another substep so there are a total of four substeps.

4. Change the names and add actions for the four substeps as shown in the image. The fourth step, else, handles simulation conditions outside of the preceding when conditions. In this step, you do not specify any actions.

TestAssessmentEditorFilled.png

5. Save the changes and close the Test Sequence Editor.

6. In the test harness, add a Scope block and connect the speed, throttle, and gear signals to the scope as shown in the image.

Harness_w_scp[e.png

7. Open the Scope block. In View > Layout, select a three-column, one-row layout.

8. In the Simulink model, in the Simulation tab, set Stop Time to 15 and click Run. View the signal data in the Scope block. The speed plot shows how the speed increases to a maximum value of 105. The throttle plot shows that the throttle value is held at 100 throughout the test. The gear plot shows that the gear shifts to the next-higher gear at the appropriate speed. After the gear has been equal to 4 for 2 seconds, the speed and throttle go to zero and the gear decreases.

scope.png

9. View the results of the verify statements in the Simulation Data Inspector.

  • In the Simulink model, in the Simulation tab, click Data Inspector.

  • Click the Visualizations and layouts button VisualizationAndLayoutIcon.png and, under Grid, set Rows to 3 and Columns to 1.

  • Select one plot, then select an assessment from the left pane. Repeat for each of the other plots and assessments.

DataInspector.png

When the model runs, the Test Assessment block verifies that the speed is in the correct range for each gear position. A pass indicates that the speed is in the correct range. Each verify statement is for a specific gear, so the speed is untested when the controller is in a different gear than the one being tested. There are two pass regions for the Check1st test assessment because the gear position goes back to first in the second step of the test sequence.

See Also

|

Related Topics