In KUKA Robot Language (KRL), is it possible to get the length of an array, or alternatively, is there a way to loop through all the values in an array? Currently I store the array length in a separate variable and do it like this:
; In the DAT file:
DECL CONST INT FOO_LENGTH = 3
DECL CONTS INT FOO[3]
FOO[1] = 12
FOO[2] = 34
FOO[3] = 56
; In the SRC file:
INT IDX
FOR IDX = 1 TO FOO_LENGTH
do_something(FOO[IDX])
ENDFOR
Essentially I'd like to get rid of the FOO_LENGTH variable.
this is probably wayyy too late to answer, but it'll help for future references.
Unfortunately there is no variable used to determine the length of the array. Once you define it, you know your number, so instead of using FOO_LENGTH, just type in 3.
You can't really use a loop to determine the length of the array, as if you hit the last number, the robot stops and doesn't know what to do. However, this is a lengthy progress, where you can do that, and then as soon as the robot stops, monitor the value and record the number, and then skip the loop and start it again at that moment. But this serve no purpose because you can always go back to DAT file and find out your length by looking at DECL FOO[3].
Hope this helps.