"Resizing of List is not supported"

Does anyone know a way around the to resize lists?
Would it be possible to delete the variable and create a new one altogether?
Just wondering.

1 Like

Assinging a new list will work. However, you do need to know the size of the list in advance to create the list. I don’t know of an easy way to generate a list of a runtime-determined size. The functions socket_read_binary_integer/socket_read_byte_list will give a list with zeros after a 2 second time-out. But I don’t think waiting two seconds is acceptable.

1 Like

Resizing is not supported in URScript, so you should know the length (or max. expected length) when generating the list-variable.
Consider padding with zeros, for unused slots.

1 Like

If we have a variable list size, we will generate a longer list than what is necessary in the before start of the program and pad it with 0’s, then we can just fill in what we need when we need it.

Also, you could use the socket_read_binary_integer(n) method to return a list of length n+1 up to a max n of 30. This will be padded with a 0 in the first position and then -1 in the balance of the positions. This could be performed in the before start of the program so even though it takes 2 seconds to return it would only be done once per program start sequence

1 Like

Thanks everyone for the responses.

I really like the -1 workaround for integer lists.

In my case, I’m dealing with a list of poses that might vary in length, so I’ve been approaching it like this:

And as long as that length does not change in a program execution, there no problem.
But in my case it might change, so I may need to create several of these lists OR, as I’m approaching it now, externalising the recursion and feeding the robot a single pose at a time, as opposed to a list of poses.

@nicolas

As you can initialize an empty pose variable, and use this to initialize a list, consider using below in a script file:

p = p[0,0,0,0,0,0]
p_list = [p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,...,p]

Eventually adding as many poses as you need instead of the three dots.

i tried last time , if the amount of element in list exceed certain amount, the system will prompt infinite time error when load.

So we recently wrote an RPC function that allows us to return a new list up to 250 elements long (it could be longer but somewhere around 270-280 it stopped printing to the screen and later calls to specific elements did the same so we capped it at 250). The cool part is if you only provide a length of list it will pad it with -1 in all indices, if you give it a value it will pad it with that specific value so our use case is to pad an equipment testing list with 1’s and then as a part fails at a certain equipment we use another RPC to push the new value onto the end of the list and then shift it to remove an element off the front so that it returns a new list of the same length as the original list but with the new value added at the end. This gives us the ability to keep a running average or total on the list by calling another RPC call which simply reduces the list to whatever kind of value we require (average, max, min, sum, etc.). The really nice thing is most of these RPC calls happen in under 10ms so the robot never gets into a time issue as has been the case doing some other methods plus you don’t have to wait 2 seconds for the socket call to time out.

3 Likes