I personally have come across a couple weird ways to create arrays of different sizes. Here they are in order of greasiness to most applicable to your situation. URScript isn’t the greatest at handling that.
list of length 32:
L = 0
L = integer_to_binary_list(L)
creates a list of False that is 32 items long.
list of variable length:
this involves registering a function on an xmlrpc server that returns the array:
python3 example
set this server up directly on the robot or start it with a URCap
from xmlrpc.server import SimpleXMLRPCServer
def create_array(length):
return [0]*length
server = SimpleXMLRPCServer(('localhost', XXXX)
server.register_function(create_array, "create_array")
server.serve_forever()
unfortunately right now it seems that the array length limit coming through XMLRPC is 511. I’m currently trying to get an answer on why that changed in software version 5.6.
Good luck and hopefully there are some other ideas floating around!
Very ingenious work around.
I am developing a cap and was trying to avoid polyscope for some of the communication but I guess I’ll have to dive in there…
So we have xmlrpc functions available that allow you to get back a list of a given length, padded with a starting value that you can define which works great if you have an rpc server running.
One of our software guys wrote a bit of node code that auto-generates a script file for getting back a list of any length, up to 250 elements currently, that you can pad with a value you specify. Our robot programmers have switched to using this over the rpc call as its faster and reduces one of the calls that they have to make to the rpc server.
I attached the file, when you see it you will probably chuckle as it’s a bit “heavy” but in lieu of anything native being provided it works really well. We use it for creating lists of numbers, booleans or poses.
You could also build on top of this new functions for simply getting a specific type of list with a preset default
For instance
def getDynamicArrayOfPoses(size):
return generated_getArrayOfSize(size, p[0,0,0,0,0,0])
end
Thanks Matt! Clever, and the guys and I got a good chuckle out of that script in the office. It’s amazing what we have to resort to haha. I’m still surprised it’s not a feature.
Yeah, I wish it was a native function but I also wish we could store strings in lists and could also have lists of lists…but you know, I feel like the only one at times that wants these language features
This is what I was fishing for actually.
I’m getting a message from a socket server and I’d like to split it into different strings and shove them on a list…
Good afternoon, I would like to know how you managed to start the python code you wrote, have you written a ur script? you installed a UR cap and if yes which? I am trying to make a dynamic array and I tried many things with no satisfactory results.
Would be great to get a solution thank you very much!
Let’s say you want to have this Python server running on the robot. There are at least 3 ways we could do this.
Start the server with the URCap MyDaemon example (Java gives me bad feels so I don’t do this)
System V scripts (michael_scott_nonono.gif)
Start the server on boot in the underlying Debian Jessie OS using systemd.
Method 3 (The sane way):
Create the python code
Create a service file and enable the service using systemctl
Now you have a python 2.7 xmlrpc server that starts at boot and hosts a function that returns an array of whatever length you want (Up to length 512 of course)
#from xmlrpclib.SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCServer
def create_array(length):
# Could also use False instead of 0 if you're doing booleans
return [0]*length
ip = 'localhost'
port = 42069 # Nice
server = SimpleXMLRPCServer((ip, port))
server.register_function(create_array, "create_array")
server.serve_forever()
print "Started server on {}:{}".format(ip, port)
Check for new service files, Enable/Start service + Check status
$ systemctl daemon-reload # This line makes the system check for new service files
$ systemctl enable MyServer.service
$ systemctl start MyServer.service
$ systemctl status MyServer.service # This should spit out the current status of the server or any exceptions on start
Hello first of all thank you very much for your rapid response.
It seemed to work but at the end I get an failure message, do you know why this happens? have I got something wrong or do you have any additional tips to try and solve them?
Thank you
Yea I should have run that Python first, it’s the import that’s the problem as seen 3rd from last line in your status readout. Try to dig up the example code for starting the server in Python 2.7 and it should point you in the right direction. I might get to it in the next day or two but this is recreational for me.
I agree, writing a custom server in python 2… kicking off it off, then running sockets to get access to a means to create an array of said length is insane. UR really needs to figure this out instead of passing the pain along to their customers.
What tree do we need to collectively bark up to motivate UR management to throw money at this problem?
Beginning in PolyScope 5.15, the script function make_list(length, initial_value, capacity=length) was introduced. The function has two mandatory arguments for length and initial value. If capacity is not provided, then it defaults to the provided length value. Variables for initial_value can be of any existing type at declaration, but cannot be changed after creation.
Example use:
myList=make_list(4, 0) assigns a list of [0,0,0,0] to the variable myList.
myList=make_list(3, p[0,0,0,0,0,0]) assigns a list of [p[0,0,0,0,0,0], p[0,0,0,0,0,0], p[0,0,0,0,0,0]] to the variable myList.