Is it possible to change the wobj in a loop?
AZamfir
✭
in RobotStudio
I defined a few wobj as below:
and then I used them in a script as follows:
FOR a FROM 0 TO 90 STEP 5 DO
Is it possible to replace the six FOR above with a kind of two-level FOR 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
0
Best Answers
-
Not like that. Put the names of your workobjects into an array, then use \Wobj:=ArgName{a}; I think this will work, might need some playing around with to get it exactly right. Good luck!Lee Justice5
-
Looks like you will have to use a similar strategy for your robtargets, the robot will not like it the way you have written it.Lee Justice5
-
That is correct, wobjdata cannot be in an array. What I was suggesting is a string array with those workobject's names in it. Thus, the function ArgName to identify the workobject.Lee Justice5
-
OK, tried it out and debugged it myself in RS....PROC Routine2()FOR i FROM 1 TO 6 DO! Make a string array with the names of your workobjects
! myWobj needs to be declared variable
GetDataVal stWobjName{i},myWobj;
! Declare myWobj2 as PERSmyWobj2:=myWobj;MoveJ p201,v1000,z50,miniGun8_45mmFlame\WObj:=myWobj2;ENDFORENDPROCLee Justice5 -
Sorry about the ArgName misinformation, I further tried it with the addition of the robtargets, which I mentioned before will need to have a similar strategy.PROC Routine2()FOR i FROM 1 TO 6 DOGetDataVal stWobjName{i},myWobj;myWobj2:=myWobj;FOR j FROM 1 TO 10 DOGetDataVal stTargetName{j},myRobtarget;myRobtarget2:=myRobtarget;MoveJ myRobtarget2,v1000,z50,miniGun8_45mmFlame\WObj:=myWobj2;ENDFORENDFORENDPROCLee Justice5
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:
"LimitationsThe work object data should be defined as a persistent variable (PERS) and shouldnot be defined within a routine. The current values are then saved when the programis saved and are retrieved on loading.Arguments of the type work object data in any motion instruction should only bean entire persistent (not array element or record component)."
What do you think?0 -
Sorry, A little error I noticed: \Wobj:=ArgName(WorkobjectName{a});Lee Justice0
-
Dear "lemster68",
I have adapted the simple, short code you suggested and the problem is now solved!
Thank you very much!
0 -
You are welcome.Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 788 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings