# How do I add custom modbus code to my URScript via Robots plugin?

**URL:** <https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298>\
**Category:** URScript\
**Created:** [October 2, 2024, 12:34am UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298 "2024-10-02T00:34:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abalalimoghaddam](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@abalalimoghaddam](https://forum.universal-robots.com/u/abalalimoghaddam)\
**Post date:** [October 2, 2024, 12:34am UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298/1 "2024-10-02T00:34:36Z")

</div>

This is a Robots plugin and URScript question

Using the Robots plugin for grasshopper we are able to generate movement commands easily. However, we have a custom extruder that uses Modbus register. First we need a code similar to this at the initialization.

```auto
modbus_add_signal("127.0.0.1", 255, 0, 16, "output2", False, 10)
list_var:=[10,9,8,7,6,5,4,3,2,1]

```

This part can be added easily using the `Init commands` input to the `Create Program` component.

Then at every movement we would need to set the extruder speed and orientation (our extruder orientation changes) using a custom code like this:

```auto
modbus_set_output_register("extruder_speed", 1500 , false)
modbus_set_output_register("extruder_orientation", 45 , false)

```

Is there a way from inside the robot plugin to add our custom extruder code to every line movement? This of course has to run in parallel to the movement and not cause interruptions in the movement of the robot.

Any help will be appreciated!

Note: the program below is incorrect because `modbus_set_output_register` only runs once during initialization

 ![WIP program](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/9/9daf5f72e38f2a77a918859f07d9f1cde3fb1e51.jpeg)

---

<div class="post-metadata">

**Author:** ![robin\_gdwl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robin_gdwl/32/2676_2.png) [@robin\_gdwl](https://forum.universal-robots.com/u/robin_gdwl)\
**Post date:** [October 2, 2024, 6:57am UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298/2 "2024-10-02T06:57:04Z")

</div>

Right click on the “Create Target” Component.  
There you can add an input for a command.

Note that the command is executed **after** the robot reached the target.

 ![Screenshot 2024-10-02 at 08.56.53](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/0/0fdce574cb3c9e11a1c301e284cd95e36108d1f4.png)

---

<div class="post-metadata">

**Author:** ![abalalimoghaddam](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@abalalimoghaddam](https://forum.universal-robots.com/u/abalalimoghaddam)\
**Post date:** [October 9, 2024, 1:25am UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298/3 "2024-10-09T01:25:54Z")

</div>

@robin_gdwl thank you so much for your quick reply and also for all the great tutorials you make!

I am wondering if I did not explain my question well, or maybe I do not understand the problem well enough.

Here is an example UR Script of what I _think_ I need to be creating:

```auto
def Program():
    DefaultToolTcp = p[0, 0, 0, 0, 0, 1.5708]
    DefaultToolWeight = 0
    DefaultToolCog = [0, 0, 0]
    DefaultSpeed = 0.1
    DefaultZone = 0

    modbus_add_signal("127.0.0.1", 255, 0, 16, "auger", False, 10)

    set_tcp(DefaultToolTcp)
    set_payload(DefaultToolWeight, DefaultToolCog)

    modbus_set_output_register("auger", 523, false)  
    movej([0.8233, -0.3309, 1.3827, 0.519, -1.5708, 2.3183], a=3.1416, v=0.3142, r=DefaultZone)

    modbus_set_output_register("auger", 320, false)  
    movej(p[-0.34976, -0.62209, 0, 0, 0, 0], a=3.1416, v=0.2475, r=DefaultZone)

    modbus_set_output_register("auger", 101, false)  
    movej(p[-0.30511, -0.60227, 0, 0, 0, 0], a=3.1416, v=0.1844, r=DefaultZone)

end

```

I tried using the command input with the create target component as you suggested, but I am unable to even create a single line such as `modbus_set_output_register("auger", 523, false) ` let alone how to integrate it with the `movej` commands.

I have not been able to find any good documentation on this topic. Any further help is much appreciated!

---

<div class="post-metadata">

**Author:** ![robin\_gdwl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/robin_gdwl/32/2676_2.png) [@robin\_gdwl](https://forum.universal-robots.com/u/robin_gdwl)\
**Post date:** [October 14, 2024, 10:06pm UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298/4 "2024-10-14T22:06:27Z")

</div>

![Screenshot 2024-10-15 at 00.05.50](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/f/fe095829f1d65211f0e2bc9b1bbed92d83f4d9e0.jpeg)  
Is this what you are trying to do?

---

<div class="post-metadata">

**Author:** ![abalalimoghaddam](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@abalalimoghaddam](https://forum.universal-robots.com/u/abalalimoghaddam)\
**Post date:** [October 22, 2024, 9:52pm UTC](https://forum.universal-robots.com/t/how-do-i-add-custom-modbus-code-to-my-urscript-via-robots-plugin/36298/5 "2024-10-22T21:52:33Z")

</div>

@robin_gdwl thank you so much! This was VERY helpful. We should be able to test our custom end-effector clay extruder very soon.
