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.6K RobotStudio
 - 401 UpFeed
 - 21 Tutorials
 - 15 RobotApps
 - 306 PowerPacs
 - 407 RobotStudio S4
 - 1.8K Developer Tools
 - 250 ScreenMaker
 - 2.9K Robot Controller
 - 363 IRC5
 - 81 OmniCore
 - 8 RCS (Realistic Controller Simulation)
 - 853 RAPID Programming
 - 31 AppStudio
 - 4 RobotStudio AR Viewer
 - 19 Wizard Easy Programming
 - 110 Collaborative Robots
 - 5 Job listings