Control Requirement Execution by Using Temporal Logic
You can control the evaluation and execution of requirements in Requirements Table blocks in Simulink® models by using temporal logic. Because the Duration column and temporal operators rely on simulation time or data values at different time steps, you can use them to execute temporal logic.
Using the Duration Column
The Duration column specifies how long a requirement precondition must be valid before the block checks the postconditions or executes actions. If the duration is not met, the block does not check the requirement postconditions or execute the requirement actions. You must specify a precondition to use the Duration column.
You can view or hide the Duration column by right-clicking the column and selecting Toggle Column > Toggle Duration Column. You can also view or hide the column in the Table tab, in the Columns section, by clicking Show Columns > Duration. The column appears in the Requirements tab only.
To use the Duration column, define a requirement and enter the amount of time that the precondition must be true for the precondition to be satisfied. You must specify the duration in seconds and the duration must evaluate to a positive scalar.
Example Using Duration Column
The example uses a Requirements Table block to check that an input signal satisfies temporally dependent requirements. The block uses the Duration column to specify how long a requirement must be valid before executing outputs.
Open the Requirements Table block. The block uses three requirements to check the input data u
and to specify the output data y
:
If
u
is greater than or equal to0
for more than 2 seconds, the block setsy
to1
.If
u
is less than0
for more than 2 seconds, the block setsy
to-1
.If neither requirement is met, the block sets
y
to0
.
Run the simulation to view the output in the Scope block.
For an additional example, see Define Formal Requirements with a Duration.
Use Temporal Logic Operators
You can also add temporal logic to a Requirements Table block by using operators. These operators can appear in preconditions, postconditions, or actions in either the Requirements or Actions tabs.
Operator | Syntax | Description |
---|---|---|
duration | duration(C) | Returns the length of time in seconds that has elapsed since the
conditional expression C became
true . |
isStartup |
| Returns true if the simulation time equals
0 and returns false at the
other simulation times. |
getPrevious |
| Returns the value of the data at the previous time step. |
t | t | Returns the simulation time in seconds. |
Considerations When Using Temporal Logic Operators
If you use a Requirements Table block containing
isStartup
in an Enabled Subsystem (Simulink) block, the
isStartup
operator returns true
at the
time step you reenable the Enabled Subsystem block. However, the
t
operator captures the time value used in the top model,
and therefore does not reset in the same circumstances.
Example Using Temporal Logic Operators
This example shows a Requirements Table block that uses temporal logic operators to check an input signal. The Requirements Table block checks the value of the input signal and the simulation time to execute different values for the two outputs.
Open the Requirements Table block. The block uses the four top-level requirements and the two child requirements of the third requirement to check the value of the input data u
:
If the simulation has just started, the block sets the output data
y1
to0
. Otherwise, the block setsy1
to the value ofu
at the previous time step.If
u
is greater than or equal to0
, the block checks if the condition is true for more than 1 second. If the condition is satisfied for more than 1 second, the block setsy2
to1
. Otherwise, the block setsy2
to0
.If
u
is less than0
, the block setsy2
equal to the simulation time divided by10
.
Run the simulation to view the outputs in the Scope block.