RAPID Syntax Error

innebandy
innebandy Korea, South ✭✭
edited February 25 in RAPID Programming
Hello,
I'd like to use a FOR loop to reduce the number of instructions. However, a syntax error occurs when I coded a routine as below. Can anyone help implement it? 
THX.

  PERS jointtarget jpos0:=[[8.64979E-6,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos1:=[[8.64979E-6,9.76204E-6,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos2:=[[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos3:=[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos4:=[[-180,-87.5354,-27.4211,-180,85.0435,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos5:=[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos6:=[[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
  PERS jointtarget jpos7:=[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];

PROC rTruncate()
  FOR i FROM 0 TO 7 DO
    jpos{i}.robax.rax_1:=Trunc(jpos{i}.robax.rax_1\dec:=2);
    jpos{i}.robax.rax_2:=Trunc(jpos{i}.robax.rax_2\dec:=2);
    jpos{i}.robax.rax_3:=Trunc(jpos{i}.robax.rax_3\dec:=2);
    jpos{i}.robax.rax_4:=Trunc(jpos{i}.robax.rax_4\dec:=2);
    jpos{i}.robax.rax_5:=Trunc(jpos{i}.robax.rax_5\dec:=2);
    jpos{i}.robax.rax_6:=Trunc(jpos{i}.robax.rax_6\dec:=2);
    !... 
  ENDFOR
ENDPROC

Comments

  • jmf
    jmf South Africa
    Try this.
        PERS jointtarget jpos{8}:=[[[0,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[8.64979E-6,93.09,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                                   [[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                                   [[-180,-87.5354,-27.4211,-180,-85.04,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                                   [[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]]];
        PERS jointtarget jpos0:=[[8.64979E-6,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos1:=[[8.64979E-6,9.76204E-6,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos2:=[[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos3:=[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos4:=[[-180,-87.5354,-27.4211,-180,85.0435,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos5:=[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos6:=[[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
        PERS jointtarget jpos7:=[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    
        PROC rTruncate()
            FOR i FROM 0 TO 7 DO
                jpos{1}.robax.rax_1:=Trunc(jpos1.robax.rax_1\dec:=2);
                jpos{2}.robax.rax_2:=Trunc(jpos2.robax.rax_2\dec:=2);
                jpos{3}.robax.rax_3:=Trunc(jpos3.robax.rax_3\dec:=2);
                jpos{4}.robax.rax_4:=Trunc(jpos4.robax.rax_4\dec:=2);
                jpos{5}.robax.rax_5:=Trunc(jpos5.robax.rax_5\dec:=2);
                jpos{6}.robax.rax_6:=Trunc(jpos6.robax.rax_6\dec:=2);
                !... 
            ENDFOR
        ENDPROC

  • innebandy
    innebandy Korea, South ✭✭
    I tried a similar method as you, but failed. I Probably missed something.
    Thanks a lot.
  • jmf
    jmf South Africa
    Pleasure.
  • Micky
    Micky Germany ✭✭✭
    edited February 26
    Hello,

    Arrays in RAPID start with index 1 and not with index 0.

    But since you don't use an array you have to use the instructions "GetDataVal" and "SetDataVal" to access the content of variables by name.

    Here is an example:

     PROC Example()
        
        FOR i FROM 0 TO 7 DO 
          TruncJointTarget "jpos"+Valtostr(i);
        ENDFOR 
        
      endproc 
      
      PROC TruncJointTarget(string JointName)
        VAR jointtarget jtTemp;
        
        GetDataVal JointName,jtTemp;   
        jtTemp.robax.rax_1:=Trunc(jtTemp.robax.rax_1\dec:=2);
        jtTemp.robax.rax_2:=Trunc(jtTemp.robax.rax_2\dec:=2);
        jtTemp.robax.rax_3:=Trunc(jtTemp.robax.rax_3\dec:=2);
        jtTemp.robax.rax_4:=Trunc(jtTemp.robax.rax_4\dec:=2);
        jtTemp.robax.rax_5:=Trunc(jtTemp.robax.rax_5\dec:=2);
        jtTemp.robax.rax_6:=Trunc(jtTemp.robax.rax_6\dec:=2);
        SetDataVal JointName,jtTemp;
        
      ENDPROC 
  • innebandy
    innebandy Korea, South ✭✭
    Hello Micky,
    I fixed the problem using an array and your idea is also a good alternative. Thanks.