I am trying to run a function routine and cant figure out how to call it in the main routine. I know if you want to call a normal routine you just write routinename; and then it will jump into that routine. I wrote a func routine instead of a Proc routine and i can call it in the main routine. Does anyone know how to call it out in a main routine?
ABB function Routine
-
rissley1216 -
May 4, 2017 at 9:48 AM -
Thread is marked as Resolved.
-
-
A function must return a value, so you have to assign the value of the function to something, like this:
MyVar:=MyFunc();Don't forget to include () when calling a function even if you don't have parameters.
-
Are you trying to pass parameters to a function, or act on the results?
This function takes a parameter, but always returns TRUE.
A quick/dirty example I haven't tried.
-
this is what i have I'm just trying to figure out function routines so this is not going in my robot. I have the function routine figured out on how to write it but when i run the program I cant get it to run the func routine.
so if I'm running main and want to jump to rRoutine1 i just put it in there and it runs it but if I put in my function routine target_distance; it wont jump to it. How would I call it out in my main routine to run it and get my ndistance so I have that num data.PROC rmain()
MoveL pHome,v500,z10,tool0;
MoveL plocation1,v500,z10,tool0;
rRoutine1;
target_distance; HERE IS WHERE IM HAVING A PROBLEM CANT GET IT TO RUN THIS ROUTINE
ENDPROCPROC rRoutine1()
MoveL pHome,v500,z10,tool0;
MoveL plocation1,v500,z10,tool0;
ENDPROCFUNC num target_distance(robtarget pHome,robtarget plocation1)
VAR num X_diff;
VAR num y_diff;
VAR num z_diff;
VAR num ndistance;
X_diff:=pHome.trans.x-plocation1.trans.x;
y_diff:=pHome.trans.y-plocation1.trans.y;
z_diff:=pHome.trans.z-plocation1.trans.z;
ndistance:=sqrt((x_diff*x_diff)+(y_diff*y_diff)+(z_diff*z_diff));
RETURN ndistance;
ENDFUNC -
Ok I Reread the post and tried them again and think I got it so if i can call a num data in my routine and make the data equal to the func routine it should run the routine and put the answer in the num data. will try this and see how it works.
PROC rRoutine1()
VAR num Myvar;
Myvar:= rtarget_distance();
movel pHome,v500,z10,tool0;
movel plocation1,v500,z10,tool0;
movel pPncPart,v500,z10,tool0;
movel pOnPart,v500,z10,tool0;
ENDPROC
FUNC num rtarget_distance()
VAR num X_diff;
VAR num y_diff;
VAR num z_diff;
VAR num ndistance;
X_diff:=pHome.trans.x-plocation1.trans.x;
y_diff:=pHome.trans.y-plocation1.trans.y;
z_diff:=pHome.trans.z-plocation1.trans.z;
ndistance:=sqrt((x_diff*x_diff)+(y_diff*y_diff)+(z_diff*z_diff));
RETURN ndistance;
ENDFUNC -
Looks like it should work. A permutation:
Code
Display MorePROC rRoutine1() VAR num Myvar; Myvar:= rtarget_distance(plocation1); movel pHome,v500,z10,tool0; movel plocation1,v500,z10,tool0; movel pPncPart,v500,z10,tool0; movel pOnPart,v500,z10,tool0; ENDPROC FUNC num rtarget_distance(robtarget p1) VAR num X_diff; VAR num y_diff; VAR num z_diff; VAR num ndistance; X_diff:=pHome.trans.x-p1.trans.x; y_diff:=pHome.trans.y-p1.trans.y; z_diff:=pHome.trans.z-p1.trans.z; ndistance:=sqrt((x_diff*x_diff)+(y_diff*y_diff)+(z_diff*z_diff)); RETURN ndistance; ENDFUNC
This one should calculate the distance from pHome to whatever point you pass in as a parameter.
Another permutation would add another parameter (p2) to calculate the distance between any two points...
although there is already a built-in function that does that (Distance).