Skip to main content

15.4.11 Logic commands

15.4.11.1 Return

Explanation

Function return.
When the program encounters a RETURN command, if the program is currently in a subroutine, the program will return to the previous function. If the program is currently in the main function, the program ends directly.

15.4.11.2 Wait

Explanation

The program waits for a period of time ranging from 0 to 2147484 seconds.

Example

Example 1

Wait (2);

It indicates waiting for 2s.

15.4.11.3 WaitUntil

Explanation

It is used to wait for a certain condition to be established; the timeout sign is set to true if it is exceeded, and after the waiting, the program proceeds to the next execution.

Definition

WaitUntil(cond, \MaxTime, \TimeFlag)

Cond, bool type logic expression

MaxTime, timeout and optional parameter, in seconds, with int or double type

TimeFlag, timeout flag, set to true if timeout occurs with optional parameter, using the bool type variable

Example

Example 1

WaitUntil (di2 == true);

It means waiting until the di2 signal value is true before executing the following statements.

Example 2

WaitUntil (di2 == true, 5);

It means waiting until the di2 signal value is true. If the waiting time is over 5s and the di2 signal is still false, the following statement is executed.

Example 3

Bool flag = false;
WaitUntil (di2 == true, 5, flag);

It means waiting until the di2 signal value is true. If the waiting time is over 5s and the di2 signal is still false, the flag is set to true, and the following statement is executed. If the di2 turns to true within 5s, the flag is set to false. The flag can be used for subsequent logic judgment.

15.4.11.4 Break

Explanation

It is used to jump out of the current loop, and is used in the WHILE loop in the RL language. When the WHILE loop is executed to Break, regardless of WHILE’s CONDITION, it will jump out from the WHILE loop directly.

Example

Example 1

VAR int counter = 0;
WHILE(1)
    IF(counter == 5)
        break;
    Endif
    counter{plus}{plus};
ENDWHILE

The program will jump out of the WHILE loop when the counter is 5.

15.4.11.5 IF…Else if…Else

Explanation

Conditional judgment command

Example

Example 1

IF(condition1)
  // a
Else if (condition2)
  // b
Else if (condition3)
  // c
Else
  // d
Endif

Execute logic a when condition1 is true, logic b when condition2 is true, and so on.

15.4.11.6 Goto

Explanation

The Goto command allows the pointer to jump to the marked command

Example

Example 1

int a = 0;
int b = 9;
Goto end;
print(a);
end:;
print(b);

Define two variables a and b, then use the print function to print two statements. Use the Goto statement to force a jump to the end marker position of the print b statement, at which point the print of a will not be executed.

15.4.11.7 For

Explanation

It is used to define a loop control structure that executes a specified number of times.

Example

Example 1

For(int i from 1 to 10)
    Print(“i = %d+n”, i);
endfor

This program prints i 9 times from 1 to 10 by adding 1 each time in sequence.

Example 2

For(int i from 1 to 10 step 3)
    Print(“i = %d+n”, i);
Endfor

This program prints i 3 times from 1 to 10 by adding 3 each time in sequence.

Supplementary explanation:

Continue and Break can be used to control the For flow. See the Continue and Break commands for details.

15.4.11.8 Continue

Explanation

Exit this loop. Continue executing the commands from the beginning of the loop, but just end the loop without exiting from the loop body.

Example

Example 1

VAR int count = 0
WHILE(1)
    count{plus}{plus}
    IF(count == 1)
        Continue
    Else
        Break;
    MoveAbsJ(j10, v500, fine, tool1);
    Endif
ENDWHILE

The code for MoveAbsJ will not be executed.

15.4.11.9 Inzone

Explanation

It is used with SetDO or modbus, cclink, and other IO operations or commands; this command can ensure that the signal is triggered at a defined point position, instead of being triggered earlier by the lookahead pointer.

Example

MoveL p1
MoveL p2
Inzone
    SetDO(dox, true);
    print(123);
EndInzone
MoveL p3;

Supplementary explanation:

In the example, an Inzone command is used. After the interpreter looks ahead to Inzone, instead of executing this command immediately, it generates an additional function which includes SetDo and print commands. This additional function takes effect when the motion command move p2 is completed.

1. If there is a turning zone between the two motion commands p2 and p3, the additional function will be executed at the moment when the robot reaches the turning zone

