Main Content

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 to 0 for more than 2 seconds, the block sets y to 1.

  • If u is less than 0 for more than 2 seconds, the block sets y to -1.

  • If neither requirement is met, the block sets y to 0.

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.

OperatorSyntaxDescription
durationduration(C)Returns the length of time in seconds that has elapsed since the conditional expression C became true.
isStartup

isStartup

isStartup()

Returns true if the simulation time equals 0 and returns false at the other simulation times.
getPrevious

prev(data_name)

getPrevious(data_name)

Returns the value of the data at the previous time step.
ttReturns the simulation time in seconds.

Considerations When Using Temporal Logic Operators

If getPrevious attempts to return the value of the data at a time step when it was not defined, it returns an undefined value. For example, data is not defined before the simulation time is 0.

Use the isStartup operator in the preconditions to define additional requirements at a simulation time of 0, and ~isStartup at the other time steps. Avoid using prev in preconditions unless ~isStartup is used in the parent requirement. See Add Child Rows and Check Previous Data Values.

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 to 0. Otherwise, the block sets y1 to the value of u at the previous time step.

  • If u is greater than or equal to 0, 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 sets y2 to 1. Otherwise, the block sets y2 to 0.

  • If u is less than 0, the block sets y2 equal to the simulation time divided by 10.

Run the simulation to view the outputs in the Scope block.

See Also

Related Topics