RobotStudio event

GetDataVal issue

Hi all!

I am trying to create a loop where I read joint values from a jointtarget on at a time. For this purpose I use the GetDataVal function but am experiencing some problems. The GetDataVal funciton returns the error  ERR_SYM_ACCESS when I execute the code below. Is there something wrong with my code or are there some limitations in the GetDataVal function that makes it impossible to use the GetDataVal function for this purpose?

Thanx!



PERS jointtarget jActJoint;
VAR num i;
VAR num nTemp;
PERS num nJointValues{6}:=[0,0,0,0,0,0];

PROC ReadJointValues()
  jActJoint:=CJointT();
  FOR i FROM 1 TO 6 STEP 1 DO
       GetDataVal "jActJoint.robax.rax_" + NumToStr(i,0),nTemp;
       nJointValues{i}:=nTemp;
       !TBD....
  ENDFOR
ENDPROC



Comments

  • Hello,
     

    GetDataVal cannot get the fields inside record types (built-in or user-defined).

    You can always access the fields explicitely, i.e.  jActJoint.robax.rax_1, but this may not be what you want to code.

     

    If you really have to do this programmatically, then one possible idea is to build your own field access procedures and then use late binding to execute them:

     

    PROC ReadJointValues()

    VAR num nJointValues{6};

    VAR num i;

    VAR jointtarget CJointTarget;

    VAR string tempString;

    CJointTarget := CJointT();

    FOR i FROM 1 TO 6 DO

    tempString := "getJtargetRobAx_Rax_" + NumToStr(i, 0);

    %tempString% CJointTarget, nJointValues{i};

    ENDFOR

    ENDPROC

    PROC getJtargetRobax_Rax_1(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_1;

    ENDPROC

    PROC getJtargetRobax_Rax_2(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_2;

    ENDPROC

    PROC getJtargetRobax_Rax_3(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_3;

    ENDPROC

    PROC getJtargetRobax_Rax_4(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_4;

    ENDPROC

    PROC getJtargetRobax_Rax_5(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_5;

    ENDPROC

    PROC getJtargetRobax_Rax_6(jointtarget tempTarget, VAR num jointValue)

    jointValue := tempTarget.robax.rax_6;

    ENDPROC

    This may not the be cleanest way, better to simply do a known extraction:

    nJointValue{1}:=jActJoint.robax.rax_1;

    nJointValue{2}:=jActJoint.robax.rax_2;

    nJointValue{3}:=jActJoint.robax.rax_3;

    and so on,

     

      Steve

     

     

  • [QUOTE=Steve_Murphy]Hello,
     

    GetDataVal cannot get the fields inside record types (built-in or user-defined).

    You can always access the fields explicitely, i.e.  jActJoint.robax.rax_1, but this may not be what you want to code.

     [/QUOTE]

    Thanks alot, Steve!
    Now I know the cause of this error. Too bad it doesn't say anything about this in the 'Limits' section of the help file.

    When I posted my question I had already made a workaround that addresses the values directly (reg1:=jActJoint.robax.rax_1;). It works fine and  for this particular application it's not that much code to write. For future projects it would have been neat if the GetDataVal (or some equivalent method) could retrieve values from records. Who knows, next time it may not stop with 6 values to retrieve...

    Thanks again!