Home› Programming
Discussion
Back to discussions page
VT_340
Posts: 24 Apprentice
Using URScript to get data into a programm? |
4.7K views
|
Answered | |
/ Most recent by mariem_werfelli22
in Programming
|
12 comments |

in Programming
Hi!
I would like to know how to get data (e.g a X/Y Variable position from a sensor outside the robot) via TCP into the robotic program?
In general this is described here:
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-tcp-socket-test/
But I don't feel like to remake this huge program within the PolyScope GUI. Lets say for testing I just want to send a variable from my computer (e.g via Python) to the robot that I can check their value within the "Variables" tab. In a second step I want to make the robot move to positions given by the variables.
I was succsellful in sending complete move commands to the robot via Python but I want to use the advantage of the GUI which means easy programming but insert changes from the computer.
Thanks,
Hans
I would like to know how to get data (e.g a X/Y Variable position from a sensor outside the robot) via TCP into the robotic program?
In general this is described here:
http://www.zacobria.com/universal-robots-zacobria-forum-hints-tips-how-to/script-tcp-socket-test/
But I don't feel like to remake this huge program within the PolyScope GUI. Lets say for testing I just want to send a variable from my computer (e.g via Python) to the robot that I can check their value within the "Variables" tab. In a second step I want to make the robot move to positions given by the variables.
I was succsellful in sending complete move commands to the robot via Python but I want to use the advantage of the GUI which means easy programming but insert changes from the computer.
Thanks,
Hans
Best Answer
-
louis_bergeron Posts: 94 Handy
You may also use the Modbus TCP server in the UR controller. Registers 128-255, for example, are for a general purpose. You may use pymodbus to build a simple python program like this to write desired X and Y values.
from pymodbus.client.sync import ModbusTcpClient as ModbusClientimport logginglogging.basicConfig()log = logging.getLogger()log.setLevel(logging.DEBUG)##Connect to the IP adresse of the robot controllerclient = ModbusClient('192.168.0.102', port=502)client.connect()##Writting desired x position in register 128rq = client.write_register(128, 100)rr = client.read_holding_registers(128,1)assert(rq.function_code < 0x80) # test that we are not an errorprint rr.registers[0]#Writting desired y position in register 129rq = client.write_register(129, 40)rr = client.read_holding_registers(129,1)assert(rq.function_code < 0x80) # test that we are not an errorprint rr.registers[0]client.close()The UR program may look like this to read values from the register and place them in variables. the variables will then be visible in the variable tab. In the following program, the MoveL are relative to a feature. The robot goes to 0, 0, 0 and then goes to 0.1, 0.04, 0ProgramRobot ProgramMoveLmy_pos≔p[0,0,0,0,0,0]my_pospos_x≔read_port_register(128)pos_y≔read_port_register(129)my_pos[0]=pos_x/1000my_pos[1]=pos_y/1000my_pos
If you need more specifics on how to implement let me know and I can setup a simple demo when I'm home tomorrow.
Thanks Louis for your example script.
So far I just sent the move command via TCP on Port 30002 and this works like charm. As I am not into Modbus I would rather use ordinary TCP socket. Another thing is: How can I get the code into Polyscope? I just can open .urp data.
Thanks,
Hans
how to receive data from a server to the client ? i know the comand "socket_read_ascii_float(4)" i got as a received data(receiveFromServe:=[6.0,0.0,0.0,0.0,0.0] then after less than a second it's change to [0.0,NAN,NAN,NAN,NAN] i don't undesrtand what is the problem i need help
yes it's a loop the new error noww is "getInverse: the function did not find a solution" maybe
Are you sending the distances back in mm or m? The robot needs meters and radians to work, that gets me sometimes.
it works,