2. If there is no turning zone, the additional function will be executed at the moment the robot reaches p2

15.4.11.10 While

Explanation

While loop allows you to write a loop control structure that keeps executing before conditions are met.

Example

Example 1

int count = 0;
while(count < 10)
    count{plus}{plus};
    print(count);
endwhile

This program enables a loop that counts by 1 from 0 to 10 and prints.

Supplementary explanation: Continue and Break can be used to control the While flow. See the Continue and Break commands for details.

15.4.11.11 Pause

Explanation

It is used to pause the program.

The program enters the pause state after the previous statement of the pause statement is executed. The program must be resumed by clicking on the teach pendant or running the signal through an external program.

Attention

This command does not support auxiliary programming for the moment

15.4.11.12 try/catch

Explanation

The try-catch command is an error handling mechanism in RL language. If an error occurs between the try and the catch commands, the program will convert the execution error into an error message set "e" and continue running from the catch-end try code block

Definition

try

/ / do something

catch(error e)

print(e);

endtry

For example, reading data from a network link is a command that is likely to fail, but at this point, the user does not want the robot to stop. Instead, the user can use try-catch to capture errors and process them through RL programming

Description

error type description: error is a structure consisting of four parameters, namely

  • file: string (error occurred in file name)

  • line: int (error line)

  • num: int (error code)

  • reason: string (error reason)

The error structure can be printed directly through the print command.

/ / error data

…​ catch(error e) print(e.line); print(e.num); print(e.reason); print(e); endtry

Example

Example 1

ReadOnce:;
Try
    Double xyz = ReadDouble(3, timeout, socketname);
    Robtarget_0.trans.x = xyz[1];
    Robtarget_0.trans.y = xyz[2];
    Robtarget_0.trans.z = xyz[3];
    MoveL (Robtarget_0, v2000, fine, tool0);
Catch(error e)
    SendString(“Recv rob xyz error”, socketname);
    Goto ReadOnce;
endtry

This program supports a simple application scenario. The communication command ReadDouble is used to read a three-dimensional array from the TcpSocket as the xyz parameter of the motion point position, and then the MoveL command is called to move to the corresponding Cartesian point.

If the try/catch command is not used and the point position received from the TcpSocket is wrong, the robot will report "out of range" or "planning error" and stop the program.

If the try/catch command is used, the motion command error is still reported, but the program does not stop. Instead, it jumps to the code segment between catch and endtry and handles the error as desired by the user. In this example, SendString tells Socket the point position error received by the host, and the host decides how to handle the error and calls the goto command to re-execute ReadDouble and wait for the next position.

Example 2

re_read:;
try
    opendev("conn_name");
    string_res = readstring("conn_name");
catch (error e)
    if (e.num == xxx)
        / / Non-stop for an error that can be processed
        goto re_read;
    else
        print(e);
        Pause;
    endif
endtry

Attention

Note: Force control commands cannot trigger try-catch

The error types and standard error codes that try/catch can process:

Classification

Error command

Explanation

error.num

error.reason

Default error

Commands without dedicated error codes

-1

Unknown error

Serial port related command

When the serial port does not exist

-1

Unknown error

Motion related command

MoveXX, Search, TrigL, etc.

AccRamp, HomeSet, and other motion parameter settings

Tool and work object errors in motion coordinates

Motion speed error

Motion load error

Beyond the motion range

Planning error

Encounter singularity, etc.

-1

Unknown error

Network command

OpenDev

Network link port error

-1

Unknown error

All network commands

RL-operated connection for external communication

-1

Unknown error

Calculation and logic commands

CalcJoinT

CalcRobt

CRobT

CJointT

CLKSTOP

GOTO

Internal error of controller

-1

Unknown error

Peripheral control

(Jodell series)

(RM series)

JodellGripInit

JodellSuckInit

JodellSuckStatus

RMRGMGripPosMove

RMRGMGripTrqMove

RMRGMGripStatus

RMRGMResetErr

RMCGripPosMove

RMCGripTrqMove

RMCGripStatus

RMCResetErr

RMRGMGripInit

RMCGripInit

Peripheral communication abnormal

-1

Unknown error

Laser control

All laser commands

Laser welding OFF

-1

Unknown error

Stacking control

TrayUpdate

TrayCount

