I’m trying to write a script in Python. I want to send commands robot to move from A to B, also, to get information about coordinates and digital inputs. I’ve seen that we can use URscript for writing the program for UR, but if I just write command according to URscript manual ( scriptManual_SW5.11.pdf) obviously I will get an error (e.g : get_digital_input(0) — writes that get_digital_input is undefined). Could you give me recommendation how to import library/class for this kind of commands?
I’ve been using RTDE library, but that library doesn’t give me possibility to do that.
I get input information with binary format but I just need Booleans.
Wasn’t get_digital_input() deprecated?
On this URScript manual it shows that the currently functions are get_standard_digital_in() and get_tool_digital_in()
Thanks for response,
Yes, get_digital_input() doesn’t work. When I write it and try to send it via RTDE, it’s just undefined. It needs to be imported from somewhere, but I can’t find a library from where i can import.
The same does with get_standard_digital_in() and get_tool_digital_in(). Can you please send me any example of this script? Or just suggest me how to make it defined.
I thought at first that you were trying to send a command to the robot, rather than reading an input in Python.
So, OK, what you are doing wrong is that you are using URScript statements to read from a package in Python, so don’t go there.
On RTDE the values that you get from the robot are defined on the .xml file, and they have specific names and formats, such as
So, in your Python code, what you do is to send this xml file as an argument and then, read the fields that you want from your variables. I use RTDE for reading the joints position and speed, and the code is like:
# initialization here (see example record.py)
keep_running = True
while keep_running:
try:
if args.buffered:
state = con.receive_buffered(args.binary)
else:
state = con.receive(args.binary)
if state is not None:
# get joints position
q_robot = state.actual_q
# get joints speed
dq_robot = state.actual_qd
time.sleep(0.01)
To get what you want, I would use a similar approach and based on the example_control_loop.py, which reads the input_register. The thing is, I am not sure what type of “input” is meant within this register, but you could modify that example a little bit:
# control loop
while keep_running:
# receive the current state
state = con.receive()
if state is None:
break;
# do something...
if state.output_int_register_0 != 0:
new_setp = setp1 if setp_to_list(setp) == setp2 else setp2
list_to_setp(setp, new_setp)
# send new setpoint
con.send(setp)
# NEW
input_list = setp_to_list(setp)
print(input_list)
print(input_list[0]) # <- check if this is digitan_in(0)?
# ----------- functions definition --------------
def setp_to_list(setp):
list = []
for i in range(0,6):
list.append(setp.__dict__["input_double_register_%i" % i])
return list
# î this function changes the register to a list with individual values
Thanks a lot,
I tried it and as it seams they aren’t digital_input registers. I even added input_double_registers but when I execute the program it doesn’t have reaction with changing sensor state, thus digital_input state.