In ABB robot Many built-in functions are used in programming, such as clkRead, NumToStr, Crobt, etc. You can also create user-defined functions according to your own needs.
The following describes how to create a user-defined function:
The function must be terminated by the return instruction. The data type returned by return must be consistent with the data type of the function.
Functions must be called through expressions, such as assignment instructions, which cannot be completed through ProcCall. When calling a Function with parameters, the mandatory parameters must be specified and the order of the parameters must be correct; Optional parameters can be defaulted.
Example (user-defined function: please distance between two points):
FUNC Num n_Distance(robtarget pStart,robtarget pEnd)
VAR num Dx;
VAR num Dy;
VAR num Dz;
VAR num Dtemp;
Dx:=pStart.trans.x-pEnd.trans.x;
Dy:=pStart.trans.y-pEnd.trans.y;
Dz:=pStart.trans.z-pEnd.trans.z;
Dtemp:=Pow(Dx,2)+Pow(Dy,2)+Pow(Dz,2);
RETURN Sqrt(Dtemp);
ENDFUNC
Note: Pow (used to calculate the index value in any base); Sqrt (used to calculate the square root value)
Application example:
PROC main()
MoveJ p100, v100, fine, MyTool;
MoveJ p110, v100, fine, MyTool;
v_Distance := n_Distance(p100,p110);
TPWrite "v_distance="\Num:=v_Distance;
Stop;
ENDPROC
The teaching pendant displays as follows:
The distance between points p100 and p110 is 629.75mm
Please check the video number for specific steps to create a custom function.