RobotStudio event

Is it possible to change the wobj in a loop?

I defined a few wobj as below:
PERS wobjdata wobj_0  :=[ FALSE, TRUE, "", [ [0, -1570, 550], [1, 0, 0 ,0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];
PERS wobjdata wobj_5  :=[ FALSE, TRUE, "", [ [0, -1570, 550], [0.99905, 0.03082, -0.03082, 0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];
PERS wobjdata wobj_10 :=[ FALSE, TRUE, "", [ [0, -1570, 550], [0.99619, 0.06163, -0.06163, 0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];
PERS wobjdata wobj_15 :=[ FALSE, TRUE, "", [ [0, -1570, 550], [0.99144, 0.09230, -0.09230, 0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];
PERS wobjdata wobj_20 :=[ FALSE, TRUE, "", [ [0, -1570, 550], [0.98481, 0.12279, -0.12279, 0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];
PERS wobjdata wobj_25 :=[ FALSE, TRUE, "", [ [0, -1570, 550], [0.97630, 0.15305, -0.15305, 0] ], [ [0, 0, 0], [1, 0, 0 ,0] ] ];

and then I used them in a script as follows:
   FOR a FROM 0 TO 90 STEP 5 DO
   X     := R*sin(45-a);
   Y     := R*cos(45-a);
   Z     := 0;
   q1    := 0.5*sqrt(1-sin(45-a));
   q2    := 0.5*sqrt(1+sin(45-a));
   q3    := 0.5*sqrt(1-sin(45-a));
   q4    := -0.5*sqrt(1+sin(45-a));
   nenorm := [q1, q2, q3, q4];
   p{a+1} := [[X,Y,Z],nenorm,[-1,0,0,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
   ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_0;
ENDFOR
FOR a FROM 90 TO 0 STEP -5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_5;
ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_10;
ENDFOR
FOR a FROM 90 TO 0 STEP -5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_15;
ENDFOR

FOR a FROM 0 TO 90 STEP 5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_20;
ENDFOR
FOR a FROM 90 TO 0 STEP -5 DO
MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_25;
ENDFOR

Is it possible to replace the six FOR above with a kind of two-level FOR as below?

FOR n FROM 0 TO 20 STEP 10 DO
     FOR a FROM 0 TO 90 STEP 5 DO
     MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_n;
     ENDFOR
     FOR a FROM 90 TO 0 STEP -5 DO
     MoveJ p{a+1}, v400, fine, tool0 \WObj:=wobj_n+5;
     ENDFOR
ENDFOR

Best Answers

Answers

  • Thank you very much!

    I have inserted, before "PROC main()", the following statement:
    PERS wobjdata wobjtest{45};
    The immediate effect was an Error message:
    Description: Persistent name wobjtest ambiguous.
    Actions: Program data must have names that are unique within the module. Rename the data or change the conflicting name.

    In fact I am not sure I can define an Array of wobjdata. In the "RAPID Instructions Functions and Data types", chapter 3.76 (wobjdata - Work object data) I found the following:
    "Limitations
    The work object data should be defined as a persistent variable (PERS) and should
    not be defined within a routine. The current values are then saved when the program
    is saved and are retrieved on loading.
    Arguments of the type work object data in any motion instruction should only be
    an entire persistent (not array element or record component)."

    What do you think?
  • lemster68
    lemster68 ✭✭✭
    Sorry, A little error I noticed:  \Wobj:=ArgName(WorkobjectName{a});
    Lee Justice
  • Dear "lemster68",

    I have adapted the simple, short code you suggested and the problem is now solved!

    Thank you very much!
  • lemster68
    lemster68 ✭✭✭
    You are welcome.  :)
    Lee Justice