JAKA Script Manual
JAKA Script Manual(JKS) is a specific programming language used to control JAKA robot.
Users can program in accordance with grammar specified by JKS to control the robot.
Basis of JKS
Basic Grammars
Identifier
In JAKA Script Manual, identifiers are case-insensitive, and their naming shall follow the rules below:
- Only English letters, numbers and underlines can be used.
- The first character cannot be number.
- Key words cannot be used as identifiers.
- 255 characters can be used at most, and it is better not to be more than 30 characters.
Example:
_var1 = 1
var2 = 1
VAR3 = 1
_2KDDinKAEld74Zl8WzKP = 1
# illegal
4VAR = 1
if = 1
Reserved Keywords
The table below shows reserved words in JAKA Script Manual.
These reserved words cannot be used as constants or variable or any other identifier names.
and | exec | not |
---|---|---|
assert | finally | or |
break | for | pass |
class | from | |
continue | global | raise |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |
Script Comments
JAKA Script Manual applies single-line comments, rather than multi-line comments.
Single-line comments shall start with # and can be placed at the end of statement or expression.
Example:
# the first comment
str = "Hello, World!" # the second comment
Statement
JAKA Script Manual only supports single-line statement.
It neither supports a line of statement split into multiple lines nor multiple statements in a line.
Basic Type
JAKA Script Manual supports three basic types of data: scalar, string and array.
Based on array, users can use predefined system variables.
Scalar
JAKA Script does not distinguish Boolean type, integer, and float.
For Boolean type, false corresponds to 0 and true corresponds to 1.
Example:
var = 1
# or
var = 1.0
# or
var = (expr1 > expr2)
String
Users need to use English double quotation marks (“”) to wrap the string when defining it.
At present, escape characters used by JAKA Script Manual are shown in the following table and users shall pay attention when define string. Otherwise, parse errors will be caused.
Escape Character | Description |
---|---|
\\ | Backslash |
\’ | Single quote |
\” | Double quote |
\n | New line |
\t | Horizontal tab |
\r | Enter |
Example:
string = "this is a \"string\""
string = "This is a string \n"
Array
Array is a container that holds a set of data of the same type.
At present, JAKA only supports scalar type rather than string array or nested array.
Definition of array
- Grammatical form:
arr = [...] # define an array arr = [] # define an empty array
Negative index access to a single element
Assuming that the length of array variable is N, for access to single element, it supports the following forms: array[index]
Element index supports negative value, meaning that the index scope is [-N, N-1].
When index is a non-negative value, element access meets the following relation:
array[index] = array[-N+index]
When index value is beyond the scope, array access violation will be reported, and program execution will be terminated.
Example:
a = [1,2,3,4,5,6,7,8,9,0]
b = a[-10] # b = a[0]
b = a[-11] # array access violation
- Access to sub-array
Supports accessing subsequences within a specified range of an array at a specified interval and returning as an array.
Format is as: array[startIndx:endIndex:step]
If ‘step’ is 0, error will occur in the program and the execution will be terminated.
In other cases, even if startIndex
, endIndex
, or step
are logically incorrect (out of array bounds), no error will occur.
The program will return values within the valid range of the array that meets the conditions.
If none exist, an empty array is returned.
A special form of subarray access with step
set to 1 is provided by omitting the step
parameter: array[startIndex,endIndex]
Example:
a = [1,2,3,4,5,6,7,8,9,0]
b = a[0:5] #[1, 2, 3, 4, 5]
b = a[-5:10:1] #[6, 7, 8, 9, 0]
- Array and pose representation
In JAKA Script Manual, 6-element array is used to represent robot joint position or spatial pose. The length unit is mm and the angle unit is °.
Example:
endPosJ = [90,90,90,90,90,90] #joint space position array
endPosL = [663.5,8.159996,6.950005,90,0,0] #Cartesian spatial position array
System Variable
Variable defined in operation program will be released after the program is executed.
For a variable whose value wants to be kept for a long time, JAKA Script Manual provides system variable mechanism to do so.
System variable can be directly used in program and the value of the variable can be retained when the value in program is modified or closed.
System variable only supports scalar type, and 100 system variables can be used by users currently.
Their access modes are as: sysvar[id], id∈[5500, 5599]
Example:
sysvar[5500] = 100
a = sysvar[5500]
Note:
System variable does not support negative index and interval access for now.
Expression
Arithmetic Operators
Arithmetic operators are used for four arithmetic operations and are grouped based on operator precedence.
Precedence of (*, /, %, **) is higher than that of (+, -).
Operators with higher precedence combine more closely than operators with low precedence.
Operators in the following table meet left associativity, namely operation is carried out from the left to right when operator precedence is the same.
Operator | Function | Usage |
---|---|---|
* | Multiplication | expr * expr |
/ | Division | expr / expr |
% | Complementation | expr % expr |
** | Exponentiation | expr ** expr |
+ | Addition | expr + expr |
- | Subtraction | expr - expr |
Logic and Relation Operator
Relation operator is applicable to arithmetic type.
Logic operator is applicable to any type that can be converted into Boolean value.
Type of return value of logic operator and relation operator belongs to Boolean type.
Associativity | Operator | Function | Usage | Supported Input Data Type |
---|---|---|---|---|
Right | ! | Logic negation | !expr | Integer |
Left | && | Logic and | expr && expr | Integer |
Left | II | Logic or | expr II expr | Integer |
Left | < | Less than | expr < expr | Integer, string |
Left | > | More than | expr > expr | Integer, string |
Left | == | Equal to | expr == expr | Integer, string, array |
Left | != | Not equal to | expr != expr | Integer, string, array |
Left | <= | Less than or equal to | expr <= expr | Integer, string |
Left | >= | More than or equal to | expr >= expr | Integer, string |
Bitwise Operator
Bitwise operator is applicable to operation object in integer type and the operation object is taken as a collection of binary digits.
At present, it only supports operation of XOR.
Bitwise Operator (Left Associativity)
Operator | Function | Usage |
---|---|---|
^ | XOR | expr ^ expr |
Statement
Under normal conditions, statements are implemented in sequence, but it only applies to the simplest program.
Therefore, JAKA Script Manual provides a set of control flow statement to support more complex implementation control.
Simple Statement
In JAKA Script Manual, statement needs to be placed in a line separately and most statements do not need terminators.
Simple statement includes expression statement, function call statement, etc.
Conditional Statement
- if...end statement
The function of if
statement is: to judge whether a designated condition is true and decide whether another statement is implemented based on the judgement results.
If
statement includes two forms, one includes else
branch and the other does not.
Grammatical form is as follows:
if(condition):
statement
end
Example:
condition = get_digital_output(0,1)
if(condition):
endPosJ = [0,0,0,0,0,0]
movj(endPosJ,0,60,200,0)
end
- if...else...end statement
Grammatical form is as follows:
if(condition):
statement
else:
statement
end
Example:
condition = get_digital_output(0,1)
if(condition):
endPosJ = [0,0,0,0,0,0]
movj(endPosJ,0,60,200,0)
else:
endPosL = [663.5,8.159996,6.950,90,0,0]
movl(endPosL,0,250,250,0)
end
- if...elif...else...end statement
Grammatical form is as follows:
if(condition1):
statement
elif(condition2):
statement
else:
statement
end
Example:
condition = get_digital_output(0,1)
if(condition):
endPosJ1 = [0,0,0,0,0,0]
movj(endPosJ,0,60,200,0)
elif(condition):
endPosJ2 = [90,90,90,90,-90,0]
movj2(endPosJ,0,10,600,0)
else:
endPosL = [663.5,8.159996,6.950,90,0,0]
movl(endPosL,0,250,250,0)
end
Loop Statement
- while loop statement
If the condition is true, while
statement will repeatedly implement loop.
Grammatical form is as follows:
while(condition):
statement
end
In while
structure, if the evaluation result of condition is true, statement
will always be implemented (generally it is a statement block), and condition
cannot be empty.
If the first evaluation of condition
is false, statement
will not be implemented at all.
Example:
i = 0
while(i <= 4):
endPosJ1 =[0,90,90,90,-90,0]
movj(endPosJ1,0,10,600,0)
endPosJ2 =[90,90,90,90,-90,0]
movj(endPosJ2,0,10,600,0)
i = (i+1)
end
Jump Statement
Jump
statement can be used to interrupt the ongoing while
statement.
JAKA Script Manual provides two kinds of jump statements: break
statement and continue
statement.
Break
statement
Break
statement is responsible for terminating while
statement that is nearest to it and continues execution from the first statement after those statements.
The function of Break is only limited to the nearest while loop.
Example:statement
is statement block, and condition1
and condition2
are judgement conditions.
while(condition1):
statement
...
if(condition2):
break
end
...
statement
end
Continue
statement
Continue
statement terminates current iteration of the nearest loop and immediately starts the next iteration.
Continue
statement only occurs inside the while
loop.
Like break
, continue
only works on the nearest while
loop.
Continue
will interrupt current iteration but will continue executing current loop.
For while
statement, it means to continuously judge the value of condition.
Example:
statement
is statement block and condition1
and condition2
are judgement conditions.
while(condition1):
statement
...
if(condition2):
continue
end
...
statement
end
Thread
The latest controller software supports multi-threading function. Users can use specific non-motion-related instructions in non-main threads.
Create a Thread
User must define the execution body of the thread by means of a subprogram file, that is, the execution body of the thread is stored separately in the script file with the suffix of jks.
When creating a thread, the absolute path of the subprogram file of the thread execution body needs to be specified, and the thread will start automatically to execute after being created.
JAKA controller supports 5 sub-threads at most.
When a thread is created, the thread name needs to be written synchronously. The thread name is used for managing the sub-thread resources, such as thread destruction, synchronization, and pause.
Example:/path/to/thread/file.jks
is the absolute path of the script file corresponding to the sub-thread, and thread_name is a unique string that identifies the thread.
create_thread(“/path/to/thread/file. JKS ”, “thread_name”)
Operation on a Thread
JKS supports thread waiting (join) and thread destruction but does not support thread separation (detach).
All sub-threads will be terminated after the main thread ends, and the resources will be reclaimed.
Thread operation instructions can only be called in the main thread, and calling in sub-thread is invalid.
User should specify a valid thread name for thread operation instructions, and an invalid thread name will cause a run-time error.
Motion-related instructions and some parameter-setting instructions (such as: load setting, coordinate system setting) can only be used in the main thread, and these instructions in the sub-thread will be skipped and not be executed.
Example:
Join a thread:
thread_join(“thread_name”)
Destroy a thread:
thread_destroy(“thread_name”)
The sub-thread and the main thread can call the program pause instruction, after the execution, all threads in the program will enter the pause state; program recovery will resume all threads to continue running.
Thread Scheduling
All sub-threads created in the program maintain the same priority and are unchangeable.
In one control cycle, only one thread is allowed to have the right to call the underlying control interface, which needs to be implemented through competition between threads.
In the process of competition, other tasks of the thread will be blocked.
Conflicts of Thread
When multiple threads access shared data or resources (such as system variables, IO control, etc.) at the same time, there may be conflicts. JKS provide operation interfaces for entering and exiting critical areas to resolve resource conflicts.
When entering the critical section, all other threads will wait until the thread exits the critical section.
Since entering the critical region is equivalent to the exclusive running authority, to ensure that other threads can run normally, the instructions executed during entering and exiting the critical region are required to be as short as possible.
Example:
thread_enter_critical()
# do some stuff
thread_exit_critical()
Preset Script Function
Motion-related Commands
Basic Motion
movel
movl(var_pos, rel_flag, vel, acc, tol, end_cond, ori_vel, ori_acc, planner_type)
Use:
To control the robot to move in a straight line in Cartesian space.
Parameters:
var_pos | A six-element array variable that is used for designating Cartesian space target position and needs to be predefined. |
rel_flag | Designates this motion as relative motion or absolute motion. 0 indicates an absolute motion to user frame. At this time, set value of var_pos is explained as some absolute position of Cartesian space. 1 indicates a relative motion to user frame. At this time, the target position satisfies that: tas_pos.P = curr_pos.P + var_pos.P
2 indicates a relative motion to tool frame. At this time, the target position satisfies that: tar_pos.P = curr_pos.R * var_pos.P + curr_pos.P
|
vel | Represents motion speed (mm/s). |
acc | Represents linear acceleration (mm/s^2). |
tol | The tolerance for reaching the specified end point. If it is 0, the target point will be reached accurately. If it is a positive value, the position may be mixed with subsequent distance and the target point cannot be reached accurately. |
end_cond | Represents the stopping condition of commands in such segment, the optional parameter of which is an array composed of 3 parameters, including: di_type: Input type.
di_index: IO address. di_state: Represents state of 0/1 that meets the condition. |
ori_vel | Orientation speed. An optional parameter. Unit: deg/s^2. If this parameter is not entered, the robot will run at the fastest orientation speed. |
ori_acc | Orientation acceleration. An optional parameter. Unit: deg/s^2. If this parameter is not entered, the robot will run at the fastest orientation acceleration. |
planner_type | Trajectory speed planner type that can be chosen based on different applications. 0: Speed priority. 1: Smooth priority. |
Return Value:
None.
movej
movj(var_pos, rel_flag, vel, acc, tol, end_cond, planner_type)
Use:
Make the robot perform joint movement.
Parameters:
var_pos | Six-element array variable that is used for designating joint space target position and needs to be predefined. |
rel_flag | Designates this motion as relative motion or absolute motion. 0 represents absolute motion. At this time, set value of var_pos is explained as some absolute position of joint space. 1 represents relative motion. At this time, set value of var_pos is explained as increment of joint space position. |
vel | Command speed of each joint (deg/s). At the time of actual motion, it will be subject to the maximum actual speed of each joint. |
acc | Represents linear acceleration (deg/s^2). |
tol | The tolerance for reaching the specified end point. If it is 0, the target point will be reached accurately. If it is a positive value, the position may be mixed with subsequent distance and the target point cannot be reached accurately. |
end_cond | Represents the stopping condition of commands in such segment, the optional parameter of which is an array composed of 3 parameters, including: di_type: Input type.
di_index: IO address. di_state: Represents the state of 0/1 that meets the condition. |
planner_type | Trajectory speed planner type that can be chosen based on different applications. 0: Speed priority. 1: Smooth priority. |
Return Value: None.
movec
movc(var_pos_mid, var_pos_end, rel_flag, vel, acc, tol, turn_cnt, end_cond, movc_mode, planner_type)
Use:
Make the robot perform arc movement in Cartesian space.
Parameters:
var_pos_mid | Six-element array variable that is used for designating middle point of space arc and needs to be predefined. |
var_pos_end | Six-element array variable that is used for designating the final stop point of space arc and needs to be predefined. |
rel_flag | Designates this motion as relative motion or absolute motion. 0 represents absolute motion. At this time, set value of var_pos is explained as some absolute position of joint space. |
vel | The joint speed set in the command. Unit: deg/s. During the actual movement, it will be constrained by the actual maximum speed of each joint. |
acc | To designate acceleration of motion, with the unit of mm/s^2. |
tol | The tolerance for reaching the specified end point. If it is 0, the target point will be reached accurately. If it is a positive value, the position may be mixed with subsequent distance and the target point cannot be reached accurately. |
turn_cnt | Number of circles of circular motion (non-negative real number) designated by user and is an optional parameter. When the number of circles is 0, circular motion will be confirmed based on three points. When the number of circles is not 0, number of circles is designated in accordance with circular motion confirmed by three points and the orientation shall be maintained the same as the angle between orientation of initial point and rotating shaft. |
end_cond | Represents the stopping condition of commands in such segment, which is an optional parameter. But it is a necessary parameter in version 1.7.1_28 and above when controlling the intermediate orientation of an arc movement. It is an array composed of 3 parameters, including: di_type: Input type.
di_index: IO address. di_state: Represents the state of 0/1 that meets the condition. |
movc_mode | This parameter is used to specify the mode of robot’s orientation during arc movement. This parameter is optional, and it takes effect when turn_cnt is 0. 0: the minimal orientation change mode. The robot’s orientation will move toward the direction which requires the smallest angular change of the robot’s orientation around the axis defined by the start-end orientation. 1: the large orientation change mode. The robot’s orientation will move toward the direction which requires the large angular change (the opposite of the minimal orientation) of the robot’s orientation around the axis defined by the start-end orientation. 2: the intermediate point orientation adaptation mode. The robot will automatically choose the minimal or the large orientation based on its intermediate point. 3: the fixed orientation angle mode. The robot will move with the fixed angle between the tool orientation and the coordinate system formed by the Cartesian arc axis-radius. |
planner_type | Single move command trajectory speed planner type that can be chosen based on different applications. 0: Speed priority. 1: Smooth priority. |
Return Value:
None.
get_atl_joint_pose
atlJntPos = get_atl_joint_pose()
Use:
To obtain current actual joint position of robot.
Return Value:
Return to the current actual joint position.
get_atl_tcp_pose
atlTcpPos = get_atl_tcp_pose()
Use:
To obtain the current actual central point pose of end tool of robot.
Return Value:
Return to the current actual central point pose of end tool.
get_atl_flange_pose
atlFlangePos = get_atl_flange_pose()
Use:
To obtain current central point pose of end flange of robot.
Return Value:
Return to the current actual central point pose of end flange.
enable_speed_override
enable_speed_override(type, vel, acc)
Use:
To set speed and acceleration of function block.
Parameters:
type | 0 represents Cartesian space motion type. 1 represents joint space motion type. |
vel | Double type data represents the covering speed of setting. |
acc | Double type data represents the covering speed of setting. |
Return Value:
None.
disable_speed_override
disable_speed_override(type)
Use:
To cancel the setting of speed and acceleration of function block.
Parameters:
type | 0 represents Cartesian space motion type. 1 represents joint space motion type. |
Return Value:
None.
enable_planner_override()
enable_planner_override(type)
Use:
To set the global speed planner type.
Parameters:
type | Global speed planner type that can be chosen based on different applications. 0: Speed priority. 1: Smooth priority. When using global speed planner on commands, the speed parameter of single command won’t take effect. |
Return Value:
None.
disable_planner_override
disable_planner_override()
Use:
To cancel the global speed planner type.
Return Value:
None.
Tracking of Conveyor Belt
enable_conveyor_linear_track
enable_conveyor_linear_track(dir, mm_per_pulse, trigger, com_dis, max_dis)
Use:
To enable tracking of conveyor belt.
Parameters:
dir | Tracking direction, can be any of X+, Y+, Z+, X-, Y- and Z-. |
mm_per_pulse | To specify the pulse equivalent, which means correlating each pulse of the encoder feedback on the conveyor belt to the displacement in the direction of the conveyor belt (unit: mm). |
trigger | Optional parameter, referring to the distance between the robot movement’s starting point to the point where the tracking of conveyor begins. This is used to define the position of robot to start tracking the conveyor, with a range of 0~3000 mm. |
com_dis | To compensate for the error between the attained position and teaching position, with a range of ±100 mm. |
max_dis | Optional parameter, referring to the distance between the starting point and the ending point of the robot’s movement. |
Return Value:
None.
enable_conveyor_circular_track
enable_conveyor_circular_track(convey_P1, convey_P2, convey_P3, rad_per_pulse, rotate_tool, com_dis, max_dis)
Use:
To enable circular conveyor tracking.
Parameters:
convey_P1 convey_P2 convey_P3 | This parameter represents the position vector of the next point in the world coordinate system, for example: convey_P1 = [P1x, P1y, P1z] convey_P2 = [P2x, P2y, P2z] convey_P3 = [P3x, P3y, P3z] convey_P1, convey_P2, convey_P3 are the position coordinates of the three points on the conveyor belt in the world coordinate system, which are selected in turn in the rotation direction of the conveyor belt to obtain the transformation matrix of the center coordinate system {O} of the conveyor belt in the world coordinate system, which can be obtained by inputting or teaching. |
rad_per_pulse | This parameter is used to specify the pulse equivalent, which refers to the angle of rotation in the positive direction of the Oz axis (right-hand rule) corresponding to each feedback pulse of the encoder tracking the conveyor belt. Unit: °/cnt. |
rotate_tool | 0 means that the end attitude remains unchanged during the tracking process of the circular conveyor belt. 1 means that the end rotates around the axis of the conveyor belt, and the orientation changes (the App’s default is 1). |
com_dis | To compensate for the error between the attained position and teaching position, with a range of ±20°. |
max_dis | Optional parameter, referring to the distance between the starting point and the ending point of the robot’s movement. This parameter is used to limit the robot’s tracking distance, preventing the robot from exceeding the range of the conveyor or reaching singularities. The range is 1~360°. |
Return Value:
None.
disable_convayor_track
disable_convayor_track()
Use:
To disable tracking of conveyor belt.
Return Value:
None.
record_pulse_cond()
record_pulse_cond(type, index, state)
Use:
To get and store the position of material on the conveyor belt. One I/O must be configured to use with this command. This command can prevent the robot from missing out materials on the conveyor due to the conveyor’s moving speed is too fast.
This command must be used with “Dequeue for conveyor”. When using this command, the material positions on the conveyor are stored in the controller, and when the program runs the “Dequeue for conveyor” command, the stored material position is retrieved in the order they stored.
Parameters:
type | 0 means the standard IO (control cabinet). 1 means tool IO. 2 means extended IO. 3 means reserved. 4 means Modbus IO. 5 means PROFINET IO. 6 means Ethernet I/P IO. |
index | The number of the controlled digital output. Starts from 0. |
state | 1 means on. 0 means off. |
Return Value:
None.
get_pulse_cond()
get_pulse_cond()
Use:
To get the information on the queue of conveyor’s stored pulse.
Return Value:
None.
clear_pulse_cond()
clear_pulse_cond()
Use:
To clear the information on the queue of conveyor’s stored pulse.
Return Value:
None.
record_pos_cond()
record_cond(array)
Use:
To store the queue of pose array variables. This can be used with visual devices to store the pose information sent by the camera.
Parameters:
array | Position variable or program variable, an array of 1-12 elements. |
Return Value:
None.
get_pos_cond()
get_pos_cond()
Use:
To store the queue of pose array variables. This can be used with visual devices to store the pose information sent by the camera.
Return Value:
The array variable got from the pose queue.
clear_pos_cond()
clear_pos_cond()
Use:
To clear the queue of pose array variables.
Return Value:
None.
get_pulse_num()
get_pulse_num()
Use:
To get the number of stored pulses in the queue of the current conveyor.
Return Value:
The number of stored pulses.
get_pos_num()
get_pos_num()
Use:
To get the number of stored poses in the pose queue.
Return Value:
The number of stored poses.
Motion Compliance Control
set_compliance_ft_config
set_compliance_ft_config(id, admitctrlconfig, immed)
Use:
For constant force compliance control configuration.
admitctrlconfig
is the parameter array of configuration.
Parameters:
id | Represents the number of configuration shaft [0, 5] |
admitctrlconfig | = [opt, FTuser, FTreboundK, FTconstant, FTnormalTrack] opt: to enable constant force compliance in the specified direction (as indicated by the ‘id’ parameter). 1 means enabled. 0 means disabled. FTuser: the stiffness exhibited by the robot during constant force compliance control. The value should generally be set larger than 5 in the force direction and larger than 0.2 in the torque direction. FTreboundK: the elasticity of the robot movement. Refers to its tendency to rebound to its original position when being moved by external forces. This parameter needs to be set as non-negative value. 0 represents no rebounding. FTconstant: represents the target constant force. FTnormalTrack: the preset parameter and must be set as 0. |
immed | The preset parameter and must be set as 1. |
Return Value:
None.
set_compliance_velocity_level
velCompliantCtrl = [level, rate1, rate2, rate3, rate4]
set_compliance_velocity_level(velCompliantCtrl)
Use:
To set speed compliance control speed.
Parameters:
velCompliantCtrl | In the speed mode, when force at the robot end is greater than controller setting value, the robot will slow down in accordance with the set decelerated level until sensor detection value is less than set value of control force. Velocity compliance control speed is divided into three rates, and 1 > rate1 > rate2 > rate3 > rate4 > 0. When the level is 1, rate1 and rate2 can be set, rate3 and rate4 values are 0. When the level is 2, rate1, rate2 and rate 3 can be set, and rate4 value is 0. When the level is 3, rate1, rate2, rate3 and rate4 can be set. |
Return Value:
None.
set_compliance_condition
compliantCondition = [fx, fy, fz, tx, ty, tz]
set_compliance_condition(compliantCondition)
Use:
用于设置速度柔顺控制力。
Parameters:
compliantCondition | For setting stopping conditions of force and torque. When actual force of robot is greater than this condition, robot starts to slow down in accordance with the magnification set by set_compliance_velocity_level. Scope of fx,fy,fz,tx,ty and tz is more than 0. |
Return Value:
None.
disable_force_control
disable_force_control()
Use:
To disable force control.
Return Value:
None.
enable_force_control
enable_force_control(type, compensation)
Use:
To enable force control with compliance control type configuration and sensor compensation.
Parameters:
type | 0 represents no use of any kind of compliance control. 1 represents constant force compliance control. 2 represents speed compliance control. |
compensation | 1 represents opening of sensor compensation. 0 represents closing of sensor compensation. |
Return Value:
None.
set_end_force_condition
condition = [enableEndCond, lowFlag, lowLimitForce, upFlag, upLimitForce]
set_end_force_condition(axis, condition)
Use:
To set force control termination condition.
Setting of force control termination condition will not immediately take effect and will be deemed as non-non-immediate command by default.
This command only takes effect on the first motion command behind it.
When the command to terminate its execution is triggered, the motion command will be ended immediately, and the program will skip this motion command to execute the next one.
Parameters:
axis | Represents axis number, with a value scope of [0, 5] |
enableEndCond | Whether to enable. 1 represents taking effect. 0 represents the contrary condition. |
lowFlag | Represents effective flag bit of lower limit of motion termination force. 1 represents taking effect. 0 represents the contrary condition. |
lowLimitForce | The lower limit of motion termination force. |
upFlag | Represents effective flag bit of upper limit of motion termination force. 1 represents taking effect. 0 represents the contrary condition. |
upLimitForce | The upper limit of motion termination. |
Return Value:
None.
set_force_control_frame
set_force_control_frame(ftFrame)
Use:
To set force control coordinate system.
Parameters:
ftFrame | 0 represents tooling coordinate system. 1 represents world coordinate system. |
Return Value:
None.
get_sensor_torque
torq = get_sensor_torque(type)
Use:
To obtain torque value of torque base or torque sensor at the end.
The value is net torque value after compensating payload at the end of sensor.
Parameters:
type | 0 represents the end torque sensor. Other values are retained. |
Return Value:
The value of the six-axis torque sensor represented by an array of six-axis.
torque_sensor_enable
torque_sensor_enable(enable)
Use:
To enable the torque sensor.
Parameters:
enable | 0 means enabled. 1 means disabled. |
Return Value:
None.
set_force_sensor_zero
set_force_sensor_zero()
Use:
Zero-calibrate the force sensor.
Parameters:
None.
Return Value:
None.
Interface Setting and Inquiry
IO Control and Inquiry
set_digital_output
set_digital_output(type, index, tarState, immed)
Use:
To control digital output signal.
Parameters:
type | The type of digital output to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents the number of controlled digital output, begin with 0. |
tarState | The target state of the digital output via this instruction. 1 represents ON. 0 represents OFF. |
immed | The flag to indicate whether it will be executed immediately. 1 represents immediate command. 0 represents non-immediate command. If it is a non-immediate command, actual execution of the command will be executed before the next motion command. |
Note:
Immediate IO commands will interrupt the blend between different motion segments.
Non-immediate IO commands are only for the control of control cabinet's DO/AO.
Return Value:
None.
set_analog_output
set_analog_output(type, index, tarValue, immed)
Use:
To control analog output signal.
Parameters:
type | The type of analog output to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents the number of controlled digital output, begin with 0. |
tarValue | Represents Real type value and used to designate target value of analog output. |
immed | 1 represents immediate command. 0 represents non-immediate command. If it is a non-immediate command, actual execution of the command will be executed before the next motion command. |
Note:
Immediate IO commands will interrupt the blend between different motion segments.
Non-immediate IO commands are only for the control of control cabinet's DO/AO.
Return Value:
None.
get_digital_output
get_digital_output(type, index)
Use:
To obtain the state of designated digital output.
Parameters:
type | The type of digital output to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents digital output index. |
Return Value:
Inquiry result returned by function: 0 -> off, 1 -> on.
get_analog_output
get_analog_output(type, index)
Use:
To obtain the state of designated analog output.
Parameters:
type | The type of analog output to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents analog output index. |
Return Value:
The function returns to query results of double type.
get_digital_input
get_digital_input(type, index)
Use:
To obtain the state of designated digital input.
Parameters:
type | The type of digital input to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents digital input index. |
Return Value:
The function returns query results.
0 represents off.
1 represents on.
get_analog_input
get_analog_input(type, index)
Use:
To obtain the state of designated analog input.
Parameters:
type | The type of analog input to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Analog input index. |
Return Value:
Inquiry result of double type returned by function.
wait_input
wait_input(type, index, state, time)
Use:
To wait for the designated input to become the specified state.
If the maximum waiting time is exceeded, TIMEOUT
state mark shall be set and GETTIMEOUT
function can be used for inquiry.
Parameters:
type | The type of wait input to be controlled. 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for Profinet IO. 6 for EthterNet/IP IO. |
index | Represents input index. |
state | Represents expected input state. |
time | Represents the longest waiting time and 0 represents indefinite waiting (at most 10000000000 seconds) |
Return Value:
None.
get_timeout
get_timeout()
Use:
To obtain execution results of wait_input
command.
1 represent wait timeout.
0 represents that the signal is successfully waited for within specified time. Return Value:
None.
set_motion_digital_output
set_motion_digital_output(type, index, refpoint, distance, tarState)
Use:
To control the digital output during a robot movement.
Parameters:
type | 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for PROFINET IO. 6 for EthterNet/IP IO. |
index | The index of controlled digital output, starting from 0. |
refpoint | The reference point to trigger the signal. 0 means the starting point. 1 means the ending point. |
distance | Distance to trigger the signal. |
tarState | 1 means on. 0 means off. |
Note:
When setting an I/O command in a movement, there must be a move command to make this I/O command take effect.
At most 8 I/O commands can be set between 2 move commands.
Return Value:
None.
set_motion_analog_output
set_motion_analog_output(type, index, refpoint, distance, tarValue)
Use:
To control the analog output during a robot movement.
Parameters:
type | 0 for basic IO (control cabinet). 1 for TIO. 2 for extended IO. 3 is reserved. 4 for Modbus IO. 5 for PROFINET IO. 6 for EthterNet/IP IO. |
index | The index of controlled analog output, starting from 0. |
refpoint | The reference point to trigger the signal. 0 means the starting point. 1 means the ending point. |
distance | Distance to trigger the signal. |
tarValue | Real type of value. To set the target value of the specified analog output. |
Note:
When setting an I/O command in a movement, there must be a move command to make this I/O command take effect.
At most 8 I/O commands can be set between 2 move commands.
Return Value:
None.
TIO Control and Inquiry
tio_update_signal
tio_update_signal(strId, freq)
Use:
To refresh designated TIO Modbus RTU signal with a certain period.
Parameters:
strId | Identifier of signal. |
freq | When it is 0, refreshing will be conducted once. When it is other positive value, such value is taken as refresh frequency which will be automatically subject to CAN communication bottleneck internally. |
Return Value:
None.
tio_get_signal_value
res = tio_get_signal_value(strId)
Use:
To obtain value of designated signal.
Parameters:
strId | Identifier of signal. |
Return Value:
Return to the value of signal.
tio_send_command
tio_send_command(chnId, cmdBuf, crcType)
Use:
To send byte data to designate TIO RS485 channel.
Parameters:
chnId | Channel number. 0 represents RS485 CHN1. 1 represents RS485 CHN2. |
cmdBuf | Byte array of the command. |
crcType | Represents the type of sent data. It is effective only when designated channel is RS485 transparent transmission and 0 is written at the time of Modbus RTU. |
Return Value:
None.
Network Communication
socket_open
sockid = socket_open(ip, port)
Use:
To open designated IP and port number and store created SOCKET handle in variable and return.
Parameters:
ip | Represents TCP server address in string format, such as “192.168.1.10”. |
port | Represents TCP server port number. |
Return Value:
Return to the socket handle.
socket_close
socket_close(sockid)
Use:
To close designated socket.
Parameters:
sockid | Represents socket connection that needs to be closed. |
Return Value:
None.
socket_get_var
varname = socket_get_var(sockid, type, argname, timeout)
Use:
To request remote parameter configuration.
Parameters:
sockid | Represents socket ID and needs to be created in advance. |
type | Represents parameter type. 0 represents integer. 1 represents float number. 2 represents string. |
argname | Represents variable name of string type, showing the variable value to be obtained. The form can be |
timeout | Feedback waiting timeout. 0 means permanent waiting (65536 seconds at most). |
Return Value:
Represents storage variable of returned value.
The function will send string: get <arg_varname>
through socket. And the data form:<arg_varname><value>
is expected to be received.
There are 2s timeout and it will return 0 after timeout.
When an array is expected to be sent, sending form in host computer is as follows:
<arrName><{num1, num2, ..., numN}>
When a string is expected to be send, sending form of host computer is as follows:
<strName><“stringValue”>
socket_read_real
res = socket_read_real(sockid, num, timeout)
Use:
To obtain (a set of) array from the outside through formulated socket and store in array variable.
Parameters:
sockid | Represents socket ID and needs to be created in advance. |
num | The number of arrays expected to be received. |
timeout | Feedback waiting timeout. 0 means permanent waiting (65536 seconds at most). |
Return Value:
Represents received data results.
If it fails to receive, it will return scalar 0.
If succeeded, it will be stored in array.
There is 2s timeout, and if it fails to receive, it will return 0.
socket_read_string
res = socket_read_string(sockid, prefix, suffix, timeout)
Use:
To obtain a string from the outside through designated socket to be stored in variable.
The format of function being send is get#string#prefix#suffix#
, the format of data being received isprefixSTRINGsuffix
.
Parameters:
sockid | Represents socket ID and needs to be created in advance. |
prefix | Prefix requirements for string expected to be received. |
suffix | Suffix requirements for string expected to be received. |
timeout | Feedback waiting timeout. 0 means permanent waiting. |
Return Value:
Represents received data result.
There is 2s timeout. If it fails to receive, it will return empty string.
socket_send
res = socket_send(sockid, var)
Use:
To send a variable value in string format through specified socket.
Parameters:
sockid | Represents socket ID and needs to be created in advance. |
var | Represents variable expected to be sent and variable supports When |
Return Value:
res>
is the mark of sent result.
There is 2s sending timeout.
If it is successively sent, it will return 1, otherwise it will return 0.
Data is sent in the form of:
<varName><varValue>
<intVar><12>
<strVar><“string”>
<listVar><{ele1, ele2, ele3, ...}>
socket_recv
res = socket_recv(sockid, timeout)
Use:
To receive data from designated socket and user can set timeout.
Note:
The command is purely used to receive data and will not send request to another link end.
Parameters:
sockid | Represents socket ID and needs to be created in advance. |
timeout | Represents receiving timeout setting. |
Return Value:
If data are not received out of time, it will return empty string.
If data are normally received, function will return received string.
If data are not received overtime, function will return empty string.
For network fault, function will return -1.
Parameters Setting and Inquiry
set_payload
set_payload(m, centriod)
Use:
To set current robot payload.
Parameters:
m | Payload mass (unit: kg). |
centroid | Mass center of payload, including array composed of three components (unit: mm). |
Note:
The command will move in sync and interrupt Blend.
Return Value:
None.
get_payload
payload = get_payload()
Use:
To obtain current robot payload.
Return Value:
Return to the total payload of the robot end flange.
Payload [0] is payload mass (unit: kg).
Payload [1]-[3] is the centroid of payload (unit: mm).
set_collision_level
set_collision_level(clsnLevel)
Use:
This command is not supported by default.
If the executed JKS command includes this command, error will occur when the main thread parses such command. And the main thread would jump this command and continue to execute the following command.
If the child-thread parses this command, it will directly skip this one and continue to run the following command (the child-thread would not handle motion command and modify motion parameter command).
get_collision_level
res = get_collision_level()
Use:
To obtain current collision detection sensitivity.
Return Value:
Return to current collision sensitivity.
set_tool
set_tool(var_tool)
Use:
To set position offset of tool end relative to end flange.
Vertical end face of flange coordinate system is the positive direction of z axis if it faces externally, and tool IO connection port is the negative direction of y axis.
Parameters:
var_tool | It is offset of tool end relative to flange coordinate system. It’s an array of six elements. |
Return Value:
None.
set_tool_id
set_tool_id(id)
Use:
To set tool coordinate system id.
Parameters:
id | The value is taken as [0, 15]. 16 tools are supported at most in control system and tool offset value currently used is designated through setting ID. When ID is 0, it means the default tool coordinate system is the same as the flange coordinate system. |
Return Value:
None.
get_tool_offsets
res = get_tool_offsets()
Use:
The function is used to obtain current tool coordinate system offset value.
Return Value:
Return to the array of six elements.
get_tool_offsets_of
res = get_tool_offsets_of(id)
Use:
To obtain offset value of designated tool coordinate system.
Parameters:
id | Represents designated tool coordinate system, and its value is taken as [1, 15]. |
Return Value:
Return to the array of six elements.
set_user_frame
set_user_frame(user_frame)
Use:
To set user coordinate system.
When set, tool ID will be -1 and will not be saved after being set in program.
Parameters:
user_frame | User tool coordinate system, an array of six elements. |
Return Value:
None.
set_user_frame_id
set_user_frame_id(id)
Use:
To set user coordinate system id.
Parameters:
id | The value is taken as [0, 15]. 16 tools are supported at most in control system and tool offset value currently used is designated through setting ID. When the id is 0, it means that no use of the user coordinate system. |
Return Value:
None.
get_user_frame
res = get_user_frame()
Use:
To obtain offset value of current user coordinate system.
Return Value:
Return to the array of six elements.
get_user_frame_of
res = get_user_frame_of(id)
Use:
To obtain offset value of designated user coordinate system.
Parameters:
id | Represents designated user coordinate system and the value is taken as [1, 15]. |
Return Value:
Return to the array of six elements.
Auxiliary Function Library
Mathematical Calculation
Function | Description |
---|---|
res = atan2(arg_y, arg_x) | Arc-tangent function, which will return the arc-tangent of value y/x, in degree. |
res = abs(arg) | Find the absolute value of expression. |
res = acos(arg) | Arc-cosine function, in degree. |
res = asin(arg) | Arc-sine function, in degree. |
res = cos(arg) | Cosine function. |
res = sin(arg) | Sine function. |
res = tan(arg) | Tangent function. |
res = floor(arg) | Round down to an integer. |
res = ceil(arg) | Round up to an integer. |
res = round(arg) | Round off. |
res = sqrt(arg) | Take the square root. |
res = rad2deg(arg) | Radians to degrees. |
res = deg2rad(arg) | Degrees to radians. |
Pose Calculation
pose_add
res = pose_add(pos1, pos2)
Use:
To calculate simple accumulation between two poses and return calculation result.
The result pose is calculated as:
res.P = pos1.P + pos2.P
The orientation is calculated as:
res.R = pos2.R * pos1.R
Note:
R represents rotation matrix.
Return Value:
Return to calculation result.
pose_sub
res = pose_sub(pos1, pos2)
Use:
To calculate simple subtraction between two poses and return calculation results.
The result pose is calculated as:
res.P = pos1.P - pos2.P
The orientation is calculated as:
res.R = inv(pos2.R) * pos1.R
Note:
R represents rotation matrix.
Return Value:
Return to calculation result.
pose_dist
res = pose_dist(pos1, pos2)
Use:
To calculate distance between two poses.
Position coordinate is only considered.
Return Value:
Return to calculation result.
pose_inv
res = pose_inv(pos)
Use:
To calculate inverse transformation of some position.
Return Value:
Return to calculation result in the form of pose.
pose_trans
res = pose_trans(p_from, p_from_to)
Use:
To calculate position transformation.
The formula is as follows:
p_res = p_from * p_from_to
Return Value:
Return to position result.
pose_intpl
res = pose_intpl(pos1, pos2, alpha)
Use:
To calculate interpolation point between two points in accordance with given coefficient:
p_res = pos1 + (pos2 - pos1) * alpha,
where alpha >= 0 and alpha <= 1, this includes orientation and employs the same method of linear interpolation.
Return Value:
Return to the position variable of interpolation point.
xy_plane_trans
res = xy_plane_trans(posebase, dx, dy, drz)
Use:
To transform rigid body in XY plane and rotate by drz degrees around Z axis at posebase.
Then it will move horizontally along X axis for dx and along Y axis for dy.
Return Value:
Return to pose after transformation.
yz_plane_trans
res = yz_plane_trans(posebase, dy, dz, drx)
Use:
To transform rigid body in YZ plane and rotate by drx degrees around X axis at posebase.
Then it will move horizontally along Y axis for dy and along Z axis for dz.
Return Value:
Return to pose after transformation.
zx_plane_trans
res = zx_plane_trans(posebase, dz, dx, dry)
Use:
To transform rigid body in ZX plane and rotate by dry degrees around Y axis at posebase.
Then it will move horizontally along Z axis for dz and along X axis for dx.
Return Value:
Return to pose after transformation.
kine_inverse
res = kine_inverse(posJ, posP)
Use:
To calculate inverse kinematics solution.
It’s to calculate joint space position corresponding to Cartesian space position posP.
PosJ is a set of joint value near the inverse solution joint value, that is used to confirm selection of multiple solutions of inverse function.
Return Value:
Returns to calculation result of inverse kinematics.
When inverse solution fails, program error reporting will be terminated.
kine_forward
res = kine_forward(posJ)
Use:
Enables users to calculate forward kinematics solution.
To calculate Cartesian space position where the input joint degree is located.
Return Value:
Return to positive calculation result of kinematics.
is_pose_reachable
res = is_pose_reachable(posP)
Use:
It judges whether it can move to posP through the Cartesian space motion command under the current pose.
Return Value:
Returns to 1 (the condition is true) if it is possible, otherwise it returns 0 (the condition is false).
String Operation
sprintf
resLen = sprint(bufferOut, stringFormat, …)
Use:
To output data in the format of string.
Parameters:
bufferOut | Data that has already been outputted in the form of string. |
stringFormat | fDefine the string format, currently only supporting variables in the forms of %f、%s、%d. |
… | Variables to be formatted. Supports integer, float, and string variables, as well as constants. |
Return Value:
strLen: return to the length of the string if succeeds. Return to -1 if not.
sscanf
resNum = sscanf(bufferIn, stringFormat, …)
Use:
To input data in the format of string.
Parameters:
bufferIn | Data that is about to be inputted in the form of string. |
stringFormat | Define the string format, currently only supporting variables in the forms of %f、%s、%d. %f: one float number. %d: one decimal integer, with an option of ‘+’ or ‘-’ sign in the front. %s: one string, reading consecutive characters until a whitespace character (space, newline, tab, etc.) or the next matching character in the format string (other than %s, %f, %d). |
… | Variables to be formatted. Supports integer, float, and string variables, as well as constants. |
Return Value:
resNum: return to the number of matched variables if succeeds. Return to -1 if not.
string_concat
strRes = string_concat(str1, str2)
Use:
To concatenate two strings and return to the concatenated string.
Parameters:
str1 | Substring, variable or constant to be concatenated. |
str2 | Substring, variable or constant to be concatenated. |
Return Value:
Return to the concatenated result of string.
get_string_from_array
resLen = get_string_from_array(arrayIn, splittingToken, stringOut)
Use:
To convert strings that meet a certain format into array variables.
Parameters:
arrayIn | Array designated by the user. |
splittingToken | String format delimiter. |
stringOut | String that has been converted successfully. |
Return Value:
resLen: return to the length of the string (excluding delimiter) if succeeds. Return to -1 if not.
get_array_from_string
resNum = get_array_from_string(stringIn, splittingToken, arrayOut)
Use:
To convert specified strings into array variables.
Parameters:
stringIn | String designated by the user (including data in the array). |
splittingToken | String format delimiter. |
arrayOut | Array that has been converted successfully. |
Return Value:
resNum: return to the number of the array if succeeds. Return to -1 if not.
get_length
len = get_length(str_or_arr)
Use:
To obtain length of string or array.
If parameter data type does not match, errors will be reported.
Return Value:
Return to the length of string or array.
Example:
len = get_length(int_val)
If the parameter int_val is an integer variable, the result of the instruction execution will be len = -1.
strcmp
res = strcmp(str1, str2)
Use:
To compare two strings.
Return Value:
If str1=str2
, it will return to zero;
If str1<str2
, it will return to a negative number;
If str1>str2
, it will return to a positive number.
Program Control and Debug
log_message
log_message(level, message)
Use:
Enables users to add log information by themselves.
Parameters:
level | log message type, the specific definitions are as follows: INFO: 1 WARNING: 2 ERROR: 3 |
message | log message text, not supporting Unicode type. |
Return Value:
None.
get_system_clock
clock = get_system_clock()
Use:
Enables users to obtain real-time clock of the system.
Return Value:
Returned value is the number of floats in double type and unit is ms (millisecond), accurate to ns.
CLOCK_MONOTONIC is used in bottom layer, representing the elapsed time since the system was last started.
sleep
sleep(time)
Use:
To delay the execution of the program for a while.
Parameters:
time | To delay the execution time, and the unit is s. |
Note:
The command will interrupt mixing of different motion segments.
Return Value:
None.
pause
pause()
Use:
To control the pause of an operating program. When call such command during the execution of a program, all sub-thread shall be paused.
Return Value:
None.
exit
exit()
Use:
To control termination of the operation of a program.
Return Value:
None.
Thread Instructions
create_thread
create_thread(thread_file_path, thread_name)
Use:
To create a sub-thread and start the thread to run. Parameters:
thread_file_path | The absolute path where the thread program file is saved. It must be saved under |
thread_name | Unique string for thread identification, does not support Unicode. Duplicate thread name will result in failure of thread creation. |
Return Value:
None.
thread_join
thread_join(thread_name)
Use:
To synchronize the operation of the specified thread, and this function only takes effect in the main thread.
Parameters:
thread_name | Unique string for thread identification, does not support Unicode. Duplicate thread name will result in failure of thread creation. |
Return Value:
None.
thread_destroy
thread_destroy(thread_name)
Use:
To destroy the operation of the specified thread, and this function only takes effect in the main thread.
Parameters:
thread_name | Unique string for thread identification, does not support Unicode. Duplicate thread name will result in failure of thread creation. |
Return Value:
None.
thread_enter_critical
thread_enter_critical()
Use:
For current thread to enter the critical section operation.
Return Value:
None.
thread_exit_critical
thread_exit_critical()
Use:
For current thread to exit the critical section operation.
Return Value:
None.