PalletUpdate

PalletLayerCount

PalletWobjCount

SolarVisionExec

Data sending and receiving error with the host computer

-1

Unknown error

Register control

ReadRegByteByName

Data reading failed

-1

Unknown error

Axis 4 locking

SingAreaLockAxis4

Pose error, unable to activate the Axis 4 locking function

-1

Unknown error

Internal error of interpreter

Parameter type and quantity errors of most commands

-1

XXX parameter error

Internal error of interpreter

0

a

Network command

Serial port command

OpenDev

Connect to server failed

101

OpenDevConn failed

OpenDev

Robot failed to start as server

102

OpenDevServer failed

GetSocketConn

SocketConn not established

103

GetSocketConn failed, connection absent

GetSocketConn

Obtaining the name of SocketConn structure is a server

104

GetSocketConn failed, the object is SocketServer

GetSocketServer

GetSocketServer failed, server absent

105

GetSocketServer failed, server absent

OpenDev

Error in connection enabled input parameter, there is no connection matched in the variable list

106

OpenDev failed, non-existent object is used

SocketAccept

Input parameter is not a server name

107

SocketAccept (server) requires a server name

GetSocketConn

Error in obtaining the name of SocketConn structure

108

GetSocketConn(conn), non-existent SocketConn

GetSocketServer

Error in obtaining the name of SocketConn structure

109

GetSocketConn (server), non-existent SocketServer

ReadBit

Command input parameter error

110

ReadBit must read integer multiples of 8

ReadDouble

Command input parameter error

111

ReadDouble exceeds the preset range (0, 4096]

ReadInt

Command input parameter error

112

ReadInt exceeds the preset range (0, 96]

ReadByte

Command input parameter error

113

ReadByte exceeds the preset range (0, 4096]

ReadBit ReadDouble

ReadInt ReadByte ReadString

Input time is too long

114

ReadXX time exceeds the preset range (0, 86400]

ReadBit

ReadDouble

ReadInt

ReadByte

ReadString

Connection disconnected or data read error

115

Read failed

ReadDouble

Beyond the limit time

116

ReadDouble timeout

ReadInt

Beyond the limit time

117

ReadInt timeout

ReadString

Beyond the limit time

118

ReadString timeout

ReadBit

Beyond the limit time

119

ReadBit timeout

ReadByte

Beyond the limit time

120

ReadByte timeout

SendString

Command timeout or connection disconnected

121

SendString timeout or connection disconnected

SendByte

Command timeout or connection disconnected

122

SendByte timeout or connection disconnected

Conveyor belt tracking

WaitObj

When executing the command, work object is out of the start window and cannot be tracked

123

Out StartWindow

WaitObj

Waiting for tracking work object timeout

124

Out WaitTime

WaitObj

Repeated tracking of work object

125

Connected Twice

Possible occurrence after tracking enabled

Tracking process exceeds the working area and throws an exception

126

Out MaxDistance

15.4.11.13 SwitchCase

Explanation

SwitchCase, like the IF command, controls the flow control based on the input variable conditions.

RL interpreter will compare the variables in the Case field in order based on the input variable (condition).

If the two variables are equal, the interpreter will enter the code branch of the corresponding Case and stop comparing and entering other code branches.

If all conditions are not met, it will enter the Default branch;

If no Case condition matches and there is no Default branch, it will enter no branch and the Switch command ends;

Multiple conditions can be input for the Case command (see command structure Case C1, C12, C13 and example 1).

Definition

Switch(condition)

Case C1, C12, C13:

Functions1()

Case C2:

Functions2()

Default:

DefaultFunction();

EndSwitch

Example

Example 1

reg_int is a register variable, the host (PLC) will update the value of the variable through relevant register protocols (e.g. modbus, cclink). The production project expects the robot to execute the corresponding function branch (e.g. a blocked trajectory) according to the value of the register. If the register inputs 1, 2, and 3, then function A will be executed; if the register inputs 4, 5, and 6, then function B is executed. If the above conditions are not met, function C will be executed in the Default branch.

Switch(reg_int)
Case 1, 2, 3:
    FunctionsA();// The robot follows point positions related to function A
Case 4, 5, 6:
    FunctionsB();// The robot follows point positions related to function B
Default:
    FunctionC();// Execute function C if without specified input
EndSwitch