FunctionBlocks BasicMove MC_ReturnToPrimaryFB - ThorstenBrach/SRCI GitHub Wiki

MC_ReturnToPrimaryFB

📝 Description:

Return to path left during active interrupt.

⚙️ 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

PriorityMode.NORMAL

Priority of the command

M

Enable

BOOL

FALSE

Enable / Disable the command at rising / falling edge

M

ParCmd

[ReturnToPrimaryParCmd]

FALSE

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

[ReturnToPrimaryOutCmd]

-

Command specific outputs

M

⚙️ FB Structures:

ReturnToPrimaryParCmd
Parameter Data Type Default Value Description Required

ReturnMode

ReturnMode

-

Defines target position when function is executed:
• 0: Interrupt position (default) – Returns to position active when interrupt was executed
• 1: End position – Returns to target position of interrupted segment

M

VelocityRate

REAL

-

TCP velocity in % of nominal velocity
• <0%: Use default velocity (default)
• 0%: Use internal minimal velocity
• 100%: Use maximal reference velocity

M

AccelerationRate

REAL

-

Acceleration in % of nominal acceleration
• <0%: Use default acceleration (default)
• 0%: Use internal minimal acceleration
• 100%: Use maximal reference acceleration

M

DecelerationRate

REAL

-

Deceleration in % of nominal deceleration
• <0%: Use default deceleration (default)
• 0%: Use internal minimal deceleration
• 100%: Use maximal reference deceleration

M

JerkRate

REAL

-

Jerk in % of nominal jerk
• <0%: Use default jerk (default)
• 0%: Use internal minimal jerk
• 100%: Use maximal reference jerk

M

ToolNo

USINT

-

Tool index
• 0: Flange (default)
• 1..254: Tool frames

M

FrameNo

USINT

-

Frame index
• 0: WCS (default)
• 1..254: User frames

M

DistanceLimit

REAL

-

Used if >0 (default).
Maximum allowed distance between current and target position per ReturnMode.
Error returned if exceeded

M

TrajectoryMode

TrajectoryMode

-

Defines type of movement command.
One of the optional modes must be supported

M

MoveTime

TIME

-

Used if >0 (default)
• Velocity input ignored
• Defines fixed time to reach target
Error returned if time cannot be held

M

AllowDifferences

BOOL

-

Set TRUE to deactivate comparison of:
• ToolData and FrameData
• ToolNo and PrimaryPosToolNo
• FrameNo and PrimaryPosFrameNo

M

ReturnToPrimaryOutCmd
Parameter Data Type Default Value Description Required

RemainingDistance

REAL

-

Distance-to-go of the current job
• -1: No valid value (command not active or not supported)
• >0: Actual distance to target position
• 0: Target position reached

M

Progress

REAL

-

Percentage of already traversed distance of current job
• -1: Not supported

M

PrimaryPosToolNo

USINT

-

Tool index of target position
• 0: Flange
• 1..254: Tool frames

M

PrimaryPosFrameNo

USINT

-

Frame index of target position
• 0: WCS
• 1..254: User frames

M

⏳ Timing Diagram:

Work in progress – more content coming soon.

📋 Examples:

Declaration
VAR_GLOBAL
  /// Robot assignment of function
  AxesGroup       : AxesGroup;
  /// Robot Task
  RobotTask       : MC_RobotTaskFB;
  /// Return to primary
  ReturnToPrimary : MC_ReturnToPrimaryFB;
END_VAR
Call
// call function block
ReturnToPrimary
(
  Name      := 'SRCI_Robot',
  ExecMode  := ExecutionMode.SEQUENCE_PRIMARY,
  Priority  := PriorityLevel.NORMAL,
  AxesGroup := AxesGroup
);
Usage
VAR_INPUT
  /// Start command execution
  Execute : BOOL;
  /// Command parameter
  ParCmd  : ReturnToPrimaryParCmd;
END_VAR

VAR_OUTPUT
  /// Error ID
  ErrorID     : DINT;
  /// Error addition text
  ErrorAddTxt : STRING;
  /// Command output
  OutCmd      : ReturnToPrimaryOutCmd;
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)
ReturnToPrimary.ParCmd := ParCmd;
// forwarding command outputs(s)
OutCmd := ReturnToPrimary.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 ReturnToPrimary.Busy  ) AND
         ( NOT ReturnToPrimary.Error ))
     THEN
       // start execution
       ReturnToPrimary.Enable := 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 (ReturnToPrimary.Error)
       THEN
         ErrorID     := ReturnToPrimary.ErrorID;
         ErrorAddTxt := CONCAT('_stepCmd = ' , DINT_TO_STRING(_stepCmd));
       END_IF
     END_IF

  2: // Wait Execution done ?
     IF (( NOT ReturnToPrimary.Busy ) AND
         (     ReturnToPrimary.Done ))
     THEN
       // stop execution
       ReturnToPrimary.Enable := 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 (ReturnToPrimary.Error)
       THEN
         ErrorID     := ReturnToPrimary.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** ⚠️