Array position offset
in RobotStudio
I need to offset the y coordinate 0,.2,-.4,0,.2,-4..... So on the first pass I have no offset, second pass needs an offset .2in and on the third pass -.4in lastly on the fourth pass I need 0 offset so on and so forth. I want to learn how to use an array in this manner. Any ideas???
0
Best Answers
-
Hi RichPorras,
You can try the following:MODULE Module1! Current pass. Starting value = 1PERS num pass:=1;! Offset arrayCONST num Y_OFFSETS{3}:=[0,0.2,-0.4];! Target to modifyPERS robtarget myRobtarget:=[[100,200,300],[1,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];PROC main()VAR num offset;WHILE TRUE DO! Get offset from array based on current passoffset:=Y_OFFSETS{3};IF ((pass MOD Dim(Y_OFFSETS,1)) > 0) offset:=Y_OFFSETS{pass MOD (Dim(Y_OFFSETS,1))};! Apply offset to targetmyRobtarget.trans.y:=myRobtarget.trans.y+offset;! Next passIncr pass;ENDWHILEENDPROCENDMODULE5 -
If you can, try to avoid changing your reference target by getting a new offset target from the reference target. And Rapid arrays use one-based indexing so you have to adjust for it when calculating the array index when using MOD to cycle around the array.
MODULE Sandbox ! Current pass. Starting value = 1 VAR num pass:=1; ! Offset array CONST num Y_OFFSETS{3}:=[0,0.2,-0.4]; ! Reference target. A constant to avoid modifying it due to rounding errors or programming errors, etc. CONST robtarget reference_robtarget:=[[100,200,300],[1,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; ! Offset target VAR robtarget offset_robtarget; PROC SandboxMain() VAR num y_offsets_index; VAR num y_offsets_length; y_offsets_length:=dim(Y_OFFSETS,1); WHILE TRUE DO ! Calculate the array index. (One-based indexing, so subtract 1 from pass, then add 1 after MOD.) y_offsets_index:=((pass-1) MOD y_offsets_length)+1; ! Calculate the offset from the reference offset_robtarget:=offs(reference_robtarget,0,Y_OFFSETS{y_offsets_index},0); ! Next pass Incr pass; ENDWHILE ENDPROC ENDMODULE<br>
6
Answers
-
Thank you very much!0
Categories
- All Categories
- 5.5K RobotStudio
- 395 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)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings