Triggers
Triggers can be used to perform actions such as switching on a tool when a defined position on the path is reached, or with a time shift before or after. For this purpose, CODESYS SoftMotion provides the capability of configuring triggers to movements and then continuously reading out the remaining time until the position is reached.
When using triggers, pay attention to the following:
The time until a trigger is reached can be retrieved only when the axis group has approached the trigger up to the time of a configurable forecast. How this forecast is configured and which impacts the settings have is explained in the Configuring the application to use triggers section.
The trajectory is not changed by the use of triggers. In particular, the trajectory is not slowed down in order to comply with the configured forecast. If, for example, the position of a trigger at the beginning of a movement is already reached after 0.01 seconds, then even a higher forecast cannot achieve that a notification is provided about reaching the point more than 0.01 seconds beforehand.
For more information, see the examples Trigger Example 1: Simple Example and Trigger Example 2: Gluing Process.
Configuring the application to use triggers
Configuration of the forecast duration
The forecast duration determines how far in the future the planning is done. This is set by the fPlanningForecastDuration
parameter of the SMC_TuneCPKernel
function block. How this parameter should be set depends on the requirements of the application. There are two principally contradictory requirements:
Longest possible forecast duration
Lowest possible latency. The latency when starting a movement increases because the forecast has to be established first. The size of this additional latency basically depends on the performance of the controller used and is generally much lower than the configured forecast. Moreover, the latency of the axis group to react to aborting movements and interrupts increases by the configured forecast. The forecast does not have any impact on
MC_GroupHalt
andMC_GroupStop
. Both function blocks always act immediately and independently of the configured forecast.
The fPlanningForecastDuration
parameter of the SMC_TuneCPKernel
function block should therefore be set as high as necessary but as low as possible. If a forecast is not required, then the parameter can be left at the default value of 0.
The actual available forecast can differ from the configured one for various reasons, for example, if the end of the last movement is already almost reached. The current available forecast can be monitored by means of the CurrentPlanningForecast
output of MC_GroupReadStatus
.
Configuration of the maximum number of triggers per movement
As delivered, CODESYS SoftMotion supports up to 8 triggers per movement. If this number is not enough, then the MAX_NUM_TRIGGERS_PER_MOVEMENT
parameter can be changed as a library parameter. This is possible with the Library Manager and the respective editor for the library parameters. For using library parameters, a CODESYS version >= SP19 is recommended.
Commanding and evaluating triggers
Two function blocks are available for commanding triggers: SMC_GroupPrepareTrigger and SMC_GroupReadTrigger.
Triggers are assigned to a movement. Each individual trigger has to be prepared using the SMC_GroupPrepareTrigger
function block. The position can be specified relative, absolute, or as an intersection with a plane (see SMC_TriggerPositionType). The call order of SMC_GroupPrepareTrigger
and the respective movement is of particular importance because the prepared triggers are assigned to the next movement commanded in the same cycle. Therefore, in every application you need to pay attention to the following:
SMC_GroupPrepareTrigger
always has to be called before the movement function block.Triggers and the respective movement always have to be commanded in the same cycle. If no movement is started in the cycle, then the prepared triggers are discarded and the
CommandAborted
output of theSMC_GroupPrepareTrigger
function blocks is set.
When the trigger is assigned to a movement, information about a trigger can be retrieved using SMC_GroupReadTrigger
. As soon as the trigger is within the available forecast duration, the status changes to SMC_TRIGGER_STATUS.Active
and the time until the trigger is reached can be read out. The time always refers to the start time of the current cycle. Depending on when the trigger should be triggered (before, during, or after the position is reached), the desired action can be executed in the application in a suitable cycle.
Triggers cannot be aborted when they have been assigned to a movement. Instead, they can simply be ignored.
If a movement is aborted by a second movement with MC_BUFFER_MODE.Aborting
, then the triggers assigned to the first movement also disappear.
Triggers for movements with blending
For movements with Buffering and Blending of Movements, the triggers are projected onto the blending path. The following image qualitatively shows a case in which a movement from P1 to P2 as well as a subsequent movement were each commanded with blending. Blending to the first movement ends at point B, and blending to the subsequent movement starts at point A. The blue trigger is located between P1 and B. It gets projected onto the back half of the first blending movement (highlighted by the blue line). In the same way, the red trigger, located between A and P2, is projected onto the front half of the second blending movement (highlighted by the red line). The green trigger is outside of the blending areas and is not shifted.

When blending with triggers, there is a special feature concerning the status of the movement and the respective triggers. The command function block for moving from P1 to P2 reports Done
as soon as point A is reached. However, the red trigger associated with this movement remains active until the position on the blending element to which it was projected is reached.