This example shows how to use Simulink to interact with SystemTest. The Simulink model characterizes an inverted pendulum's motion given an initial step movement to perturb the equilibrium. The test varies the mass of the pendulum, the mass of the cart the pendulum is on, and the distance to the pendulum's center of mass. The test also determines the pendulum's ability to return to equilibrium. This example shows how to:
Override a Simulink block's parameters.
Override Workspace variables used by a Simulink model.
Map Simulink data from To Workspace blocks to Test Variables.
Map Simulink data from outports to Test Variables.
Map Simulink data from logged signals to Test Variables.
Use a Limit Check Element in a test.
Use General Plot with vector plotting in a test.
Varying Simulink Parameters in the Test
A Simulink element is used to execute the following model for every main test iteration:
In order to vary the parameters of interest, two methods have been illustrated in this test.
The pendulum mass (
masspend) and the distance to the center of mass of the pendulum (
penddistance) are base workspace variables used by the model. In the Simulink element, Model Overrides are created for these workspace variables such that the Test Vector,
pend, will override
masspend, and the Test Vector,
distance, will override
The second method for varying a parameter of the Simulink model is by directly specifying the Block Parameter. In the model, select the 'Pendulum' block, then in SystemTest, create a model override for the "Selected Block's Parameter". Now select the 'Mass of the cart' as the Simulink Data to be overridden, and assign the Test Vector
cart as the overriding value.
Mapping Simulink Data to Test Variables
As each main test iteration is executed, the Simulink data needs to be mapped to Test Variables. Three different methods for this mapping are illustrated in this example.
Data from the model can be mapped from Logged signals, from the model Outports directly, or from To Workspace blocks.
Testing for Equilibrium
A MATLAB element is added to parse time and signal data from the model for use by the General Plot and the Limit Check elements. The General Plot shows the behavior of the pendulum position for each set of inputs. When the position diverges, the pendulum was unable to return to equilibrium.
Another way to test for equilibrium is by using the Limit Check element. By comparing the final value to a threshold, the stability of the pendulum can be determined.
Opening the Test
systemtest function to open the test.