Tips on runtime optimisation
In large applications with multiple axes, it may be necessary to invoke function block instances time-optimised, i.e. the function block instances are only executed when they are required.
The following short code section in StructuredText illustrates the technique for reducing the runtime of an application. The function block “MC_MoveVelocity” is used as an example here.
The variable “MC_MoveVelocity_Active” controls the function block. It may assume the following values:
Value | Meaning |
0 | Function block is not executed. |
1 | Function block is executed; input “Execute”/”Enable” is TRUE. |
2 | Function block is executed until the requested acknowledgement is set (e.g. “Done”, “CommandAborted” etc.). “Execute“/”Enable“ is FALSE. |
At the beginning, “MC_MoveVelocity_Active” is set to 1 depending on the input “Execute”/”Enable”. The function block “MC_MoveVelocity” is executed in this setting. This state remains until the input is reset.
IF ( Execute_MoveVelocity = TRUE ) AND
( MC_MoveVelocity_Active = 0 ) THEN
MC_MoveVelocity_Active := 1;
END_IF;
Only when the input “Execute”/”Enable” is set to FALSE does the value of “MC_MoveVelocity_Active” change to 2. The function block is then executed until an acknowledgement is applied to the output (here: “Done”, “CommandAborted”, etc.). In case of error, which is not considered here, proceed in a similar manner.
IF MC_MoveVelocity_Active > 0 THEN
MC_MoveVelocity( Axis := AxisReference,
Execute := Execute_MoveVelocity,
Velocity := Velocity_MoveVelocity,
Acceleration := Acceleration_MoveVelocity,
Deceleration := Deceleration_MoveVelocity,
Jerk := Jerk_MoveVelocity,
Direction := Direction_MoveVelocity );
AxisReference := MC_MoveVelocity_0.Axis;
InVelocity_MoveVelocity := MC_MoveVelocity_0.InVelocity;
CommandAborted_MoveVelocity := MC_MoveVelocity_0.CommandAborted;
Error_MoveVelocity := MC_MoveVelocity_0.Error;
ErrorID_MoveVelocity := MC_MoveVelocity_0.ErrorID;
IF MC_MoveVelocity_Active = 2 AND
(InVelocity_MoveVelocity = TRUE OR
CommandAborted_MoveVelocity = TRUE ) THEN
MC_MoveVelocity_Active := 0;
ELSIF Execute_MoveVelocity = FALSE THEN
MC_MoveVelocity_Active := 2;
END_IF;
END_IF;