RobotStudio event

Get robtarget values from array

Hello,
I have multiple robtargets in arrays and a string with the name of the target. How do I go about pulling out the first target from an array?

For example:
CONST jointtarget 0614_1550{161} := [
[[-14.724370, 27.791708, 41.837761, 92.336242, 87.393000, -131.890905], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]],
[[-14.724370, 27.791708, 41.837761, 92.336242, 87.393000, -131.890905], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]],
[[-14.724370, 27.791708, 41.837761, 92.336242, 87.393000, -131.890905], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]],
[[-14.724370, 27.791708, 41.837761, 92.336242, 87.393000, -131.890905], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]],
[[-14.724370, 27.791708, 41.837761, 92.336242, 87.393000, -131.890905], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]]]

VAR string sCurrentTarget = "0614_1550";
VAR jointtarget jCurrentTarget;

I tried GetDataVal but the command doesn't seem to be able to access data from an array. How do i go about doing this?

Comments

  • Micky
    Micky ✭✭✭
    Hello,

    Variable names are not allowed to start with a number, i.e. the name "0614_1550" is invalid.
    Generally the prefix "jt" is used for the name of jonttarget, so your array should be named "jt0614_1550".

    "GetDataVal can read complete arrays, but not single elements. 
    That means you have to define an array into which the data of the source array is copied and both arrays must have the same dimension. If the dimensions are different, a handleable error is generated.
    Afterwards you can access the content of the array.


    PROC Example()
      MoveAbsJ jt0614_1550{1},v1000,z50,tool0;
      MoveAbsJ GetPosition(1),v1000,z50,tool0;
    ENDPROC 

    FUNC jointtarget GetPosition(num Index)
      VAR jointtarget jtTemp{161};
     
      GetDataVal "jt"+sCurrentTarget,jtTemp;
      RETURN jtTemp{Index};
    ENDFUNC