FunctionBlocks Trigger MC_WaitForTriggerFB - ThorstenBrach/SRCI GitHub Wiki

MC_WaitForTriggerFB

📝 Description:

Wait to process next command in sequence until trigger signal is received.

⚙️ FB Variables:

VAR_INPUT
Parameter Data Type Default Value Description Required

InternalLogger

IMessageLogger

-

For internal usage only

-

ExternalLogger

IMessageLogger

-

For internal usage only

-

LogLevel

LogLevelEnum

-

For internal usage only

-

Name

STRING(20)

-

User defined command name

O

ExecMode

ExecutionMode

ExecutionMode.SEQUENCE_PRIMARY

Execution mode of the command

M

Priority

PriorityLevel

PriorityLevel.NORMAL

Priority of the command

M

ProcessingMode

ProcessingMode

-

ProcessingMode

M

SequenceFlag

SequenceFlag

-

Defines the target sequence in which the command will be executed

M

Execute

BOOL

-

Start of the command at the rising edge

M

ParCmd

[WaitForTriggerParCmd]

-

Command specific parameter

M

VAR_IN_OUT
Parameter Data Type Default Value Description Required

AxesGroup

AxesGroup

-

Robot group assigned to the function

M

VAR_OUTPUT
Parameter Data Type Default Value Description Required

CommandData

RobotLibraryCommandDataFB

-

For internal usage only

-

ResponseData

RobotLibraryResponseDataFB

-

For internal usage only

-

Error

BOOL

-

Error occurred during execution. See ErrorID for details

M

ErrorID

WORD

-

Error ID as raw value for error diagnosis

M

ErrorIDEnum

RobotLibraryErrorIdEnum

-

Error ID as enumeration for error diagnosis

M

ErrorAddTxt

STRING(MAX_ADD_TEXT_LENGTH)

-

Additional error text information

M

WarningID

WORD

-

Warning ID as raw value for identifying warnings

M

WarningIDEnum

RobotLibraryWarningIdEnum

-

Warning ID as enumeration for identifying warning

M

InfoID

WORD

-

Info ID for as raw value for identifying additional information

M

InfoIDEnum

RobotLibraryInfoIdEnum

-

Info ID for as enumeration for identifying additional information

M

Done

BOOL

-

Command executed successfully

M

Busy

BOOL

-

Function block is being processed

M

CommmandBuffered

BOOL

-

Command was transferred to the robot-controller and confirmed

M

OutCmd

[WaitForTriggerOutCmd]

-

Command specific outputs

M

⚙️ FB Structures:

WaitForTriggerParCmd
Parameter Data Type Default Value Description Required

ListenerID

SINT

ID of the associated trigger function.
• 0: Immediately (default) → Start executing this function immediately
• >0: Trigger → Start executing when the trigger function with the identical EmitterID is triggered
Always positive.

ConditionalWait

BOOL

-

Defines the time at which the trigger can be reacted to.
• 0: Conditional → Trigger signal accepted as soon as the function is BUFFERED
• 1: Absolute → Trigger signal accepted as soon as the function is ACTIVE

WaitForTriggerOutCmd
Parameter Data Type Default Value Description Required

OriginID

INT

-

Unique system-generated ID of the "Action" when the function is triggered.
• >0: The "Action" is started by the trigger function with identical FollowID.
• <0: The "Action" is stopped by the trigger function with identical FollowID.

InvocationCounter

USINT

-

Applies to ListenerID >0. Number of successful trigger-based command invocations.

⏳ Timing Diagram:

Work in progress – more content coming soon.

📋 Examples:

Declaration
VAR_GLOBAL
  /// Robot assignment of function
  AxesGroup      : AxesGroup;
  /// Robot Task
  RobotTask      : MC_RobotTaskFB;
  /// Wait for trigger
  WaitForTrigger : MC_WaitForTriggerFB;
END_VAR
Call
// call function block
WaitForTrigger
(
  Name           := 'SRCI_Robot',
  ExecMode       := ExecutionMode.SEQUENCE_PRIMARY,
  ProcessingMode := ProcessingMode.TRIGGER_BUFFERED,
  SequenceFlag   := SequenceFlag.PRIMARY_SEQUENCE,
  Priority       := PriorityLevel.NORMAL,
  AxesGroup      := AxesGroup
);
Usage
VAR_INPUT
  /// Start command execution
  Execute : BOOL;
  /// Command parameter
  ParCmd  : WaitForTriggerParCmd;
END_VAR

VAR_OUTPUT
  /// Error ID
  ErrorID     : DINT;
  /// Error addition text
  ErrorAddTxt : STRING;
  /// Command outputs
  OutCmd      : WaitForTriggerOutCmd;
END_VAR

VAR
  /// internal step counter
 _stepCmd    : DINT;
  /// internal timer for command
 _timerCmd   : TON;
  /// internal timeout for command
 _timeoutCmd : TIME := T#5S;
END_VAR
// forwarding command parameter(s)
WaitForTrigger.ParCmd := ParCmd;
// forwarding command output(s)
OutCmd := WaitForTrigger.OutCmd;

CASE _stepCmd OF

  0: // start execution ?
     IF ( Execute )
     THEN
       // Reset request
       Execute := FALSE;
       // set timeout
       SetTimeout(PT := _timeoutCmd, rTimer := _timerCmd);
       // inc step counter
      _stepCmd := _stepCmd + 1;
     END_IF

  1: // Start Execution
     IF (( NOT WaitForTrigger.Busy  ) AND
         ( NOT WaitForTrigger.Error ))
     THEN
       // start execution
       WaitForTrigger.Execute := TRUE;
       // set timeout
       SetTimeout(PT := _timeoutCmd, rTimer := _timerCmd);
       // inc step counter
      _stepCmd := _stepCmd + 1;
     ELSE
       // timeout exceeded ?
       IF (CheckTimeout(_timerCmd) = RobotLibraryConstants.OK)
       THEN
         ErrorID     := RobotLibraryErrorIdEnum.ERR_TIMEOUT_CMD;
         ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
       END_IF

       // Error occurred ?
       IF (WaitForTrigger.Error)
       THEN
         ErrorID     := WaitForTrigger.ErrorID;
         ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
       END_IF
     END_IF

  2: // Wait Execution done ?
     IF (( NOT WaitForTrigger.Busy ) AND
         (     WaitForTrigger.Done ))
     THEN
       // stop execution
       WaitForTrigger.Execute := FALSE;
       // set timeout
       SetTimeout(PT := _timeoutCmd, rTimer := _timerCmd);
       // set step counter
      _stepCmd := 0;
     ELSE
       // timeout exceeded ?
       IF (CheckTimeout(_timerCmd) = RobotLibraryConstants.OK)
       THEN
         ErrorID     := RobotLibraryErrorIdEnum.ERR_TIMEOUT_CMD;
         ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
       END_IF

       // Error occurred ?
       IF (WaitForTrigger.Error)
       THEN
         ErrorID     := WaitForTrigger.ErrorID;
         ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
       END_IF
     END_IF

ELSE
  // invalid step
  ErrorID     := RobotLibraryErrorIdEnum.ERR_INVALID_STEP;
  ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
END_CASE

💡 Additional Information:

Work in progress – more content coming soon.

⚠️ **GitHub.com Fallback** ⚠️