# How to use URscript

**URL:** <https://forum.universal-robots.com/t/how-to-use-urscript/21121>\
**Category:** URScript\
**Created:** [May 6, 2022, 11:39am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121 "2022-05-06T11:39:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [May 6, 2022, 11:39am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/1 "2022-05-06T11:39:39Z")

</div>

Hello UR community,

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](https://s3-eu-west-1.amazonaws.com/ur-support-site/115824/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.

P.S. I’m new in programming.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![cags](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/cags/32/6304_2.png) [@cags](https://forum.universal-robots.com/u/cags)\
**Post date:** [May 9, 2022, 7:29am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/2 "2022-05-09T07:29:38Z")

</div>

Wasn’t `get_digital_input()` deprecated?  
On this [URScript manual](https://s3-eu-west-1.amazonaws.com/ur-support-site/18679/scriptmanual_en.pdf) it shows that the currently functions are `get_standard_digital_in()` and `get_tool_digital_in()`

---

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [May 9, 2022, 7:48am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/3 "2022-05-09T07:48:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [May 9, 2022, 8:32am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/4 "2022-05-09T08:32:13Z")

</div>

Error is the following:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/8/87fdc52ce6199f349733f469ebd12530dc1e8d17.png)

The script is written according to RTDE library. Error is always the same. You can see it in the picture.

---

<div class="post-metadata">

**Author:** ![cags](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/cags/32/6304_2.png) [@cags](https://forum.universal-robots.com/u/cags)\
**Post date:** [May 9, 2022, 9:02am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/5 "2022-05-09T09:02:00Z")

</div>

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

```auto
	<recipe key="state">
		<field name="target_q" type="VECTOR6D"/>
		<field name="target_qd" type="VECTOR6D"/>
		<field name="output_int_register_0" type="INT32"/>
	</recipe>

	<recipe key="setp">
		<field name="input_double_register_0" type="DOUBLE"/>
		<field name="input_double_register_1" type="DOUBLE"/>
		<field name="input_double_register_2" type="DOUBLE"/>
		<field name="input_double_register_3" type="DOUBLE"/>
		<field name="input_double_register_4" type="DOUBLE"/>
		<field name="input_double_register_5" type="DOUBLE"/>
	</recipe>

```

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:

```auto
# 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:

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![giorgigedaminski](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@giorgigedaminski](https://forum.universal-robots.com/u/giorgigedaminski)\
**Post date:** [May 9, 2022, 10:01am UTC](https://forum.universal-robots.com/t/how-to-use-urscript/21121/6 "2022-05-09T10:01:48Z")

</div>

> [@cags](#):
>
> `input_double_register`

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.
